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

Modify that web action in the bound package can be accessed. #3880

Merged
merged 20 commits into from
Nov 7, 2018

Conversation

upgle
Copy link
Member

@upgle upgle commented Jul 16, 2018

Description

Recently, many users want to share their web actions with the package.
but, the web action in the bound package can't be accessed in the browser.

Because when it is invoked in the browser, it doesn't resolve an action to find original fully qualified action name. so, I added the action name resolver.

HOW TO TEST.

bind a package that contains web actions and access web action which is in the bound package using your browser, you may see errors like the image below.

image

Fixed

Now, the bound web action can be accessed in the browser.

image

Related issue and scope

  • I opened an issue to propose and discuss this change (#????)

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 16, 2018

Codecov Report

Merging #3880 into master will decrease coverage by 4.86%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3880      +/-   ##
==========================================
- Coverage   86.09%   81.22%   -4.87%     
==========================================
  Files         148      148              
  Lines        7249     7240       -9     
  Branches      442      440       -2     
==========================================
- Hits         6241     5881     -360     
- Misses       1008     1359     +351
Impacted Files Coverage Δ
.../main/scala/whisk/core/controller/WebActions.scala 92.43% <100%> (+1.27%) ⬆️
...core/database/cosmosdb/RxObservableImplicits.scala 0% <0%> (-100%) ⬇️
...core/database/cosmosdb/CosmosDBArtifactStore.scala 0% <0%> (-95.54%) ⬇️
...sk/core/database/cosmosdb/CosmosDBViewMapper.scala 0% <0%> (-92.6%) ⬇️
...whisk/core/database/cosmosdb/CosmosDBSupport.scala 0% <0%> (-83.34%) ⬇️
...abase/cosmosdb/CosmosDBArtifactStoreProvider.scala 0% <0%> (-58.83%) ⬇️
...la/whisk/core/database/cosmosdb/CosmosDBUtil.scala 92% <0%> (-4%) ⬇️
...ain/scala/whisk/core/entitlement/Entitlement.scala 88.42% <0%> (-2.48%) ⬇️
...cala/src/main/scala/whisk/http/ErrorResponse.scala 93.25% <0%> (+1.12%) ⬆️

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 708274c...eb9f4d8. Read the comment docs.

@rabbah
Copy link
Member

rabbah commented Jul 16, 2018

Thanks for trying this. There are some issues to be aware of for packaged actions as web actions via bindings. The lack of support isn’t a bug (it was intentional at the time). This has come up before so it’s worthwhile to try and enable this.

  1. If an action isn’t already a web action in the package, it can’t be accessed as a web action through the binding. That is a subject that binds the action can’t make it a web action (unless they already own it). So the creator/sharer of the package decides which of the actions to make available as web actions. Inherently this could create a dependence the subject can't control.

  2. The entitlement check for a web action today is straightforward: namespace must own both and so implicitly entitled to them. With a binding you need to check if the binding continues to have rights to the bound package.

  3. And of course you’ll need to add tests for the change/new feature.

@upgle upgle changed the title Fix a bug that web action in the bound package cannot be accessed. [WIP] Modify that web action in the bound package can be accessed. Jul 16, 2018
@upgle
Copy link
Member Author

upgle commented Jul 16, 2018

@rabbah
Thank you for your feedback and sorry that I thought it was a bug.
I will add some test codes including the rights check and suggest it again.

@rabbah rabbah changed the title [WIP] Modify that web action in the bound package can be accessed. Modify that web action in the bound package can be accessed. Jul 16, 2018
@upgle
Copy link
Member Author

upgle commented Jul 18, 2018

@rabbah

I modified it to check the entitlement and added tests.
Now, It returns the authentication error if a web action has no entitlement.

{
  "error": "The supplied authentication is not authorized to access 'whisk.system/share'.",
  "code": "NmSIY4dJanMT7YS3MPwFoOPL4Np72g5B"
}

Could you please remove WIP label and review again?

@upgle
Copy link
Member Author

upgle commented Jul 25, 2018

I fixed a conflict. please review it.

@rabbah rabbah added review Review for this PR has been requested and yet needs to be done. and removed wip labels Jul 27, 2018
Copy link
Member

@rabbah rabbah left a comment

Choose a reason for hiding this comment

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

I don't think this is quite right - take a look at my comment. I suggest therefore also adding additional tests to cover the issues I pointed out.

case _: ArtifactStoreException | DeserializationException(_, _, _) =>
Future.failed(RejectRequest(NotFound))
resolveAction(actionName) flatMap { resolveAction =>
getAction(resolveAction) recoverWith {
Copy link
Member

Choose a reason for hiding this comment

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

i dont believe this is right - the resolveAction method returns just the name of the action in the base package, and so getting that action means you'll miss the bound parameters. I think you want to use resolveActionAndMergeParameters instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh... I understand I'll modify it soon.

implicit transid: TransactionId): Future[Unit] = {
val resource =
Resource(action.namespace.root.toPath, Collection(Collection.PACKAGES), Some(action.namespace.last.toString))
entitlementProvider.check(identity, Privilege.READ, resource)
Copy link
Member

Choose a reason for hiding this comment

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

this check also checks the throttles - which means there's now a redundant check for throttles.
the code (before this pr), did not check entitlement through the provider because it can implicitly infer the owner (there's no indirection through a binding) so it only checked throttles.

Copy link
Member Author

@upgle upgle Jul 30, 2018

Choose a reason for hiding this comment

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

Thank you for your kind review. I've removed existing entitlementProvider.checkThrottles(), then modified to use only entitlementProvider.check ().

Copy link
Member Author

Choose a reason for hiding this comment

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

build passed :)

@rabbah rabbah added the awaits-contributor The contributor needs to respond to comments from reviewer. label Jul 29, 2018
@upgle upgle force-pushed the fix-shared-web-action branch 2 times, most recently from 31b3b21 to c3879db Compare July 30, 2018 13:28
@upgle
Copy link
Member Author

upgle commented Jul 31, 2018

@rabbah Maybe it's done. could you please review it again? 😅

@@ -552,8 +552,11 @@ trait WhiskWebActionsApi extends Directives with ValidateRequestSize with PostAc
if (a.namespace.defaultPackage) {
Future.successful(a)
Copy link
Member

Choose a reason for hiding this comment

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

i think here you've missed the throttle check that was removed above.

checkEntitlement(actionOwnerIdentity, a) flatMap { _ =>
pkgLookup(a.namespace.toFullyQualifiedEntityName) map { pkg =>
(a.inherit(pkg.parameters))
}
Copy link
Member

Choose a reason for hiding this comment

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

i think this is complicating logic unnecessary - now you're dealing with 3 cases:

  1. action in default package
  2. action in a proper package
  3. action in a bound package (new)

You might as well normalize all three code paths - it's not clear to me from looking at this small change here that the changes are complete (and as noted above, I think you missed on throttle check).

Copy link
Member Author

@upgle upgle Aug 7, 2018

Choose a reason for hiding this comment

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

@rabbah
yes, I agree that it looks complicated. so I've changed some codes. (removed pkgLookup method which is not necessary anymore)

  1. action in a default package no need to resolve, just check entitlement and if it is exported.
  2. action in a bound package(new) is handled by actionLookup() and resolveActionAndMergeParameters(), it would resolve action and merge parameters.
  3. check whether action is in a proper package -> It check whether an action is exported by confirmExportedAction() method
  4. and all types of action is checked for entitlement and throttle by checkEntitlement() method

please check changed code here

private def verifyWebAction(actionName: FullyQualifiedEntityName, authenticated: Boolean)(
    implicit transid: TransactionId) = {

    // lookup the identity for the action namespace
    identityLookup(actionName.path.root) flatMap { actionOwnerIdentity =>
      confirmExportedAction(actionLookup(actionName), authenticated) flatMap { a =>
        checkEntitlement(actionOwnerIdentity, a) map { _ => (actionOwnerIdentity, a)}
      }
    }
  }

https://github.com/apache/incubator-openwhisk/pull/3880/files#diff-a356e6b010b8aeb5ea7b6f7fec395038R535

@junoyoon
Copy link

junoyoon commented Aug 9, 2018

@upgle is it done?

@rabbah
Copy link
Member

rabbah commented Aug 9, 2018

The last commit looks a lot better now - I'll review more thoroughly.

@upgle
Copy link
Member Author

upgle commented Aug 10, 2018

@junoyoon no, i'm waiting for review.

@rabbah ok, tell me if I missed something.

Copy link
Member

@rabbah rabbah left a comment

Choose a reason for hiding this comment

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

I apologize that I couldn't review this sooner. I think the changes are correct now but please see the comments - there's a couple more minor things we should address for this change.

*/
protected def getAction(actionName: FullyQualifiedEntityName)(
protected def resolveActionAndMergeParameters(actionName: FullyQualifiedEntityName)(
Copy link
Member

Choose a reason for hiding this comment

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

We should add a comment that while parameters are merged, annotations are not. This is important because the web annotation is on an action not an entire package. We should separately add a test for this invariant.

Copy link
Member

Choose a reason for hiding this comment

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

need to update the docs here: https://github.com/apache/incubator-openwhisk/blob/master/docs/webactions.md#additional-features the precedence order would now also include package binding parameters.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok I'll update the docs soon.

Copy link
Member

Choose a reason for hiding this comment

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

thank you - it might be worth adding a section in the docs about web actions for packages and bindings (taking in some of my comments below). what do you think?

(a.inherit(pkg.parameters))
}
// lookup the identity for the action namespace
identityLookup(actionName.path.root) flatMap { actionOwnerIdentity =>
Copy link
Member

Choose a reason for hiding this comment

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

here the identity is tied to how the action is invoked: if the path is relative to the package, it's the owner of the package. But if it's via the binding, the identity is the owner binding. The two identities are not the same. It might also not make sense to invoke an action in a public package since it might require a binding to work correctly.

Copy link
Member

Choose a reason for hiding this comment

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

another aspect to document: a web action in a public package cannot be disabled so any (private) binding of the package will have the web action exposed.

// fail the request with BadRequest so as not to leak information about the existence
// of packages that are otherwise private
logging.debug(this, s"package which does not exist")
Future.failed(RejectRequest(NotFound))
Copy link
Member

Choose a reason for hiding this comment

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

we should add some tests for resolveActionAndMergeParameters to preserve the behavior represented by these request rejections (missing package or malformed package).

Copy link
Member Author

@upgle upgle Sep 17, 2018

Choose a reason for hiding this comment

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

(a.inherit(pkg.parameters))
}
// lookup the identity for the action namespace
identityLookup(actionName.path.root) flatMap { actionOwnerIdentity =>
Copy link
Member

Choose a reason for hiding this comment

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

another aspect to document: a web action in a public package cannot be disabled so any (private) binding of the package will have the web action exposed.

*/
protected def getAction(actionName: FullyQualifiedEntityName)(
protected def resolveActionAndMergeParameters(actionName: FullyQualifiedEntityName)(
Copy link
Member

Choose a reason for hiding this comment

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

need to update the docs here: https://github.com/apache/incubator-openwhisk/blob/master/docs/webactions.md#additional-features the precedence order would now also include package binding parameters.

@@ -233,7 +238,7 @@ trait WebActionsApiBaseTests extends ControllerTestCommon with BeforeAndAfterEac
if (actionName.path.defaultPackage) {
Future.successful(theAction)
} else {
getPackage(actionName.path.toFullyQualifiedEntityName) map (_ => theAction)
getPackage(actionName.path.toFullyQualifiedEntityName) map (pkg => theAction.inherit(pkg.parameters))
Copy link
Member

Choose a reason for hiding this comment

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

there's no test for actually using a package binding here (if there is, it would fail since the parameter inheritance does not include the binding).

@rabbah rabbah added awaits-reviewer The reviewer needs to respond to comments from contributer. awaits-contributor The contributor needs to respond to comments from reviewer. and removed awaits-contributor The contributor needs to respond to comments from reviewer. awaits-reviewer The reviewer needs to respond to comments from contributer. labels Sep 13, 2018
@rabbah
Copy link
Member

rabbah commented Nov 6, 2018

I fixed the test fixture cleanup and also tweaked one test.

@rabbah rabbah added ready and removed awaits-contributor The contributor needs to respond to comments from reviewer. labels Nov 6, 2018
@upgle
Copy link
Member Author

upgle commented Nov 7, 2018

@rabbah test is passed. thank you for your support 👍

@rabbah rabbah merged commit 7f52af4 into apache:master Nov 7, 2018
@rabbah
Copy link
Member

rabbah commented Nov 7, 2018

Thank you @upgle for your contribution.

BillZong pushed a commit to BillZong/openwhisk that referenced this pull request Nov 18, 2019
A web action in a shared (i.e., public) package is accessible as a web action either directly via the package's fully qualified name, or via a package binding. It is important to note that a web action in a public package will be accessible for all bindings of the package even if the binding is private. This is because the web action annotation is carried on the action and cannot be overridden. If you do not wish to expose a web action through your package bindings, then you should clone-and-own the package instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
controller enhancement ready review Review for this PR has been requested and yet needs to be done.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants