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

feat: NDEV-19285-convert-rbac-best-practices-to-cel-policies #140

Merged
merged 22 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b889a51
NDEV-19285 copy restrict-binding-system-groups
Chandan-DK Jun 6, 2024
d67c88e
NDEV-19285 convert restrict-binding-system-groups
Chandan-DK Jun 6, 2024
0269a63
NDEV-19285 copy restrict-clusterrole-nodesproxy
Chandan-DK Jun 6, 2024
42107d6
NDEV-19285 convert restrict-clusterrole-nodesproxy
Chandan-DK Jun 6, 2024
4a3ec67
NDEV-19285 test edge cases for restrict-clusterrole-nodesproxy
Chandan-DK Jun 6, 2024
42149b4
NDEV-19285 copy restrict-escalation-verbs-roles
Chandan-DK Jun 6, 2024
d8d50be
NDEV-19285 add case where rules is null in restrict-clusterrole-nodes…
Chandan-DK Jun 6, 2024
f009ec0
NDEV-19285 convert restrict-escalation-verbs-roles
Chandan-DK Jun 6, 2024
9057260
NDEV-19285 test edge cases for restrict-escalation-verbs-roles
Chandan-DK Jun 6, 2024
7de6a90
NDEV-19285 copy restrict-wildcard-resources
Chandan-DK Jun 6, 2024
2ed34b7
NDEV-19285 convert restrict-wildcard-resources
Chandan-DK Jun 6, 2024
c012a2c
NDEV-19285 rename roles and add extra cases for restrict-wildcard-res…
Chandan-DK Jun 6, 2024
b8b7029
NDEV-19285 rename roles for clarity
Chandan-DK Jun 6, 2024
1538c24
NDEV-19285 add vap tests for restrict-binding-system-groups
Chandan-DK Jun 7, 2024
393d182
NDEV-19285 add vap tests for restrict-clusterrole-nodesproxy
Chandan-DK Jun 7, 2024
36613f6
NDEV-19285 add vap tests for restrict-escalation-verbs-roles
Chandan-DK Jun 7, 2024
80fbb52
NDEV-19285 add vap tests for restrict-wildcard-resources
Chandan-DK Jun 7, 2024
1e3a8fc
NDEV-19285 add vap tests in workflow
Chandan-DK Jun 7, 2024
3543cfa
Merge branch 'main' into NDEV-19285-convert-rbac-best-practices-to-ce…
Chandan-DK Jun 7, 2024
991ee0f
Merge branch 'main' into NDEV-19285-convert-rbac-best-practices-to-ce…
anusha94 Jun 17, 2024
102dde4
exclude cel folders in chainsaw tests for kyverno version 1.10
Chandan-DK Jun 18, 2024
7180f6f
Merge branch 'main' into NDEV-19285-convert-rbac-best-practices-to-ce…
nsathyaseelan Jun 18, 2024
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
18 changes: 18 additions & 0 deletions .github/scripts/config/helm/values-vap.yaml
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
9 changes: 9 additions & 0 deletions .github/scripts/config/kind/vap-v1alpha1.yaml
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
10 changes: 10 additions & 0 deletions .github/scripts/config/kind/vap-v1beta1.yaml
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
68 changes: 67 additions & 1 deletion .github/workflows/chainsaw-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ USE_CONFIG ?= standard
TOOLS_DIR := $(PWD)/.tools
KIND := $(TOOLS_DIR)/kind
KIND_VERSION := v0.22.0
KIND_VAP_ALPHA_CONFIG := $(PWD)/.github/scripts/config/kind/vap-v1alpha1.yaml
KIND_VAP_BETA_CONFIG := $(PWD)/.github/scripts/config/kind/vap-v1beta1.yaml
HELM_VALUES_VAP := $(PWD)/.github/scripts/config/helm/values-vap.yaml
HELM := $(TOOLS_DIR)/helm
HELM_VERSION := v3.10.1
TOOLS := $(KIND) $(HELM)
Expand Down Expand Up @@ -37,12 +40,34 @@ test-chainsaw:
@echo Running chainsaw tests... >&2
@chainsaw test --config .chainsaw-config.yaml

.PHONY: test-chainsaw-exclude-cel
test-chainsaw-exclude-cel:
@echo Running chainsaw tests by excluding CEL folders... >&2
@chainsaw test --config .chainsaw-config.yaml --exclude-test-regex 'chainsaw/.*-cel'

.PHONY: test-chainsaw-vap
test-chainsaw-vap:
@echo Running chainsaw tests for VAPs... >&2
@chainsaw test --config .chainsaw-config.yaml --test-file chainsaw-test-vap.yaml

## Create kind cluster
.PHONY: kind-create-cluster
kind-create-cluster: $(KIND)
@echo Create kind cluster... >&2
@$(KIND) create cluster --name $(KIND_NAME) --image $(KIND_IMAGE)

## Create kind cluster with alpha VAP enabled
.PHONY: kind-create-cluster-vap-alpha
kind-create-cluster-vap-alpha: $(KIND)
@echo Create kind cluster... >&2
@$(KIND) create cluster --name $(KIND_NAME) --image $(KIND_IMAGE) --config $(KIND_VAP_ALPHA_CONFIG)

## Create kind cluster with beta VAP enabled
.PHONY: kind-create-cluster-vap-beta
kind-create-cluster-vap-beta: $(KIND)
@echo Create kind cluster... >&2
@$(KIND) create cluster --name $(KIND_NAME) --image $(KIND_IMAGE) --config $(KIND_VAP_BETA_CONFIG)

## Delete kind cluster
.PHONY: kind-delete-cluster
kind-delete-cluster: $(KIND)
Expand All @@ -57,6 +82,14 @@ kind-deploy-kyverno: $(HELM)
@$(HELM) repo update
@$(HELM) install kyverno nirmata/kyverno -n kyverno --create-namespace --version=$(N4K_VERSION)

## Deploy Enterprise Kyverno with VAP generation enabled
.PHONY: kind-deploy-kyverno-vap
kind-deploy-kyverno-vap: $(HELM)
@echo Install kyverno chart... >&2
@$(HELM) repo add nirmata https://nirmata.github.io/kyverno-charts
@$(HELM) repo update
@$(HELM) install kyverno nirmata/kyverno -n kyverno --create-namespace --version=$(N4K_VERSION) --values=$(HELM_VALUES_VAP)

## Check Kyverno status
.PHONY: wait-for-kyverno
wait-for-kyverno:
Expand Down
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
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
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
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
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
Loading
Loading