-
Notifications
You must be signed in to change notification settings - Fork 0
/
reporter.sh
executable file
·30 lines (25 loc) · 1011 Bytes
/
reporter.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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' \
| grep -E ".+@.+" | sort | uniq | sed "s/^/ /g"
done
else
echo -e "\nInsufficient rights"
fi
done
echo -e "\n---\n"