Created
August 17, 2020 15:23
-
-
Save BetterProgramming/d6b5c4f4e3ce44a866a0d94a16c1b7d2 to your computer and use it in GitHub Desktop.
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
cat << EOF | kubectl apply -f - | |
kind: ClusterRoleBinding | |
apiVersion: rbac.authorization.k8s.io/v1 | |
metadata: | |
name: opa-viewer | |
roleRef: | |
kind: ClusterRole | |
name: view | |
apiGroup: rbac.authorization.k8s.io | |
subjects: | |
- kind: Group | |
name: system:serviceaccounts:opa | |
apiGroup: rbac.authorization.k8s.io | |
--- | |
kind: Role | |
apiVersion: rbac.authorization.k8s.io/v1 | |
metadata: | |
namespace: opa | |
name: configmap-modifier | |
rules: | |
- apiGroups: [""] | |
resources: ["configmaps"] | |
verbs: ["update", "patch"] | |
--- | |
kind: RoleBinding | |
apiVersion: rbac.authorization.k8s.io/v1 | |
metadata: | |
namespace: opa | |
name: opa-configmap-modifier | |
roleRef: | |
kind: Role | |
name: configmap-modifier | |
apiGroup: rbac.authorization.k8s.io | |
subjects: | |
- kind: Group | |
name: system:serviceaccounts:opa | |
apiGroup: rbac.authorization.k8s.io | |
--- | |
kind: Service | |
apiVersion: v1 | |
metadata: | |
name: opa | |
namespace: opa | |
spec: | |
selector: | |
app: opa | |
ports: | |
- name: https | |
protocol: TCP | |
port: 443 | |
targetPort: 443 | |
--- | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
labels: | |
app: opa | |
namespace: opa | |
name: opa | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: opa | |
template: | |
metadata: | |
labels: | |
app: opa | |
name: opa | |
spec: | |
containers: | |
- name: opa | |
image: openpolicyagent/opa:latest | |
args: | |
- "run" | |
- "--server" | |
- "--tls-cert-file=/certs/tls.crt" | |
- "--tls-private-key-file=/certs/tls.key" | |
- "--addr=0.0.0.0:443" | |
- "--addr=http://127.0.0.1:8181" | |
- "--log-format=json-pretty" | |
- "--set=decision_logs.console=true" | |
volumeMounts: | |
- readOnly: true | |
mountPath: /certs | |
name: opa-server | |
readinessProbe: | |
httpGet: | |
path: /health?plugins&bundle | |
scheme: HTTPS | |
port: 443 | |
initialDelaySeconds: 3 | |
periodSeconds: 5 | |
livenessProbe: | |
httpGet: | |
path: /health | |
scheme: HTTPS | |
port: 443 | |
initialDelaySeconds: 3 | |
periodSeconds: 5 | |
- name: kube-mgmt | |
image: openpolicyagent/kube-mgmt:0.11 | |
args: | |
- "--replicate-cluster=v1/namespaces" | |
- "--replicate=extensions/v1beta1/ingresses" | |
volumes: | |
- name: opa-server | |
secret: | |
secretName: opa-server | |
--- | |
kind: ConfigMap | |
apiVersion: v1 | |
metadata: | |
name: opa-default-system-main | |
namespace: opa | |
data: | |
main: | | |
package system | |
import data.kubernetes.admission | |
main = { | |
"apiVersion": "admission.k8s.io/v1beta1", | |
"kind": "AdmissionReview", | |
"response": response, | |
} | |
default uid = "" | |
uid = input.request.uid | |
response = { | |
"allowed": false, | |
"uid": uid, | |
"status": { | |
"reason": reason, | |
}, | |
} { | |
reason = concat(", ", admission.deny) | |
reason != "" | |
} | |
else = {"allowed": true, "uid": uid} | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment