Skip to content

Commit

Permalink
Merge pull request #4 from equinor/helm-chart
Browse files Browse the repository at this point in the history
Helm chart
  • Loading branch information
Richard87 authored Apr 9, 2024
2 parents cca1d42 + 558a520 commit 8df9843
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 52 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,16 @@ jobs:
run: go mod download
- name: Run Tests
run: go test -cover `go list ./... | grep -v 'pkg/client'`

lint-helm:
name: Lint Helm
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: azure/setup-helm@b7246b12e77f7134dc2d460a3d5bad15bbe29390 # v4.1.0

- name: Helm Lint
run: helm lint charts/radix-oauth-guard
33 changes: 33 additions & 0 deletions .github/workflows/release-chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Release Charts

on:
push:
tags:
- '**'
workflow_dispatch:

jobs:
release:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Install Helm
uses: azure/setup-helm@v3
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

- name: Run chart-releaser
uses: helm/[email protected]
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
4 changes: 2 additions & 2 deletions auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestMissingAuthHeaderFails(t *testing.T) {
req, _ := http.NewRequest("GET", "/auth", nil)
handler.ServeHTTP(writer, req)

assert.Equal(t, http.StatusForbidden, writer.Code)
assert.Equal(t, http.StatusUnauthorized, writer.Code)
}

func TestAuthFailureFails(t *testing.T) {
Expand All @@ -57,7 +57,7 @@ func TestAuthFailureFails(t *testing.T) {
req.Header.Set("Authorization", "Bearer abcdabcd")
handler.ServeHTTP(writer, req)

assert.Equal(t, http.StatusForbidden, writer.Code)
assert.Equal(t, http.StatusUnauthorized, writer.Code)
}

func TestInvalidJWTFails(t *testing.T) {
Expand Down
22 changes: 22 additions & 0 deletions charts/radix-oauth-guard/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
6 changes: 6 additions & 0 deletions charts/radix-oauth-guard/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
appVersion: 0.2.3
version: 0.2.3
description: Forward Auth to validate, authenticate and authorize JWT tokens
name: radix-oauth-guard
icon: https://radix.equinor.com/images/logos/logo.svg
58 changes: 58 additions & 0 deletions charts/radix-oauth-guard/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "oauth-guard.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 "oauth-guard.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 "oauth-guard.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "oauth-guard.labels" -}}
helm.sh/chart: {{ include "oauth-guard.chart" . }}
{{ include "oauth-guard.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "oauth-guard.selectorLabels" -}}
app.kubernetes.io/name: {{ include "oauth-guard.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "oauth-guard.serviceAccountName" -}}
{{- default (include "oauth-guard.fullname" .) .Values.serviceAccount.name }}
{{- end }}
58 changes: 58 additions & 0 deletions charts/radix-oauth-guard/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "oauth-guard.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
labels:
{{- include "oauth-guard.labels" . | nindent 4 }}
{{- with .Values.deploymentAnnotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
replicas: 1
selector:
matchLabels:
{{- include "oauth-guard.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "oauth-guard.selectorLabels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
fsGroup: 1000
supplementalGroups:
- 1000
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: 8000
name: http
env:
- name: LOG_PRETTY
value: {{ .Values.logPretty | quote }}
- name: LOG_LEVEL
value: {{ .Values.logLevel | quote }}
- name: ISSUER
value: {{ .Values.issuer | quote }}
- name: AUDIENCE
value: {{ .Values.audience | quote }}
- name: SUBJECTS
value: {{ (join "," .Values.subjects) | quote }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
securityContext:
privileged: false
readOnlyRootFilesystem: true
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
11 changes: 11 additions & 0 deletions charts/radix-oauth-guard/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "oauth-guard.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
spec:
selector:
{{- include "oauth-guard.selectorLabels" . | nindent 6 }}
ports:
- name: http
port: 8000
31 changes: 31 additions & 0 deletions charts/radix-oauth-guard/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Default values for charts.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
nameOverride: ""
fullnameOverride: ""

image:
repository: ghcr.io/equinor/radix-oauth-guard
tag: latest
pullPolicy: Always

# Annotations to add to the Deployment
deploymentAnnotations: {}
# Extra pod labels
podLabels: {}

# Logging
logLevel: info
logPretty: "False"
issuer: ""
audience: ""
subjects: []
# - "system:serviceaccount:monitor:prometheus-operator-prometheus"

resources:
limits:
cpu: 50m
memory: 100Mi
requests:
cpu: 50m
memory: 100Mi
50 changes: 0 additions & 50 deletions deploymet.yaml

This file was deleted.

0 comments on commit 8df9843

Please sign in to comment.