From 14f9d428898b088eca14ef527eeeec26eb467127 Mon Sep 17 00:00:00 2001 From: Jonathan Perret Date: Fri, 20 Mar 2026 11:24:45 +0100 Subject: [PATCH] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20(oidc-test-client)=20creat?= =?UTF-8?q?e=20Helm=20chart=20for=20test=20client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This helps running tests with the app running in a Kubernetes cluster. --- .github/workflows/ci-tests.yml | 8 +++ Tiltfile | 5 ++ docker/oidc-test-client/Dockerfile | 2 +- .../dev/values.oidc-test-client.yaml.gotmpl | 22 ++++++ .../env.d/dev/values.oidc2fer.yaml.gotmpl | 5 +- src/helm/helmfile.yaml.gotmpl | 8 +++ src/helm/oidc-test-client/Chart.yaml | 24 +++++++ .../oidc-test-client/templates/_helpers.tpl | 51 +++++++++++++ .../templates/deployment.yaml | 71 +++++++++++++++++++ .../oidc-test-client/templates/ingress.yaml | 38 ++++++++++ .../oidc-test-client/templates/service.yaml | 16 +++++ src/helm/oidc-test-client/values.yaml | 71 +++++++++++++++++++ 12 files changed, 318 insertions(+), 3 deletions(-) create mode 100644 src/helm/env.d/dev/values.oidc-test-client.yaml.gotmpl create mode 100644 src/helm/oidc-test-client/Chart.yaml create mode 100644 src/helm/oidc-test-client/templates/_helpers.tpl create mode 100644 src/helm/oidc-test-client/templates/deployment.yaml create mode 100644 src/helm/oidc-test-client/templates/ingress.yaml create mode 100644 src/helm/oidc-test-client/templates/service.yaml create mode 100644 src/helm/oidc-test-client/values.yaml diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index a004600..4bb2ccc 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -123,6 +123,14 @@ jobs: with: submodules: recursive token: ${{ steps.app-token.outputs.token }} + - + name: Install mkcert + run: | + apt-get update -y -q && apt-get install -y -q libnss3-tools + curl -Ss -L -o mkcert https://github.com/FiloSottile/mkcert/releases/download/v1.4.4/mkcert-v1.4.4-linux-amd64 + chmod +x mkcert + mv mkcert /usr/local/bin/ + TRUST_STORES=none mkcert -install - name: Helmfile lint env: diff --git a/Tiltfile b/Tiltfile index 6580209..859fc0a 100644 --- a/Tiltfile +++ b/Tiltfile @@ -13,6 +13,11 @@ docker_build( ] ) +docker_build( + 'localhost:5001/oidc-test-client:latest', + context='docker/oidc-test-client' +) + watch_file('src/helm') k8s_yaml(local('cd src/helm && helmfile -n oidc2fer -e dev template .')) diff --git a/docker/oidc-test-client/Dockerfile b/docker/oidc-test-client/Dockerfile index 71b9360..7e9ef98 100644 --- a/docker/oidc-test-client/Dockerfile +++ b/docker/oidc-test-client/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.14 +FROM python:3.14.3-slim-trixie COPY . /app diff --git a/src/helm/env.d/dev/values.oidc-test-client.yaml.gotmpl b/src/helm/env.d/dev/values.oidc-test-client.yaml.gotmpl new file mode 100644 index 0000000..337e304 --- /dev/null +++ b/src/helm/env.d/dev/values.oidc-test-client.yaml.gotmpl @@ -0,0 +1,22 @@ +image: + repository: localhost:5001/oidc-test-client + pullPolicy: Always + tag: "latest" + +ingress: + enabled: true + host: oidc-test-client.127.0.0.1.nip.io + +env: + - name: OIDC_ROOT_URL + value: https://oidc-test-client.127.0.0.1.nip.io + - name: OIDC_PROVIDER + value: https://oidc2fer.127.0.0.1.nip.io + - name: OIDC_CLIENT_ID + value: oidc-test-client + - name: OIDC_CLIENT_SECRET + value: oidc-test-secret + - name: OIDC_SCOPES + value: openid,uid,given_name,usual_name,email,siret + - name: EXTRA_ROOT_CA + value: {{ exec "mkcert" (list "-CAROOT") | trim | printf "%s/rootCA.pem" | readFile | quote }} \ No newline at end of file diff --git a/src/helm/env.d/dev/values.oidc2fer.yaml.gotmpl b/src/helm/env.d/dev/values.oidc2fer.yaml.gotmpl index 0da7b0c..e064866 100644 --- a/src/helm/env.d/dev/values.oidc2fer.yaml.gotmpl +++ b/src/helm/env.d/dev/values.oidc2fer.yaml.gotmpl @@ -30,8 +30,9 @@ satosa: ], "redirect_uris": [ "https://oidc-test-client.traefik.me/redirect_uri", - "https://oidc-test-client.traefik.me:8443/redirect_uri" - ], + "https://oidc-test-client.traefik.me:8443/redirect_uri", + "https://oidc-test-client.127.0.0.1.nip.io/redirect_uri" + ], "client_secret": "oidc-test-secret", "token_endpoint_auth_method": "client_secret_post" } diff --git a/src/helm/helmfile.yaml.gotmpl b/src/helm/helmfile.yaml.gotmpl index 1fa97ed..d58bc3f 100644 --- a/src/helm/helmfile.yaml.gotmpl +++ b/src/helm/helmfile.yaml.gotmpl @@ -48,3 +48,11 @@ releases: - env.d/{{ .Environment.Name }}/values.oidc2fer.yaml.gotmpl secrets: - env.d/{{ .Environment.Name }}/secrets.enc.yaml + + - name: oidc-test-client + installed: {{ eq .Environment.Name "dev" }} + version: {{ .Values.version }} + namespace: {{ .Namespace }} + chart: ./oidc-test-client + values: + - env.d/{{ .Environment.Name }}/values.oidc-test-client.yaml.gotmpl diff --git a/src/helm/oidc-test-client/Chart.yaml b/src/helm/oidc-test-client/Chart.yaml new file mode 100644 index 0000000..6c670d8 --- /dev/null +++ b/src/helm/oidc-test-client/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: oidc-test-client +description: Test OIDC client + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.0.0" diff --git a/src/helm/oidc-test-client/templates/_helpers.tpl b/src/helm/oidc-test-client/templates/_helpers.tpl new file mode 100644 index 0000000..5482362 --- /dev/null +++ b/src/helm/oidc-test-client/templates/_helpers.tpl @@ -0,0 +1,51 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "oidc-test-client.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "oidc-test-client.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "oidc-test-client.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "oidc-test-client.labels" -}} +helm.sh/chart: {{ include "oidc-test-client.chart" . }} +{{ include "oidc-test-client.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "oidc-test-client.selectorLabels" -}} +app.kubernetes.io/name: {{ include "oidc-test-client.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} \ No newline at end of file diff --git a/src/helm/oidc-test-client/templates/deployment.yaml b/src/helm/oidc-test-client/templates/deployment.yaml new file mode 100644 index 0000000..998ffbe --- /dev/null +++ b/src/helm/oidc-test-client/templates/deployment.yaml @@ -0,0 +1,71 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "oidc-test-client.fullname" . }} + namespace: {{ .Release.Namespace | quote }} + labels: + {{- include "oidc-test-client.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "oidc-test-client.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "oidc-test-client.labels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + {{ with .Values.livenessProbe }} + livenessProbe: {{ toJson . }} + {{- end }} + {{ with .Values.readinessProbe }} + readinessProbe: {{ toJson . }} + {{- end }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.env }} + env: + {{- toYaml . | nindent 12 }} + {{- end }} + command: + - sh + - -ec + - |- + printenv EXTRA_ROOT_CA >> $(python -m certifi) + exec python app.py + + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/src/helm/oidc-test-client/templates/ingress.yaml b/src/helm/oidc-test-client/templates/ingress.yaml new file mode 100644 index 0000000..e96d94f --- /dev/null +++ b/src/helm/oidc-test-client/templates/ingress.yaml @@ -0,0 +1,38 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "oidc-test-client.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: {{ $fullName }} + namespace: {{ .Release.Namespace | quote }} + labels: + {{- include "oidc-test-client.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + ingressClassName: {{ .Values.ingress.className }} + {{- if .Values.ingress.tls.enabled }} + tls: + {{- if .Values.ingress.host }} + - secretName: {{ $fullName }}-tls + hosts: + - {{ .Values.ingress.host | quote }} + {{- end }} + {{- end }} + rules: + {{- if .Values.ingress.host }} + - host: {{ .Values.ingress.host | quote }} + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- end }} +{{- end }} diff --git a/src/helm/oidc-test-client/templates/service.yaml b/src/helm/oidc-test-client/templates/service.yaml new file mode 100644 index 0000000..bb273e6 --- /dev/null +++ b/src/helm/oidc-test-client/templates/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "oidc-test-client.fullname" . }} + namespace: {{ .Release.Namespace | quote }} + labels: + {{- include "oidc-test-client.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "oidc-test-client.selectorLabels" . | nindent 4 }} diff --git a/src/helm/oidc-test-client/values.yaml b/src/helm/oidc-test-client/values.yaml new file mode 100644 index 0000000..c4fa6b3 --- /dev/null +++ b/src/helm/oidc-test-client/values.yaml @@ -0,0 +1,71 @@ +# Default values for oidc-test-client. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: oidc-test-client + pullPolicy: Always + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +podAnnotations: {} +podLabels: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 5000 + +ingress: + enabled: true + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: [] + tls: + enabled: true + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +livenessProbe: + httpGet: + path: /healthz + port: http + periodSeconds: 30 + +readinessProbe: null + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +env: []