Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and test self-signed issuer #118

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions charts/s3gw/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,16 @@ COSI endpoint
{{- $endpoint := default $defaultendpoint .Values.cosi.driver.endpoint }}
{{- $endpoint }}
{{- end }}


{{- define "s3gw.tlsIssuerName" -}}
{{- if .Values.customTlsIssuer }}
{{- printf "%s" .Values.customTlsIssuer }}
{{- else if eq .Values.tlsIssuer "s3gw-issuer" }}
{{- printf "%s-%s-self-signed-issuer" .Release.Name .Release.Namespace }}
{{- else if eq .Values.tlsIssuer "s3gw-letsencrypt-issuer" }}
{{- printf "%s-%s-letsencrypt-issuer" .Release.Name .Release.Namespace }}
{{- else }}
{{- printf "%s-%s-%s-issuer" .Release.Name .Release.Namespace .Values.tlsIssuer }}
{{- end }}
{{- end }}
7 changes: 5 additions & 2 deletions charts/s3gw/templates/certificate.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{{- if .Values.useCertManager }}
---
# s3gw-ca root certificate
# This is the root certificate that will be used by the private ca issuer to
# issue a certificate for the cluster-internal connection
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
Expand All @@ -13,13 +15,14 @@ spec:
isCA: true
issuerRef:
kind: ClusterIssuer
name: {{ .Release.Name }}-{{ .Release.Namespace }}-self-signed-issuer
name: {{ .Release.Name }}-{{ .Release.Namespace }}-private-issuer
privateKey:
algorithm: ECDSA
size: 256
secretName: {{ .Release.Name }}-{{ .Release.Namespace }}-ca-root
---
# s3gw internal service certificate (private domain)
# This is the certificate that is requested for the cluster internal connection
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
Expand All @@ -33,6 +36,6 @@ spec:
- '*.{{ include "s3gw.serviceName" . }}.{{ .Release.Namespace }}.{{ .Values.privateDomain }}'
issuerRef:
kind: ClusterIssuer
name: {{ .Release.Name }}-{{ .Release.Namespace }}-issuer
name: {{ .Release.Name }}-{{ .Release.Namespace }}-private-issuer
secretName: {{ .Release.Name }}-{{ .Release.Namespace }}-cluster-ip-tls
{{- end }}
4 changes: 2 additions & 2 deletions charts/s3gw/templates/ingress-traefik.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ metadata:
traefik.ingress.kubernetes.io/router.tls: "true"
traefik.ingress.kubernetes.io/router.middlewares:
'{{ .Release.Namespace }}-{{ include "s3gw.CORSMiddlewareName" . }}@kubernetescrd'
cert-manager.io/cluster-issuer: {{ default .Values.tlsIssuer .Values.customTlsIssuer | quote }}
m-ildefons marked this conversation as resolved.
Show resolved Hide resolved
cert-manager.io/cluster-issuer: {{ include "s3gw.tlsIssuerName" . | quote }}
spec:
tls:
- hosts:
Expand Down Expand Up @@ -88,7 +88,7 @@ metadata:
traefik.ingress.kubernetes.io/router.tls: "true"
traefik.ingress.kubernetes.io/router.middlewares:
'{{ .Release.Namespace }}-{{ include "s3gw.CORSMiddlewareName" . }}@kubernetescrd'
cert-manager.io/cluster-issuer: {{ default .Values.tlsIssuer .Values.customTlsIssuer | quote }}
cert-manager.io/cluster-issuer: {{ include "s3gw.tlsIssuerName" . | quote }}
spec:
tls:
- hosts:
Expand Down
29 changes: 14 additions & 15 deletions charts/s3gw/templates/tls-issuer.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
{{- if .Values.useCertManager }}
{{- if eq .Values.tlsIssuer "s3gw-issuer" }}
---
# Self-signed issuer
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: {{ .Release.Name }}-{{ .Release.Namespace }}-self-signed-issuer
labels:
{{ include "s3gw.labels" . | indent 4}}
spec:
selfSigned: {}
---
# Private s3gw-ca issuer
# This issuer is needed in all cases to issue a certificate for the
# cluster-internal connection
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: {{ .Release.Name }}-{{ .Release.Namespace }}-issuer
name: {{ .Release.Name }}-{{ .Release.Namespace }}-private-issuer
labels:
{{ include "s3gw.labels" . | indent 4}}
spec:
ca:
secretName: {{ .Release.Name }}-{{ .Release.Namespace }}-ca-root
{{- else if eq .Values.tlsIssuer "s3gw-letsencrypt-issuer" }}
{{- if empty .Values.customTlsIssuer }}
---
# Let's encrypt production issuer
# This issuer is either using self-signed certificates or requesting
# certificates from Letsencrypt. This is used to issue certificates for the
# ingress, both for the S3 endpoint at the ingres as well as the UI.
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: {{ .Release.Name }}-{{ .Release.Namespace }}-letsencrypt-issuer
name: {{ include "s3gw.tlsIssuerName" . | quote }}
labels:
{{ include "s3gw.labels" . | indent 4}}
spec:
{{- if eq .Values.tlsIssuer "s3gw-issuer" }}
# Self-signed issuer
selfSigned: {}
{{- else if eq .Values.tlsIssuer "s3gw-letsencrypt-issuer" }}
# Let's encrypt production issuer
acme:
email: {{ .Values.email }}
preferredChain: ""
Expand All @@ -47,3 +45,4 @@ spec:
traefik.ingress.kubernetes.io/router.tls: "true"
{{- end }}
{{- end }}
{{- end }}
121 changes: 121 additions & 0 deletions charts/s3gw/tests/certmanager_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
suite: Certificate Manager
templates:
- ingress-traefik.yaml
- tls-issuer.yaml
- certificate.yaml
release:
name: s3gw-release
namespace: s3gw-system
set:
ingress.enabled: true
useCertManager: true
certManagerNamespace: "cert-manager-system"
tests:

- it: Certificates
asserts:

- hasDocuments:
count: 2
template: certificate.yaml

- containsDocument:
kind: Certificate
apiVersion: cert-manager.io/v1
name: s3gw-release-s3gw-system-ca-cert
namespace: cert-manager-system
documentIndex: 0
template: certificate.yaml

- containsDocument:
kind: Certificate
apiVersion: cert-manager.io/v1
name: s3gw-release-s3gw-system-cluster-ip-cert
namespace: s3gw-system
documentIndex: 1
template: certificate.yaml

- it: Custom TLS Issuer
set:
tlsIssuer: "s3gw-issuer"
customTlsIssuer: "my-tls-issuer"
asserts:

- hasDocuments:
count: 1
template: tls-issuer.yaml

- containsDocument:
kind: ClusterIssuer
apiVersion: cert-manager.io/v1
name: s3gw-release-s3gw-system-private-issuer
documentIndex: 0
template: tls-issuer.yaml

- isSubset:
path: metadata.annotations
content:
cert-manager.io/cluster-issuer: my-tls-issuer
documentIndex: 0
template: ingress-traefik.yaml

- it: Self Signed Issuer
set:
tlsIssuer: "s3gw-issuer"
asserts:

- hasDocuments:
count: 2
template: tls-issuer.yaml

- containsDocument:
kind: ClusterIssuer
apiVersion: cert-manager.io/v1
name: s3gw-release-s3gw-system-private-issuer
documentIndex: 0
template: tls-issuer.yaml

- containsDocument:
kind: ClusterIssuer
apiVersion: cert-manager.io/v1
name: s3gw-release-s3gw-system-self-signed-issuer
documentIndex: 1
template: tls-issuer.yaml

- isSubset:
path: metadata.annotations
content:
cert-manager.io/cluster-issuer: s3gw-release-s3gw-system-self-signed-issuer
documentIndex: 0
template: ingress-traefik.yaml

- it: Letsencrypt Issuer
set:
tlsIssuer: "s3gw-letsencrypt-issuer"
asserts:

- hasDocuments:
count: 2
template: tls-issuer.yaml

- containsDocument:
kind: ClusterIssuer
apiVersion: cert-manager.io/v1
name: s3gw-release-s3gw-system-private-issuer
documentIndex: 0
template: tls-issuer.yaml

- containsDocument:
kind: ClusterIssuer
apiVersion: cert-manager.io/v1
name: s3gw-release-s3gw-system-letsencrypt-issuer
documentIndex: 1
template: tls-issuer.yaml

- isSubset:
path: metadata.annotations
content:
cert-manager.io/cluster-issuer: s3gw-release-s3gw-system-letsencrypt-issuer
documentIndex: 0
template: ingress-traefik.yaml
14 changes: 8 additions & 6 deletions charts/s3gw/tests/cosi_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,27 @@ tests:
count: 2
template: cosi-rbac.yaml

- isKind:
of: ClusterRole
documentIndex: 0
template: cosi-rbac.yaml

- containsDocument:
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
name: s3gw-name-s3gw-namespace-objectstorage-provisioner-role
documentIndex: 0
template: cosi-rbac.yaml

- isKind:
of: ClusterRole
documentIndex: 0
of: ClusterRoleBinding
documentIndex: 1
template: cosi-rbac.yaml

- containsDocument:
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
name: s3gw-name-s3gw-namespace-objectstorage-provisioner-role-binding
template: cosi-rbac.yaml

- isKind:
of: ClusterRoleBinding
documentIndex: 1
template: cosi-rbac.yaml

Expand Down
4 changes: 4 additions & 0 deletions charts/s3gw/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ certManagerNamespace: cert-manager
# The name of the predefined TLS issuer to use (s3gw-issuer,
# s3gw-letsencrypt-issuer).
tlsIssuer: "s3gw-issuer"
# The customTlsIssuer overrides any other TLS issuer. It is otherwise completely
# independent from the provided config, but can be used for any configuration
# not possible with the letsencrypt issuer or the self-signed issuer
# customTlsIssuer: ""
# The email address you are planning to use for getting notifications
# about your certificates. Fill this if you are using the
# 's3gw-letsencrypt-issuer'.
Expand Down