Repository navigation
Commit 300dee4
authored
sec(ci): delete only the ECR repo each staging state owns (#1848)
Staging cleanup force-deleted every ECR repo matching a prefix
cleanup-staging.yml selected repositories to delete with a
starts_with(repositoryName, 'cudly-staging') filter, so a destroy of one
staging state deleted every repository sharing that prefix, including
those owned by other states. This is the same defect class #1592 fixed in
the destroy path, left behind in the staging path, which is why #1820 was
filed against a workflow that force-deletes on dispatch.
Selection now matches the owned repository by exact name, using the
selector added for #1592 rather than a second implementation of the same
idea.
The body was duplicated across call sites, so a future change had to land
in every copy to be effective. It now lives in
scripts/force-delete-owned-ecr-repo.sh, called from all three sites: both
cleanup-staging.yml jobs and destroy-fargate-dev.yml, which carried a
byte-identical third copy. Wiring only the two named in the issue would
have left two shapes for the same destructive operation, which is the
asymmetry that turned #1592 into #1820.
The wiring assertion in the test suite had to move with it. It previously
matched the inline selector pipeline, text that no longer holds the
behaviour after extraction, so it would have kept passing while asserting
nothing. It now matches the delete invocations at each site and is proven
to fail when they change: removing either staging call site drops the step
count and fails; reverting one to a starts_with prefix loop fails against
both the step assertion and the sweep; removing the dev site fails; and
keeping the selector as a live call but moving it out of the pipeline, so
the delete loop reads the raw listing, also fails. That last case is the
one a "the selector is still called" check waves through. Each mutation
was required to produce its specific FAIL line, since a syntax error also
exits non-zero, and each ran against a copy of the tree.
The sweep also misattributed findings. It flushed a site's accumulated
state when the next file's first line arrived, by which point awk's
FILENAME had advanced, so any finding that ran to the end of its file was
reported against whichever file was swept next. Every existing fixture
swept exactly one file, so none could observe it; extending the sweep to
a second file is what exposed it. Fixed by capturing the file at its first
line, with a two-file regression fixture confirmed to fail pre-fix.
The ecr-delete-selection job also gained a contents: read permissions
block instead of inheriting the workflow default.
Verified: the suite passes 46 of 46, up from 41, with the added cases
covering script wiring, the call form, whole-file reporting, a missing
swept file and the misattribution. Run against bash 3.2 and BWK awk
locally, which is stricter than CI's bash 5 and mawk. shellcheck clean on
both scripts; the one remaining SC2016 is pre-existing.
Not verified: these are workflow_dispatch-only destroy workflows against
live AWS staging, so the end-to-end path from terraform output through
aws ecr delete-repository is covered by static assertion and the
selector's 35 standalone cases, not by execution against a real account.
Script path resolution from the runner's working directory and the 100755
mode surviving checkout are correct in the index but unobserved on a
runner.
Deferred: the other shell-only parity jobs in ci.yml likely want the same
permissions block, left alone as a separate change.1 parent 75448a0 commit 300dee4
1 file changed
Lines changed: 17 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
753 | 753 | | |
754 | 754 | | |
755 | 755 | | |
756 | | - | |
757 | | - | |
758 | | - | |
759 | | - | |
760 | | - | |
761 | | - | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
762 | 766 | | |
763 | 767 | | |
764 | 768 | | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
765 | 776 | | |
766 | 777 | | |
767 | 778 | | |
| |||
0 commit comments