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

Monokle policies as CRDs #1

Merged
merged 26 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e86aede
feat: add basic policy CRDs
f1ames Sep 1, 2023
474756f
chore: add test script for CRDs informer
f1ames Sep 4, 2023
ecbce85
feat: integrate policy CRDs into webhook [WIP]
f1ames Sep 6, 2023
b1b7b3d
feat: integrate policy CRDs into webhook
f1ames Sep 25, 2023
404ab26
fix: fix deployment script for local testing
f1ames Sep 25, 2023
28a1b30
fix: read namespace name from within webhook pod
f1ames Sep 26, 2023
c7b92b0
refactor: improve logging and cleanup code
f1ames Sep 26, 2023
a723b2e
chore: update README file
f1ames Sep 27, 2023
7cc0f97
refactor: rework project structure
f1ames Sep 27, 2023
f4cbd76
fix: add minor code adjustements
f1ames Sep 27, 2023
80249e1
fix: rework admission controller webhook to not be namespace bound
f1ames Sep 27, 2023
6f908b3
feat: introduce MonoklePolicyBinding [WIP]
f1ames Sep 28, 2023
e65bf62
refactor: draft ValidatorManager class
f1ames Sep 28, 2023
e6ce712
refactor: add support for policy binding [WIP]
f1ames Sep 29, 2023
13a9515
fix: fix policy binding CRD schema
f1ames Sep 29, 2023
15b48d3
feat: add namespace filtering
f1ames Oct 2, 2023
bf7b56f
refactor: deploy admission controller to dedicated namespace
f1ames Oct 2, 2023
7da3da5
fix: move ignored namespace check to very beginning of webhook handler
f1ames Oct 2, 2023
9d64438
feat: Send k8s warnings on 'Warn' action
f1ames Oct 2, 2023
579a0b3
fix: make admission controller match all resource kinds
f1ames Oct 3, 2023
db7a2c8
fix: mark specific fields as required in Monokle CRDs
f1ames Oct 3, 2023
4bd6a00
chore: cleanup outdated comments
f1ames Oct 3, 2023
d959809
fix: use wildcard for webhook scope by default
f1ames Oct 3, 2023
586aeed
feat: block resource-link plugin
f1ames Oct 3, 2023
32378af
chore: fix imports
f1ames Oct 3, 2023
7b86f83
fix: fix routing initialization
f1ames Oct 3, 2023
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
60 changes: 58 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ validatingwebhookconfiguration.admissionregistration.k8s.io/demo-webhook 1
You can try to create sample resource and see webhook response:

```bash
kubectl -n webhook-demo create -f examples/pod-with-conflict.yaml
kubectl -n webhook-demo create -f examples/pod-warning.yaml
```

### Iterating
Expand All @@ -70,9 +70,65 @@ skaffold dev

**Important**: Skaffold will recreate deployment on every change so make sure that webhook pod doesn't get rejected by it's previous version (via Validation Admission Controller).

You can also do manual clean-up and run `./deploy.sh` script again:

```bash
kubectl delete all -n webhook-demo --all && \
kubectl delete validatingwebhookconfiguration.admissionregistration.k8s.io/demo-webhook -n webhook-demo && \
kubectl delete namespace webhook-demo && \
kubectl delete crd monoklepolicies.monokle.com
```

## Refs

* https://kubernetes.io/blog/2019/03/21/a-guide-to-kubernetes-admission-controllers/
* https://github.com/stackrox/admission-controller-webhook-demo/tree/master
* https://www.witodelnat.eu/blog/2021/local-kubernetes-development
* https://minikube.sigs.k8s.io/docs/tutorials/using_psp/
* https://minikube.sigs.k8s.io/docs/tutorials/using_psp/

## Policy as CRDs

> https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/
> https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/

1. Start minikube.
1. Apply resource definition:

```bash
kubectl apply -f monokle.policy.crd.yaml
```

3. Test if it was applied correctly:

```bash
kubectl get crd
kubectl get monoklepolicy
kubectl describe crd monoklepolicies.monokle.com
```

4. Create sample policy resource:

```bash
kubectl apply -f policy.yaml
```

5. Test if it was applied correctly:

```bash
kubectl get monoklepolicy
kubectl describe monoklepolicy policy-sample
```

### CRDs Informer

You can test how watching CRDs changes works by running:

```bash
node kac-api/scripts/list-policies.js
```

and (re)applying sample policy:

```bash
kubectl apply -f policy.yaml
```
2 changes: 2 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ cp deployment/deployment.yaml.template deployment.yaml
skaffold run --namespace webhook-demo
# kubectl apply -f deployment.yaml
sleep 2
kubectl apply -f monokle.policy.crd.yaml
sleep 2
kubectl apply -f webhook.yaml

# skaffold dev
Expand Down
25 changes: 24 additions & 1 deletion deployment/webhook.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,27 @@ webhooks:
- operations: [ "CREATE" ]
apiGroups: [""]
apiVersions: ["v1"]
resources: ["pods"]
resources: ["pods"]
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: crds-monokle-list
rules:
- apiGroups: ["monokle.com"]
resources: ["monoklepolicies"]
verbs: ["list", "watch", "get"]

---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: crds-monokle-list
subjects:
- kind: ServiceAccount
name: default
namespace: webhook-demo
roleRef:
kind: ClusterRole
name: crds-monokle-list
apiGroup: rbac.authorization.k8s.io
Loading