Skip to content

Commit

Permalink
feat: add authservice to uds-core (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjnagel authored Feb 10, 2024
1 parent 4b3bdcf commit b0b33b9
Show file tree
Hide file tree
Showing 18 changed files with 672 additions and 11 deletions.
9 changes: 9 additions & 0 deletions packages/standard/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ metadata:
# x-release-please-end

components:
# CRDs
- name: prometheus-operator-crds
required: true
import:
Expand Down Expand Up @@ -65,12 +66,20 @@ components:
import:
path: ../../src/prometheus-stack

# Promtail
- name: promtail
required: true
import:
path: ../../src/promtail

# Grafana
- name: grafana
required: true
import:
path: ../../src/grafana

# Authservice
- name: authservice
required: true
import:
path: ../../src/authservice
23 changes: 23 additions & 0 deletions src/authservice/chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v2
name: authservice
description: A Helm chart for Istio Authservice

# 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.5.3

# 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.
appVersion: 0.5.3
58 changes: 58 additions & 0 deletions src/authservice/chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "authservice.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 "authservice.fullname" -}}
{{- $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 }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "authservice.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "authservice.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "authservice.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
20 changes: 20 additions & 0 deletions src/authservice/chart/templates/authn.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Authservice is non-functional without Istio/RequestAuthentication but we wrap this in a conditional to handle standalone testing
{{- if .Capabilities.APIVersions.Has "security.istio.io/v1beta1" }}
apiVersion: security.istio.io/v1beta1
kind: RequestAuthentication
metadata:
name: jwt-authn
namespace: istio-system
spec:
selector:
matchLabels:
{{ .Values.selector.key }}: {{ .Values.selector.value | quote }}
jwtRules:
- issuer: https://{{ .Values.global.oidc.host }}/auth/realms/{{ .Values.global.oidc.realm }}
{{- if .Values.global.jwks }}
jwks: {{ .Values.global.jwks | quote }}
{{- else }}
jwksUri: https://{{ .Values.global.oidc.host }}/auth/realms/{{ .Values.global.oidc.realm }}/protocol/openid-connect/certs
{{- end }}
forwardOriginalToken: true
{{- end }}
41 changes: 41 additions & 0 deletions src/authservice/chart/templates/authz.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Authservice is non-functional without Istio/AuthorizationPolicy but we wrap this in a conditional to handle standalone testing
{{- if .Capabilities.APIVersions.Has "security.istio.io/v1beta1" }}
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: authservice
namespace: istio-system
spec:
selector:
matchLabels:
{{ .Values.selector.key }}: {{ .Values.selector.value | quote }}
action: CUSTOM
provider:
name: authservice
rules:
{{- if .Values.allow_unmatched_requests }}
- {}
{{- else if .Values.custom_authpolicy_rules }}
{{ .Values.custom_authpolicy_rules | toYaml | indent 2 }}
{{- else }}
- to:
- operation:
hosts:
- "*.{{ .Values.domain }}"
{{- end }}
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
name: jwt-authz
namespace: istio-system
spec:
selector:
matchLabels:
{{ .Values.selector.key }}: {{ .Values.selector.value | quote }}
rules:
- from:
- source:
requestPrincipals:
- "https://{{ .Values.global.oidc.host }}/auth/realms/{{ .Values.global.oidc.realm }}/*"
{{- end }}
99 changes: 99 additions & 0 deletions src/authservice/chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "authservice.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "authservice.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "authservice.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
checksum/config: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "authservice.selectorLabels" . | nindent 8 }}
spec:
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- if .Values.global.certificate_authority }}
env:
- name: SSL_CERT_FILE
value: /mnt/ca-bundle/ca-bundle.crt
{{- end}}
ports:
- name: http
containerPort: 10003
protocol: TCP
livenessProbe:
tcpSocket:
port: 10003
readinessProbe:
tcpSocket:
port: 10003
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
- name: {{ include "authservice.name" . }}
mountPath: /etc/authservice
{{- if .Values.global.certificate_authority }}
- name: ca-bundle
mountPath: /mnt/ca-bundle
{{- end }}
{{- if .Values.global.certificate_authority }}
initContainers:
- name: update-ca-bundle
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
command:
- sh
- -c
- |
cat /etc/pki/tls/certs/* > /mnt/ca-bundle/ca-bundle.crt
volumeMounts:
- name: sso-tls-ca
mountPath: /etc/pki/tls/certs/oidc-ca.crt
subPath: oidc-ca.crt
readOnly: true
- name: ca-bundle
mountPath: /mnt/ca-bundle
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
- name: {{ include "authservice.name" . }}
secret:
secretName: {{ include "authservice.fullname" . }}
{{- if .Values.global.certificate_authority }}
- name: sso-tls-ca
secret:
secretName: {{ include "authservice.fullname" . }}-sso-tls-ca
- name: ca-bundle
emptyDir:
sizeLimit: 5Mi
{{- end}}
33 changes: 33 additions & 0 deletions src/authservice/chart/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "authservice.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "authservice.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "authservice.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
11 changes: 11 additions & 0 deletions src/authservice/chart/templates/secret-ca.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{- if .Values.global.certificate_authority }}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "authservice.fullname" . }}-sso-tls-ca
namespace: {{ .Release.Namespace }}
labels:
{{- include "authservice.labels" . | nindent 4 }}
stringData:
oidc-ca.crt: {{ .Values.global.certificate_authority | quote }}
{{- end }}
Loading

0 comments on commit b0b33b9

Please sign in to comment.