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

Allow checking multiple permissions at once #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ A couple of helper scripts are provided to aid in searching/listing of the outpu

* `list-all-permissions.sh` grabs the unique list of all permissions contained in all roles fetched
* `list-alpha/beta/ga-roles.sh` lists the roles labeled by GCP as alpha, beta, or GA (generally available)
* `list-roles-with-permission.sh <api.resource.verb>` lists the roles that contain a specific permission passed by the first argument. e.g.: `./list-roles-with-permission.sh container.clusters.get`
* `list-roles-with-permissions.sh <api.resource.verb1>[ <api.resource.verbN>]` lists the roles that contain all of the specific permissions passed as one or more arguments. e.g.: `./list-roles-with-permissions.sh autoscaling.sites.writeMetrics logging.logEntries.create`
* `list-roles-with-permission.sh <api.resource.verb>` compatibility alias for the single-permission version of `list-roles-with-permissions.sh`. e.g.: `./list-roles-with-permission.sh container.clusters.get`
* `list-permissions-of-role.sh <role.name>` lists the permissions contained by the role named `<role.name>`. e.g. `./list-roles-with-permission.sh container.admin` (no need to prepend the `roles/`)
14 changes: 2 additions & 12 deletions list-roles-with-permission.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
#!/usr/bin/env bash

if [ "$#" -ne 1 ]
then
echo "Error: Must specify the permission to search for"
echo ""
echo "e.g: $0 resourcemanager.projects.get"
echo ""
exit 1
fi

source ./lib/helper.sh

cat roles/* | jq -r --arg PERM "$1" 'select(.includedPermissions!=null and (.includedPermissions[] | contains($PERM))) | "\(.name)"'
# Note: this is just a compatibility alias to not break pipelines using the old single-permission version
source ./list-roles-with-permissions.sh
16 changes: 16 additions & 0 deletions list-roles-with-permissions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

if [ "$#" -lt 1 ]
then
echo "Error: Must specify at least one permission to search for. Specifying multiple permissions will return roles matching ALL of the supplied permissions."
echo ""
echo "e.g: $0 autoscaling.sites.writeMetrics logging.logEntries.create"
echo ""
exit 1
fi

source ./lib/helper.sh

arg_json=$(jq --compact-output --null-input '$ARGS.positional' --args -- "${@}")

cat roles/* | jq -r "select(.includedPermissions!=null and (.includedPermissions | contains($arg_json))) | \"\(.name)\""