Skip to content

Commit 823727d

Browse files
committed
working OPA deployment
1 parent 7ed8100 commit 823727d

File tree

10 files changed

+92
-125
lines changed

10 files changed

+92
-125
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Grant OPA/kube-mgmt read-only access to resources. This lets kube-mgmt
2+
# replicate resources into OPA so they can be used in policies.
3+
kind: ClusterRoleBinding
4+
apiVersion: rbac.authorization.k8s.io/v1
5+
metadata:
6+
name: opa-viewer
7+
roleRef:
8+
kind: ClusterRole
9+
name: view
10+
apiGroup: rbac.authorization.k8s.io
11+
subjects:
12+
- kind: Group
13+
name: system:serviceaccounts:opa
14+
apiGroup: rbac.authorization.k8s.io
15+
---
16+
# Define role for OPA/kube-mgmt to update configmaps with policy status.
17+
kind: Role
18+
apiVersion: rbac.authorization.k8s.io/v1
19+
metadata:
20+
name: configmap-modifier
21+
rules:
22+
- apiGroups: [""]
23+
resources: ["configmaps"]
24+
verbs: ["update", "patch"]
25+
---
26+
# Grant OPA/kube-mgmt role defined above.
27+
kind: RoleBinding
28+
apiVersion: rbac.authorization.k8s.io/v1
29+
metadata:
30+
name: opa-configmap-modifier
31+
roleRef:
32+
kind: Role
33+
name: configmap-modifier
34+
apiGroup: rbac.authorization.k8s.io
35+
subjects:
36+
- kind: Group
37+
name: system:serviceaccounts:opa
38+
apiGroup: rbac.authorization.k8s.io
Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,56 @@
1-
---
2-
# Source: opa/templates/deployment.yaml
31
apiVersion: apps/v1
42
kind: Deployment
53
metadata:
6-
name: opa
74
labels:
85
app: opa
9-
chart: "opa-2.0.0"
10-
release: "opa"
11-
heritage: "Helm"
6+
name: opa
127
spec:
138
replicas: 1
149
selector:
1510
matchLabels:
1611
app: opa
1712
template:
1813
metadata:
19-
annotations:
20-
checksum/certs: 8b0af3ffc1e4a45847580d3650728057e5aba2869d5bf9f51780777916e801f7
2114
labels:
2215
app: opa
2316
name: opa
2417
spec:
2518
containers:
2619
- name: opa
27-
ports:
28-
- name: https
29-
containerPort: 443
30-
image: openpolicyagent/opa:0.32.1
31-
imagePullPolicy: IfNotPresent
32-
resources:
33-
{}
20+
image: openpolicyagent/opa:0.32.0-rootless
3421
args:
3522
- "run"
3623
- "--server"
3724
- "--tls-cert-file=/certs/tls.crt"
3825
- "--tls-private-key-file=/certs/tls.key"
39-
- "--addr=0.0.0.0:443"
40-
- "--log-level=info"
41-
- "--log-format=json"
26+
- "--addr=0.0.0.0:8443"
27+
- "--addr=http://127.0.0.1:8181"
28+
- "--log-format=json-pretty"
29+
- "--set=decision_logs.console=true"
4230
volumeMounts:
43-
- name: certs
44-
readOnly: true
31+
- readOnly: true
4532
mountPath: /certs
33+
name: opa-server
4634
readinessProbe:
4735
httpGet:
48-
path: /health
36+
path: /health?plugins&bundle
4937
scheme: HTTPS
50-
port: 443
51-
initialDelaySeconds: 5
52-
periodSeconds: 10
38+
port: 8443
39+
initialDelaySeconds: 3
40+
periodSeconds: 5
5341
livenessProbe:
5442
httpGet:
5543
path: /health
5644
scheme: HTTPS
57-
port: 443
58-
initialDelaySeconds: 10
59-
periodSeconds: 15
60-
- name: sarproxy
61-
image: lachlanevenson/k8s-kubectl:latest
62-
imagePullPolicy: IfNotPresent
63-
resources:
64-
{}
65-
command:
66-
- kubectl
67-
- proxy
68-
- --accept-paths=^/apis/authorization.k8s.io/v1/subjectaccessreviews$
69-
serviceAccountName: opa
45+
port: 8443
46+
initialDelaySeconds: 3
47+
periodSeconds: 5
48+
- name: kube-mgmt
49+
image: openpolicyagent/kube-mgmt:0.11
50+
args:
51+
- "--replicate-cluster=v1/namespaces"
52+
- "--replicate=extensions/v1beta1/ingresses"
7053
volumes:
71-
- name: certs
54+
- name: opa-server
7255
secret:
73-
secretName: opa-cert
74-
affinity:
75-
{}
76-
nodeSelector:
77-
{}
78-
tolerations:
79-
[]
56+
secretName: opa-server

examples/multi-tenacy/open-policy-agent/kustomization.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ kind: Kustomization
33
namespace: opa
44
resources:
55
- namespace.yaml
6-
- sar-clusterrole.yaml
7-
- sar-clusterrolebinding.yaml
8-
- serviceaccount.yaml
6+
- clusterrolebinding.yaml
7+
- opa-server.yaml
98
- service.yaml
10-
- webhookconfiguration.yaml
119
- deployment.yaml
1210

1311
configMapGenerator:

examples/multi-tenacy/open-policy-agent/sar-clusterrole.yaml

Lines changed: 0 additions & 19 deletions
This file was deleted.

examples/multi-tenacy/open-policy-agent/sar-clusterrolebinding.yaml

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
---
2-
# Source: opa/templates/service.yaml
31
kind: Service
42
apiVersion: v1
53
metadata:
64
name: opa
7-
labels:
8-
app: opa
9-
chart: "opa-2.0.0"
10-
release: "opa"
11-
heritage: "Helm"
125
spec:
136
selector:
147
app: opa
158
ports:
16-
- name: https
17-
protocol: TCP
18-
port: 443
19-
targetPort: 443
9+
- name: https
10+
protocol: TCP
11+
port: 443
12+
targetPort: 8443

examples/multi-tenacy/open-policy-agent/serviceaccount.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.

examples/multi-tenacy/open-policy-agent/webhookconfiguration.yaml

Lines changed: 0 additions & 15 deletions
This file was deleted.

resources/opa/generate_certs.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
openssl genrsa -out ca.key 2048
4+
openssl req -x509 -new -nodes -key ca.key -days 100000 -out ca.crt -subj "/CN=admission_ca"
5+
6+
openssl genrsa -out server.key 2048
7+
openssl req -new -key server.key -out server.csr -config server.conf
8+
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 100000 -extensions v3_req -extfile server.conf
9+
10+
kubectl create secret tls opa-server \
11+
--dry-run=client \
12+
--cert=server.crt \
13+
--key=server.key -o yaml > ../../examples/multi-tenacy/open-policy-agent/opa-server.yaml

resources/opa/server.conf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[req]
2+
req_extensions = v3_req
3+
distinguished_name = req_distinguished_name
4+
prompt = no
5+
[req_distinguished_name]
6+
CN = opa.opa.svc
7+
[ v3_req ]
8+
basicConstraints = CA:FALSE
9+
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
10+
extendedKeyUsage = clientAuth, serverAuth
11+
subjectAltName = @alt_names
12+
[alt_names]
13+
DNS.1 = opa.opa.svc

0 commit comments

Comments
 (0)