Skip to content

Commit 4af70b8

Browse files
committed
Make the action's downloadable for the shared user
1 parent 02099e1 commit 4af70b8

File tree

4 files changed

+75
-26
lines changed

4 files changed

+75
-26
lines changed

common/scala/src/main/scala/org/apache/openwhisk/core/entity/WhiskAction.scala

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -367,23 +367,41 @@ object WhiskAction extends DocumentFactory[WhiskAction] with WhiskEntityQueries[
367367

368368
// notes on users, just have 2 type users,
369369
// 1. the action's owner
370-
// 2. the user (not the owner) who used the shared action directly(e.g. get, invoke)
370+
// 2. the user (not the owner) who used the shared action directly(e.g. get, invoke), we call it "the shared user"
371371
//
372372
// Notes on permission control
373-
// 1. the action's read permission should open forever, because under invoke action or update action and so on,
374-
// need to use `fetch` api to get the action to judge it whether exist.
375-
// 2. the user(not the owner) can't update/delete the action forever.
376-
// 3. the owner's permission can affect other user's permission, e.g
377-
// if the owner is not given execute permission, the user(not the owner) can't have execute permission as well.
373+
// 1. the owner has read(or download) permission on any situation, but for the shared user,
374+
// in spite of has read permission on any situation, but can set it undownloadable or downloadable
375+
// 2. the shared user can't update/delete the action on any situation.
376+
// 3. the owner's permission can affect the shared user's permission, e.g
377+
// if the owner is not given execute permission, the shared user can't have execute permission as well.
378378
//
379379
// Notes on permission values, include below permission value
380-
// 1. permission code:rwxr-x: owner:read(yes)/write(yes)/execute(yes)|the shared action's user:read(yes)/write(no)/execute(yes), this is default
381-
// 2. permission code:rwxr--: owner:read(yes)/write(yes)/execute(yes)|the shared action's user:read(yes)/write(no)/execute(no)
382-
// 3. permission code:r-xr-x: owner:read(yes)/write(no)/execute(yes)|the shared action's user:read(yes)/write(no)/execute(yes)
383-
// 4. permission code:r-xr--: owner:read(yes)/write(no)/execute(yes)|the shared action's user:read(yes)/write(no)/execute(no)
384-
// 5. permission code:r--r--: owner:read(yes)/write(no)/execute(no)|the shared action's user:read(yes)/write(no)/execute(no)
385-
// 6. permission code:rw-r--: owner:read(yes)/write(yes)/execute(no)|the shared action's user:read(yes)/write(no)/execute(no)
386-
val permissionList = List(defaultPermissions, "rwxr--", "r-xr-x", "r-xr--", "r--r--", "rw-r--")
380+
// 1. permission code:rwxr-x: owner:read(yes)/write(yes)/execute(yes)|the shared action's user:download(yes)/write(no)/execute(yes), this is default
381+
// 2. permission code:rwxr--: owner:read(yes)/write(yes)/execute(yes)|the shared action's user:download(yes)/write(no)/execute(no)
382+
// 3. permission code:r-xr-x: owner:read(yes)/write(no)/execute(yes)|the shared action's user:download(yes)/write(no)/execute(yes)
383+
// 4. permission code:r-xr--: owner:read(yes)/write(no)/execute(yes)|the shared action's user:download(yes)/write(no)/execute(no)
384+
// 5. permission code:r--r--: owner:read(yes)/write(no)/execute(no)|the shared action's user:download(yes)/write(no)/execute(no)
385+
// 6. permission code:rw-r--: owner:read(yes)/write(yes)/execute(no)|the shared action's user:download(yes)/write(no)/execute(no)
386+
// 7. permission code:rwx--x: owner:read(yes)/write(yes)/execute(yes)|the shared action's user:download(no)/write(no)/execute(yes)
387+
// 8. permission code:rwx---: owner:read(yes)/write(yes)/execute(yes)|the shared action's user:download(no)/write(no)/execute(no)
388+
// 9. permission code:r-x--x: owner:read(yes)/write(no)/execute(yes)|the shared action's user:download(no)/write(no)/execute(yes)
389+
// 10. permission code:r-x---: owner:read(yes)/write(no)/execute(yes)|the shared action's user:download(no)/write(no)/execute(no)
390+
// 11. permission code:r-----: owner:read(yes)/write(no)/execute(no)|the shared action's user:download(no)/write(no)/execute(no)
391+
// 12. permission code:rw----: owner:read(yes)/write(yes)/execute(no)|the shared action's user:download(no)/write(no)/execute(no)
392+
val permissionList = List(
393+
defaultPermissions,
394+
"rwxr--",
395+
"r-xr-x",
396+
"r-xr--",
397+
"r--r--",
398+
"rw-r--",
399+
"rwx--x",
400+
"rwx---",
401+
"r-x--x",
402+
"r-x---",
403+
"r-----",
404+
"rw----")
387405

388406
override val collectionName = "actions"
389407
override val cacheEnabled = true

core/controller/src/main/scala/org/apache/openwhisk/core/controller/Actions.scala

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,19 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
368368
parameter('code ? true) { code =>
369369
code match {
370370
case true =>
371-
getEntity(WhiskAction.resolveActionAndMergeParameters(entityStore, entityName), Some { action: WhiskAction =>
372-
val mergedAction = env map {
373-
action inherit _
374-
} getOrElse action
375-
complete(OK, mergedAction)
376-
})
371+
onComplete(
372+
entitlementProvider
373+
.checkActionPermissions("download", user, entityStore, entityName, WhiskAction.get)) {
374+
case Success(_) =>
375+
getEntity(WhiskAction.resolveActionAndMergeParameters(entityStore, entityName), Some {
376+
action: WhiskAction =>
377+
val mergedAction = env map {
378+
action inherit _
379+
} getOrElse action
380+
complete(OK, mergedAction)
381+
})
382+
case Failure(f) => super.handleEntitlementFailure(f)
383+
}
377384
case false =>
378385
getEntity(WhiskActionMetaData.resolveActionAndMergeParameters(entityStore, entityName), Some {
379386
action: WhiskActionMetaData =>

core/controller/src/main/scala/org/apache/openwhisk/core/entitlement/Entitlement.scala

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,26 @@ protected[core] abstract class EntitlementProvider(
334334
Future.successful(())
335335
}
336336
}
337-
} else { //get
338-
Future.successful(())
337+
} else { // download the code
338+
get(entityStore, entityName.toDocId, DocRevision.empty, true).flatMap { whiskAction =>
339+
val currentPermissions = whiskAction.annotations
340+
.get(WhiskAction.permissionsFieldName)
341+
.map(value => value.convertTo[String])
342+
.getOrElse(WhiskAction.defaultPermissions)
343+
344+
val errorInfo = s"have no permission to download this shared action"
345+
val currentDownloadPermission = currentPermissions.charAt(3)
346+
if (user.namespace.name.asString != entityName.path.root.asString) { // the shared user who download the action
347+
if (currentDownloadPermission == '-') {
348+
Future.failed(RejectRequest(Forbidden, Some(ErrorResponse(errorInfo, transid))))
349+
} else {
350+
Future.successful(())
351+
}
352+
} else {
353+
// the owner has download permission on any situation
354+
Future.successful(())
355+
}
356+
}
339357
}
340358
}
341359

docs/actions.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -662,14 +662,14 @@ You can clean up by deleting actions that you do not want to use.
662662

663663
* Notes on users, just have 2 type users,
664664
- the action's owner
665-
- the user (not the owner) who used the shared action directly(e.g. get, invoke)
665+
- the user (not the owner) who used the shared action directly(e.g. get, invoke), we call it "the shared user"
666666

667667
* Notes on permission control
668-
- the action's read permission should open forever, because under invoke action or update action and so on,
669-
need to use `fetch` api to get the action to judge it whether exist.
670-
- the user(not the owner) can't update/delete the action forever.
668+
- the owner has read(or download) permission on any situation, but for the shared user,
669+
in spite of has read permission on any situation, but can set it undownloadable or downloadable
670+
- the shared user can't update/delete the action forever.
671671
- the owner's permission can affect other user's permission, e.g
672-
if the owner is not given execute permission, the user(not the owner) can't have execute permission as well.
672+
if the owner is not given execute permission, the shared user can't have execute permission as well.
673673

674674
* Notes on permission values, include below permission value
675675
- permission code:rwxr-x: owner:read(yes)/write(yes)/execute(yes)|the shared action's user:read(yes)/write(no)/execute(yes), this is default
@@ -678,6 +678,12 @@ You can clean up by deleting actions that you do not want to use.
678678
- permission code:r-xr--: owner:read(yes)/write(no)/execute(yes)|the shared action's user:read(yes)/write(no)/execute(no)
679679
- permission code:r--r--: owner:read(yes)/write(no)/execute(no)|the shared action's user:read(yes)/write(no)/execute(no)
680680
- permission code:rw-r--: owner:read(yes)/write(yes)/execute(no)|the shared action's user:read(yes)/write(no)/execute(no)
681+
- permission code:rwx--x: owner:read(yes)/write(yes)/execute(yes)|the shared action's user:download(no)/write(no)/execute(yes)
682+
- permission code:rwx---: owner:read(yes)/write(yes)/execute(yes)|the shared action's user:download(no)/write(no)/execute(no)
683+
- permission code:r-x--x: owner:read(yes)/write(no)/execute(yes)|the shared action's user:download(no)/write(no)/execute(yes)
684+
- permission code:r-x---: owner:read(yes)/write(no)/execute(yes)|the shared action's user:download(no)/write(no)/execute(no)
685+
- permission code:r-----: owner:read(yes)/write(no)/execute(no)|the shared action's user:download(no)/write(no)/execute(no)
686+
- permission code:rw----: owner:read(yes)/write(yes)/execute(no)|the shared action's user:download(no)/write(no)/execute(no)
681687

682688
When create action without permissions annotation, permission control keeps the same as before,
683689
e.g. the owner has all permissions(create/update(or delete)/invoke), the user(not owner) doesn't have update/delete permission on the shared action.

0 commit comments

Comments
 (0)