Merge pull request #6581 from dokku/tls-handling
Fix issues in tls handling when deploying via k3s
This commit is contained in:
7 files changed
+76
-33
No files matched your search
@@ -243,7 +243,7 @@ dokku scheduler-k3s:set --global letsencrypt-email-prod automated@dokku.sh
|
|||||||
dokku scheduler-k3s:set --global letsencrypt-email-stag automated@dokku.sh
|
dokku scheduler-k3s:set --global letsencrypt-email-stag automated@dokku.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
After enabling and rebuilding, all apps with an `https` port mapping that utilize the related letsencrypt server will be automatically updated to enable ssl. All http requests will then be redirected to https.
|
After enabling and rebuilding, all apps with an `http:80` port mapping will have a corresponding `https:443` added and ssl will be automatically enabled. All http requests will then be redirected to https.
|
||||||
|
|
||||||
### Customizing the letsencrypt server
|
### Customizing the letsencrypt server
|
||||||
|
|
||||||
|
|||||||
@@ -149,16 +149,18 @@ func applyClusterIssuers(ctx context.Context) error {
|
|||||||
clusterIssuerValues := ClusterIssuerValues{
|
clusterIssuerValues := ClusterIssuerValues{
|
||||||
ClusterIssuers: map[string]ClusterIssuer{
|
ClusterIssuers: map[string]ClusterIssuer{
|
||||||
"letsencrypt-stag": {
|
"letsencrypt-stag": {
|
||||||
Email: letsencryptEmailStag,
|
Email: letsencryptEmailStag,
|
||||||
Enabled: letsencryptEmailStag != "",
|
Enabled: letsencryptEmailStag != "",
|
||||||
Name: "letsencrypt-stag",
|
IngressClass: getGlobalIngressClass(),
|
||||||
Server: "https://acme-staging-v02.api.letsencrypt.org/directory",
|
Name: "letsencrypt-stag",
|
||||||
|
Server: "https://acme-staging-v02.api.letsencrypt.org/directory",
|
||||||
},
|
},
|
||||||
"letsencrypt-prod": {
|
"letsencrypt-prod": {
|
||||||
Email: letsencryptEmailProd,
|
Email: letsencryptEmailProd,
|
||||||
Enabled: letsencryptEmailProd != "",
|
Enabled: letsencryptEmailProd != "",
|
||||||
Name: "letsencrypt-prod",
|
IngressClass: getGlobalIngressClass(),
|
||||||
Server: "https://acme-v02.api.letsencrypt.org/directory",
|
Name: "letsencrypt-prod",
|
||||||
|
Server: "https://acme-v02.api.letsencrypt.org/directory",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -496,7 +498,7 @@ func getComputedImagePullSecrets(appName string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getGlobalIngressClass() string {
|
func getGlobalIngressClass() string {
|
||||||
return common.PropertyGetDefault("scheduler-k3s", "global", "ingress-class", DefaultIngressClass)
|
return common.PropertyGetDefault("scheduler-k3s", "--global", "ingress-class", DefaultIngressClass)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getIngressAnnotations(appName string, processType string) (map[string]string, error) {
|
func getIngressAnnotations(appName string, processType string) (map[string]string, error) {
|
||||||
|
|||||||
@@ -161,12 +161,11 @@ type ProcessCron struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ProcessPortMap struct {
|
type ProcessPortMap struct {
|
||||||
ContainerPort int32 `yaml:"container_port"`
|
ContainerPort int32 `yaml:"container_port"`
|
||||||
HostPort int32 `yaml:"host_port"`
|
HostPort int32 `yaml:"host_port"`
|
||||||
Scheme string `yaml:"scheme"`
|
Scheme string `yaml:"scheme"`
|
||||||
Protocol PortmapProtocol `yaml:"protocol"`
|
Protocol PortmapProtocol `yaml:"protocol"`
|
||||||
Name string `yaml:"name"`
|
Name string `yaml:"name"`
|
||||||
RedirectToHttps bool `yaml:"redirect_to_https"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type PortmapProtocol string
|
type PortmapProtocol string
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
{{- $processName := "PROCESS_NAME" }}
|
{{- $processName := "PROCESS_NAME" }}
|
||||||
{{- $config := index .Values.processes "PROCESS_NAME" }}
|
{{- $config := index .Values.processes "PROCESS_NAME" }}
|
||||||
|
{{- $mappings := dict }}
|
||||||
|
{{- range $pdx, $port_map := $config.web.port_maps }}
|
||||||
|
{{- $mappings := set $mappings $port_map.name "true" }}
|
||||||
|
{{- end }}
|
||||||
---
|
---
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
@@ -76,6 +80,9 @@ spec:
|
|||||||
{{- if eq $processName "web" }}
|
{{- if eq $processName "web" }}
|
||||||
ports:
|
ports:
|
||||||
{{- range $pdx, $port_map := $config.web.port_maps }}
|
{{- range $pdx, $port_map := $config.web.port_maps }}
|
||||||
|
{{- if and (eq $port_map.scheme "https") (hasKey $mappings (printf "http-80-%.0f" $port_map.container_port)) }}
|
||||||
|
{{- continue }}
|
||||||
|
{{- end }}
|
||||||
- containerPort: {{ $port_map.container_port }}
|
- containerPort: {{ $port_map.container_port }}
|
||||||
name: {{ $port_map.name }}
|
name: {{ $port_map.name }}
|
||||||
protocol: {{ $port_map.protocol }}
|
protocol: {{ $port_map.protocol }}
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
{{- $processName := "PROCESS_NAME" }}
|
{{- $processName := "PROCESS_NAME" }}
|
||||||
{{- $config := index .Values.processes "PROCESS_NAME" }}
|
{{- $config := index .Values.processes "PROCESS_NAME" }}
|
||||||
{{- if and $config.web.domains (eq $.Values.global.network.ingress_class "traefik") }}
|
{{- if and $config.web.domains (eq $.Values.global.network.ingress_class "traefik") }}
|
||||||
|
{{- $mappings := dict }}
|
||||||
{{- range $pdx, $port_map := $config.web.port_maps }}
|
{{- range $pdx, $port_map := $config.web.port_maps }}
|
||||||
|
{{- $mappings := set $mappings $port_map.name "true" }}
|
||||||
|
{{- end }}
|
||||||
|
{{- range $pdx, $port_map := $config.web.port_maps }}
|
||||||
|
{{- if and (eq $port_map.scheme "https") (hasKey $mappings (printf "http-80-%.0f" $port_map.container_port)) }}
|
||||||
|
{{- continue }}
|
||||||
|
{{- end }}
|
||||||
---
|
---
|
||||||
apiVersion: traefik.io/v1alpha1
|
apiVersion: traefik.io/v1alpha1
|
||||||
kind: IngressRoute
|
kind: IngressRoute
|
||||||
@@ -26,16 +33,15 @@ metadata:
|
|||||||
namespace: {{ $.Values.global.namespace }}
|
namespace: {{ $.Values.global.namespace }}
|
||||||
spec:
|
spec:
|
||||||
entryPoints:
|
entryPoints:
|
||||||
{{- if and $config.web.tls.enabled (eq $port_map.scheme "https") }}
|
{{- if $config.web.tls.enabled }}
|
||||||
- websecure
|
- websecure
|
||||||
{{- else }}
|
|
||||||
- web
|
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
- web
|
||||||
routes:
|
routes:
|
||||||
{{- range $ddx, $domain := $config.web.domains }}
|
{{- range $ddx, $domain := $config.web.domains }}
|
||||||
- kind: Rule
|
- kind: Rule
|
||||||
match: Host(`{{ $domain }}`)
|
match: Host(`{{ $domain }}`)
|
||||||
{{- if and $config.web.tls.enabled (and (eq $port_map.scheme "http") $port_map.redirect_to_https) }}
|
{{- if $config.web.tls.enabled }}
|
||||||
middlewares:
|
middlewares:
|
||||||
- name: {{ $.Values.global.app_name}}-{{ $processName }}-redirect-to-https
|
- name: {{ $.Values.global.app_name}}-{{ $processName }}-redirect-to-https
|
||||||
namespace: {{ $.Values.global.namespace }}
|
namespace: {{ $.Values.global.namespace }}
|
||||||
@@ -47,7 +53,7 @@ spec:
|
|||||||
port: {{ $port_map.name }}
|
port: {{ $port_map.name }}
|
||||||
scheme: http
|
scheme: http
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if and $config.web.tls.enabled (eq $port_map.scheme "https") }}
|
{{- if $config.web.tls.enabled }}
|
||||||
tls:
|
tls:
|
||||||
secretName: tls-{{ $.Values.global.app_name }}-{{ $processName }}
|
secretName: tls-{{ $.Values.global.app_name }}-{{ $processName }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
{{- $processName := "PROCESS_NAME" }}
|
{{- $processName := "PROCESS_NAME" }}
|
||||||
{{- $config := index .Values.processes "PROCESS_NAME" }}
|
{{- $config := index .Values.processes "PROCESS_NAME" }}
|
||||||
{{- if and $config.web.domains (eq $.Values.global.network.ingress_class "nginx") }}
|
{{- if and $config.web.domains (eq $.Values.global.network.ingress_class "nginx") }}
|
||||||
|
{{- $mappings := dict }}
|
||||||
{{- range $pdx, $port_map := $config.web.port_maps }}
|
{{- range $pdx, $port_map := $config.web.port_maps }}
|
||||||
|
{{- $mappings := set $mappings $port_map.name "true" }}
|
||||||
|
{{- end }}
|
||||||
|
{{- range $pdx, $port_map := $config.web.port_maps }}
|
||||||
|
{{- if and (eq $port_map.scheme "https") (hasKey $mappings (printf "http-80-%.0f" $port_map.container_port)) }}
|
||||||
|
{{- continue }}
|
||||||
|
{{- end }}
|
||||||
---
|
---
|
||||||
apiVersion: networking.k8s.io/v1
|
apiVersion: networking.k8s.io/v1
|
||||||
kind: Ingress
|
kind: Ingress
|
||||||
@@ -18,6 +25,9 @@ metadata:
|
|||||||
{{ $k }}: {{ $v | quote }}
|
{{ $k }}: {{ $v | quote }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- if $config.web.tls.enabled }}
|
||||||
|
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
|
||||||
|
{{- end }}
|
||||||
labels:
|
labels:
|
||||||
app.kubernetes.io/instance: {{ $.Values.global.app_name }}-{{ $processName }}
|
app.kubernetes.io/instance: {{ $.Values.global.app_name }}-{{ $processName }}
|
||||||
app.kubernetes.io/name: {{ $processName }}
|
app.kubernetes.io/name: {{ $processName }}
|
||||||
@@ -26,7 +36,7 @@ metadata:
|
|||||||
namespace: {{ $.Values.global.namespace }}
|
namespace: {{ $.Values.global.namespace }}
|
||||||
spec:
|
spec:
|
||||||
ingressClassName: nginx
|
ingressClassName: nginx
|
||||||
{{- if and $config.web.tls.enabled (eq $port_map.scheme "https") }}
|
{{- if $config.web.tls.enabled }}
|
||||||
tls:
|
tls:
|
||||||
- hosts:
|
- hosts:
|
||||||
{{- range $ddx, $domain := $config.web.domains }}
|
{{- range $ddx, $domain := $config.web.domains }}
|
||||||
|
|||||||
@@ -351,7 +351,7 @@ func TriggerSchedulerDeploy(scheduler string, appName string, imageTag string) e
|
|||||||
},
|
},
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
Network: GlobalNetwork{
|
Network: GlobalNetwork{
|
||||||
IngressClass: common.PropertyGetDefault("scheduler-k3s", "--global", "ingress-class", DefaultIngressClass),
|
IngressClass: getGlobalIngressClass(),
|
||||||
PrimaryPort: primaryPort,
|
PrimaryPort: primaryPort,
|
||||||
},
|
},
|
||||||
Secrets: map[string]string{},
|
Secrets: map[string]string{},
|
||||||
@@ -417,20 +417,39 @@ func TriggerSchedulerDeploy(scheduler string, appName string, imageTag string) e
|
|||||||
protocol = PortmapProtocol_UDP
|
protocol = PortmapProtocol_UDP
|
||||||
}
|
}
|
||||||
|
|
||||||
redirecToHttps := false
|
|
||||||
if _, ok := portMaps[fmt.Sprintf("https-443-%d", portMap.ContainerPort)]; ok && portMap.Scheme == "http" {
|
|
||||||
redirecToHttps = true
|
|
||||||
}
|
|
||||||
processValues.Web.PortMaps = append(processValues.Web.PortMaps, ProcessPortMap{
|
processValues.Web.PortMaps = append(processValues.Web.PortMaps, ProcessPortMap{
|
||||||
ContainerPort: portMap.ContainerPort,
|
ContainerPort: portMap.ContainerPort,
|
||||||
HostPort: portMap.HostPort,
|
HostPort: portMap.HostPort,
|
||||||
Name: portMap.String(),
|
Name: portMap.String(),
|
||||||
Protocol: protocol,
|
Protocol: protocol,
|
||||||
RedirectToHttps: redirecToHttps,
|
Scheme: portMap.Scheme,
|
||||||
Scheme: portMap.Scheme,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, portMap := range processValues.Web.PortMaps {
|
||||||
|
_, httpOk := portMaps[fmt.Sprintf("http-80-%d", portMap.ContainerPort)]
|
||||||
|
_, httpsOk := portMaps[fmt.Sprintf("https-443-%d", portMap.ContainerPort)]
|
||||||
|
if portMap.Scheme == "http" && !httpsOk && tlsEnabled {
|
||||||
|
processValues.Web.PortMaps = append(processValues.Web.PortMaps, ProcessPortMap{
|
||||||
|
ContainerPort: portMap.ContainerPort,
|
||||||
|
HostPort: 443,
|
||||||
|
Name: fmt.Sprintf("https-443-%d", portMap.ContainerPort),
|
||||||
|
Protocol: PortmapProtocol_TCP,
|
||||||
|
Scheme: "https",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if portMap.Scheme == "https" && !httpOk {
|
||||||
|
processValues.Web.PortMaps = append(processValues.Web.PortMaps, ProcessPortMap{
|
||||||
|
ContainerPort: portMap.ContainerPort,
|
||||||
|
HostPort: 80,
|
||||||
|
Name: fmt.Sprintf("http-80-%d", portMap.ContainerPort),
|
||||||
|
Protocol: PortmapProtocol_TCP,
|
||||||
|
Scheme: "http",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sort.Sort(NameSorter(processValues.Web.PortMaps))
|
sort.Sort(NameSorter(processValues.Web.PortMaps))
|
||||||
sort.Strings(processValues.Web.Domains)
|
sort.Strings(processValues.Web.Domains)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user