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

new script to diff 2 roles #2

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.envrc
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@

This repository fetches the ~1,170 primitive and predefined IAM Roles in JSON format to the `roles` directory. A GitHub Action is configured to refresh them daily. This allows for automatic tracking of changes as they are made by GCP.

## Scripts

A couple of helper scripts are provided to aid in searching/listing of the output:

### Roles

* `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`

### Permissions

* `diff-role-permissions.sh <role1.name> <role2.name>` shows the permission differences between 2 roles
* this script uses the built-in `diff` by default, but you can customize this by setting the `DIFF` environment variable
* ex. `export DIFF='git diff --no-index'`
* improve this even further by installing [direnv](https://direnv.net/) and throwing the export in an `.envrc` file
* `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-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/`)
22 changes: 22 additions & 0 deletions diff-role-permissions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

if [ "$#" -ne 2 ]
then
cat << EOF
Error: Must specify the 2 roles to diff

e.g: $0 artifactregistry.writer artifactregistry.repoAdmin
EOF
exit 1
fi

source ./lib/helper.sh

FROM=$(mktemp)
TO=$(mktemp)

./list-permissions-of-role.sh "$1" | sort -u > "$FROM"
./list-permissions-of-role.sh "$2" | sort -u > "$TO"

# allow customized output styling. see README
${DIFF:-diff} "$FROM" "$TO"