-
Notifications
You must be signed in to change notification settings - Fork 17
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 #140 from nirmata/NDEV-19285-convert-rbac-best-pra…
…ctices-to-cel-policies feat: NDEV-19285-convert-rbac-best-practices-to-cel-policies
- Loading branch information
Showing
41 changed files
with
1,274 additions
and
1 deletion.
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,18 @@ | ||
features: | ||
generateValidatingAdmissionPolicy: | ||
enabled: true | ||
|
||
admissionController: | ||
rbac: | ||
clusterRole: | ||
extraResources: | ||
- apiGroups: | ||
- admissionregistration.k8s.io | ||
resources: | ||
- validatingadmissionpolicies | ||
- validatingadmissionpolicybindings | ||
verbs: | ||
- create | ||
- update | ||
- delete | ||
- list |
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,9 @@ | ||
kind: Cluster | ||
apiVersion: kind.x-k8s.io/v1alpha4 | ||
featureGates: | ||
ValidatingAdmissionPolicy: true | ||
runtimeConfig: | ||
admissionregistration.k8s.io/v1alpha1: true | ||
nodes: | ||
- role: control-plane | ||
- role: worker |
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 @@ | ||
kind: Cluster | ||
apiVersion: kind.x-k8s.io/v1alpha4 | ||
featureGates: | ||
ValidatingAdmissionPolicy: true | ||
runtimeConfig: | ||
admissionregistration.k8s.io/v1beta1: true | ||
admissionregistration.k8s.io/v1alpha1: true | ||
nodes: | ||
- role: control-plane | ||
- role: worker |
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 |
---|---|---|
|
@@ -45,7 +45,7 @@ jobs: | |
run: chainsaw version | ||
|
||
- name: Test with Chainsaw | ||
run: make test-chainsaw | ||
run: make test-chainsaw-exclude-cel | ||
|
||
run-e2etest-2: | ||
runs-on: ubuntu-latest | ||
|
@@ -84,3 +84,69 @@ jobs: | |
|
||
- name: Test with Chainsaw | ||
run: make test-chainsaw | ||
|
||
run-e2etest-vap-alpha: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
k8s-version: [v1.27.3, v1.26.3] | ||
n4k-chart-version: [3.1.14] | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Prepare environment | ||
run: | | ||
K8S_VERSION=${{ matrix.k8s-version }} make kind-create-cluster-vap-alpha | ||
- name: Install kyverno | ||
run: | | ||
N4K_VERSION=${{ matrix.n4k-chart-version }} make kind-deploy-kyverno-vap | ||
- name: Check Kyverno status | ||
run: make wait-for-kyverno | ||
|
||
- name: Install chainsaw | ||
uses: kyverno/[email protected] | ||
|
||
- name: Verify Chainsaw Installation | ||
run: chainsaw version | ||
|
||
- name: Test with Chainsaw | ||
run: make test-chainsaw-vap | ||
|
||
run-e2etest-vap-beta: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
k8s-version: [v1.29.2, v1.28.0] | ||
n4k-chart-version: [3.1.14] | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Prepare environment | ||
run: | | ||
K8S_VERSION=${{ matrix.k8s-version }} make kind-create-cluster-vap-beta | ||
- name: Install kyverno | ||
run: | | ||
N4K_VERSION=${{ matrix.n4k-chart-version }} make kind-deploy-kyverno-vap | ||
- name: Check Kyverno status | ||
run: make wait-for-kyverno | ||
|
||
- name: Install chainsaw | ||
uses: kyverno/[email protected] | ||
|
||
- name: Verify Chainsaw Installation | ||
run: chainsaw version | ||
|
||
- name: Test with Chainsaw | ||
run: make test-chainsaw-vap |
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
67 changes: 67 additions & 0 deletions
67
rbac-best-practices-cel/restrict-binding-system-groups/e2e/bad-resource.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,67 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: badcrb01 | ||
subjects: | ||
- kind: Group | ||
name: bar | ||
apiGroup: rbac.authorization.k8s.io | ||
roleRef: | ||
kind: ClusterRole | ||
name: "system:masters" | ||
apiGroup: rbac.authorization.k8s.io | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: badcrb02 | ||
subjects: | ||
- kind: Group | ||
namespace: foo | ||
name: bar | ||
apiGroup: rbac.authorization.k8s.io | ||
roleRef: | ||
kind: ClusterRole | ||
name: "system:masters" | ||
apiGroup: rbac.authorization.k8s.io | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: badrb01 | ||
subjects: | ||
- kind: Group | ||
name: bar | ||
apiGroup: rbac.authorization.k8s.io | ||
roleRef: | ||
kind: Role | ||
name: "system:masters" | ||
apiGroup: rbac.authorization.k8s.io | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: badrb02 | ||
subjects: | ||
- kind: Group | ||
name: bar | ||
namespace: foo | ||
apiGroup: rbac.authorization.k8s.io | ||
roleRef: | ||
kind: Role | ||
name: "system:masters" | ||
apiGroup: rbac.authorization.k8s.io | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: badrb03 | ||
subjects: | ||
- kind: Group | ||
name: bar | ||
namespace: foo | ||
apiGroup: rbac.authorization.k8s.io | ||
roleRef: | ||
kind: Role | ||
name: "system:masters" | ||
apiGroup: rbac.authorization.k8s.io |
28 changes: 28 additions & 0 deletions
28
rbac-best-practices-cel/restrict-binding-system-groups/e2e/chainsaw-test-vap.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,28 @@ | ||
apiVersion: chainsaw.kyverno.io/v1alpha1 | ||
kind: Test | ||
metadata: | ||
name: restrict-binding-system-groups-policy | ||
spec: | ||
steps: | ||
- name: test-restrict-binding-system-groups | ||
try: | ||
- apply: | ||
file: ../restrict-binding-system-groups.yaml | ||
- assert: | ||
file: policy-assert.yaml | ||
- script: | ||
content: | | ||
sed 's/validationFailureAction: Audit/validationFailureAction: Enforce/' ../restrict-binding-system-groups.yaml | kubectl apply -f - | ||
- assert: | ||
file: enforce-policy-assert.yaml | ||
- assert: | ||
file: vap-assert.yaml | ||
- assert: | ||
file: vap-binding-assert.yaml | ||
- apply: | ||
file: good-resource.yaml | ||
- apply: | ||
expect: | ||
- check: | ||
($error != null): true | ||
file: bad-resource.yaml |
24 changes: 24 additions & 0 deletions
24
rbac-best-practices-cel/restrict-binding-system-groups/e2e/chainsaw-test.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,24 @@ | ||
apiVersion: chainsaw.kyverno.io/v1alpha1 | ||
kind: Test | ||
metadata: | ||
name: restrict-binding-system-groups-policy | ||
spec: | ||
steps: | ||
- name: test-restrict-binding-system-groups | ||
try: | ||
- apply: | ||
file: ../restrict-binding-system-groups.yaml | ||
- assert: | ||
file: policy-assert.yaml | ||
- script: | ||
content: | | ||
sed 's/validationFailureAction: Audit/validationFailureAction: Enforce/' ../restrict-binding-system-groups.yaml | kubectl apply -f - | ||
- assert: | ||
file: enforce-policy-assert.yaml | ||
- apply: | ||
file: good-resource.yaml | ||
- apply: | ||
expect: | ||
- check: | ||
($error != null): true | ||
file: bad-resource.yaml |
11 changes: 11 additions & 0 deletions
11
rbac-best-practices-cel/restrict-binding-system-groups/e2e/enforce-policy-assert.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: kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: restrict-binding-system-groups | ||
spec: | ||
validationFailureAction: Enforce | ||
status: | ||
conditions: | ||
- reason: Succeeded | ||
status: "True" | ||
type: Ready |
77 changes: 77 additions & 0 deletions
77
rbac-best-practices-cel/restrict-binding-system-groups/e2e/good-resource.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,77 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: goodcrb01 | ||
subjects: | ||
- kind: Group | ||
name: secret-reader | ||
apiGroup: rbac.authorization.k8s.io | ||
roleRef: | ||
kind: ClusterRole | ||
name: manager | ||
apiGroup: rbac.authorization.k8s.io | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: goodcrb02 | ||
subjects: | ||
- kind: ServiceAccount | ||
namespace: foo | ||
name: foo-reader | ||
roleRef: | ||
kind: ClusterRole | ||
name: manager | ||
apiGroup: rbac.authorization.k8s.io | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: goodcrb03 | ||
subjects: | ||
- kind: ServiceAccount | ||
namespace: foo | ||
name: "system.foo" | ||
roleRef: | ||
kind: ClusterRole | ||
name: manager | ||
apiGroup: rbac.authorization.k8s.io | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: goodrb01 | ||
subjects: | ||
- kind: User | ||
name: foo | ||
apiGroup: rbac.authorization.k8s.io | ||
roleRef: | ||
kind: Role | ||
name: foo-bar | ||
apiGroup: rbac.authorization.k8s.io | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: goodrb02 | ||
subjects: | ||
- kind: ServiceAccount | ||
name: foo | ||
namespace: foo | ||
roleRef: | ||
kind: Role | ||
name: foo-bar | ||
apiGroup: rbac.authorization.k8s.io | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: goodrb03 | ||
subjects: | ||
- kind: Group | ||
name: "system:foo" | ||
apiGroup: rbac.authorization.k8s.io | ||
roleRef: | ||
kind: Role | ||
name: foo | ||
apiGroup: rbac.authorization.k8s.io |
Oops, something went wrong.