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

feat: OpenShift Projects and Rights Reporter Script #1748

Closed
wants to merge 6 commits into from
Closed
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
30 changes: 30 additions & 0 deletions scripts/rights_reporter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
set -euo pipefail

# This script reports on rights in OpenShift projects
echo -e "OpenShift users for projects accessible to $(oc whoami)"

# Projects available to the current user
PROJECTS=$(oc projects | sed "s/\*/ /g" | grep -E "^ +.*-.*(.*)$")

# Roles to report on, can be overridden with a quoted parameter
ROLES=${1:-"admin edit view"}

# Loop through the projects and report on rights
for p in $(echo "${PROJECTS}" | awk '{print $1}'); do
echo -e "\n---\n\nProject: $p"
echo -e "Name: $(echo "${PROJECTS}" | grep $p | awk -F" - " '{print $2}')"

# Report on requested roles, where possible
if oc get rolebindings -n $p &> /dev/null; then
for role in ${ROLES}; do
echo -e "\n${role}:"
oc get rolebindings -n $p -o json \
| jq -r '.items[] | select(.subjects[].kind=="User", .roleRef.name=="${role}") | .subjects[].name' \
| sort | uniq | sed "s/^/ /g"
done
else
echo -e "\nInsufficient rights"
fi
done
echo -e "\n---\n"