Skip to content

Commit

Permalink
Support using a custom CA (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkjpryor authored Oct 10, 2024
1 parent 0b0b9fc commit a7a36e8
Show file tree
Hide file tree
Showing 15 changed files with 232 additions and 60 deletions.
10 changes: 10 additions & 0 deletions charts/server/templates/configmap-trust-bundle.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{- if .Values.common.trustBundle }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "zenith.componentname" (list . "trust-bundle") }}
labels: {{ include "zenith.componentLabels" (list . "trust-bundle") | nindent 4 }}
data:
ca-certificates.crt: |
{{- nindent 4 .Values.common.trustBundle }}
{{- end }}
10 changes: 10 additions & 0 deletions charts/server/templates/registrar/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ spec:
- name: etc-zenith
mountPath: /etc/zenith
readOnly: true
{{- if .Values.common.trustBundle }}
- name: trust-bundle
mountPath: /etc/ssl/certs
readOnly: true
{{- end }}
{{- with .Values.registrar.nodeSelector }}
nodeSelector: {{ toYaml . | nindent 8 }}
{{- end }}
Expand All @@ -50,4 +55,9 @@ spec:
- name: etc-zenith
secret:
secretName: {{ include "zenith.componentname" (list . "registrar-conf") }}
{{- if .Values.common.trustBundle }}
- name: trust-bundle
configMap:
name: {{ include "zenith.componentname" (list . "trust-bundle") }}
{{- end }}
{{- end }}
10 changes: 10 additions & 0 deletions charts/server/templates/sshd/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ spec:
readOnly: true
- name: var-run-sshd
mountPath: /var/run/sshd
{{- if .Values.common.trustBundle }}
- name: trust-bundle
mountPath: /etc/ssl/certs
readOnly: true
{{- end }}
{{- with .Values.sshd.nodeSelector }}
nodeSelector: {{ toYaml . | nindent 8 }}
{{- end }}
Expand All @@ -70,4 +75,9 @@ spec:
name: {{ include "zenith.componentname" (list . "sshd-conf") }}
- name: var-run-sshd
emptyDir: {}
{{- if .Values.common.trustBundle }}
- name: trust-bundle
configMap:
name: {{ include "zenith.componentname" (list . "trust-bundle") }}
{{- end }}
{{- end }}
3 changes: 3 additions & 0 deletions charts/server/templates/sync/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
{{- $common := deepCopy .Values.common.ingress }}
{{- $ingress := mergeOverwrite $global $common }}
kubernetes:
{{- if .Values.common.trustBundle }}
trustBundleConfigmapName: {{ include "zenith.componentname" (list . "trust-bundle") }}
{{- end }}
targetNamespace: {{ .Values.common.kubernetes.targetNamespace }}
# By default, we use the same chart version for the service chart
serviceChartVersion: {{ .Chart.Version }}
Expand Down
10 changes: 10 additions & 0 deletions charts/server/templates/sync/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ spec:
- name: etc-zenith
mountPath: /etc/zenith
readOnly: true
{{- if .Values.common.trustBundle }}
- name: trust-bundle
mountPath: /etc/ssl/certs
readOnly: true
{{- end }}
- name: tmp
mountPath: /tmp
{{- with .Values.sync.nodeSelector }}
Expand All @@ -61,6 +66,11 @@ spec:
- name: etc-zenith
configMap:
name: {{ include "zenith.componentname" (list . "sync-conf") }}
{{- if .Values.common.trustBundle }}
- name: trust-bundle
configMap:
name: {{ include "zenith.componentname" (list . "trust-bundle") }}
{{- end }}
# Mount a writable directory at /tmp
- name: tmp
emptyDir: {}
Expand Down
20 changes: 20 additions & 0 deletions charts/server/templates/sync/role-trust-bundle-reader.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{- if and .Values.sync.enabled .Values.common.trustBundle }}
# This role allows the holder to read the trust bundle configmap in the release namespace
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ include "zenith.componentname" (list . "sync") }}-trust-bundle-reader
labels: {{ include "zenith.componentLabels" (list . "sync") | nindent 4 }}
rules:
# We only need access to the named configmap
- apiGroups:
- ""
resources:
- configmaps
resourceNames:
- {{ include "zenith.componentname" (list . "trust-bundle") }}
verbs:
- list
- get
- watch
{{- end }}
17 changes: 17 additions & 0 deletions charts/server/templates/sync/rolebinding-trust-bundle-reader.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- if and .Values.sync.enabled .Values.common.trustBundle }}
# This role binding allows the sync service account to access the trust bundle configmap
# in the release namespace
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ include "zenith.componentname" (list . "sync") }}-trust-bundle-reader
labels: {{ include "zenith.componentLabels" (list . "sync") | nindent 4 }}
subjects:
- kind: ServiceAccount
namespace: {{ .Release.Namespace }}
name: {{ include "zenith.componentname" (list . "sync") }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ include "zenith.componentname" (list . "sync") }}-trust-bundle-reader
{{- end }}
2 changes: 2 additions & 0 deletions charts/server/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ global:

# Common configuration
common:
# A bundle of trusted CAs to use instead of the defaults
trustBundle:
# Ingress configuration
# This overrides global.ingress, and can be overridden by component-specific settings
ingress: {}
Expand Down
4 changes: 4 additions & 0 deletions client/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ FROM ubuntu:jammy
# Don't buffer stdout and stderr as it breaks realtime logging
ENV PYTHONUNBUFFERED 1

# Make requests use the system trust roots
# By default, this means we use the roots baked into the image
ENV REQUESTS_CA_BUNDLE /etc/ssl/certs/ca-certificates.crt

# Create the user that will be used to run the client process
ENV ZENITH_UID 1001
ENV ZENITH_GID 1001
Expand Down
4 changes: 4 additions & 0 deletions operator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ FROM ubuntu:jammy
# Don't buffer stdout and stderr as it breaks realtime logging
ENV PYTHONUNBUFFERED 1

# Make httpx use the system trust roots
# By default, this means we use the CAs from the ca-certificates package
ENV SSL_CERT_FILE /etc/ssl/certs/ca-certificates.crt

# Create the user that will be used to run the app
ENV ZENITH_UID 1001
ENV ZENITH_GID 1001
Expand Down
4 changes: 4 additions & 0 deletions registrar/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ FROM ubuntu:jammy
# Don't buffer stdout and stderr as it breaks realtime logging
ENV PYTHONUNBUFFERED 1

# Make httpx use the system trust roots
# By default, this means we use the CAs from the ca-certificates package
ENV SSL_CERT_FILE /etc/ssl/certs/ca-certificates.crt

# Create the user that will be used to run the app
ENV ZENITH_UID 1001
ENV ZENITH_GID 1001
Expand Down
5 changes: 5 additions & 0 deletions sshd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ FROM ubuntu:jammy
# Don't buffer stdout and stderr as it breaks realtime logging
ENV PYTHONUNBUFFERED 1

# Make requests and httpx use the system trust roots
# By default, this means we use the CAs from the ca-certificates package
ENV SSL_CERT_FILE /etc/ssl/certs/ca-certificates.crt
ENV REQUESTS_CA_BUNDLE /etc/ssl/certs/ca-certificates.crt

# Create an unprivileged user to accept tunnel requests
# The user has a home directory, a restricted shell to allow the tunnel script
# to run and an empty password to allow anonymous SSH
Expand Down
4 changes: 4 additions & 0 deletions sync/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ FROM ubuntu:jammy
# Don't buffer stdout and stderr as it breaks realtime logging
ENV PYTHONUNBUFFERED 1

# Make httpx use the system trust roots
# By default, this means we use the CAs from the ca-certificates package
ENV SSL_CERT_FILE /etc/ssl/certs/ca-certificates.crt

# Tell Helm to use /tmp for mutable data
ENV HELM_CACHE_HOME /tmp/helm/cache
ENV HELM_CONFIG_HOME /tmp/helm/config
Expand Down
8 changes: 6 additions & 2 deletions sync/zenith/sync/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,16 @@ class KubernetesConfig(Section):
#: Default values for releases of the service chart
service_default_values: t.Dict[str, t.Any] = Field(default_factory = dict)

#: The name of a configmap containing a trust bundle
#: If not given, the default trust will be used
trust_bundle_configmap_name: t.Optional[str] = None

#: The label used to indicate a managed resource
created_by_label: str = "app.kubernetes.io/created-by"
#: The label used to indicate the corresponding Zenith service for a resource
service_name_label: str = "zenith.stackhpc.com/service-name"
#: The annotation used to record that a secret is a mirror of another secret
tls_mirror_annotation: str = "zenith.stackhpc.com/mirrors"
#: The annotation used to record that a resource is a mirror of another
mirror_annotation: str = "zenith.stackhpc.com/mirrors"
#: The maximum number of concurrent reconciliations
reconciliation_max_concurrency: t.Annotated[int, Field(gt = 0)] = 20
#: The maximum delay between retries when backing off
Expand Down
Loading

0 comments on commit a7a36e8

Please sign in to comment.