Skip to content
Closed
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 .github/workflows/panel-scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,4 @@ jobs:
- run: bash tests/scripts/tailscale_api_test.sh
- run: bash tests/scripts/proxmox_gpu_lxc_test.sh
- run: bash tests/scripts/gpu_node_check_test.sh
- run: bash tests/scripts/api_rbac_test.sh
3 changes: 3 additions & 0 deletions base/api/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ rules:
verbs:
- get
- list
# create: a stream sent to Twitch reads its key from a Secret owned by its
# Job, which Kubernetes deletes with the Job.
- apiGroups:
- ''
resources:
- secrets
verbs:
- create
- get
- list
- apiGroups:
Expand Down
45 changes: 45 additions & 0 deletions tests/scripts/api_rbac_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

# shellcheck source=tests/scripts/lib.sh
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"

ROLE="$TEST_ROOT/base/api/rbac/role.yaml"

# The verbs the api's Role grants on a core resource, sorted, one line.
verbs() {
awk -v want="$1" '
function flush() {
if (core && (" " res " ") ~ (" " want " ") && !names) {
out = out vb
}
}
/^ - apiGroups:/ { flush(); section = "g"; core = 0; res = ""; vb = ""; names = 0; next }
/^ resources:/ { section = "r"; next }
/^ verbs:/ { section = "v"; next }
/^ resourceNames:/ { section = "n"; names = 1; next }
/^ - / {
item = $2
gsub(/[\047"]/, "", item)
if (section == "g" && item == "") { core = 1 }
if (section == "r") { res = res " " item }
if (section == "v") { vb = vb " " item }
next
}
END { flush(); print out }
' "$ROLE" | tr ' ' '\n' | sed '/^$/d' | sort -u | tr '\n' ' ' | sed 's/ $//'
}

# A stream sent to Twitch reads its key from a Secret its Job owns, so the key
# is never in the Job spec. The api creates that Secret; Kubernetes deletes it
# with the Job.
test_the_api_creates_a_secret_for_a_job() {
assert_eq "$(verbs secrets)" "create get list"
}

test_the_api_still_cannot_change_or_delete_a_secret() {
assert_not_contains "$(verbs secrets)" "update"
assert_not_contains "$(verbs secrets)" "patch"
assert_not_contains "$(verbs secrets)" "delete"
}

run_tests
Loading