Просмотр исходного кода

contrib/sni-router: render mtg-config.toml from a tracked .example

Track `mtg-config.toml.example` with `secret = "${MTG_SECRET}"`; the
rendered `mtg-config.toml` and local `.env` are gitignored, so the
secret never lands in a tracked file.

Quick start switches from "paste the secret into mtg-config.toml" to
either `envsubst < mtg-config.toml.example > mtg-config.toml` or
`cp` + hand-edit `${MTG_SECRET}` for users without envsubst.

After #502 made DOMAIN env-driven, the secret was the last hand-edit
of a tracked file in the example. Follow-up to #506.
pull/525/head
Alexey Dolotov 3 дней назад
Родитель
Сommit
3fc3e51e47

+ 5
- 0
contrib/sni-router/.gitignore Просмотреть файл

1
+# Rendered from mtg-config.toml.example; contains the live secret.
2
+mtg-config.toml
3
+
4
+# Local environment overrides (DOMAIN, MTG_SECRET, ...)
5
+.env

+ 7
- 2
contrib/sni-router/README.md Просмотреть файл

29
 
29
 
30
 # 3. Configure:
30
 # 3. Configure:
31
 #    - .env (or export)  →  DOMAIN=your.domain   # used by HAProxy + Caddy
31
 #    - .env (or export)  →  DOMAIN=your.domain   # used by HAProxy + Caddy
32
-#    - mtg-config.toml   →  paste the secret
32
+#    - render mtg-config.toml from the tracked template
33
+#      (the rendered file is gitignored — secret stays out of git):
34
+MTG_SECRET=<secret-from-step-2> envsubst < mtg-config.toml.example > mtg-config.toml
35
+#      (Or `cp mtg-config.toml.example mtg-config.toml` and edit ${MTG_SECRET}
36
+#      by hand if you don't have envsubst.)
33
 
37
 
34
 # 4. (Optional) put your site content into www/
38
 # 4. (Optional) put your site content into www/
35
 
39
 
120
 |---|---|
124
 |---|---|
121
 | `docker-compose.yml` | Service definitions |
125
 | `docker-compose.yml` | Service definitions |
122
 | `haproxy.cfg` | SNI routing rules (reads `$DOMAIN` from the environment) |
126
 | `haproxy.cfg` | SNI routing rules (reads `$DOMAIN` from the environment) |
123
-| `mtg-config.toml` | mtg proxy config — **paste your secret** |
127
+| `mtg-config.toml.example` | mtg proxy config template — render with `envsubst` or copy + edit |
128
+| `mtg-config.toml` | Rendered mtg proxy config (gitignored, contains your secret) |
124
 | `Caddyfile` | Web server config (auto-HTTPS) |
129
 | `Caddyfile` | Web server config (auto-HTTPS) |
125
 | `www/` | Static site content served by Caddy |
130
 | `www/` | Static site content served by Caddy |

+ 3
- 1
contrib/sni-router/docker-compose.yml Просмотреть файл

10
 #
10
 #
11
 # Quick start:
11
 # Quick start:
12
 #   1. Set DOMAIN in a .env file next to this one (or export it)
12
 #   1. Set DOMAIN in a .env file next to this one (or export it)
13
-#   2. mtg generate-secret YOUR_DOMAIN   -> paste into mtg-config.toml
13
+#   2. mtg generate-secret YOUR_DOMAIN   -> render mtg-config.toml:
14
+#        MTG_SECRET=<secret> envsubst < mtg-config.toml.example > mtg-config.toml
15
+#      (the rendered file is gitignored). See README.md for the cp+edit variant.
14
 #   3. docker compose up -d
16
 #   3. docker compose up -d
15
 #
17
 #
16
 # DOMAIN is forwarded to both Caddy (TLS cert) and HAProxy (SNI ACL),
18
 # DOMAIN is forwarded to both Caddy (TLS cert) and HAProxy (SNI ACL),

contrib/sni-router/mtg-config.toml → contrib/sni-router/mtg-config.toml.example Просмотреть файл

1
-# Minimal mtg configuration for the SNI-router setup.
1
+# Minimal mtg configuration template for the SNI-router setup.
2
 #
2
 #
3
-# 1. Generate a secret:  mtg generate-secret --hex <your.domain>
4
-# 2. Paste it into the `secret` field below.
5
-# 3. Set DOMAIN=<your.domain> in .env (HAProxy + Caddy pick it up).
3
+# This is the tracked template; `docker compose` mounts `mtg-config.toml`
4
+# (gitignored), so render or copy this file before `docker compose up -d`:
5
+#
6
+#   1. Set DOMAIN=<your.domain> in .env (HAProxy + Caddy pick it up).
7
+#   2. Generate the secret:  mtg generate-secret --hex <your.domain>
8
+#   3. Produce mtg-config.toml — pick one:
9
+#        MTG_SECRET=<secret> envsubst < mtg-config.toml.example > mtg-config.toml
10
+#      or just copy and hand-edit `${MTG_SECRET}`:
11
+#        cp mtg-config.toml.example mtg-config.toml && $EDITOR mtg-config.toml
6
 
12
 
7
-secret = "PASTE_YOUR_SECRET_HERE"
13
+secret = "${MTG_SECRET}"
8
 bind-to = "[::]:3128"
14
 bind-to = "[::]:3128"
9
 
15
 
10
 # HAProxy in front sends PROXY protocol v2 headers so mtg can see the
16
 # HAProxy in front sends PROXY protocol v2 headers so mtg can see the

Загрузка…
Отмена
Сохранить