-
Notifications
You must be signed in to change notification settings - Fork 316
Prevent GCP-2024-003 #1009
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
Closed
kurktchiev
wants to merge
15
commits into
kyverno:main
from
kurktchiev:restrict-clusteradmin-rolebindings-gcp-2024-003
Closed
Prevent GCP-2024-003 #1009
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
afeef59
add policy
ffd1735
Merge branch 'kyverno:main' into restrict-clusteradmin-rolebindings-g…
kurktchiev 9519290
Merge branch 'kyverno:main' into restrict-clusteradmin-rolebindings-g…
kurktchiev 630a4b7
add annotations and artifact hub
782493e
Merge branch 'main' into restrict-clusteradmin-rolebindings-gcp-2024-003
kurktchiev bb0d25a
switch to audit mode
1333726
start adding test objects
e8d49fb
add annotations
f3aa40a
Merge branch 'main' into restrict-clusteradmin-rolebindings-gcp-2024-003
kurktchiev df72ee5
update annotations
1fb9184
make changes
d8d63d0
add digest
8f4b2fa
fix match block
e0067cc
Merge branch 'main' into restrict-clusteradmin-rolebindings-gcp-2024-003
kurktchiev 82024d7
get started on tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
...restrict-clusteradmin-rolebindings-gcp-2024-003/.kyverno-test/bad-clusterrolebinding.yaml
This file contains hidden or 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: ClusterRoleBinding | ||
| metadata: | ||
| name: bad-clusterrolebinding | ||
| subjects: | ||
| - kind: Group | ||
| name: system:unauthenticated | ||
| roleRef: | ||
| kind: ClusterRole | ||
| name: cluster-admin | ||
| apiGroup: rbac.authorization.k8s.io |
12 changes: 12 additions & 0 deletions
12
other/restrict-clusteradmin-rolebindings-gcp-2024-003/.kyverno-test/bad-rolebinding.yaml
This file contains hidden or 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,12 @@ | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: RoleBinding | ||
| metadata: | ||
| name: bad-rolebinding | ||
| namespace: default | ||
| subjects: | ||
| - kind: Group | ||
| name: system:authenticated | ||
| roleRef: | ||
| kind: ClusterRole | ||
| name: cluster-admin | ||
| apiGroup: rbac.authorization.k8s.io |
11 changes: 11 additions & 0 deletions
11
...estrict-clusteradmin-rolebindings-gcp-2024-003/.kyverno-test/good-clusterrolebinding.yaml
This file contains hidden or 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: ClusterRoleBinding | ||
| metadata: | ||
| name: good-clusterrolebinding | ||
| subjects: | ||
| - kind: User | ||
| name: jane.doe | ||
| roleRef: | ||
| kind: ClusterRole | ||
| name: view | ||
| apiGroup: rbac.authorization.k8s.io |
12 changes: 12 additions & 0 deletions
12
other/restrict-clusteradmin-rolebindings-gcp-2024-003/.kyverno-test/good-rolebinding.yaml
This file contains hidden or 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,12 @@ | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: RoleBinding | ||
| metadata: | ||
| name: good-rolebinding | ||
| namespace: default | ||
| subjects: | ||
| - kind: User | ||
| name: john.doe | ||
| roleRef: | ||
| kind: Role | ||
| name: admin | ||
| apiGroup: rbac.authorization.k8s.io |
19 changes: 19 additions & 0 deletions
19
other/restrict-clusteradmin-rolebindings-gcp-2024-003/artifacthub-pkg.yml
This file contains hidden or 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 @@ | ||
| name: restrict-clusteradmin-rolebindings-gcp-2024-003 | ||
| version: 1.0.0 | ||
| displayName: Restrict ClusterAdmin RoleBindings (GCP-2024-003) | ||
| createdAt: "2023-04-10T20:30:03.000Z" | ||
| description: >- | ||
| The cluster-admin ClusterRole allows any action to be performed on any resource in the cluster and its granting should be heavily restricted. This policy prevents binding to the cluster-admin ClusterRole in RoleBinding or ClusterRoleBinding resources to the system:authenticated, system:unauthenticated, and system:anonymous subjects. | ||
| install: |- | ||
| ```shell | ||
| kubectl apply -f https://raw.githubusercontent.com/kyverno/policies/main/other/restrict-clusteradmin-rolebindings-gcp-2024-003/restrict-clusteradmin-rolebindings-gcp-2024-003.yaml | ||
| ``` | ||
| keywords: | ||
| - kyverno | ||
| - Security | ||
| readme: | | ||
| The cluster-admin ClusterRole allows any action to be performed on any resource in the cluster and its granting should be heavily restricted. This policy prevents binding to the cluster-admin ClusterRole in RoleBinding or ClusterRoleBinding resources to the system:authenticated, system:unauthenticated, and system:anonymous subjects. | ||
| annotations: | ||
| kyverno/category: "Security" | ||
| kyverno/subject: "RoleBinding, ClusterRoleBinding" | ||
| digest: 9220d6071d8faccd37995e3fdf7b8db036b0e499268eb38993587016a0c1120e |
38 changes: 38 additions & 0 deletions
38
...usteradmin-rolebindings-gcp-2024-003/restrict-clusteradmin-rolebindings-gcp-2024-003.yaml
This file contains hidden or 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,38 @@ | ||
| apiVersion: kyverno.io/v1 | ||
| kind: ClusterPolicy | ||
| metadata: | ||
| name: restrict-clusteradmin-rolebindings-gcp-2024-003 | ||
| annotations: | ||
| policies.kyverno.io/title: Restrict ClusterAdmin RoleBindings (GCP-2024-003) | ||
| policies.kyverno.io/category: Security | ||
| policies.kyverno.io/severity: medium | ||
| policies.kyverno.io/subject: RoleBinding, ClusterRoleBinding | ||
| kyverno.io/kubernetes-version: 1.27 | ||
| kyverno.io/kyverno-version: 1.10 | ||
| policies.kyverno.io/description: >- | ||
| The cluster-admin ClusterRole allows any action to be performed on any resource in the cluster and its granting should be heavily restricted. This policy prevents binding to the cluster-admin ClusterRole in RoleBinding or ClusterRoleBinding resources to the system:authenticated, system:unauthenticated, and system:anonymous subjects. | ||
|
|
||
| Refer to the documentation for more details on Kyverno annotations: https://artifacthub.io/docs/topics/annotations/kyverno/ | ||
| spec: | ||
| validationFailureAction: Audit | ||
| rules: | ||
| - name: validate-restricted-cluster-admin-bindings | ||
| match: | ||
| resources: | ||
| kinds: | ||
| - ClusterRoleBinding | ||
| - RoleBinding | ||
| validate: | ||
| message: "Binding ClusterRole 'cluster-admin' is restricted, system:authenticated, system:unauthenticated and system:anonymous are not allowed. GCP-2024-003" | ||
| deny: | ||
| conditions: | ||
| all: | ||
| - key: "{{ request.object.subjects[].name }}" | ||
| operator: AnyIn | ||
| value: | ||
| - system:authenticated | ||
| - system:unauthenticated | ||
| - system:anonymous | ||
| - key: "{{ request.object.roleRef.name }}" | ||
| operator: Equals | ||
| value: "cluster-admin" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.