aws-samples / aws-samples/sample-autonomous-cloud-coding-agents

feat(bootstrap): live-account preflight validator

Offen
#126 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
enhancement infra-cdk
Vorherrschende Sprache
TypeScript
Sterne
143
Forks
46
Ø Merge
3 T. 10 Std.
Gemergte PRs (30 T.)
24

Beschreibung

## Parent

Sub-issue 6 of #120 (RFC: Least-privilege CDK bootstrap policies as code)

## Branch strategy

`feat/bootstrap-preflight` → targets `feat/bootstrap-aspect`

## Estimated review time: ~30 min

## Summary

Implement a validator that checks the deployed CDKToolkit stack's CloudFormation outputs against the required bootstrap version/hash before deploying. This prevents the "pull latest, deploy, fail 15 minutes later" failure mode.

## Deliverables

- [ ] Create `cdk/src/bootstrap/preflight/validator.ts`:
- Reads CDKToolkit stack CF outputs (`BootstrapPolicyVersion`, `BootstrapPolicyHash`) via `CloudFormation.describeStacks`
- Compares against required version/hash from the app's policy code
- Returns structured result:
- **PASS**: version matches, hash matches → safe to deploy
- **WARN**: version compatible but hash mismatch → possible console drift, recommend re-bootstrap
- **FAIL**: version too old → lists missing permissions, provides exact remediation command
- **FAIL**: no outputs found → default bootstrap detected (AdministratorAccess), provide bootstrap command
- Outputs both structured JSON (for CI parsing) and human-readable summary (for terminal)
- [ ] Create `cdk/test/bootstrap/validator.test.ts`:
- Mock `CloudFormation.describeStacks` responses for each scenario
- Version match → PASS
- Hash mismatch with compatible version → WARN with advisory message
- Version too old → FAIL with specific missing actions listed
- No CDKToolkit stack → FAIL with "not bootstrapped" message
- No version/hash outputs → FAIL with "default bootstrap detected" message
- AWS SDK error (permissions, network) → clear error message
- [ ] Add `mise //cdk:preflight` task in `cdk/mise.toml`:
- Runs the validator
- Exits 0 on PASS or WARN
- Exits 1 on FAIL
- Prints remediation: exact `mise //cdk:bootstrap` command to fix

## Key design decisions

- Requires only `cloudformation:DescribeStacks` permission (read-only, safe for CI with minimal credentials)
- WARN does **not** block deploy — hash drift from console edits is advisory, not fatal
- FAIL prints the exact `mise //cdk:bootstrap` command needed (copy-paste friendly)
- Validator is importable as a library (for integration tests) and runnable as a CLI entry point (for mise task)
- Uses `@aws-sdk/client-cloudformation` (already a transitive dep via CDK)

## Acceptance criteria

- All test scenarios pass with mocked AWS responses
- `mise //cdk:preflight` exits cleanly when CDKToolkit outputs match
- `mise //cdk:preflight` exits 1 with actionable message when versions mismatch
- Error messages include the exact command to run (no guessing for operators)

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit cdk/src/bootstrap/preflight/validator.ts und cdk/test/bootstrap/validator.test.ts, untersuche anschließend den vorhandenen Policy-Code und die cdk/mise.toml-Einstiegspunkte. Führe die gemockten Szenarien für Übereinstimmung, Drift, alte oder fehlende Ausgaben und AWS-Fehler aus. Die Arbeit ist abgeschlossen, wenn strukturierte und Terminal-Ergebnisse erzeugt werden, der mise-Task die erforderlichen Exit-Codes verwendet und Fehler den genauen bootstrap-Befehl ausgeben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
aws, typescript
Bereich
ci-cd, cloud, devops, infrastructure
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Ruhig
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
52/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.