Commit ec16d7b
Add Redis / Valkey storage backend with optional Sentinel
Adds a third storage backend alongside filesystem and etcd, backed by a
Redis- (or Valkey-) compatible server. The backend targets clusters that
already run Redis/Valkey as HA infrastructure and want to reuse it for CA
state rather than stand up etcd.
Connectivity supports both direct (redis_addrs) and Sentinel-managed
failover (redis_sentinel_master_name + redis_sentinel_addrs) via
go-redis's FailoverClient, with ACL auth and TLS for both the primary and
the Sentinels.
Storage layout mirrors the etcd backend's shape: values carry an 8-byte
big-endian UnixNano mtime prefix so ModTime is answered from the same
round-trip as the value; atomic cross-replica inventory appends are
performed by a server-side Lua script that reads, strips the old mtime,
appends, and writes back in one step.
Distributed locks — surfaced through the existing Locker capability and
StorageService.WithLock — use the standard Redis recipe: SET NX PX with a
per-acquisition random token, a background heartbeat that extends the
TTL via a token-checking Lua script, and an Unlock that runs the
token-matching delete script so a stale caller cannot release a lock
another holder has since acquired. A per-name process-local mutex wraps
the distributed lock the same way the etcd backend wraps concurrency.Mutex,
because SET NX is not re-entrant from a single client either.
Under Sentinel the replication is asynchronous, so an in-flight failover
can narrow the lock guarantee; this is documented with a pointer to the
etcd backend for operators needing strict linearizability.
Tests:
- 10 unit tests against in-process miniredis (CRUD, ModTime, List,
concurrent AppendLine across two backends, end-to-end via
StorageService, cross-replica lock mutual exclusion / serialisation /
distinct-names / cross-backend, and stale-token-safe Unlock after a
fast-forwarded TTL expiry).
- An opt-in integration suite behind -tags=redis_integration driven by
PUPPET_CA_TEST_REDIS_ADDR that exercises the same behaviours against a
real Redis / Valkey.
Config is exposed via YAML, PUPPET_CA_REDIS_* env vars, and CLI flags
(--storage-backend redis|valkey, --redis-addrs, --redis-sentinel-*,
--redis-key-prefix). docs/storage-backends.md gains a full section with
the key layout, coordination semantics, direct and Sentinel
configurations, and an updated backend comparison table.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 5ed55f4 commit ec16d7b
9 files changed
Lines changed: 1736 additions & 35 deletions
File tree
- cmd/puppet-ca
- docs
- internal/storage
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
81 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
82 | 84 | | |
83 | 85 | | |
84 | 86 | | |
| |||
90 | 92 | | |
91 | 93 | | |
92 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
93 | 114 | | |
94 | 115 | | |
95 | 116 | | |
| |||
280 | 301 | | |
281 | 302 | | |
282 | 303 | | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
283 | 357 | | |
284 | 358 | | |
285 | 359 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
99 | 118 | | |
100 | 119 | | |
101 | 120 | | |
| |||
192 | 211 | | |
193 | 212 | | |
194 | 213 | | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
200 | 223 | | |
201 | 224 | | |
202 | 225 | | |
| |||
278 | 301 | | |
279 | 302 | | |
280 | 303 | | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
281 | 316 | | |
282 | 317 | | |
283 | 318 | | |
| |||
630 | 665 | | |
631 | 666 | | |
632 | 667 | | |
633 | | - | |
| 668 | + | |
634 | 669 | | |
635 | 670 | | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
636 | 675 | | |
637 | 676 | | |
638 | 677 | | |
| |||
0 commit comments