Skip to content

NV-4418 Fix and harden the GitLab and GitHub demo scripts#3

Merged
blackoutjack merged 4 commits into
mainfrom
NV-4418-gitlab-poc-unblockers
Jun 12, 2026
Merged

NV-4418 Fix and harden the GitLab and GitHub demo scripts#3
blackoutjack merged 4 commits into
mainfrom
NV-4418-gitlab-poc-unblockers

Conversation

@blackoutjack

@blackoutjack blackoutjack commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Makes both demo scripts run clean on the first try and safe to re-run, then adds a shell lint gate so that hardening cannot silently regress. Each script had a first-run showstopper: demo-scripts/gitlab-demo.sh read its token from a nonexistent token file and aborted under set -e, and demo-scripts/github-actions-demo.sh built its clone URL from the git display name rather than the GitHub login.

Implementation

  • Fix the showstopper token line: pass $TOKEN as the glab variable set value instead of < token from a missing file.
  • Correct repo namespace: glab repo create targets $GROUP/$REPO instead of the bare repo name.
  • Token upsert: glab variable set || glab variable update rotates masked NIGHTVISION_TOKEN per run, aborting if both fail.
  • Empty-token guard: strip whitespace from nightvision token create output and abort if the result is empty.
  • Idempotency: guard the clone and repo/app/target creation; re-runs reset the gitlab remote to the current $GROUP/$REPO instead of pushing to a previous run's project.
  • Logins first: both auths run before the first create step, so an aborted login leaves nothing half-created.
  • Shell hardening: quote all expansions; extend set -e to set -euo pipefail.
  • Hygiene: notice plus documented revert for the sudo /etc/hosts edit; credentials labeled as demo defaults.
  • Port the hardening to github-actions-demo.sh: same strict mode, quoting, auth-first ordering, empty-token guard, and idempotent creates.
  • Fix the GitHub clone owner: derive it from the authenticated gh login; git config user.name is a display name, not a repo owner.
  • Keep the token off disk: pass it to gh secret set from a variable instead of a temporary token file.
  • Validate checkout reuse: a pre-existing clone must point at $OWNER/java-github-actions-demo, and the Actions secret is pinned to that repo explicitly rather than inferred from the remote.
  • Add a shell lint gate: tests/run.sh runs bash -n and shellcheck over every tracked *.sh; local and CI invoke the same entrypoint so they cannot drift, and it stays bash 3.2 compatible for macOS.
  • Harden the lint CI: lint.yml runs with a contents: read default and a SHA-pinned actions/checkout; dependabot.yml refreshes that pin on a 7-day cooldown.
  • Add .gitignore: ignore __pycache__, the demo clone and its scan artifacts, and the local .agent-sandbox-config and analysis trees.

Out-of-scope

Phase 1 GitLab demo consolidation is tracked in NV-4412.

@blackoutjack blackoutjack force-pushed the NV-4418-gitlab-poc-unblockers branch 4 times, most recently from 80cd829 to 0b1d99d Compare June 11, 2026 11:39
@blackoutjack blackoutjack changed the title NV-4418 Fix and harden the GitLab Easy Mode demo script NV-4418 Fix and harden the GitLab and GitHub demo scripts Jun 11, 2026
@blackoutjack blackoutjack force-pushed the NV-4418-gitlab-poc-unblockers branch 5 times, most recently from 91d69b9 to d108339 Compare June 11, 2026 20:01
Make gitlab-demo.sh run clean on first try and safe to re-run.

- Fix the showstopper token line: it read a nonexistent 'token' file and
  aborted under set -e before anything was created. Pass the captured
  $TOKEN as the value argument and drop the '< token' redirect, and guard
  against an empty/whitespace token before setting the masked CI variable.
- Create the repo in the correct namespace ("$GROUP/$REPO").
- Quote all expansions; add set -u -o pipefail.
- Idempotency: skip the clone if present; guard repo/app/target creation
  and the masked CI variable so a second run reuses existing resources
  with a logged warning instead of erroring out; reconcile the gitlab
  remote to the current "$GROUP/$REPO" so a re-run with different
  arguments does not push to the previous run's project.
- Pass '--type API' to target create, matching the casing the NightVision
  docs use.
- Hygiene: print a notice and document a revert command for the
  /etc/hosts edit; label the echoed credentials as the javaspringvulny
  demo defaults; use literal placeholders in the cleanup notes, since
  script-internal variables do not expand in a fresh shell.

Phase 1 GitLab consolidation is tracked in NV-4412.
Port the gitlab-demo.sh fixes to github-actions-demo.sh for consistency,
and fix its own showstopper: the clone URL was built from 'git config
user.name', a display name that is not a valid GitHub owner for most
users. Derive the owner from the authenticated gh session instead.

- Authenticate to GitHub and NightVision before any other step.
- Capture the token in a variable instead of writing it to a 'token'
  file on disk; strip whitespace and abort on an empty result.
- Pin 'gh secret set' to the fork with an explicit --repo instead of
  inferring the repository from the checkout's git remote.
- Quote all expansions; add set -u -o pipefail.
- Idempotency: reuse an existing clone only after confirming its origin
  points at the expected fork; guard app/target creation so a re-run
  reuses existing resources ('gh secret set' already upserts).
- Hygiene: label the echoed credentials as the javaspringvulny demo
  defaults; add cleanup notes with literal placeholders.
Add a static lint gate for the repo's shell scripts so the hardening on the
demo scripts is enforced going forward instead of relying on manual checks.

- tests/run.sh is the single entrypoint: it runs bash -n and shellcheck over
  every git-tracked *.sh file. Both local dev and CI call this exact script, so
  the two can never check different things or drift apart.
- The script enumerates targets via git ls-files so untracked / vendored files
  are never linted, and treats a missing shellcheck as a hard error rather than
  silently downgrading to a weaker check than CI.
- .github/workflows/lint.yml runs tests/run.sh on pushes to main and on all
  pull requests, with a read-only permissions default and a SHA-pinned
  actions/checkout.
- .github/dependabot.yml keeps that SHA pin refreshed as reviewable PRs, with a
  7-day cooldown so freshly published versions are not pinned immediately. This
  matches the GitHub Actions security posture used in the demo target repo.
The repo had no .gitignore, leaving Python bytecode and local-only trees
exposed to accidental commits.

- Ignore __pycache__ / *.pyc from the sarif/ converters.
- Ignore the java-github-actions-demo checkout the demo scripts clone into,
  along with the scan artifacts written inside it.
- Ignore the local .agent-sandbox-config tree and the analysis/ work-product
  directory, neither of which is part of the published reference material.
@blackoutjack blackoutjack force-pushed the NV-4418-gitlab-poc-unblockers branch from d108339 to 7e7d040 Compare June 11, 2026 21:22
@blackoutjack blackoutjack merged commit 155a9df into main Jun 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant