From 33d98eaa3e944ff8bb25b9912ad152178c274a56 Mon Sep 17 00:00:00 2001 From: kfox1111 Date: Tue, 26 Feb 2019 09:37:20 -0800 Subject: [PATCH] Add kube-mgmt to OPA (#10860) * Initial attempt at adding kube-mgmt to the chart Signed-off-by: Kevin Fox * Updated to add auth/imagePullPolicy/rbac Signed-off-by: Kevin Fox * Fix linting issues Signed-off-by: Kevin Fox * Update kube-mgmt image to 0.8. Signed-off-by: Kevin Fox * Add the ability to turn off authz Signed-off-by: Kevin Fox * Add note about authz. Signed-off-by: Kevin Fox * Add in fixes from tsandall Signed-off-by: Kevin Fox --- stable/opa/Chart.yaml | 4 +- stable/opa/templates/NOTES.txt | 20 +++--- stable/opa/templates/_helpers.tpl | 5 ++ stable/opa/templates/deployment.yaml | 68 +++++++++++++++++++ stable/opa/templates/mgmt-clusterrole.yaml | 14 ++++ .../templates/mgmt-clusterrolebinding.yaml | 20 ++++++ stable/opa/values.yaml | 41 ++++++++++- 7 files changed, 160 insertions(+), 12 deletions(-) create mode 100644 stable/opa/templates/mgmt-clusterrole.yaml create mode 100644 stable/opa/templates/mgmt-clusterrolebinding.yaml diff --git a/stable/opa/Chart.yaml b/stable/opa/Chart.yaml index 0d451dc832..254b32c55a 100644 --- a/stable/opa/Chart.yaml +++ b/stable/opa/Chart.yaml @@ -1,12 +1,12 @@ apiVersion: v1 -appVersion: 0.10.1 +appVersion: 0.10.2 description: Open source, general-purpose policy engine. Enforce fine-grained invariants over arbitrary Kubernetes resources. name: opa keywords: - opa - admission control - policy -version: 0.2.0 +version: 0.3.0 home: https://www.openpolicyagent.org icon: https://raw.githubusercontent.com/open-policy-agent/opa/master/logo/logo.png sources: diff --git a/stable/opa/templates/NOTES.txt b/stable/opa/templates/NOTES.txt index 1264bb6da2..c3a596db53 100644 --- a/stable/opa/templates/NOTES.txt +++ b/stable/opa/templates/NOTES.txt @@ -2,14 +2,6 @@ Please wait while the OPA is deployed on your cluster. For example policies that you can enforce with OPA see https://www.openpolicyagent.org. -You can query OPA to see the policies it has loaded: - -export OPA_POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "opa.fullname" . }}" -o jsonpath="{.items[0].metadata.name}") - -kubectl port-forward $OPA_POD_NAME 8080:443 - -curl -k -s https://localhost:8080/v1/policies | jq -r '.result[].raw' - If you installed this chart with the default values, you can exercise the sample policy. # 1. Create a namespace called "opa-example" @@ -53,3 +45,15 @@ spec: EOF kubectl -n opa-example create -f ingress-bad.yaml + +If you want to turn off authz for debugging purposes, you can do so by upgrading the chart like so: +helm upgrade {{ .Release.Name }} stable/opa --reuse-values --set authz.enabled=false + +You can query OPA to see the policies it has loaded (you will need to turn off authz as described above): + +export OPA_POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "opa.fullname" . }}" -o jsonpath="{.items[0].metadata.name}") + +kubectl port-forward $OPA_POD_NAME 8080:443 + +curl -k -s https://localhost:8080/v1/policies | jq -r '.result[].raw' + diff --git a/stable/opa/templates/_helpers.tpl b/stable/opa/templates/_helpers.tpl index 99cdea89e4..69b91ba71b 100644 --- a/stable/opa/templates/_helpers.tpl +++ b/stable/opa/templates/_helpers.tpl @@ -29,6 +29,11 @@ If release name contains chart name it will be used as a full name. {{- printf "%s-sar" $name -}} {{- end -}} +{{- define "opa.mgmtfullname" -}} +{{- $name := (include "opa.fullname" . | trunc 58 | trimSuffix "-") -}} +{{- printf "%s-mgmt" $name -}} +{{- end -}} + {{/* Create chart name and version as used by the chart label. */}} diff --git a/stable/opa/templates/deployment.yaml b/stable/opa/templates/deployment.yaml index 7bea7c6c39..940f3736d1 100644 --- a/stable/opa/templates/deployment.yaml +++ b/stable/opa/templates/deployment.yaml @@ -15,9 +15,32 @@ spec: app: {{ template "opa.fullname" . }} name: {{ template "opa.fullname" . }} spec: +{{- if .Values.authz.enabled }} + initContainers: + - name: initpolicy + image: {{ .Values.mgmt.image }}:{{ .Values.mgmt.imageTag }} + imagePullPolicy: {{ .Values.mgmt.imagePullPolicy }} + command: + - /bin/sh + - -c + - | + tr -dc 'A-F0-9' < /dev/urandom | dd bs=1 count=32 2>/dev/null > /authz/mgmt-token + TOKEN=`cat /authz/mgmt-token` + cat > /authz/authz.rego <