[GitHub] markusthoemmes commented on a change in pull request #3788: Store and pass variant data in AuthKey
markusthoemmes commented on a change in pull request #3788: Store and pass variant data in AuthKey URL: https://github.com/apache/incubator-openwhisk/pull/3788#discussion_r197821706 ## File path: core/controller/src/main/scala/whisk/core/controller/Triggers.scala ## @@ -387,15 +387,17 @@ trait WhiskTriggersApi extends WhiskCollectionAPI { .map(pkg => Path / pkg.namespace / rule.action.name.asString) .getOrElse(Path / rule.action.name.asString) -val request = HttpRequest( - method = POST, - uri = url.withPath(actionUrl ++ actionPath), - headers = List( -Authorization(BasicHttpCredentials(user.authkey.uuid.asString, user.authkey.key.asString)), -transid.toHeader), - entity = HttpEntity(MediaTypes.`application/json`, args.compactPrint)) +user.authkey.getCredentials + .map { creds => +val request = HttpRequest( + method = POST, + uri = url.withPath(actionUrl ++ actionPath), + headers = List(Authorization(creds), transid.toHeader), + entity = HttpEntity(MediaTypes.`application/json`, args.compactPrint)) -singleRequest(request) +singleRequest(request) + } + .getOrElse(Future.failed(new RuntimeException("invalid credentials passed"))) Review comment: Need to think about which exception to throw here and which message to use. If we need to write it ourselves, let's add it to `Messages.scala` This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] markusthoemmes commented on a change in pull request #3788: Store and pass variant data in AuthKey
markusthoemmes commented on a change in pull request #3788: Store and pass variant data in AuthKey URL: https://github.com/apache/incubator-openwhisk/pull/3788#discussion_r197824106 ## File path: tests/src/test/scala/whisk/core/containerpool/test/ContainerProxyTests.scala ## @@ -761,10 +761,13 @@ class ContainerProxyTests override def run(parameters: JsObject, environment: JsObject, timeout: FiniteDuration)( implicit transid: TransactionId): Future[(Interval, ActivationResponse)] = { runCount += 1 - environment.fields("api_key") shouldBe message.user.authkey.toJson + environment.fields("api_key") shouldBe message.user.authkey.toEnvironment.fields("api_key") environment.fields("namespace") shouldBe invocationNamespace.name.toJson environment.fields("action_name") shouldBe message.action.qualifiedNameWithLeadingSlash.toJson environment.fields("activation_id") shouldBe message.activationId.toJson + message.user.authkey.toEnvironment.fields.keySet +.filter(environment.fields.contains(_)) +.size shouldBe message.user.authkey.toEnvironment.fields.size Review comment: This test can be narrowed down a lot, like: ```scala val authEnvironment = environment.fields.filterKeys(message.user.authkey.toEnvironment.fields.contains) message.user.authkey.toEnvironment shouldBe authEnvironment ``` Will also compare the values and you can drop the explicit api_key check above. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] markusthoemmes commented on a change in pull request #3788: Store and pass variant data in AuthKey
markusthoemmes commented on a change in pull request #3788: Store and pass variant data in AuthKey URL: https://github.com/apache/incubator-openwhisk/pull/3788#discussion_r197821428 ## File path: common/scala/src/main/scala/whisk/core/entity/GenericAuthKey.scala ## @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package whisk.core.entity + +import akka.http.scaladsl.model.headers.HttpCredentials +import spray.json._ + +/** + * Base class for Authentication + * + * provides methods to serialize variant forms of authkeys using a JsObject + */ Review comment: A little bit more "flesh" would be great here. Like: > Is used to transport data generated by the Authentication provider to the invoker to then be passed to the action. Can by itself not be used to provide meaningful authentication. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] markusthoemmes commented on a change in pull request #3788: Store and pass variant data in AuthKey
markusthoemmes commented on a change in pull request #3788: Store and pass variant data in AuthKey URL: https://github.com/apache/incubator-openwhisk/pull/3788#discussion_r196834704 ## File path: common/scala/src/main/scala/whisk/core/entity/AuthKey.scala ## @@ -17,24 +17,31 @@ package whisk.core.entity +import akka.http.scaladsl.model.headers.{BasicHttpCredentials, HttpCredentials} import spray.json._ import spray.json.DefaultJsonProtocol._ +trait AuthKeyEnv { + val authElements: Map[String, String] + def toEnvironment = authElements.toJson.asJsObject + def getCredentials: HttpCredentials +} + /** * Authentication key, consisting of a UUID and Secret. * - * It is a value type (hence == is .equals, immutable and cannot be assigned null). * The constructor is private so that argument requirements are checked and normalized * before creating a new instance. * * @param k (uuid, key) the uuid and key, assured to be non-null because both types are values */ -protected[core] class AuthKey private (private val k: (UUID, Secret)) extends AnyVal { - def uuid: UUID = k._1 - def key: Secret = k._2 - def revoke = new AuthKey(uuid, Secret()) - def compact: String = s"$uuid:$key" +protected[core] case class AuthKey private (authElements: Map[String, String]) extends AuthKeyEnv { + def uuid: UUID = UUID(this.authElements("api_key").split(":")(0)) + def key: Secret = Secret(this.authElements("api_key").split(":")(1)) + def revoke = AuthKey(uuid, Secret()) + def compact: String = this.authElements("api_key") override def toString: String = uuid.toString + override def getCredentials: HttpCredentials = BasicHttpCredentials(uuid.asString, key.asString) } Review comment: I feel like this class should stay mostly the same as today. In this implementation, each call to `uuid` would (unsafely) get an element from the map, split it, and (unsafely) get it's 0 index. For an AuthKey, we can statically know, that it contains both UUID and Secret at compile time. ```scala protected[core] case class AuthKey private (private val k: (UUID, Secret)) extends AuthenticationCredentials { def uuid: UUID = k._1 def key: Secret = k._2 def revoke = new AuthKey(uuid, Secret()) def compact: String = s"$uuid:$key" override def toEnvironment = JsObject("api_key" -> s"${uuid.asString}:${key.asString}".toJson) override def getCredentials: HttpCredentials = BasicHttpCredentials(uuid.asString, key.asString) } ``` Would be the implementation then. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] markusthoemmes commented on a change in pull request #3788: Store and pass variant data in AuthKey
markusthoemmes commented on a change in pull request #3788: Store and pass variant data in AuthKey URL: https://github.com/apache/incubator-openwhisk/pull/3788#discussion_r196834822 ## File path: core/invoker/src/main/scala/whisk/core/containerpool/ContainerProxy.scala ## @@ -354,16 +354,19 @@ class ContainerProxy( .flatMap { initInterval => val parameters = job.msg.content getOrElse JsObject() +val authkey = job.msg.user.authkey.toEnvironment + val environment = JsObject( - "api_key" -> job.msg.user.authkey.compact.toJson, "namespace" -> job.msg.user.namespace.name.toJson, "action_name" -> job.msg.action.qualifiedNameWithLeadingSlash.toJson, "activation_id" -> job.msg.activationId.toString.toJson, // compute deadline on invoker side avoids discrepancies inside container // but potentially under-estimates actual deadline "deadline" -> (Instant.now.toEpochMilli + actionTimeout.toMillis).toString.toJson) -container.run(parameters, environment, actionTimeout)(job.msg.transid).map { +logging.info(this, s"***MH env JSON: ${JsObject(authkey.fields ++ environment.fields)}") Review comment: Please remove this logline. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] markusthoemmes commented on a change in pull request #3788: Store and pass variant data in AuthKey
markusthoemmes commented on a change in pull request #3788: Store and pass variant data in AuthKey URL: https://github.com/apache/incubator-openwhisk/pull/3788#discussion_r196835596 ## File path: core/invoker/src/main/scala/whisk/core/containerpool/ContainerProxy.scala ## @@ -354,16 +354,19 @@ class ContainerProxy( .flatMap { initInterval => val parameters = job.msg.content getOrElse JsObject() +val authkey = job.msg.user.authkey.toEnvironment Review comment: `val authEnvironment = ...`? This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] markusthoemmes commented on a change in pull request #3788: Store and pass variant data in AuthKey
markusthoemmes commented on a change in pull request #3788: Store and pass variant data in AuthKey URL: https://github.com/apache/incubator-openwhisk/pull/3788#discussion_r196835878 ## File path: tests/src/test/scala/whisk/core/containerpool/test/ContainerProxyTests.scala ## @@ -761,7 +761,7 @@ class ContainerProxyTests override def run(parameters: JsObject, environment: JsObject, timeout: FiniteDuration)( implicit transid: TransactionId): Future[(Interval, ActivationResponse)] = { runCount += 1 - environment.fields("api_key") shouldBe message.user.authkey.toJson + environment.fields("api_key") shouldBe message.user.authkey.toEnvironment.fields("api_key") Review comment: Should this check if `environment` contains all keys + values from `message.user.authkey.toEnvironment` for completeness? This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] markusthoemmes commented on a change in pull request #3788: Store and pass variant data in AuthKey
markusthoemmes commented on a change in pull request #3788: Store and pass variant data in AuthKey URL: https://github.com/apache/incubator-openwhisk/pull/3788#discussion_r196833607 ## File path: common/scala/src/main/scala/whisk/core/entity/AuthKey.scala ## @@ -17,24 +17,31 @@ package whisk.core.entity +import akka.http.scaladsl.model.headers.{BasicHttpCredentials, HttpCredentials} import spray.json._ import spray.json.DefaultJsonProtocol._ +trait AuthKeyEnv { + val authElements: Map[String, String] + def toEnvironment = authElements.toJson.asJsObject + def getCredentials: HttpCredentials +} Review comment: Since `authElements` is used nowhere, what do you think about narrowing this interface to ```scala trait AuthenticationCredentials { def toEnvironment: JsObject def credentials: HttpCredentials } ``` Since the interface includes the `getCredentials` bit, I think `AuthKeyEnv` doesn't transport the meaning of the class. After all this is about the credentials being passed in. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services