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

fix: resourceName with empty item can lead to list resources #5

Open
wants to merge 2 commits 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
10 changes: 9 additions & 1 deletion lib/list_secrets.rego
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import future.keywords.in

describe[{"desc": desc, "severity": severity}] {
desc := "Identities that can list secrets cluster-wide may access confidential information, and in some cases serviceAccount tokens"
severity := "Medium"
severity := "Critical"
}
targets := {"serviceAccounts", "nodes", "users", "groups"}

Expand All @@ -15,4 +15,12 @@ evaluateRoles(roles, owner) {
pb.valueOrWildcard(rule.resources, "secrets")
pb.valueOrWildcard(rule.verbs, "list")
pb.valueOrWildcard(rule.apiGroups, "")
resourceNamesNotExistOrContainEmptyItem(rule)
}

resourceNamesNotExistOrContainEmptyItem(rule) {
not pb.hasKey(rule, "resourceNames")
} {
pb.hasKey(rule, "resourceNames")
"" in rule.resourceNames
}
12 changes: 10 additions & 2 deletions lib/retrieve_token_secrets.rego
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ evaluateRoles(roles, owner) {
some role in roles
pb.affectsPrivNS(role)
some rule in role.rules
pb.valueOrWildcard(rule.apiGroups, "")
pb.valueOrWildcard(rule.resources, "secrets")
canBruteOrListSecrets(rule)
}

canBruteOrListSecrets(rule) {
pb.getOrListOrWildcard(rule.verbs) # get -> bruteforcing token secrets names
pb.valueOrWildcard(rule.apiGroups, "")
not pb.hasKey(rule, "resourceNames")
}
} {
pb.valueOrWildcard(rule.verbs, "list")
pb.hasKey(rule, "resourceNames") # '' resourceName can also lead to list resources
"" in rule.resourceNames
}