Give b2keys least-privilege defaults, require opt-in for key-management capabilities, and add tests

Aperta
#189 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
cli, security

Direzione di ricerca

Start with bin/b2keys/b2keys.go and the listed reference points in examples/simple/simple.go, base/base.go, and internal/b2types/b2types.go; check how the other Backblaze tools handle capability restrictions. Add tests in bin/b2keys using a fake creater, then run go test ./... there. Done means unsafe defaults and inputs are rejected or require opt-in before authorization, output and credential behavior match the stated requirements, and the acceptance criteria pass.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement testing

Summary

bin/b2keys is the repository's only shipped tool. By default it creates a key with no expiration that covers every bucket, and it accepts any capability list, including writeKeys, deleteKeys and the governance-override capability, without a prompt or warning. Other Backblaze tools refuse key-management grants and unscoped write keys unless an explicit override is set. The new secret is printed on stdout in a key=..., secret=... line, which tends to end up in shell history and CI logs. Its legacy environment fallbacks differ from the other program in the repository, a prefix without a bucket fails only after authorizing, and the module has no tests although CI runs go test on it.

Current behavior

At a5e0d13, in bin/b2keys/b2keys.go:

  • :42-44: -duration defaults to 0 and -bucket to empty.
  • :70-77: a zero duration adds no Lifetime; capabilities pass through unchecked.
  • :85-94: without -bucket, the key is created account-wide.
  • :101: fmt.Printf("key=%s, secret=%s\n", ...).
  • :18-19: legacy fallbacks B2_ACCOUNT_ID / B2_SECRET_KEY; examples/simple/simple.go:43-48 uses B2_ACCOUNT_ID / B2_ACCOUNT_KEY.
  • :58: the missing-credentials message has no trailing newline.
  • :71-72: any positive -duration is passed to Lifetime. The library converts the lifetime to whole seconds (base/base.go:2053, :2069), and validDurationInSeconds is omitted when it is 0 (internal/b2types/b2types.go:446, :456), so -duration 500ms creates a key with no expiration.
  • :74-75: -prefix is accepted without -bucket.

.github/workflows/ci.yml:94-97 and the Makefile b2keys target (Makefile:36-37) build and run go test ./... in bin/b2keys, which has no test files. README.md:69-70 advises giving a key "only the capabilities and buckets your program uses"; the tool's defaults do the opposite.

Expected behavior

The tool creates bucket-scoped, expiring keys by default, asks for explicit flags for broader grants, and validates input before calling B2.

Proposed change

  • Require -bucket (or an explicit -all-buckets) and default -duration to a finite value such as 24h, with -no-expiry to opt out.
  • Refuse writeKeys, deleteKeys, listKeys and governance override unless -allow-key-management (or a matching flag) is passed.
  • Validate capabilities against the documented list, reject -prefix without -bucket, and reject -duration under one second, all before authorizing.
  • Print only the secret on stdout (no label) or write it to a 0600 file via -out; print the key ID and a "shown once" note on stderr.
  • Align the legacy variable names with the rest of the repository, or drop them with a CHANGELOG note.
  • Add tests with a fake creater for defaults, refusals and output.

Acceptance criteria

  • b2keys create name writeFiles without -bucket exits non-zero with a usage error.
  • b2keys create -bucket b name writeKeys exits non-zero unless -allow-key-management is passed.
  • A key created without -duration carries the default lifetime.
  • go test ./... in bin/b2keys runs these tests in CI.

Related

None

Lingua principale
Go
Stelle
66
Fork
18
Merge medio
1g 10h
PR unite (30g)
132

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Backblaze/blazer

Tutte le issue di Backblaze/blazer

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.