-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
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.
|
@rabbah |
I modified it to check the entitlement and added tests.
Could you please remove WIP label and review again? |
I fixed a conflict. please review it. |
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
build passed :)
31b3b21
to
c3879db
Compare
@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) |
There was a problem hiding this comment.
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)) | ||
} |
There was a problem hiding this comment.
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:
- action in default package
- action in a proper package
- 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).
There was a problem hiding this comment.
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)
- action in a default package no need to resolve, just check entitlement and if it is exported.
- action in a bound package(new) is handled by
actionLookup()
andresolveActionAndMergeParameters()
, it would resolve action and merge parameters. - check whether action is in a proper package -> It check whether an action is exported by
confirmExportedAction()
method - 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)}
}
}
}
5ed3a34
to
91ec9bc
Compare
@upgle is it done? |
The last commit looks a lot better now - I'll review more thoroughly. |
There was a problem hiding this 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)( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 => |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolveActionAndMergeParameters
method is for mock testing, and the code which is removed here is covered in this line. https://github.com/apache/incubator-openwhisk/blob/91ec9bca7d5f6d0c8c95018a2c9fede131b02b6b/core/controller/src/main/scala/whisk/core/controller/WebActions.scala#L677
also, test for missing package exists already here.
https://github.com/apache/incubator-openwhisk/blob/91ec9bca7d5f6d0c8c95018a2c9fede131b02b6b/tests/src/test/scala/whisk/core/controller/test/WebActionsApiTests.scala#L362
(a.inherit(pkg.parameters)) | ||
} | ||
// lookup the identity for the action namespace | ||
identityLookup(actionName.path.root) flatMap { actionOwnerIdentity => |
There was a problem hiding this comment.
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)( |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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).
It is no necessary anymore because we use 'WhiskActionMetaData.resolveActionAndMergeParameters()' for resolving and merging parameters.
…s in one test to binding from package.
e970d3a
to
eb9f4d8
Compare
I fixed the test fixture cleanup and also tweaked one test. |
@rabbah test is passed. thank you for your support 👍 |
Thank you @upgle for your contribution. |
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.
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.
Fixed
Now, the bound web action can be accessed in the browser.
Related issue and scope
My changes affect the following components
Types of changes
Checklist: