Skip to content

Commit

Permalink
Fix tls mode ca and external
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed May 3, 2024
1 parent ec2929f commit d51b5e0
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 35 deletions.
8 changes: 1 addition & 7 deletions apis/installer/v1alpha1/ace_options_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ type AceOptionsNatsSettings struct {
type AceOptionsPlatformInfra struct {
StorageClass LocalObjectReference `json:"storageClass"`
KubeStash KubeStashOptions `json:"kubestash"`
TLS AceOptionsInfraTLS `json:"tls"`
TLS InfraTLS `json:"tls"`
DNS InfraDns `json:"dns"`
CloudServices AceOptionsInfraCloudServices `json:"cloudServices"`
}
Expand All @@ -217,12 +217,6 @@ type KubeStashBackendInfra struct {
GCS store.GCSSpec `json:"gcs"`
}

type AceOptionsInfraTLS struct {
Issuer TLSIssuerType `json:"issuer"`
Acme TLSIssuerAcme `json:"acme"`
Certificate TLSData `json:"certificate"`
}

type AceOptionsInfraCloudServices struct {
Provider ObjstoreProvider `json:"provider"`
Objstore AceOptionsInfraObjstore `json:"objstore"`
Expand Down
23 changes: 23 additions & 0 deletions apis/installer/v1alpha1/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Copyright AppsCode Inc. and Contributors
Licensed under the AppsCode Community License 1.0.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://github.com/appscode/licenses/raw/1.0.0/AppsCode-Community-1.0.0.md
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

func (i InfraTLS) MountCACerts() bool {
return i.Issuer == TLSIssuerTypeCA ||
i.Issuer == TLSIssuerTypeLEStaging ||
(i.Issuer == TLSIssuerTypeExternal && i.CA.Cert != "")
}
17 changes: 0 additions & 17 deletions apis/installer/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions charts/ace/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ Returns the ServiceMonitor labels
{{- printf "%s-nats-cred" (include "ace.fullname" .) -}}
{{- end }}

{{- define "settings.caProviderClass" -}}
{{- if (has .Values.global.infra.tls.issuer (list "ca" "letsencrypt-staging")) }}{{ include "ace.fullname" . }}{{end -}}
{{- end }}

{{/*
Determine database host name
*/}}
Expand Down
8 changes: 7 additions & 1 deletion charts/ace/templates/ingress/ca.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{{- if and (eq .Values.global.infra.tls.issuer "ca") .Values.global.infra.tls.ca.cert .Values.global.infra.tls.ca.key }}

{{- $data := dict
"tls.crt" .Values.global.infra.tls.ca.cert
"tls.key" .Values.global.infra.tls.ca.key
}}

apiVersion: v1
kind: Secret
metadata:
Expand All @@ -7,5 +13,5 @@ metadata:
labels:
{{- include "ace.labels" . | nindent 4 }}
type: kubernetes.io/tls
stringData: {{ dict "tls.crt" .Values.global.infra.tls.ca.cert "tls.key" .Values.global.infra.tls.ca.key | toJson }}
stringData: {{ $data | toJson }}
{{- end }}
17 changes: 17 additions & 0 deletions charts/ace/templates/ingress/caprovicerclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,21 @@ spec:
kind: Issuer
namespace: {{ .Release.Namespace }}
name: {{ include "ace.fullname" . }}

{{- else if and (eq .Values.global.infra.tls.issuer "external") .Values.global.infra.tls.ca.cert }}

apiVersion: cacerts.csi.cert-manager.io/v1alpha1
kind: CAProviderClass
metadata:
name: {{ include "ace.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "ace.labels" . | nindent 4 }}
spec:
refs:
- apiGroup: ""
kind: Secret
namespace: {{ .Release.Namespace }}
name: {{ include "ace.fullname" . }}-cert
key: "ca.crt"
{{- end}}
11 changes: 10 additions & 1 deletion charts/ace/templates/ingress/secret.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{{- if (eq .Values.global.infra.tls.issuer "external") }}

{{ $data := dict
"tls.crt" .Values.global.infra.tls.certificate.cert
"tls.key" .Values.global.infra.tls.certificate.key
}}
{{- with .Values.global.infra.tls.ca.cert }}
{{- $_ := set $data "ca.crt" . }}
{{- end }}

apiVersion: v1
kind: Secret
metadata:
Expand All @@ -7,5 +16,5 @@ metadata:
labels:
{{- include "ace.labels" . | nindent 4 }}
type: kubernetes.io/tls
stringData: {{ dict "tls.crt" .Values.global.infra.tls.certificate.cert "tls.key" .Values.global.infra.tls.certificate.key | toJson }}
stringData: {{ $data | toJson }}
{{- end }}
11 changes: 8 additions & 3 deletions charts/ace/templates/platform/setup-job.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{{- $infra := .Values.global.infra -}}

{{- $mountCACerts := or
(has $infra.tls.issuer (list "ca" "letsencrypt-staging"))
(and (eq $infra.tls.issuer "external") $infra.tls.ca.cert )
}}

apiVersion: batch/v1
kind: Job
metadata:
Expand Down Expand Up @@ -120,7 +125,7 @@ spec:
- name: objstore-cred
mountPath: {{ $infra.objstore.mountPath }}
{{- end }}
{{- if (include "settings.caProviderClass" .) }}
{{- if $mountCACerts }}
- name: cacerts
mountPath: /etc/ssl/certs
{{- end }}
Expand All @@ -147,14 +152,14 @@ spec:
defaultMode: 420
secretName: {{ $secretName }}
{{- end }}
{{- with $cpc := (include "settings.caProviderClass" .) }}
{{- if $mountCACerts }}
- name: cacerts
csi:
driver: cacerts.csi.cert-manager.io
readOnly: true
volumeAttributes:
os: debian
caProviderClasses: {{ $cpc }}
caProviderClasses: {{ include "ace.fullname" . }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
Expand Down
8 changes: 7 additions & 1 deletion charts/service-presets/templates/egress-cert/ca.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{{- if (eq .Values.infra.tls.issuer "ca") }}

{{- $data := dict
"tls.crt" .Values.infra.tls.ca.cert
"tls.key" .Values.infra.tls.ca.key
}}

apiVersion: v1
kind: Secret
metadata:
Expand All @@ -7,5 +13,5 @@ metadata:
labels:
{{- include "service-presets.labels" . | nindent 4 }}
type: kubernetes.io/tls
stringData: {{ dict "tls.crt" .Values.infra.tls.ca.cert "tls.key" .Values.infra.tls.ca.key | toJson }}
stringData: {{ $data | toJson }}
{{- end }}
17 changes: 17 additions & 0 deletions charts/service-presets/templates/egress-cert/caprovicerclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,21 @@ spec:
kind: Issuer
namespace: {{ .Release.Namespace }}
name: {{ include "service-presets.fullname" . }}

{{- else if and (eq .Values.infra.tls.issuer "external") .Values.infra.tls.ca.cert }}

apiVersion: cacerts.csi.cert-manager.io/v1alpha1
kind: CAProviderClass
metadata:
name: {{ include "service-presets.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "service-presets.labels" . | nindent 4 }}
spec:
refs:
- apiGroup: ""
kind: Secret
namespace: {{ .Release.Namespace }}
name: {{ include "service-presets.fullname" . }}-cert
key: "ca.crt"
{{- end}}
4 changes: 4 additions & 0 deletions charts/service-presets/templates/egress-cert/issuer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ metadata:
{{- include "service-presets.labels" . | nindent 4 }}
spec:
{{- if eq .Values.infra.tls.issuer "ca" }}
{{- if and .Values.infra.tls.ca.cert .Values.infra.tls.ca.key }}
ca:
secretName: {{ include "service-presets.fullname" . }}-ca
{{- else }}
selfSigned: {}
{{- end }}
{{- end }}
{{- if has .Values.infra.tls.issuer (list "letsencrypt" "letsencrypt-staging") }}
acme:
Expand Down
11 changes: 10 additions & 1 deletion charts/service-presets/templates/egress-cert/secret.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{{- if (eq .Values.infra.tls.issuer "external") }}

{{- $data := dict
"tls.crt" .Values.infra.tls.certificate.cert
"tls.key" .Values.infra.tls.certificate.key
}}
{{- with .Values.infra.tls.ca.cert }}
{{- $_ := set $data "ca.crt" . }}
{{- end }}

apiVersion: v1
kind: Secret
metadata:
Expand All @@ -7,5 +16,5 @@ metadata:
labels:
{{- include "service-presets.labels" . | nindent 4 }}
type: kubernetes.io/tls
stringData: {{ dict "tls.crt" .Values.infra.tls.certificate.cert "tls.key" .Values.infra.tls.certificate.key | toJson }}
stringData: {{ $data | toJson }}
{{- end }}
8 changes: 8 additions & 0 deletions schema/ace-options/values.openapiv3_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,13 @@ properties:
required:
- email
type: object
ca:
properties:
cert:
type: string
key:
type: string
type: object
certificate:
properties:
cert:
Expand All @@ -838,6 +845,7 @@ properties:
type: string
required:
- acme
- ca
- certificate
- issuer
type: object
Expand Down

0 comments on commit d51b5e0

Please sign in to comment.