devbox/internal/secret/secret.go
shoemoney c2bfb5eac7 feat(M1): ignore + chunk + secret + manifest 👀
- internal/ignore: gitignore-syntax .devignore matcher (stdlib, last-match-wins,
  ** / negation / anchoring, always-ignore .devbox/)
- internal/chunk: FastCDC (jotfs/fastcdc-go) + BLAKE3 (zeebo/blake3); Split/Hash,
  dedup-localizes-edits verified (~98% reuse on mid-blob edit)
- internal/secret: default-on deny-list guard (reuses ignore matcher); .env/keys/
  certs/secrets blocked, .env.example allowed, user extras + negation un-block
- internal/manifest: tree walk -> filter (ignore + secret) -> chunk -> content-
  addressed manifest (ID = BLAKE3) + Diff (added/modified/deleted) + blocked list

Full filter->chunk->manifest->diff pipeline tested green.
2026-06-22 23:10:21 -05:00

49 lines
1.4 KiB
Go

// Package secret is devbox's default-on secret guard: it hard-refuses to sync
// files whose paths match a built-in deny-list (plus user extras), independent
// of .devignore. This is the "secrets never leave the machine" guarantee.
package secret
import "git.shoemoney.ai/shoemoney/devbox/internal/ignore"
// DefaultPatterns are always blocked from upload. Gitignore syntax, so the
// .env.example re-include works via last-match-wins. Users can un-block a
// default with a negation in their extra patterns (e.g. "!config.pem").
var DefaultPatterns = []string{
".env",
".env.*",
"!.env.example",
"*.pem",
"*.key",
"*.p12",
"*.pfx",
"*.kdbx",
"*.ppk",
"id_rsa*",
"id_dsa*",
"id_ecdsa*",
"id_ed25519*",
"secrets/",
".aws/credentials",
".ssh/id_*",
}
// Guard decides whether a path must never be uploaded.
type Guard struct{ m *ignore.Matcher }
// New compiles the default deny-list plus any extra gitignore-syntax patterns.
func New(extra []string) (*Guard, error) {
pats := make([]string, 0, len(DefaultPatterns)+len(extra))
pats = append(pats, DefaultPatterns...)
pats = append(pats, extra...)
m, err := ignore.Compile(pats)
if err != nil {
return nil, err
}
return &Guard{m: m}, nil
}
// Blocked reports whether path (forward-slash, relative to the share root) is a
// secret that must not be uploaded.
func (g *Guard) Blocked(path string) bool {
return g.m.Match(path, false)
}