Skip to content

Admin: scope the secrets and the token of the CI workflows, lock the actions - #10551

Open
Totara-thib wants to merge 4 commits into
getmoto:masterfrom
Totara-thib:ci-hardening
Open

Totara-thib wants to merge 4 commits into
getmoto:masterfrom
Totara-thib:ci-hardening

Conversation

@Totara-thib

Copy link
Copy Markdown

Hello, four commits, workflows hardening only:

  • build.yml called the two unit test workflows with secrets: inherit, so every test job could read all the repository secrets, Docker Hub credentials included. They read one, CODECOV_TOKEN, now passed by name.
  • Nineteen workflows had no permissions block. None of their jobs writes with it, so they get contents: read.
  • Thirty-nine checkouts stop storing the token, the data update ones included: create-pull-request brings its own credentials. release.yml keeps it, it pushes with git.
  • .github/workflows/actions.lock, GitHub's workflow dependency lockfile from gh actions-lock, records the commit every action resolves to. The major tags become the exact releases they point at, and Dependabot updates both. pypa/gh-action-pypi-publish moves from release/v1 to v1.14.3, the same commit, and run_moto_server becomes $/ so the lockfile covers it.

Why: a moved tag reaches whatever its job holds (the tj-actions incident, CVE-2025-30066), here the PyPI, Docker Hub and GHCR publishing rights and the AWS role.

Found and fixed with Plumber (D 31/100 before, B 88/100 after), reviewed and submitted by me.

build.yml called tests_decoratormode.yml and tests_servermode.yml with
secrets: inherit, so every job of the test matrix could read all the
repository secrets, the Docker Hub credentials included, while running
the test suite. The only secret those two workflows use is
CODECOV_TOKEN.

They now declare that secret and build.yml passes it by name. It is
marked optional, so runs from forks behave as before.
Nineteen workflows declared no permissions, so their 41 jobs ran with
whatever the repository default grants. None of them writes anything
with the job token: they check out, build, run the tests and upload
artifacts.

Each of them now declares contents: read. The release, data update,
CodeQL and real AWS workflows already scope their jobs and are left
alone.
actions/checkout leaves the job token in .git/config, where every
later step can read it, and the test jobs then run the whole test
suite next to it. Thirty-nine checkouts now set
persist-credentials: false.

That includes the eight data update workflows: create-pull-request
sets up its own credentials for the push and does not use the stored
ones. The release workflow keeps the default, it commits and pushes
with git directly.
.github/workflows/actions.lock is GitHub's workflow dependency
lockfile, generated with gh actions-lock v0.4.1. It records the commit
each action resolves to, the ones an action calls in turn included,
and the runner refuses a commit that is not the recorded one.

Until now the actions were referenced by major tag, which the
publisher can move, in the jobs that publish to PyPI, Docker Hub and
GHCR and in the ones that assume the AWS role. The references become
the exact release each tag points at today (actions/checkout@v7.0.1
and so on), so Dependabot keeps bumping them. pypa/gh-action-pypi-publish
moves from the release/v1 branch to v1.14.3, the same commit. The
run_moto_server action is referenced as $/ instead of ./ so the
lockfile can cover the download-artifact it calls.

After adding an action or changing a version, run gh actions-lock and
commit the regenerated file.
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