shell: add shellcheck CI guard and drive the tree to zero findings #19
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: Jinemi/thermograph#19
Loading…
Reference in a new issue
No description provided.
Delete branch "shell-lint"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds
.forgejo/workflows/shell-lint.ymland fixes everything it reports.~2k lines of shell deploy, provision secrets, and bootstrap hosts as root over
SSH, with no static analysis in front of them. This adds that guard and drives
the tree to zero findings so it starts green.
The guard
apt-get install shellcheck. The distro version drifts with the job image,and a drifted shellcheck grows new warnings that fail CI on an unrelated
push. Pin verified to match the
koalaman/shellcheck:stableimage thezero-findings pass was run against.
secrets-guard: a backstop that onlyruns when you expect it to isn't a backstop, and 26 scripts is seconds.
find, not listed, so a new script is covered themoment it lands.
-x(follow sources), default severity, no excludes. The tree is at zero, soanything reported is a regression, not noise. Findings become
::errorannotations on the diff.
The defect shellcheck cannot see
render-secrets.sh— plaintext secrets could survive in/tmp. Themktempreceiving decrypted vault contents was only removed on the successpath and one failure branch. If the
sops -dfailed, the caller'sset -eaborted the function and neither cleanup ran, leaving decrypted
POSTGRES_PASSWORDin/tmpindefinitely on a live host.Fixed with explicit
rm -f "$tmp"on every exit path, plus|| return 1onboth
sopscalls so a decrypt failure can never write a partial/etc/thermograph.envregardless of the caller's shell options.Worth recording why it is not a
trap ... RETURN, which is the tidier-lookingfix and was the first attempt here (
56be0ddreverts it): a RETURN trap setinside a sourced function is not function-scoped. It persists in the
caller's shell after the function returns, and a RETURN trap also fires when a
./source completes — sodeploy.shsourcing/etc/thermograph.envsix lineslater re-fired it at top level, where
tmp(function-local) is unset. Fatalunder
deploy.sh'sset -u, and silent, because that line already sendsstderr to
/dev/null. Every SOPS host would have rendered secrets and then diedwith no diagnostic before pulling or rolling anything. The comment in the file
now records this so it doesn't get "tidied" back in.
The write section also now captures its status in
rcand cleans up once. Theold trailing
rmwas the function's last command, so it masked a failedin-place
catwrite to status 0 — a half-written/etc/thermograph.envwouldhave deployed as if it succeeded.
Shellcheck findings
autoscale.sh[manual] —set -euwithoutpipefailwhile pipingdocker statsintoawk, so a failure on the left of the pipe was swallowedand the loop autoscaled on empty input. Promoted to
pipefail, withavg_cpufailure treated as a missed sample so a daemon hiccup can't kill the
autoscaler. Verified the busybox ash in
docker:27-cli(the image thatactually runs this) supports
pipefailand the script still parses there.capture-fixtures.sh[SC2015] —jq . || catrancatafterjqhadalready consumed stdin, silently writing a truncated fixture. Now a real
if/else that fails loudly.
capture-fixtures.sh[SC2012] —ls | wc -l→find.deploy.sh/deploy-stack.sh[SC1090/SC1091] —# shellcheck source=paths corrected for the monorepo layout (they still pointed at the split-repo
paths);
/etc/thermograph.envmarked unfollowable, since it is rendered atdeploy time from the SOPS vault and cannot exist at lint time.
dry-run-render.sh[SC2024] — not a bug:sudois needed only to read theroot-owned live env, and the redirect target is a caller-owned
mktemp, sothe redirect running as the invoking user is correct (
sudo teewould bewrong). Suppressed with a directive and the reasoning.
smoke.sh[SC2034] — unused loop counter →_.Base branch
Targets
mainrather thandevdeliberately.devis currently behindmainand its
thermograph-stack.ymlstill carries the pre-cutover/opt/thermograph/deploy/...bind-mount paths; promoting through it wouldrevert
main's monorepo path fix (0ed7e89).Verification
shellcheck -xover all 26 scripts: 0 findings.render-secrets.shexercised in a container against the real call pattern(strict-mode caller → source lib → call → source the rendered env): success
path returns 0 and the caller survives the subsequent source; decrypt-failure
path aborts the caller with no
/etc/thermograph.envwritten; both leave zerotemp files.
autoscale.shsyntax-checked underdocker:27-cli's busybox ash.