| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "os" |
| 6 | "strings" |
| 7 | |
| 8 | "golang.org/x/crypto/acme/autocert" |
| 9 | ) |
| 10 | |
| 11 | // The certificate-cache seam (issue #550 Part 12, Phase 0 item 8): router |
| 12 | // boxes in a pool must eventually SHARE issued certs — the per-host autocert |
| 13 | // certs, the DNS-01 wildcard PEMs, and the wildcard ACME account key — so |
| 14 | // every issuance artifact goes through one autocert.Cache chosen here, never |
| 15 | // direct file I/O. autocert already defines exactly the interface a remote |
| 16 | // backend needs (Get/Put/Delete with ctx, ErrCacheMiss for absent), so there |
| 17 | // is no parallel abstraction: an S3 backend is a drop-in behind this |
| 18 | // constructor. |
| 19 | |
| 20 | // newCertCache returns the certificate cache selected by LCHAT_CERT_CACHE. |
| 21 | // Unset (or "dir") is today's on-disk layout — autocert.DirCache over dir, |
| 22 | // cache keys as plain file names — byte-identical to what a box already has |
| 23 | // at /data/acme, so an existing cache keeps working over a restart with no |
| 24 | // migration. "s3" is reserved for the pooled-router backend; until it exists |
| 25 | // it refuses to start, because failing loudly beats silently minting certs |
| 26 | // into a local dir the rest of the pool can't see. |
| 27 | func newCertCache(dir string) (autocert.Cache, error) { |
| 28 | switch backend := strings.TrimSpace(os.Getenv("LCHAT_CERT_CACHE")); backend { |
| 29 | case "", "dir": |
| 30 | return autocert.DirCache(dir), nil |
| 31 | case "s3": |
| 32 | // TODO(#550): a thin Get/Put/Delete over S3 GetObject/PutObject/ |
| 33 | // DeleteObject, mapping a missing key to autocert.ErrCacheMiss. The |
| 34 | // AWS SDK v2 S3 client is already a module dependency |
| 35 | // (internal/activator uses it for hibernation), so no new client code |
| 36 | // is needed — only bucket/prefix config and the pooled-router rollout. |
| 37 | return nil, fmt.Errorf("LCHAT_CERT_CACHE=s3: reserved, not implemented yet") |
| 38 | default: |
| 39 | return nil, fmt.Errorf("LCHAT_CERT_CACHE=%q: want unset, \"dir\", or \"s3\"", backend) |
| 40 | } |
| 41 | } |
| 42 | |