Commit 6c9386f
authored
feat: live MITM cert reload (#18)
**feat: live MITM cert reload**
Adds the ability to reload the MITM CA certificate in a running
greyproxy instance without restarting the service.
Before this PR, regenerating the CA cert required manually restarting
greyproxy for the new cert to take effect. This PR makes cert rotation
seamless — the daemon detects cert file changes automatically and
reloads in place. First-time install also generates the CA certificate
automatically.
**CLI**
* Added `greyproxy cert reload` subcommand — sends a reload request to
the running daemon and reports success or failure
* `greyproxy install` now auto-generates the CA certificate if one does
not exist, so the first-time setup works out of the box
**Daemon**
* Extracted `injectCertPaths()` so cert path injection runs on both
startup and config reload
* Added `watchCertFiles()` goroutine — uses fsnotify (inotify/kqueue)
and triggers a reload only after
both `ca-cert.pem` and `ca-key.pem` have been written, preventing a key
mismatch if the watcher fires between the two sequential writes
* Added `certMtime` tracking so the daemon records the mtime of the cert
at last successful load
**API**
* Added `POST /api/cert/reload` endpoint (`CertReloadHandler`) with
mtime guard — skips reload and returns `cert unchanged, no reload
needed` if the cert file has not changed since the last load
**UI**
* Removed 3 stale "restart greyproxy to apply" messages from the
settings page
**Tests**
* `TestCertReloadHandler_unchanged_skipsReload` — mtime guard skips
reload when cert is unchanged
* `TestCertReloadHandler_changed_triggersReload` — reload fires when
cert mtime has advanced
* Tests for `injectCertPaths`
* * *
---
<img width="897" height="223" alt="yata"
src="https://github.com/user-attachments/assets/c806b2b0-7147-4da9-a898-ac18e1859b80"
/>
---
<img width="1042" height="638" alt="tsl"
src="https://github.com/user-attachments/assets/a8ebbe29-ef69-4b64-ac3f-5ad1ad07ff86"
/>1 parent 262188a commit 6c9386f
File tree
11 files changed
+521
-44
lines changed- cmd/greyproxy
- internal/greyproxy
- api
- ui/templates
11 files changed
+521
-44
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
48 | 77 | | |
49 | 78 | | |
50 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
| 13 | + | |
11 | 14 | | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
| |||
24 | 28 | | |
25 | 29 | | |
26 | 30 | | |
| 31 | + | |
27 | 32 | | |
28 | 33 | | |
29 | 34 | | |
| |||
40 | 45 | | |
41 | 46 | | |
42 | 47 | | |
| 48 | + | |
| 49 | + | |
43 | 50 | | |
44 | 51 | | |
45 | 52 | | |
| |||
62 | 69 | | |
63 | 70 | | |
64 | 71 | | |
65 | | - | |
66 | 72 | | |
67 | 73 | | |
68 | 74 | | |
69 | 75 | | |
70 | 76 | | |
71 | 77 | | |
72 | | - | |
73 | 78 | | |
74 | 79 | | |
75 | 80 | | |
| |||
96 | 101 | | |
97 | 102 | | |
98 | 103 | | |
99 | | - | |
100 | 104 | | |
101 | 105 | | |
102 | 106 | | |
103 | 107 | | |
104 | 108 | | |
105 | | - | |
106 | 109 | | |
107 | 110 | | |
108 | 111 | | |
| |||
115 | 118 | | |
116 | 119 | | |
117 | 120 | | |
118 | | - | |
119 | 121 | | |
120 | 122 | | |
121 | 123 | | |
| |||
290 | 292 | | |
291 | 293 | | |
292 | 294 | | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
| 113 | + | |
113 | 114 | | |
114 | 115 | | |
115 | 116 | | |
| |||
226 | 227 | | |
227 | 228 | | |
228 | 229 | | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
229 | 236 | | |
230 | 237 | | |
231 | 238 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
50 | 55 | | |
51 | 56 | | |
52 | 57 | | |
| |||
75 | 80 | | |
76 | 81 | | |
77 | 82 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
| 83 | + | |
99 | 84 | | |
100 | 85 | | |
101 | 86 | | |
| |||
114 | 99 | | |
115 | 100 | | |
116 | 101 | | |
| 102 | + | |
117 | 103 | | |
118 | 104 | | |
119 | 105 | | |
120 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
121 | 200 | | |
122 | 201 | | |
123 | 202 | | |
| |||
244 | 323 | | |
245 | 324 | | |
246 | 325 | | |
| 326 | + | |
247 | 327 | | |
248 | 328 | | |
249 | 329 | | |
| |||
254 | 334 | | |
255 | 335 | | |
256 | 336 | | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
257 | 345 | | |
258 | 346 | | |
259 | 347 | | |
| |||
365 | 453 | | |
366 | 454 | | |
367 | 455 | | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
368 | 462 | | |
369 | 463 | | |
370 | 464 | | |
371 | 465 | | |
372 | 466 | | |
373 | | - | |
374 | | - | |
| 467 | + | |
| 468 | + | |
375 | 469 | | |
376 | 470 | | |
377 | 471 | | |
378 | 472 | | |
379 | 473 | | |
380 | | - | |
381 | | - | |
| 474 | + | |
| 475 | + | |
382 | 476 | | |
383 | 477 | | |
384 | 478 | | |
| |||
0 commit comments