Skip to content

Commit

Permalink
Add initial OPA
Browse files Browse the repository at this point in the history
  • Loading branch information
rafzei committed Jan 8, 2022
1 parent c14921f commit 4795c51
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 0 deletions.
15 changes: 15 additions & 0 deletions opa/check-container-user.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package kubernetes.validating.privileged

deny[msg] {
some http-api
input_container[http-api]
http-api.securityContext.privileged
msg := sprintf("Container '%v' should not run in privileged mode.", [http-api.name])
}

input_container[container] {
container := input.request.object.spec.containers[_]
}

input_container[container] {
container := input.request.object.spec.initContainers[_]
1 change: 1 addition & 0 deletions opa/check-serviceaccount.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TODO
51 changes: 51 additions & 0 deletions opa/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: opa
labels:
app: opa
spec:
replicas: 1
selector:
matchLabels:
app: opa
template:
metadata:
labels:
app: opa
name: opa
spec:
containers:
- name: opa
image: openpolicyagent/opa:0.36.0
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 8181
args:
- "run"
- "--ignore=.*" # exclude hidden dirs created by Kubernetes
- "--server"
- "/policies"
volumeMounts:
- readOnly: true
mountPath: /policies/check-container-user
name: check-container-user
livenessProbe:
httpGet:
scheme: HTTP # assumes OPA listens on localhost:8181
port: 8181
initialDelaySeconds: 5 # tune these periods for your environemnt
periodSeconds: 5
readinessProbe:
httpGet:
path: /health?bundle=true # Include bundle activation in readiness
scheme: HTTP
port: 8181
initialDelaySeconds: 5
periodSeconds: 5
resources: # TODO: add CPU and Memory Requirements
volumes:
- name: check-container-user
configMap:
name: check-container-user
28 changes: 28 additions & 0 deletions opa/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
# Source: http-api/templates/ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: opa
labels:
app.kubernetes.io/name: opa
app.kubernetes.io/instance: opa
annotations:
kubernetes.io/ingress.class: nginx
spec:
defaultBackend:
service:
name: opa
port:
number: 8181
rules:
- host: "minikube.local"
http:
paths:
- path: /opa/
pathType: ImplementationSpecific
backend:
service:
name: opa
port:
number: 8181
15 changes: 15 additions & 0 deletions opa/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
kind: Service
apiVersion: v1
metadata:
name: opa
labels:
app: opa
spec:
type: ClusterIP
selector:
app: opa
ports:
- name: http
protocol: TCP
port: 8181
targetPort: 8181

0 comments on commit 4795c51

Please sign in to comment.