Skip to content

Commit fcf5159

Browse files
committed
wip: improve TLS management for helm
Still need to fix some redirects issues. But main goal is to add better resources for testing diffgram in local minikube env. This will help both first time users and helm chart developers to iterate faster over the helm chart changes and test faster any changes to the k8s resources generated by helm.
1 parent ee08327 commit fcf5159

File tree

9 files changed

+79
-40
lines changed

9 files changed

+79
-40
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ example.com\+6-key.pem
1818
example.com\+6.pem
1919

2020
# Chart dependencies
21-
**/charts/*.tgz
21+
**/charts/*.tgz
22+
ca.crt
23+
24+
ca.key
25+
26+
local-ca.crt

Chart.lock

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,5 @@ dependencies:
22
- name: rabbitmq
33
repository: https://charts.bitnami.com/bitnami
44
version: 9.1.4
5-
- name: cert-manager
6-
repository: https://charts.jetstack.io
7-
version: v1.1.0
8-
digest: sha256:16a0d329ffcd4f4ec533d51af30ac1c014066795596729f5572bf93a379a5416
9-
generated: "2022-05-23T09:23:56.111110299-06:00"
5+
digest: sha256:a92c6d671ae303d36df25c5c05705ee5193e1e22a6987e1476f4f815aa9887d7
6+
generated: "2022-05-24T22:45:09.592488539-06:00"

README.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,41 @@ imagePullCredentials:
4646
### TLS Ceritificates
4747
#### Using minikube (For local testing)
4848
Install Cert Manager
49-
`helm repo add jetstack https://charts.jetstack.io`
49+
```
50+
helm repo add jetstack https://charts.jetstack.io
51+
helm install cert-manager --namespace default jetstack/cert-manager --set installCRDs=true
52+
```
5053

51-
`helm install cert-manager --namespace default jetstack/cert-manager --set installCRDs=true`
5254

5355
Default domain on diffgram is: `example.com` so make sure you add that to your local hosts file:
5456

5557
`echo "$(minikube ip) example.com" | sudo tee -a /etc/hosts`
5658

57-
#### Using cert-manager
59+
In order for TLS to work on your local machine, you will need to provide local certificate authorities.
60+
Otherwise your web browser will detect the certificates as invalid.
61+
62+
To do that you can generate a key and certificate like this:
63+
```
64+
# Generate key
65+
openssl genrsa -out ca.key 2048
66+
# Create CA certificate signing it with the previous key.
67+
openssl req -x509 -new -nodes -key ca.key -sha256 -subj "/CN=sampleissuer.local" -days 1024 -out ca.crt -extensions v3_ca
68+
```
69+
Now create the certificates as secrets on your minkube cluster:
70+
```angular2html
71+
kubectl create secret tls my-local-ca-key-pair --key=ca.key --cert=ca.crt
72+
```
73+
Finally Modify your `values.yaml` so that helm chart can grab the secret using cert-manager
74+
issuers. Set `tlsIssuer` to `issuer-local` and `localCaSecretName` to the name you have to the secret created above:
75+
76+
```angular2html
77+
tlsIssuer: issuer-local # One of: "issuer-local", "letsencrypt-staging", or "letsencrypt-prod"
78+
localCaSecretName: my-local-ca-key-pair
79+
80+
```
81+
82+
83+
#### Using cert-manager & Public Domains
5884

5985
1. If you want to have TLS connections, please make sure you have a domain available and access to the name servers so you can modify the records to point to the IP addresses of the ingress.
6086

templates/ingress.yaml

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ metadata:
1111
nginx.ingress.kubernetes.io/enable-cors: "true"
1212
nginx.ingress.kubernetes.io/hsts: "false"
1313
hsts: "false"
14-
nginx.ingress.kubernetes.io/ssl-redirect: "false"
14+
1515
nginx.ingress.kubernetes.io/configuration-snippet: |
1616
add_header Access-Control-Allow-Methods "POST, GET, PUT, PATCH, DELETE, OPTIONS";
1717
add_header Access-Control-Allow-Credentials true;
@@ -31,10 +31,9 @@ metadata:
3131

3232
nginx.org/proxy-pass-headers: directory_id
3333
{{ if eq .Values.useTls true}}
34-
cert-manager.io/issuer: "letsencrypt-prod"
34+
cert-manager.io/issuer: {{ .Values.tlsIssuer }}
3535
{{ end }}
3636
watch-namespace: {{ .Release.Namespace }}
37-
# nginx.ingress.kubernetes.io/force-ssl-redirect: "false"
3837
# Limit uploads to 8TB
3938
nginx.ingress.kubernetes.io/proxy-body-size: 800000m
4039

@@ -47,27 +46,27 @@ spec:
4746
secretName: diffgram-cert-tls-{{ .Values.diffgramDomain }}
4847
{{ end }}
4948
rules:
50-
- host: {{ .Values.diffgramDomain }}
51-
http:
52-
paths:
53-
- path: /api/walrus(/|$)(.*)
54-
pathType: ImplementationSpecific
55-
backend:
56-
service:
57-
name: diffgram-walrus
58-
port:
59-
number: 8080
60-
- path: /api(/|$)(.*)
61-
pathType: ImplementationSpecific
62-
backend:
63-
service:
64-
name: diffgram-default
65-
port:
66-
number: 8080
67-
- path: /(.*)
68-
pathType: ImplementationSpecific
69-
backend:
70-
service:
71-
name: frontend
72-
port:
73-
number: 8080
49+
- host: {{ .Values.diffgramDomain }}
50+
http:
51+
paths:
52+
- path: /api/walrus(/|$)(.*)
53+
pathType: ImplementationSpecific
54+
backend:
55+
service:
56+
name: diffgram-walrus
57+
port:
58+
number: 8080
59+
- path: /api(/|$)(.*)
60+
pathType: ImplementationSpecific
61+
backend:
62+
service:
63+
name: diffgram-default
64+
port:
65+
number: 8080
66+
- path: /(.*)
67+
pathType: ImplementationSpecific
68+
backend:
69+
service:
70+
name: frontend
71+
port:
72+
number: 8080

templates/postgres/deployment.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ metadata:
1313
# job is considered part of the release.
1414
"helm.sh/hook": pre-install
1515
"helm.sh/hook-weight": "-3"
16-
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
1716
spec:
1817
replicas: 1
1918
selector:

templates/tls/issuer_local.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{ if eq .Values.tlsIssuer "issuer-local" }}
2+
apiVersion: cert-manager.io/v1
3+
kind: Issuer
4+
metadata:
5+
name: issuer-local
6+
spec:
7+
ca:
8+
secretName: {{ .Values.localCaSecretName }}
9+
{{ end }}

templates/tls/issuer_prod.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ spec:
88
# The ACME server URL
99
server: https://acme-v02.api.letsencrypt.org/directory
1010
# Email address used for ACME registration
11-
email: pablo.estrada@diffgram.com
11+
email: {{ .Values.issuerEmail }}
1212
# Name of a secret used to store the ACME account private key
1313
privateKeySecretRef:
1414
name: letsencrypt-prod

templates/tls/issuer_staging.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ spec:
88
# The ACME server URL
99
server: https://acme-staging-v02.api.letsencrypt.org/directory
1010
# Email address used for ACME registration
11-
email: pablo.estrada@diffgram.com
11+
email: {{ .Values.issuerEmail }}
1212
# Name of a secret used to store the ACME account private key
1313
privateKeySecretRef:
1414
name: letsencrypt-staging

values.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ diffgramEdition: opencore
1212
# Set this to your public domain where you want diffgram to be.
1313
# This must be a domain name and not a public IP address.
1414
# The chart will generate TLS certificates for the provided domain if useCertManager is 'true'
15-
diffgramDomain: example.com
15+
diffgramDomain: mydiffgram1.com
1616

1717
# Set this to true if you want to use cert manager for TLS certificates generation.
1818
useCertManager: true
19+
1920
# Use it to activate TLS on the nginx ingress
2021
useTls: true
22+
tlsIssuer: issuer-local # One of: "issuer-local", "letsencrypt-staging", or "letsencrypt-prod"
23+
localCaSecretName: my-local-ca-key-pair
24+
issuerEmail: pablo.estrada@diffgram.com
2125

2226
dbSettings:
2327
# Specify How the DB Service should be created

0 commit comments

Comments
 (0)