Skip to content
This repository was archived by the owner on Jan 8, 2026. It is now read-only.

Commit 2e01e97

Browse files
authored
fix: README.md and some scripts (#36)
1 parent 5f56a68 commit 2e01e97

File tree

4 files changed

+81
-57
lines changed

4 files changed

+81
-57
lines changed

README.md

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,59 @@ Before proceeding, make sure to have the following-
2929

3030
## Configuration and Usage
3131

32-
- Generate the certificates and keys for every user by using openssl and running the following script:-
33-
```
34-
./gen_cert.sh
35-
```
36-
- Export environment variable `CA_BUNDLE`
37-
```
38-
export CA_BUNDLE=$(cat certs/ca.crt | base64 | tr -d '\n')
39-
```
40-
- Use `envsubst` to pass environment variables to `deployment.yaml.template`, generating `deployment.yaml`
41-
```
42-
cat manifests/deployment.yaml.template | envsubst > manifests/deployment.yaml
43-
```
32+
- Generate the certificates and keys for every user by using openssl and running the following script:
4433

34+
If you are on a Linux system, you can execute shell scripts directly
35+
```
36+
./gen_cert.sh
37+
```
38+
If you are on a Windows system, executing `./gen_cert.sh` can be problematic, especially if you are using `Git Bash`
39+
Follow the steps below:
40+
```
41+
# Do not use Git Bash to execute these commands (You can use cmd)
42+
43+
openssl genrsa -out certs/ca.key 2048
44+
45+
openssl req -new -x509 -key certs/ca.key -out certs/ca.crt
46+
47+
openssl genrsa -out certs/casbin-key.pem 2048
48+
49+
openssl req -new -key certs/casbin-key.pem -subj "/CN=casbin.default.svc" -out casbin.csr
50+
51+
openssl x509 -req -in casbin.csr -CA certs/ca.crt -CAkey certs/ca.key -CAcreateserial -out certs/casbin-crt.pem
52+
53+
# You can use Git Bash to execute the following command, or you can use other equivalent methods
54+
55+
export CA_BUNDLE=$(cat certs/ca.crt | base64 | tr -d '\n')
56+
57+
cat manifests/ValidatingWebhookConf.yaml.template | envsubst > manifests/ValidatingWebhookConf.yaml
58+
```
4559
46-
- Build the docker image from the [Dockerfile](https://github.com/casbin/k8s-authz/blob/master/Dockerfile) manually by running the following command and then change the build version here and at the deployment [file](https://github.com/casbin/k8s-authz/blob/718f58c46e3dbf79063b5b1c18348c2fee5de9e9/manifests/deployment.yaml#L18), as per the builds.
47-
```
48-
docker build -t casbin/k8s_authz:latest .
49-
```
60+
- For a production server, we need to create a k8s `secret` to place the certificates for security purposes.
61+
```
62+
kubectl create secret generic authz -n default \
63+
--from-file=key.pem=certs/casbin-key.pem \
64+
--from-file=cert.pem=certs/casbin-crt.pem
65+
```
66+
- Once, this part is done we need to change the directory of the certs in [main.go](https://github.com/ashish493/k8s-authz/blob/3560551427c0431a9d4594ad1206f084ede37c49/main.go#L26) and then in [manifests](https://github.com/ashish493/k8s-authz/blob/3560551427c0431a9d4594ad1206f084ede37c49/manifests/deployment.yaml#L22) with that of the `secret`.
67+
68+
- Build the docker image from the [Dockerfile](https://github.com/casbin/k8s-authz/blob/master/Dockerfile) manually by running the following command and then change the build version here and at the deployment [file](https://github.com/casbin/k8s-authz/blob/718f58c46e3dbf79063b5b1c18348c2fee5de9e9/manifests/deployment.yaml#L18), as per the builds.
69+
```
70+
docker build -t casbin/k8s_authz:latest .
71+
```
72+
5073
- Define the casbin policies in the [model.conf](https://github.com/casbin/k8s-authz/blob/master/config/model.conf) and [policy.csv](https://github.com/casbin/k8s-authz/blob/master/config/policy.csv). You can refer the [docs](https://casbin.org/docs/how-it-works) to get to know more about the working of these policies.
5174
5275
- Before deploying, you can change the ports in [main.go](https://github.com/casbin/k8s-authz/blob/master/main.go) and also in the validation webhook configuration [file](https://github.com/casbin/k8s-authz/blob/master/manifests/deployment.yaml) depending on your usage.
53-
- Deploy the validation controller and the webhook on k8s cluster by running:-
54-
```
55-
kubectl apply -f manifests/deployment.yaml
56-
```
57-
- For a production server, we need to create a k8s `secret` to place the certificates for security purposes.
58-
```
59-
kubectl create secret generic casbin -n default \
60-
--from-file=key.pem=certs/casbin-key.pem \
61-
--from-file=cert.pem=certs/casbin-crt.pem
62-
```
63-
- Once, this part is done we need to change the directory of the certs in [main.go](https://github.com/ashish493/k8s-authz/blob/3560551427c0431a9d4594ad1206f084ede37c49/main.go#L26) and then in [manifests](https://github.com/ashish493/k8s-authz/blob/3560551427c0431a9d4594ad1206f084ede37c49/manifests/deployment.yaml#L22) with that of the `secret`.
76+
77+
- Deploy the validation controller and the webhook on k8s cluster by running:
78+
```
79+
kubectl apply -f manifests/deployment.yaml
80+
81+
# Wait for Deployment Ready
82+
83+
kubectl apply -f manifests/ValidatingWebhookConf.yaml
84+
```
6485

6586
Now the server should be running and ready to validate the requests for the operations on the pods.
6687

gen_cert.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ set -o pipefail
66

77
openssl genrsa -out certs/ca.key 2048
88

9-
openssl req -new -x509 -key certs/ca.key -out certs/ca.crt
9+
openssl req -new -x509 -key certs/ca.key -out certs/ca.crt
1010

1111
openssl genrsa -out certs/casbin-key.pem 2048
1212

13-
openssl req -new -key certs/casbin-key.pem -subj "/CN=casbin.default.svc" -out casbin.csr
13+
openssl req -new -key certs/casbin-key.pem -subj "/CN=casbin.default.svc" -out casbin.csr
1414

15-
openssl x509 -req -in casbin.csr -CA certs/ca.crt -CAkey certs/ca.key -CAcreateserial -out certs/casbin-crt.pem
15+
openssl x509 -req -in casbin.csr -CA certs/ca.crt -CAkey certs/ca.key -CAcreateserial -out certs/casbin-crt.pem
16+
17+
export CA_BUNDLE=$(cat certs/ca.crt | base64 | tr -d '\n')
18+
19+
cat manifests/ValidatingWebhookConf.yaml.template | envsubst > manifests/ValidatingWebhookConf.yaml
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: admissionregistration.k8s.io/v1
2+
kind: ValidatingWebhookConfiguration
3+
metadata:
4+
name: casbin
5+
webhooks:
6+
- name: webhook.casbin.org
7+
clientConfig:
8+
service:
9+
name: casbin
10+
namespace: default
11+
path: "/validate"
12+
caBundle: "${CA_BUNDLE}"
13+
rules:
14+
- operations: ["*"]
15+
apiGroups: [""]
16+
apiVersions: ["v1"]
17+
resources: ["*/*"]
18+
failurePolicy: Fail
19+
admissionReviewVersions: ["v1"]
20+
sideEffects: None
Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ spec:
1818
spec:
1919
containers:
2020
- name: webhook
21-
image: k8s_authz:latest
22-
imagePullPolicy: Always
21+
image: casbin/k8s_authz:latest
22+
imagePullPolicy: IfNotPresent
2323
volumeMounts:
2424
- name: webhook-certs
2525
mountPath: certs
@@ -44,29 +44,8 @@ metadata:
4444
name: casbin
4545
spec:
4646
ports:
47-
- name: webhook
48-
port: 443
49-
targetPort: 8080
47+
- name: webhook
48+
port: 443
49+
targetPort: 8080
5050
selector:
51-
name: casbin
52-
---
53-
apiVersion: admissionregistration.k8s.io/v1
54-
kind: ValidatingWebhookConfiguration
55-
metadata:
56-
name: casbin
57-
webhooks:
58-
- name: webhook.casbin.org
59-
clientConfig:
60-
service:
61-
name: casbin
62-
namespace: default
63-
path: "/validate"
64-
caBundle: "${CA_BUNDLE}"
65-
rules:
66-
- operations: ["*"]
67-
apiGroups: [""]
68-
apiVersions: ["v1"]
69-
resources: ["*/*"]
70-
failurePolicy: Fail
71-
admissionReviewVersions: ["v1"]
72-
sideEffects: None
51+
name: casbin

0 commit comments

Comments
 (0)