-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #466 from kubescape/chore/add-rbac-enabled-rule-to…
…-framework feat(rules): add anonymous-access-enabled to framework
- Loading branch information
Showing
9 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
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,15 @@ | ||
{ | ||
"controlID": "C-0262", | ||
"name": "Anonymous access enabled", | ||
"description": "Granting permissions to the system:unauthenticated or system:anonymous user is generally not recommended and can introduce security risks. Allowing unauthenticated access to your Kubernetes cluster can lead to unauthorized access, potential data breaches, and abuse of cluster resources.", | ||
"remediation": "Review and modify your cluster's RBAC configuration to ensure that only authenticated and authorized users have appropriate permissions based on their roles and responsibilities within your system.", | ||
"test": "Checks if ClusterRoleBinding/RoleBinding resources give permissions to anonymous user. Also checks in the apiserver if the --anonymous-auth flag is set to false", | ||
"attributes": { | ||
"armoBuiltin": true | ||
}, | ||
"rulesNames": [ | ||
"ensure-that-the-api-server-anonymous-auth-argument-is-set-to-false", | ||
"anonymous-access-enabled" | ||
], | ||
"baseScore": 5 | ||
} |
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
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
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,30 @@ | ||
package armo_builtins | ||
|
||
# Fails is rolebinding/clusterrolebinding gives permissions to anonymous user | ||
deny[msga] { | ||
rolebindings := [rolebinding | rolebinding = input[_]; endswith(rolebinding.kind, "Binding")] | ||
rolebinding := rolebindings[_] | ||
|
||
isAnonymous(rolebinding) | ||
|
||
msga := { | ||
"alertMessage": sprintf("the following RoleBinding: %v gives permissions to anonymous users", [rolebinding.metadata.name]), | ||
"alertScore": 9, | ||
"packagename": "armo_builtins", | ||
"alertObject": { | ||
"k8sApiObjects": [rolebinding] | ||
} | ||
} | ||
} | ||
|
||
|
||
isAnonymous(binding) { | ||
subject := binding.subjects[_] | ||
subject.name == "system:anonymous" | ||
} | ||
|
||
|
||
isAnonymous(binding) { | ||
subject := binding.subjects[_] | ||
subject.name == "system:unauthenticated" | ||
} |
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 @@ | ||
{ | ||
"name": "anonymous-access-enabled", | ||
"attributes": { | ||
"armoBuiltin": true | ||
}, | ||
"ruleLanguage": "Rego", | ||
"match": [ | ||
{ | ||
"apiGroups": [ | ||
"rbac.authorization.k8s.io" | ||
], | ||
"apiVersions": [ | ||
"v1" | ||
], | ||
"resources": [ | ||
"RoleBinding", | ||
"ClusterRoleBinding" | ||
] | ||
} | ||
], | ||
"ruleDependencies": [], | ||
"description": "Fails in case anonymous access is enabled on the cluster", | ||
"remediation": "Disable anonymous access by passing the --anonymous-auth=false flag to the kube-apiserver component, or if it's a managed cluster, you can remove any RBAC rules which allow anonymous users to perform actions", | ||
"ruleQuery": "armo_builtins" | ||
} |
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,24 @@ | ||
[ | ||
{ | ||
"alertMessage": "the following RoleBinding: system:public-info-viewer gives permissions to anonymous users", | ||
"failedPaths": null, | ||
"fixPaths": null, | ||
"ruleStatus": "", | ||
"packagename": "armo_builtins", | ||
"alertScore": 9, | ||
"alertObject": { | ||
"k8sApiObjects": [ | ||
{ | ||
"apiVersion": "rbac.authorization.k8s.io/v1", | ||
"kind": "ClusterRoleBinding", | ||
"metadata": { | ||
"labels": { | ||
"kubernetes.io/bootstrapping": "rbac-defaults" | ||
}, | ||
"name": "system:public-info-viewer" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
] |
19 changes: 19 additions & 0 deletions
19
rules/anonymous-access-enabled/test/fail/input/clusterrolebinding.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,19 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
annotations: | ||
rbac.authorization.kubernetes.io/autoupdate: "true" | ||
labels: | ||
kubernetes.io/bootstrapping: rbac-defaults | ||
name: system:public-info-viewer | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: system:public-info-viewer | ||
subjects: | ||
- apiGroup: rbac.authorization.k8s.io | ||
kind: Group | ||
name: system:authenticated | ||
- apiGroup: rbac.authorization.k8s.io | ||
kind: Group | ||
name: system:unauthenticated |
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 @@ | ||
[] |
13 changes: 13 additions & 0 deletions
13
rules/anonymous-access-enabled/test/success/input/rolebinding.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,13 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: pod | ||
namespace: default | ||
subjects: | ||
- kind: User | ||
name: jane | ||
apiGroup: rbac.authorization.k8s.io | ||
roleRef: | ||
kind: Role | ||
name: pod-reader | ||
apiGroup: rbac.authorization.k8s.io |