├── .dockerignore ├── test ├── e2e │ ├── upd.sh │ ├── k3d.yaml │ ├── deploy.sh │ ├── test.sh │ ├── data.json │ └── rbac.rego └── linter │ ├── values-entries.yaml │ └── test.sh ├── .gitignore ├── Chart.yaml ├── .editorconfig ├── templates ├── secret-envsecrets.yaml ├── service-server.yaml ├── service-pgsql.yaml ├── service-client.yaml ├── cm.yaml ├── tests │ └── e2e.yaml ├── deployment-pgsql.yaml ├── _utils.tpl ├── deployment-client.yaml └── deployment-server.yaml ├── .release-it.json ├── .helmignore ├── .github └── workflows │ ├── master.yaml │ └── release.yaml ├── values.yaml ├── README.md ├── values.schema.json └── LICENSE /.dockerignore: -------------------------------------------------------------------------------- 1 | venv 2 | *.json 3 | *.yaml 4 | .github 5 | .git 6 | *.adoc 7 | .editorconfig 8 | .gitignore 9 | .helmignore 10 | -------------------------------------------------------------------------------- /test/e2e/upd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cd /opt/e2e/policy-repo-working 4 | 5 | sed -i 's/users/losers/g' data.json 6 | 7 | git commit -am 'chore: update' 8 | git push 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | venv 2 | CHANGELOG.md 3 | *.tgz 4 | node_modules 5 | package-lock.json 6 | package.json 7 | .idea 8 | values-dev.yaml 9 | README.md 10 | __pycache__ 11 | install.sh 12 | 13 | -------------------------------------------------------------------------------- /Chart.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v2 2 | name: opal 3 | type: application 4 | icon: https://www.opal.ac/icons/icon-192x192.png 5 | version: 0.0.0 # actual chart version is managed by git tags 6 | kubeVersion: ">= 1.18.0-0" 7 | appVersion: 0.7.12 8 | -------------------------------------------------------------------------------- /test/linter/values-entries.yaml: -------------------------------------------------------------------------------- 1 | imageRegistry: docker.io 2 | imagePullSecrets: 3 | - name: my_awesome_secret 4 | 5 | server: 6 | dataConfigSources: 7 | config: 8 | entries: 9 | - url: "111" 10 | - url: "222" 11 | 12 | client: null 13 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | charset = utf-8 6 | insert_final_newline = true 7 | trim_trailing_whitespace = true 8 | indent_style = space 9 | indent_size=2 10 | 11 | [*.py] 12 | indent_size = 4 13 | 14 | [README.adoc] 15 | max_line_length = 120 16 | -------------------------------------------------------------------------------- /templates/secret-envsecrets.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.server.policyRepoSshKey }} 2 | apiVersion: v1 3 | kind: Secret 4 | metadata: 5 | name: {{ include "opal.envSecretsName" . }} 6 | type: Opaque 7 | data: 8 | OPAL_POLICY_REPO_SSH_KEY: {{ .Values.server.policyRepoSshKey | replace "\n" "_" | b64enc }} 9 | {{- end }} 10 | -------------------------------------------------------------------------------- /test/linter/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | helm lint . --strict 4 | helm lint . --strict --set server=null 5 | helm lint . --strict --set client=null 6 | helm lint . --strict --set server.broadcastUri=zzz --set server.broadcastPgsql=true 7 | helm lint . --strict --set server.broadcastPgsql=true 8 | helm lint . --strict -f test/linter/values-entries.yaml 9 | -------------------------------------------------------------------------------- /.release-it.json: -------------------------------------------------------------------------------- 1 | { 2 | "ci": true, 3 | "git": { 4 | "requireBranch": "master", 5 | "requireCommits": true, 6 | "commit": false, 7 | "tagAnnotation": "chore: release ${version}" 8 | }, 9 | "npm": false, 10 | "github": { 11 | "release": true 12 | }, 13 | "plugins": { 14 | "@release-it/conventional-changelog": { 15 | "preset": "conventionalcommits" 16 | } 17 | }, 18 | "hooks": { 19 | "after:release": "echo ${version} > /tmp/opal.version" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /test/e2e/k3d.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: k3d.io/v1alpha4 2 | kind: Simple 3 | metadata: 4 | name: k3d 5 | image: rancher/k3s:v1.28.8-k3s1 6 | options: 7 | k3d: 8 | wait: true 9 | disableLoadbalancer: true 10 | k3s: 11 | extraArgs: 12 | - arg: --disable=metrics-server 13 | nodeFilters: 14 | - server:* 15 | - arg: --disable=servicelb 16 | nodeFilters: 17 | - server:* 18 | - arg: --disable=traefik 19 | nodeFilters: 20 | - server:* 21 | -------------------------------------------------------------------------------- /templates/service-server.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.server }} 2 | {{- if ne .Values.server.enabled false }} 3 | apiVersion: v1 4 | kind: Service 5 | metadata: 6 | name: {{ include "opal.serverName" . | quote }} 7 | labels: 8 | {{- include "opal.serverLabels" . | nindent 4 }} 9 | spec: 10 | type: ClusterIP 11 | ports: 12 | - name: http 13 | port: {{ .Values.server.port }} 14 | targetPort: http 15 | protocol: TCP 16 | selector: 17 | {{- include "opal.serverSelectorLabels" . | nindent 4 }} 18 | {{- end }} 19 | {{- end }} 20 | -------------------------------------------------------------------------------- /templates/service-pgsql.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.server }} 2 | {{- if and .Values.server.broadcastPgsql (not .Values.server.broadcastUri) }} 3 | apiVersion: v1 4 | kind: Service 5 | metadata: 6 | name: {{ include "opal.pgsqlName" . | quote }} 7 | labels: 8 | {{- include "opal.pgsqlLabels" . | nindent 4 }} 9 | spec: 10 | type: ClusterIP 11 | ports: 12 | - name: pgsql 13 | port: 5432 14 | targetPort: pgsql 15 | protocol: TCP 16 | selector: 17 | {{- include "opal.pgsqlSelectorLabels" . | nindent 4 }} 18 | {{- end }} 19 | {{- end }} 20 | -------------------------------------------------------------------------------- /test/e2e/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -x 4 | set -e 5 | 6 | if [ -z $MSYSTEM ]; then 7 | helm upgrade --install --wait --create-namespace -n opal myopal . \ 8 | --set e2e=true --set server.pollingInterval=5 \ 9 | --set server.policyRepoUrl='/opt/e2e/policy-repo.git' 10 | else 11 | helm upgrade --install --wait --create-namespace -n opal myopal . \ 12 | --set e2e=true --set server.pollingInterval=5 \ 13 | --set server.policyRepoUrl='//opt/e2e/policy-repo.git' 14 | fi 15 | 16 | kubectl logs -n opal service/myopal-opal-server git-init 17 | -------------------------------------------------------------------------------- /templates/service-client.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.client }} 2 | {{- if ne .Values.client.enabled false }} 3 | apiVersion: v1 4 | kind: Service 5 | metadata: 6 | name: {{ include "opal.clientName" . }} 7 | labels: 8 | {{- include "opal.clientLabels" . | nindent 4 }} 9 | spec: 10 | type: ClusterIP 11 | ports: 12 | - name: http 13 | port: {{ .Values.client.port }} 14 | targetPort: http 15 | protocol: TCP 16 | - name: opa 17 | port: {{ .Values.client.opaPort }} 18 | targetPort: opa 19 | protocol: TCP 20 | selector: 21 | {{- include "opal.clientSelectorLabels" . | nindent 4 }} 22 | 23 | {{- end }} 24 | {{- end }} 25 | -------------------------------------------------------------------------------- /templates/cm.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.e2e }} 2 | apiVersion: v1 3 | kind: ConfigMap 4 | metadata: 5 | name: policy-repo-data 6 | data: 7 | upd.sh: | 8 | {{- .Files.Get "test/e2e/upd.sh" | nindent 4 }} 9 | data.json: | 10 | {{- .Files.Get "test/e2e/data.json" | nindent 4 }} 11 | rbac.rego: | 12 | {{- .Files.Get "test/e2e/rbac.rego" | nindent 4 }} 13 | {{- end }} 14 | --- 15 | {{- if .Values.client }} 16 | {{- if .Values.client.opaStartupData }} 17 | apiVersion: v1 18 | kind: ConfigMap 19 | metadata: 20 | name: opa-startup-data 21 | data: 22 | {{- range $name, $value := .Values.client.opaStartupData }} 23 | {{ $name }}: | 24 | {{ $value | nindent 4 }} 25 | {{- end }} 26 | {{- end }} 27 | {{- end }} 28 | -------------------------------------------------------------------------------- /.helmignore: -------------------------------------------------------------------------------- 1 | # Patterns to ignore when building packages. 2 | # This supports shell glob matching, relative path matching, and 3 | # negation (prefixed with !). Only one pattern per line. 4 | .DS_Store 5 | # Common VCS dirs 6 | .git/ 7 | .gitignore 8 | .bzr/ 9 | .bzrignore 10 | .hg/ 11 | .hgignore 12 | .svn/ 13 | # Common backup files 14 | *.swp 15 | *.bak 16 | *.tmp 17 | *.orig 18 | *~ 19 | # Various IDEs 20 | .project 21 | .idea/ 22 | *.tmproj 23 | .vscode/ 24 | 25 | venv 26 | *.tgz 27 | .github 28 | *.py 29 | *.adoc 30 | *.txt 31 | .release-it.json 32 | *.adoc 33 | skaffold.yaml 34 | values-lint.yaml 35 | node_modules 36 | README.adoc 37 | package-lock.json 38 | *.puml 39 | .editorconfig 40 | .dockerignore 41 | cmak2zk/ 42 | 43 | -------------------------------------------------------------------------------- /templates/tests/e2e.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.client }} 2 | {{- $url := printf "http://%v:%v/v1/data" (include "opal.clientName" .) .Values.client.opaPort -}} 3 | apiVersion: v1 4 | kind: Pod 5 | metadata: 6 | name: opal-e2e 7 | annotations: 8 | "helm.sh/hook": test 9 | "helm.sh/hook-delete-policy": before-hook-creation 10 | spec: 11 | restartPolicy: Never 12 | containers: 13 | - name: e2e 14 | image: "apteno/alpine-jq:2021-04-25" 15 | command: 16 | - '/bin/sh' 17 | - '-c' 18 | - | 19 | set -x 20 | set -e 21 | 22 | sleep 15 23 | 24 | [ "$(curl -s {{ $url }} | jq '.result.users | keys | length')" -eq 3 ] 25 | [ "$(curl -s {{ $url }} | jq '.result.role_permissions | keys | length')" -eq 3 ] 26 | {{- end }} 27 | -------------------------------------------------------------------------------- /.github/workflows/master.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - master 7 | push: 8 | branches: 9 | - master 10 | 11 | jobs: 12 | ci_job: 13 | name: Continous integration 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v2 17 | - uses: azure/setup-helm@v1 18 | with: 19 | version: "3.19.0" 20 | - name: helm lint 21 | run: | 22 | jq --version 23 | ./test/linter/test.sh 24 | - name: start k8s with k3d 25 | uses: AbsaOSS/k3d-action@v2.4.0 26 | with: 27 | cluster-name: "opal" 28 | use-default-registry: false 29 | args: >- 30 | --config ./test/e2e/k3d.yaml 31 | - name: deploy opal 32 | run: | 33 | ./test/e2e/deploy.sh 34 | - name: e2e test 35 | run: | 36 | ./test/e2e/test.sh 37 | -------------------------------------------------------------------------------- /test/e2e/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -x 4 | set -e 5 | 6 | helm test -n opal --logs myopal 7 | 8 | DATA_URL="http://myopal-opal-client:8181/v1/data" 9 | 10 | # Check that users data is present initially 11 | RESULT=$(kubectl run -n opal curl-test --image=curlimages/curl:latest --rm -i --restart=Never -- curl -s ${DATA_URL}/users 2>&1 | grep -v "pod.*deleted") 12 | echo "Initial users: $RESULT" 13 | echo "$RESULT" | grep -q '"result"' 14 | 15 | # Run the update script 16 | if [ -z $MSYSTEM ]; then 17 | kubectl exec -n opal service/myopal-opal-server -- /opt/e2e/policy-repo-data/upd.sh 18 | else 19 | kubectl exec -n opal service/myopal-opal-server -- //opt/e2e/policy-repo-data/upd.sh 20 | fi 21 | 22 | sleep 7 23 | 24 | # Check that users data is empty after update (OPA returns {} when data is empty) 25 | RESULT=$(kubectl run -n opal curl-test --image=curlimages/curl:latest --rm -i --restart=Never -- curl -s ${DATA_URL}/users 2>&1 | grep -v "pod.*deleted") 26 | echo "After update users: $RESULT" 27 | [ "$RESULT" == '{}' ] 28 | 29 | # Check that losers data is present 30 | RESULT=$(kubectl run -n opal curl-test --image=curlimages/curl:latest --rm -i --restart=Never -- curl -s ${DATA_URL}/losers 2>&1 | grep -v "pod.*deleted") 31 | echo "Losers data: $RESULT" 32 | echo "$RESULT" | grep -q '"result"' 33 | -------------------------------------------------------------------------------- /test/e2e/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "users": { 3 | "alice": { 4 | "roles": [ 5 | "admin" 6 | ], 7 | "location": { 8 | "country": "US", 9 | "ip": "8.8.8.8" 10 | } 11 | }, 12 | "bob": { 13 | "roles": [ 14 | "employee", 15 | "billing" 16 | ], 17 | "location": { 18 | "country": "US", 19 | "ip": "8.8.8.8" 20 | } 21 | }, 22 | "eve": { 23 | "roles": [ 24 | "customer" 25 | ], 26 | "location": { 27 | "country": "US", 28 | "ip": "8.8.8.8" 29 | } 30 | } 31 | }, 32 | "role_permissions": { 33 | "customer": [ 34 | { 35 | "action": "read", 36 | "type": "dog" 37 | }, 38 | { 39 | "action": "read", 40 | "type": "cat" 41 | }, 42 | { 43 | "action": "adopt", 44 | "type": "dog" 45 | }, 46 | { 47 | "action": "adopt", 48 | "type": "cat" 49 | } 50 | ], 51 | "employee": [ 52 | { 53 | "action": "read", 54 | "type": "dog" 55 | }, 56 | { 57 | "action": "read", 58 | "type": "cat" 59 | }, 60 | { 61 | "action": "update", 62 | "type": "dog" 63 | }, 64 | { 65 | "action": "update", 66 | "type": "cat" 67 | } 68 | ], 69 | "billing": [ 70 | { 71 | "action": "read", 72 | "type": "finance" 73 | }, 74 | { 75 | "action": "update", 76 | "type": "finance" 77 | } 78 | ] 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /values.yaml: -------------------------------------------------------------------------------- 1 | openshift: 2 | enabled: false 3 | securityContext: 4 | runAsUser: 1010180000 5 | runAsGroup: 1010180000 6 | fsGroup: 1010180000 7 | containerSecurityContext: 8 | runAsNonRoot: true 9 | allowPrivilegeEscalation: false 10 | 11 | image: 12 | client: 13 | registry: docker.io 14 | repository: permitio/opal-client 15 | server: 16 | registry: docker.io 17 | repository: permitio/opal-server 18 | pgsql: 19 | registry: docker.io 20 | repository: postgres 21 | tag: alpine 22 | 23 | server: 24 | port: 7002 25 | policyRepoUrl: "https://github.com/permitio/opal-example-policy-repo" 26 | policyRepoSshKey: null 27 | policyRepoClonePath: null 28 | policyRepoMainBranch: null 29 | pollingInterval: 30 30 | dataConfigSources: 31 | # Option #1 - No data sources 32 | config: 33 | entries: [] 34 | 35 | # Option #2 - Dynamically get data sources 36 | # external_source_url: "https://your-api.com/path/to/api/endpoint" 37 | 38 | # Option #3 - Example static data sources (endpoint is empty by default) 39 | # config: 40 | # entries: 41 | # - url: http://opal-server:7002/policy-data 42 | # topics: ["policy_data"] 43 | # dst_path: "/static" 44 | 45 | # Option #4 - Leave config empty and instead supply using the OPAL_DATA_CONFIG_SOURCES environment variable through env or secret 46 | # config: null 47 | 48 | broadcastUri: null 49 | broadcastPgsql: true 50 | uvicornWorkers: 4 51 | replicas: 1 52 | extraEnv: { 53 | # "CUSTOM_ENV_VAR": "VALUE" 54 | } 55 | securityContext: {} 56 | containerSecurityContext: {} 57 | 58 | client: 59 | port: 7000 60 | opaPort: 8181 61 | replicas: 1 62 | # If you need to specify a custom hostname for the opal-sever, configure the serverUrl property 63 | # serverUrl: http://custom-hostname-for-opal:opal-port 64 | extraEnv: {} 65 | securityContext: {} 66 | containerSecurityContext: {} 67 | 68 | postgresql: 69 | securityContext: {} 70 | containerSecurityContext: {} 71 | extraEnv: {} 72 | 73 | broadcastReplicas: 1 -------------------------------------------------------------------------------- /test/e2e/rbac.rego: -------------------------------------------------------------------------------- 1 | # Role-based Access Control (RBAC) 2 | # -------------------------------- 3 | # 4 | # This example defines an RBAC model for a Pet Store API. The Pet Store API allows 5 | # users to look at pets, adopt them, update their stats, and so on. The policy 6 | # controls which users can perform actions on which resources. The policy implements 7 | # a classic Role-based Access Control model where users are assigned to roles and 8 | # roles are granted the ability to perform some action(s) on some type of resource. 9 | # 10 | # This example shows how to: 11 | # 12 | # * Define an RBAC model in Rego that interprets role mappings represented in JSON. 13 | # * Iterate/search across JSON data structures (e.g., role mappings) 14 | # 15 | # For more information see: 16 | # 17 | # * Rego comparison to other systems: https://www.openpolicyagent.org/docs/latest/comparison-to-other-systems/ 18 | # * Rego Iteration: https://www.openpolicyagent.org/docs/latest/#iteration 19 | 20 | package app.rbac 21 | 22 | # By default, deny requests. 23 | default allow = false 24 | 25 | # Allow admins to do anything. 26 | allow { 27 | user_is_admin 28 | } 29 | 30 | # Allow the action if the user is granted permission to perform the action. 31 | allow { 32 | # Find permissions for the user. 33 | some permission 34 | user_is_granted[permission] 35 | 36 | # Check if the permission permits the action. 37 | input.action == permission.action 38 | input.type == permission.type 39 | 40 | # unless user location is outside US 41 | country := data.users[input.user]["location"]["country"] 42 | country == "US" 43 | } 44 | 45 | # user_is_admin is true if... 46 | user_is_admin { 47 | 48 | # for some `i`... 49 | some i 50 | 51 | # "admin" is the `i`-th element in the user->role mappings for the identified user. 52 | data.users[input.user]["roles"][i] == "admin" 53 | } 54 | 55 | # user_is_granted is a set of permissions for the user identified in the request. 56 | # The `permission` will be contained if the set `user_is_granted` for every... 57 | user_is_granted[permission] { 58 | some i, j 59 | 60 | # `role` assigned an element of the user_roles for this user... 61 | role := data.users[input.user]["roles"][i] 62 | 63 | # `permission` assigned a single permission from the permissions list for 'role'... 64 | permission := data.role_permissions[role][j] 65 | } 66 | -------------------------------------------------------------------------------- /.github/workflows/release.yaml: -------------------------------------------------------------------------------- 1 | name: Release OPAL Helm chart 2 | 3 | on: 4 | workflow_dispatch 5 | 6 | jobs: 7 | build_chart_job: 8 | name: Build Helm chart 9 | runs-on: ubuntu-latest 10 | outputs: 11 | opalVersion: ${{ steps.opalVersion.outputs.opalVersion }} 12 | steps: 13 | - name: checkout 14 | uses: actions/checkout@v4 15 | with: 16 | fetch-depth: 0 17 | - name: nodejs 12 18 | uses: actions/setup-node@v1 19 | with: 20 | node-version: '12.x' 21 | - name: cache node_modules 22 | id: nodeCache 23 | uses: actions/cache@v4 24 | with: 25 | path: | 26 | ./node_modules 27 | ./package-lock.json 28 | key: node-modules-14-0-2--2.0.0 29 | - run: npm install release-it@14.0.2 @release-it/conventional-changelog@2.0.0 30 | - name: releaseIt 31 | run: | 32 | git config user.email "helm@opal.ac" 33 | git config user.name "Helm Opal.Ac" 34 | npx release-it --ci 35 | env: 36 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 37 | - name: opal version 38 | id: opalVersion 39 | run: | 40 | cat /tmp/opal.version 41 | echo "opalVersion=$(cat /tmp/opal.version)" >> $GITHUB_OUTPUT 42 | - uses: azure/setup-helm@v1 43 | - run: helm package . --version ${{ steps.opalVersion.outputs.opalVersion }} 44 | - name: upload artifact 45 | uses: actions/upload-artifact@v4 46 | with: 47 | name: "helm" 48 | path: "opal-${{ steps.opalVersion.outputs.opalVersion }}.tgz" 49 | 50 | publish_chart_job: 51 | name: Publish Helm chart 52 | runs-on: ubuntu-latest 53 | needs: build_chart_job 54 | steps: 55 | - name: checkout gh-pages 56 | uses: actions/checkout@v4 57 | with: 58 | ref: gh-pages 59 | - name: download artifact 60 | uses: actions/download-artifact@v4 61 | id: download 62 | with: 63 | name: helm 64 | path: /tmp/opal 65 | - uses: azure/setup-helm@v1 66 | - name: update index 67 | run: | 68 | helm repo index /tmp/opal --merge ./index.yaml 69 | mv -f /tmp/opal/* . 70 | - name: publish 71 | uses: actions-js/push@master 72 | with: 73 | github_token: ${{ secrets.GITHUB_TOKEN }} 74 | branch: gh-pages 75 | -------------------------------------------------------------------------------- /templates/deployment-pgsql.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.server }} 2 | {{- if and .Values.server.broadcastPgsql (not .Values.server.broadcastUri) }} 3 | apiVersion: apps/v1 4 | kind: Deployment 5 | metadata: 6 | name: {{ include "opal.pgsqlName" . }} 7 | labels: 8 | {{- include "opal.pgsqlLabels" . | nindent 4 }} 9 | spec: 10 | replicas: {{ .Values.broadcastReplicas }} 11 | selector: 12 | matchLabels: 13 | {{- include "opal.pgsqlSelectorLabels" . | nindent 6 }} 14 | template: 15 | metadata: 16 | labels: 17 | {{- include "opal.pgsqlLabels" . | nindent 8 }} 18 | spec: 19 | {{- with .Values.image.client.pullSecrets }} 20 | imagePullSecrets: 21 | {{- toYaml . | nindent 8 }} 22 | {{- end }} 23 | {{- if or .Values.openshift.enabled .Values.postgresql.securityContext }} 24 | securityContext: 25 | {{- if .Values.postgresql.securityContext }} 26 | {{- toYaml .Values.postgresql.securityContext | nindent 8 }} 27 | {{- else if .Values.openshift.enabled }} 28 | {{- toYaml .Values.openshift.securityContext | nindent 8 }} 29 | {{- end }} 30 | {{- end }} 31 | {{- if .Values.openshift.enabled }} 32 | volumes: 33 | - name: postgres-data 34 | emptyDir: {} 35 | {{- end }} 36 | containers: 37 | - name: pgsql 38 | image: {{ include "opal.pgsqlImage" . | quote }} 39 | imagePullPolicy: IfNotPresent 40 | {{- if or .Values.openshift.enabled .Values.postgresql.containerSecurityContext }} 41 | securityContext: 42 | {{- if .Values.postgresql.containerSecurityContext }} 43 | {{- toYaml .Values.postgresql.containerSecurityContext | nindent 12 }} 44 | {{- else if .Values.openshift.enabled }} 45 | {{- toYaml .Values.openshift.containerSecurityContext | nindent 12 }} 46 | {{- end }} 47 | {{- end }} 48 | {{- if .Values.openshift.enabled }} 49 | volumeMounts: 50 | - mountPath: /var/lib/postgresql/data 51 | name: postgres-data 52 | {{- end }} 53 | ports: 54 | - name: pgsql 55 | containerPort: 5432 56 | protocol: TCP 57 | env: 58 | - name: POSTGRES_DB 59 | value: postgres 60 | - name: POSTGRES_USER 61 | value: postgres 62 | - name: POSTGRES_PASSWORD 63 | value: postgres 64 | {{- if .Values.openshift.enabled }} 65 | - name: PGDATA 66 | value: "/var/lib/postgresql/data/pgdata" 67 | {{- end }} 68 | {{- if .Values.postgresql.extraEnv }} 69 | {{- range $name, $value := .Values.postgresql.extraEnv }} 70 | - name: {{ $name }} 71 | value: {{ $value | quote }} 72 | {{- end }} 73 | {{- end }} 74 | {{- end }} 75 | {{- end }} -------------------------------------------------------------------------------- /templates/_utils.tpl: -------------------------------------------------------------------------------- 1 | {{- define "opal.serverName" -}} 2 | {{- if eq .Release.Name .Chart.Name }} 3 | {{- printf "%s-server" .Release.Name }} 4 | {{- else }} 5 | {{- printf "%s-%s-server" .Release.Name .Chart.Name }} 6 | {{- end -}} 7 | {{- end -}} 8 | 9 | {{- define "opal.clientName" -}} 10 | {{- if eq .Release.Name .Chart.Name }} 11 | {{- printf "%s-client" .Release.Name }} 12 | {{- else }} 13 | {{- printf "%s-%s-client" .Release.Name .Chart.Name }} 14 | {{- end -}} 15 | {{- end -}} 16 | 17 | {{- define "opal.pgsqlName" -}} 18 | {{- if eq .Release.Name .Chart.Name }} 19 | {{- printf "%s-pgsql" .Release.Name }} 20 | {{- else }} 21 | {{- printf "%s-%s-pgsql" .Release.Name .Chart.Name }} 22 | {{- end -}} 23 | {{- end -}} 24 | 25 | {{- define "opal.serverImage" -}} 26 | {{- printf "%s/%s:%s" (default "docker.io" .Values.image.server.registry) (default "permitio/opal-server" .Values.image.server.repository) (default .Chart.AppVersion .Values.image.server.tag) }} 27 | {{- end -}} 28 | 29 | {{- define "opal.clientImage" -}} 30 | {{- printf "%s/%s:%s" (default "docker.io" .Values.image.client.registry) (default "permitio/opal-client" .Values.image.client.repository) (default .Chart.AppVersion .Values.image.client.tag) }} 31 | {{- end -}} 32 | 33 | {{- define "opal.pgsqlImage" -}} 34 | {{- printf "%s/%s:%s" (default "docker.io" .Values.image.pgsql.registry) (default "postgres" .Values.image.pgsql.repository) (default "alpine" .Values.image.pgsql.tag) }} 35 | {{- end -}} 36 | 37 | {{- define "opal.envSecretsName" -}} 38 | {{- if eq .Release.Name .Chart.Name }} 39 | {{- printf "%s-env-secrets" .Release.Name }} 40 | {{- else }} 41 | {{- printf "%s-%s-env-secrets" .Release.Name .Chart.Name }} 42 | {{- end -}} 43 | {{- end -}} 44 | 45 | {{- define "opal.clientSelectorLabels" -}} 46 | app.kubernetes.io/name: {{ include "opal.clientName" . | quote }} 47 | app.kubernetes.io/instance: {{ .Release.Name | quote }} 48 | opal.ac/role: client 49 | {{- end -}} 50 | 51 | {{- define "opal.serverSelectorLabels" -}} 52 | app.kubernetes.io/name: {{ include "opal.serverName" . | quote }} 53 | app.kubernetes.io/instance: {{ .Release.Name | quote }} 54 | opal.ac/role: server 55 | {{- end -}} 56 | 57 | {{- define "opal.pgsqlSelectorLabels" -}} 58 | app.kubernetes.io/name: {{ include "opal.pgsqlName" . | quote }} 59 | app.kubernetes.io/instance: {{ .Release.Name | quote }} 60 | opal.ac/role: pgsql 61 | {{- end -}} 62 | 63 | {{- define "opal.clientLabels" -}} 64 | app.kubernetes.io/managed-by: {{ .Release.Service | quote }} 65 | app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} 66 | helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | quote }} 67 | {{ include "opal.clientSelectorLabels" . }} 68 | {{- end -}} 69 | 70 | {{- define "opal.serverLabels" -}} 71 | app.kubernetes.io/managed-by: {{ .Release.Service | quote }} 72 | app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} 73 | helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | quote }} 74 | {{ include "opal.serverSelectorLabels" . }} 75 | {{- end -}} 76 | 77 | {{- define "opal.pgsqlLabels" -}} 78 | app.kubernetes.io/managed-by: {{ .Release.Service | quote }} 79 | app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} 80 | helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | quote }} 81 | {{ include "opal.pgsqlSelectorLabels" . }} 82 | {{- end -}} 83 | 84 | -------------------------------------------------------------------------------- /templates/deployment-client.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.client }} 2 | {{- if ne .Values.client.enabled false }} 3 | {{- $nm := include "opal.clientName" . | quote }} 4 | apiVersion: apps/v1 5 | kind: Deployment 6 | metadata: 7 | name: {{ $nm }} 8 | labels: 9 | {{- include "opal.clientLabels" . | nindent 4 }} 10 | spec: 11 | replicas: {{ .Values.client.replicas }} 12 | selector: 13 | matchLabels: 14 | {{- include "opal.clientSelectorLabels" . | nindent 6 }} 15 | template: 16 | metadata: 17 | labels: 18 | {{- include "opal.clientLabels" . | nindent 8 }} 19 | spec: 20 | {{- with .Values.image.client.pullSecrets }} 21 | imagePullSecrets: 22 | {{- toYaml . | nindent 8 }} 23 | {{- end }} 24 | {{- if or .Values.openshift.enabled .Values.client.securityContext }} 25 | securityContext: 26 | {{- if .Values.client.securityContext }} 27 | {{- toYaml .Values.client.securityContext | nindent 8 }} 28 | {{- else if .Values.openshift.enabled }} 29 | {{- toYaml .Values.openshift.securityContext | nindent 8 }} 30 | {{- end }} 31 | {{- end }} 32 | {{- if .Values.client.opaStartupData }} 33 | volumes: 34 | - name: opa-startup-data 35 | configMap: 36 | name: opa-startup-data 37 | defaultMode: 0444 38 | {{- end }} 39 | containers: 40 | - name: opal-client 41 | image: {{ include "opal.clientImage" . | quote }} 42 | imagePullPolicy: {{ .Values.client.imagePullPolicy | default "IfNotPresent" | quote }} 43 | {{- if or .Values.openshift.enabled .Values.client.containerSecurityContext }} 44 | securityContext: 45 | {{- if .Values.client.containerSecurityContext }} 46 | {{- toYaml .Values.client.containerSecurityContext | nindent 12 }} 47 | {{- else if .Values.openshift.enabled }} 48 | {{- toYaml .Values.openshift.containerSecurityContext | nindent 12 }} 49 | {{- end }} 50 | {{- end }} 51 | ports: 52 | - name: http 53 | containerPort: {{ .Values.client.port }} 54 | protocol: TCP 55 | - name: opa 56 | containerPort: {{ .Values.client.opaPort }} 57 | protocol: TCP 58 | env: 59 | - name: UVICORN_NUM_WORKERS 60 | value: "1" 61 | {{- if .Values.server }} 62 | {{- if .Values.client.serverUrl }} 63 | - name: OPAL_SERVER_URL 64 | value: {{ .Values.client.serverUrl | quote }} 65 | {{- else }} 66 | - name: OPAL_SERVER_URL 67 | value: {{ printf "http://%s:%v" (include "opal.serverName" .) .Values.server.port | quote }} 68 | {{- end}} 69 | {{- if not (or (.Values.server.dataConfigSources.external_source_url) (and .Values.server.dataConfigSources.config .Values.server.dataConfigSources.config.entries) (hasKey .Values.client.extraEnv "OPAL_DATA_UPDATER_ENABLED") ) }} 70 | - name: OPAL_DATA_UPDATER_ENABLED 71 | value: "False" 72 | {{- end }} 73 | {{- end }} 74 | {{- if .Values.client.extraEnv }} 75 | {{- range $name, $value := .Values.client.extraEnv }} 76 | - name: {{ $name }} 77 | value: {{ $value | quote }} 78 | {{- end }} 79 | {{- end }} 80 | {{- if .Values.client.secrets }} 81 | envFrom: 82 | {{- range $name := .Values.client.secrets }} 83 | - secretRef: 84 | name: {{ $name }} 85 | {{- end }} 86 | {{- end }} 87 | {{- if .Values.client.opaStartupData }} 88 | volumeMounts: 89 | - mountPath: /opt/opa/startup-data 90 | name: opa-startup-data 91 | readOnly: true 92 | {{- end }} 93 | readinessProbe: 94 | httpGet: 95 | path: /healthcheck 96 | port: http 97 | failureThreshold: 5 98 | initialDelaySeconds: 5 99 | timeoutSeconds: 10 100 | periodSeconds: 15 101 | 102 | livenessProbe: 103 | httpGet: 104 | path: /healthcheck 105 | port: http 106 | failureThreshold: 5 107 | timeoutSeconds: 10 108 | periodSeconds: 30 109 | {{- if .Values.client.resources }} 110 | resources: 111 | {{- toYaml .Values.client.resources | nindent 12 }} 112 | {{- end }} 113 | {{- end }} 114 | {{- end }} -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 |
3 |