forked from Checkmarx/kics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(query): add new k8s rule to detect bind or escalate permissions …
…(RBAC) (Checkmarx#5268)
- Loading branch information
Showing
5 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
assets/queries/k8s/rbac_roles_allow_privilege_escalation/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"id": "8320826e-7a9c-4b0b-9535-578333193432", | ||
"queryName": "RBAC Roles Allow Privilege Escalation", | ||
"severity": "MEDIUM", | ||
"category": "Access Control", | ||
"descriptionText": "Roles or ClusterRoles with RBAC permissions 'bind' or 'escalate' allow subjects to create new bindings with other roles. This is dangerous, as users with these privileges can bind to roles that may exceed their own privileges", | ||
"descriptionUrl": "https://kubernetes.io/docs/reference/access-authn-authz/rbac/#restrictions-on-role-binding-creation-or-update", | ||
"platform": "Kubernetes", | ||
"descriptionID": "8320826e" | ||
} |
25 changes: 25 additions & 0 deletions
25
assets/queries/k8s/rbac_roles_allow_privilege_escalation/query.rego
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package Cx | ||
|
||
import data.generic.common as common_lib | ||
|
||
CxPolicy[result] { | ||
document := input.document[i] | ||
metadata := document.metadata | ||
|
||
kinds := {"Role", "ClusterRole"} | ||
document.kind == kinds[_] | ||
|
||
verbs := {"bind", "escalate", "*"} | ||
resources := {"roles", "clusterroles"} | ||
document.rules[j].resources[_] == resources[_] | ||
document.rules[j].verbs[_] == verbs[_] | ||
|
||
result := { | ||
"documentId": document.id, | ||
"searchKey": sprintf("metadata.name={{%s}}.rules", [metadata.name]), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": sprintf("metadata.name={{%s}}.rules[%d].verbs should not include the 'bind' and/or 'escalate' permission", [metadata.name, j]), | ||
"keyActualValue": sprintf("metadata.name={{%s}}.rules[%d].verbs includes the 'bind' and/or 'escalate' permission", [metadata.name, j]), | ||
"searchLine": common_lib.build_search_line(["rules", j], ["verbs"]) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
assets/queries/k8s/rbac_roles_allow_privilege_escalation/test/negative.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: not-rbac-binder | ||
rules: | ||
- apiGroups: ["rbac.authorization.k8s.io"] | ||
resources: ["clusterrolebindings"] | ||
verbs: ["create"] |
11 changes: 11 additions & 0 deletions
11
assets/queries/k8s/rbac_roles_allow_privilege_escalation/test/positive.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: rbac-binder | ||
rules: | ||
- apiGroups: ["rbac.authorization.k8s.io"] | ||
resources: ["clusterroles"] | ||
verbs: ["bind"] | ||
- apiGroups: ["rbac.authorization.k8s.io"] | ||
resources: ["clusterrolebindings"] | ||
verbs: ["create"] |
7 changes: 7 additions & 0 deletions
7
assets/queries/k8s/rbac_roles_allow_privilege_escalation/test/positive_expected_result.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ | ||
{ | ||
"queryName": "RBAC Roles Allow Privilege Escalation", | ||
"severity": "MEDIUM", | ||
"line": 8 | ||
} | ||
] |