Skip to content

Commit bb092b7

Browse files
committed
services/nomad: use lego derived certs for traefik
1 parent e0ef776 commit bb092b7

5 files changed

Lines changed: 100 additions & 32 deletions

File tree

ansible/roles/nomad-client/templates/40-client.hcl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ client {
33
enabled = true
44
network_interface = "void0"
55
cni_path = "/usr/libexec/cni"
6+
gc_interval = "10m"
67

78
host_volume "netauth_config" {
89
path = "/etc/netauth"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
job "lego" {
2+
datacenters = ["VOID"]
3+
namespace = "infrastructure"
4+
type = "batch"
5+
6+
periodic {
7+
cron = "@weekly"
8+
}
9+
10+
group "lego" {
11+
network { mode = "bridge" }
12+
13+
task "app" {
14+
driver = "docker"
15+
16+
vault {
17+
policies = ["void-secrets-lego"]
18+
}
19+
20+
config {
21+
image = "ghcr.io/void-linux/infra-lego:v20210923RC04"
22+
}
23+
24+
env {
25+
VAULT_ADDR="http://active.vault.service.consul:8200"
26+
ACTION="renew"
27+
DO_PROPAGATION_TIMEOUT="10m"
28+
}
29+
30+
template {
31+
data = <<EOF
32+
{{- with secret "secret/lego/do_api" }}
33+
DO_AUTH_TOKEN={{.Data.api_token}}
34+
{{- end }}
35+
EOF
36+
destination = "secrets/env"
37+
env = true
38+
}
39+
}
40+
}
41+
}

services/nomad/infrastructure/traefik.nomad

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ job "traefik" {
33
namespace = "infrastructure"
44
type = "system"
55
group "lb" {
6-
volume "acme_data" {
7-
type = "host"
8-
read_only = false
9-
source = "acme_data"
10-
}
11-
126
network {
137
mode = "bridge"
148
port "http" {
@@ -25,21 +19,24 @@ job "traefik" {
2519
}
2620
}
2721

22+
service {
23+
port = "http"
24+
tags = [
25+
"traefik.enable=true",
26+
"traefik.http.routers.proxy-lb.service=api@internal",
27+
"traefik.http.routers.proxy-lb.tls=true",
28+
]
29+
}
30+
2831
task "traefik" {
2932
driver = "docker"
3033

31-
volume_mount {
32-
volume = "acme_data"
33-
destination = "/acme"
34-
read_only = false
35-
}
36-
3734
vault {
3835
policies = ["void-secrets-traefik"]
3936
}
4037

4138
config {
42-
image = "traefik:2.3.5"
39+
image = "traefik:2.5.3"
4340

4441
args = [
4542
"--api.dashboard",
@@ -48,19 +45,21 @@ job "traefik" {
4845
"--entrypoints.https.address=:443",
4946
"--entrypoints.traefik.address=:8080",
5047
"--metrics.prometheus",
48+
"--pilot.dashboard=false",
5149
"--providers.file.filename=/local/dynamic.toml",
5250
"--providers.consulcatalog.defaultrule=Host(`{{normalize .Name}}.s.voidlinux.org`)",
5351
"--providers.consulcatalog.exposedbydefault=false",
5452
"--providers.consulcatalog.endpoint.address=${attr.unique.network.ip-address}:8500",
55-
"--certificatesresolvers.do.acme.email=hostmaster@voidlinux.org",
56-
"--certificatesresolvers.do.acme.storage=/acme/acme.json",
57-
"--certificatesresolvers.do.acme.dnschallenge.provider=digitalocean",
58-
"--certificatesresolvers.do.acme.dnschallenge.resolvers=8.8.8.8",
5953
]
6054
}
6155

6256
template {
6357
data=<<EOF
58+
[tls.stores]
59+
[tls.stores.default]
60+
[tls.stores.default.defaultCertificate]
61+
certFile = "/secrets/certs/voidlinux.org.crt"
62+
keyFile = "/secrets/certs/voidlinux.org.key"
6463
[http]
6564
[http.middlewares]
6665
[http.middlewares.httpsredirect.redirectScheme]
@@ -71,15 +70,6 @@ job "traefik" {
7170
middlewares = ["httpsredirect"]
7271
rule = "HostRegexp(`{host:.+}`)"
7372
service = "noop@internal"
74-
[http.routers.wildcard-cert]
75-
entryPoints = ["http"]
76-
service = "noop@internal"
77-
rule = "Host(`noop.s.voidlinux.org`)"
78-
[http.routers.wildcard-cert.tls]
79-
certResolver = "do"
80-
[[http.routers.wildcard-cert.tls.domains]]
81-
main = "*.voidlinux.org"
82-
sans = ["*.s.voidlinux.org"]
8373
[http.routers.nomad]
8474
entryPoints = ["https"]
8575
service = "nomad"
@@ -113,14 +103,23 @@ EOF
113103
}
114104

115105
template {
116-
data=<<EOF
117-
{{- with secret "secret/traefik/do-api" }}
118-
DO_AUTH_TOKEN={{.Data.api_key}}
119-
{{- end }}
106+
data =<<EOF
107+
{{- with secret "secret/lego/data/certificates/_.voidlinux.org.crt" -}}
108+
{{.Data.contents}}
109+
{{- end -}}
110+
EOF
111+
destination = "secrets/certs/voidlinux.org.crt"
112+
perms = 400
113+
}
114+
115+
template {
116+
data =<<EOF
117+
{{- with secret "secret/lego/data/certificates/_.voidlinux.org.key" -}}
118+
{{.Data.contents}}
119+
{{- end -}}
120120
EOF
121-
destination = "secrets/env"
121+
destination = "secrets/certs/voidlinux.org.key"
122122
perms = 400
123-
env = true
124123
}
125124

126125
resources {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
data "vault_policy_document" "secrets_lego" {
2+
rule {
3+
path = "secret/lego/*"
4+
capabilities = [
5+
"create",
6+
"delete",
7+
"list",
8+
"read",
9+
"update",
10+
]
11+
description = "LEGO manages the entire prefix as an fs mirror"
12+
}
13+
}
14+
15+
resource "vault_policy" "secrets_lego" {
16+
name = "void-secrets-lego"
17+
policy = data.vault_policy_document.secrets_lego.hcl
18+
}
19+

terraform/hashistack/policy_traefik.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ data "vault_policy_document" "secrets_traefik" {
66
]
77
description = "Read Traefik Secrets"
88
}
9+
10+
rule {
11+
path = "secret/lego/data/certificates/*"
12+
capabilities = [
13+
"read"
14+
]
15+
description = "Traefik uses LEGO certificates"
16+
}
917
}
1018

1119
resource "vault_policy" "secrets_traefik" {

0 commit comments

Comments
 (0)