Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub Workflows security hardening #10510

Closed
6 of 10 tasks
emteknetnz opened this issue Sep 20, 2022 · 3 comments
Closed
6 of 10 tasks

GitHub Workflows security hardening #10510

emteknetnz opened this issue Sep 20, 2022 · 3 comments

Comments

@emteknetnz
Copy link
Member

emteknetnz commented Sep 20, 2022

Our CI builds only need read access to the repos to do their job ... except for when we do things like auto tagging?

Acceptance criteria

  • Supported modules GitHub Action CI are updated to appropriate permissions.
  • If possible, this is done in a central place.
  • Update docs for gha actions e.g. gha-issue specifying the job scope permissions required to run the action
  • The actions in the "Once the above PRs have been merged" below have been completed

Original PR

Note that this PR was made before the ACs were created. If it isn't fit for purpose, close it and create new PRs as appropriate.

Workflow PRs

Once the above PRs have been merged

  • Assign back to Steve
  • Create new branches and new tags
  • Manually test that .github issue workflows work correctly
  • Move to awaiting column for a while to see how things go over time
  • When satisified that things are stable, update module standardiser to update workflow files on both repos (get same treatment as silverstripe/admin) AND gha actions (get the same treatment as ci.yml + action-ci.yml)
  • Set all of the Action PRs below to ready and move to peer review column

Module standardiser PR

Action PRs - Update docs

@emteknetnz
Copy link
Member Author

emteknetnz commented Apr 15, 2024

permissions should be set to {} on workflow files and then add in as needed on individual jobs

In the case of shared workflows (ci.yml, action-ci.yml), set the permissions on the 'inner' shared workflow, rather that on the outer (such as framework ci.yml)

Create PR's to update workflow files in:

  • silverstripe/admin
  • silverstripe/gha-ci
  • silverstripe/action-ci
  • silverstripe/.github

Leave admin running for a few weeks to validate it's working correctly. Also manually run the "Update JS" workflow to confirm that works then delete created PR. When satisfied update module-standardiser to update the workflow files for repos - dispatch-ci.yml, keepalive.yml, merge-up.yml, update-js.yml

Also leave gha-ci working for a few weeks. Once we're happy with that use module-standardiser to update the gha specific workflow files - action-ci.yml, auto-tag.yml

Manually run .github workflows post merge to validate

You can use the following to work out the required scopes for API calls, use an finely grained token with zero permissions and access to some random repo

curl -sS -f -I -H "Authorization: token github_pat_abcdef123456" -X "GET" https://api.github.com/repos/myaccount/myrepo/branches | grep x-accepted-github-permissions

silverstripe/admin

  • dispatch-ci.yml - contents:read, actions:write ... metadata:read* (can't/shouldn't need to set metadata)
  • keepalive.yml - actions:write
  • merge-ups.yml - contents:write, actions:write
  • update-js.yml - contents:write, actions:write, pull-requests:write

gha-ci

  • ci.yml jobs
    • context - none
    • genmatrix - none
    • tests - none
    • checkgovernance - none
    • patchrelease - contents:write <<<---- note this will affect ALL repos that use ci.yml
  • auto-tag.yml - contents:write
  • keepalive.yml - actions:write
  • merge-up.yml - contents:write, actions:write

gha-action-ci

  • action-ci jobs
    • ci none
    • gaugerelease contents:read
    • patchrelease contents:write
    • dispatchautotag actions:write

.github

  • js-prs-issue.yml - issue:write
  • keepalive.yml - actions:write
  • translation-issue.yml - issue:write

permissions required for gha actions (not including gha shared workflows gha-ci and gha-action-ci)

gha-run-tests

  • required_permissions: none
  • uses_gha_actions: none

gha-merge-up

  • required_permissions: contents:write, actions:write
  • uses_gha_actions: gha-trigger-ci

gha-generate-matrix

  • required_permissions: none
  • uses_gha_actions: none

gha-dispatch-ci

  • required_permissions: contents:read, actions:write
  • uses_gha_actions: none

gha-trigger-ci

  • required_permissions: contents:read, actions:write
  • uses_gha_actions: none

gha-gauge-release

  • required_permissions: contents:read
  • uses_gha_actions: none

gha-issue

  • required_permissions: issue:write
  • uses_gha_actions: none

gha-keepalive

  • required_permissions: actions:write
  • uses_gha_actions: none

gha-update-js

  • required_permissions: contents:write, pull-request:write, actions:write
  • uses_gha_actions: gha-pull-request

gha-pull-request

  • required_permissions: contents:write, pull-request:write, actions:write
  • uses_gha_actions: gha-trigger-ci

gha-tag-release

  • required_permissions: contents:write
  • uses_gha_actions: none

gha-auto-tag

  • required_permissions: contents:write
  • uses_gha_actions: gha-tag-release

metadata
metadata isn't defined on https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
But it is defined on https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token and says that it's always read. "When the permissions key is used, all unspecified permissions are set to no access, with the exception of the metadata scope, which always gets read access."

Validation that the read tokens set on pull_request events cannot be elevated to write

Push from repo - allowed

PR from repo - allowed

PR from forked repo - disallowed

Validation that raw git commands require a contents:write permission

Test raw git commands creating a branch with contents:write on push event

Test raw git commands creating a branch with contents:read on push event

Validation that raw git commands without git push only don't require any permissions

@GuySartorelli
Copy link
Member

Initial PRs merged. Assigning to Steve for next steps

@GuySartorelli
Copy link
Member

PRs merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants