Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce SPI to swap authentication directives #3829

Merged
merged 5 commits into from
Jul 16, 2018
Merged

Introduce SPI to swap authentication directives #3829

merged 5 commits into from
Jul 16, 2018

Conversation

mhenke1
Copy link
Contributor

@mhenke1 mhenke1 commented Jul 2, 2018

This PR introduces a SPI to configure a different authentication directive used in the REST API

Description

This PR introduces a SPI to swap/exchange authentication directives in the REST API.
The existing SPI does basic authentication only. With this PR alternative authentication methods
like bearer token can be enabled. This capability is for example needed to support
external IAM systems.

Additionally it packages the existing functionality to verify the basic authentication header to be consumed in the SPI without functional changes.

[PG 1:3115 passed]

Related issue and scope

I explained the background of these changes on the mailing list
Extending Authentication and Entitlement - Heads up

My changes affect the following components

  • API
  • Controller
  • Message Bus (e.g., Kafka)
  • Loadbalancer
  • Invoker
  • Intrinsic actions (e.g., sequences, conductors)
  • Data stores (e.g., CouchDB)
  • Tests
  • Deployment
  • CLI
  • General tooling
  • Documentation

Types of changes

  • Bug fix (generally a non-breaking change which closes an issue).
  • Enhancement or new feature (adds new functionality).
  • Breaking change (a bug fix or enhancement which changes existing behavior).

Checklist:

  • I signed an Apache CLA.
  • I reviewed the style guides and followed the recommendations (Travis CI will check :).
  • I added tests to cover my changes.
  • My changes require further changes to the documentation.
  • I updated the documentation where necessary.

@codecov-io
Copy link

codecov-io commented Jul 3, 2018

Codecov Report

Merging #3829 into master will decrease coverage by 4.81%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #3829      +/-   ##
=========================================
- Coverage   75.81%     71%   -4.82%     
=========================================
  Files         146     145       -1     
  Lines        6902    6897       -5     
  Branches      428     418      -10     
=========================================
- Hits         5233    4897     -336     
- Misses       1669    2000     +331
Impacted Files Coverage Δ
...core/controller/BasicAuthenticationDirective.scala 61.53% <0%> (ø)
...rc/main/scala/whisk/core/controller/RestAPIs.scala 43.9% <0%> (-1.67%) ⬇️
...core/database/cosmosdb/RxObservableImplicits.scala 0% <0%> (-100%) ⬇️
...core/database/cosmosdb/CosmosDBArtifactStore.scala 0% <0%> (-95.08%) ⬇️
...sk/core/database/cosmosdb/CosmosDBViewMapper.scala 0% <0%> (-92.6%) ⬇️
...whisk/core/database/cosmosdb/CosmosDBSupport.scala 0% <0%> (-81.82%) ⬇️
...abase/cosmosdb/CosmosDBArtifactStoreProvider.scala 0% <0%> (-58.83%) ⬇️
...la/whisk/core/database/cosmosdb/CosmosDBUtil.scala 92% <0%> (-4%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 967f005...43f501c. Read the comment docs.

implicit val logging: Logging)
extends BasicAuthenticate {
protected implicit val executionContext = actorSystem.dispatcher
protected val authStore = WhiskAuthStore.datastore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WhiskAuthStore.datastore would use SpiLoader to load and create ArtifactStore for each request via reflection. As AuthStore does not change post startup it would be better to load it in BasicAuthenticationDirectiveProvider and pass it.

May be make BasicAuthenticate an object and pass required dependencies as validateCredentials params.

@mhenke1
Copy link
Contributor Author

mhenke1 commented Jul 9, 2018

@chetanmeh with the last commit ,the authStore is now created once and passed implicitly into the directive.

@markusthoemmes markusthoemmes self-assigned this Jul 12, 2018
@markusthoemmes markusthoemmes self-requested a review July 12, 2018 09:58
@markusthoemmes markusthoemmes added review Review for this PR has been requested and yet needs to be done. spi labels Jul 12, 2018
class AuthenticatedRouteBasicAuth(implicit val authStore: AuthStore,
implicit val actorSystem: ActorSystem,
implicit val httpRequest: HttpRequest,
implicit val materializer: ActorMaterializer,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per f2f discussion, please have a look at various extractX methods to combine the directives and avoid broad interfaces.

actorSystem: ActorSystem,
materializer: ActorMaterializer,
logging: Logging): AuthenticationDirective[Identity] =
new AuthenticatedRouteBasicAuth().getDirective
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, given all the extractX directives, we can model this to be a static directive which only needs to be instantiated once.

@@ -191,36 +194,38 @@ class RestAPIVersion(config: WhiskConfig, apiPath: String, apiVersion: String)(
"swagger_paths" -> JsObject("ui" -> s"/$swaggeruipath".toJson, "api-docs" -> s"/$swaggerdocpath".toJson)))
}

def routes(implicit transid: TransactionId): Route = {
def routes(implicit transid: TransactionId, authStore: AuthStore): Route = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need the authStore here? It's already in scope I think?

// and allow the actions themselves to respond to options
basicAuth(validateCredentials) { user =>
web.routes(user)
extractRequest { httpRequest =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Contributor

@markusthoemmes markusthoemmes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

@mhenke1
Copy link
Contributor Author

mhenke1 commented Jul 16, 2018

[PG 3:2532 is ✅ ]

@markusthoemmes markusthoemmes merged commit e96c1bb into apache:master Jul 16, 2018
@mhenke1 mhenke1 deleted the authz_spi branch July 16, 2018 09:01
BillZong pushed a commit to BillZong/openwhisk that referenced this pull request Nov 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review Review for this PR has been requested and yet needs to be done. spi
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants