mirror of
https://github.com/neondatabase/neon.git
synced 2025-12-22 21:59:59 +00:00
### Summary I'm fixing one or more of the following CI/CD misconfigurations to improve security. Please feel free to leave a comment if you think the current permissions for the GITHUB_TOKEN should not be restricted so I can take a note of it as accepted behaviour. - Restrict permissions for GITHUB_TOKEN - Add step-security/harden-runner - Pin Actions to a full length commit SHA ### Security Fixes will fix https://github.com/neondatabase/cloud/issues/26141
42 lines
1.3 KiB
YAML
42 lines
1.3 KiB
YAML
name: Check Permissions
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
github-event-name:
|
|
required: true
|
|
type: string
|
|
|
|
defaults:
|
|
run:
|
|
shell: bash -euo pipefail {0}
|
|
|
|
# No permission for GITHUB_TOKEN by default; the **minimal required** set of permissions should be granted in each job.
|
|
permissions: {}
|
|
|
|
jobs:
|
|
check-permissions:
|
|
runs-on: ubuntu-22.04
|
|
steps:
|
|
- name: Harden the runner (Audit all outbound calls)
|
|
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- name: Disallow CI runs on PRs from forks
|
|
if: |
|
|
inputs.github-event-name == 'pull_request' &&
|
|
github.event.pull_request.head.repo.full_name != github.repository
|
|
run: |
|
|
if [ "${{ contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.pull_request.author_association) }}" = "true" ]; then
|
|
MESSAGE="Please create a PR from a branch of ${GITHUB_REPOSITORY} instead of a fork"
|
|
else
|
|
MESSAGE="The PR should be reviewed and labelled with 'approved-for-ci-run' to trigger a CI run"
|
|
fi
|
|
|
|
# TODO: use actions/github-script to post this message as a PR comment
|
|
echo >&2 "We don't run CI for PRs from forks"
|
|
echo >&2 "${MESSAGE}"
|
|
|
|
exit 1
|