Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/workflows/token-access.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Token access

# Checks that the fine-grained tokens AUTOMATION_TOKEN and ADMIN_TOKEN can each
# reach every managed repository in repos.jsonnet, catching missing access on
# pull requests and daily runs before other workflows fail. The list is
# compiled without the tokens, which go only to the API check; fork and
# Dependabot pull requests skip the check because they receive no secrets.
# Fetching a repository verifies only that it is in the token's access (404
# otherwise), not its permission level, because the API reports the owner's
# role rather than the token's.

on:
push:
branches: [main]
paths:
- "repos.jsonnet"
- ".github/workflows/token-access.yaml"
pull_request:
paths:
- "repos.jsonnet"
- ".github/workflows/token-access.yaml"
schedule:
- cron: "11 6 * * *"
workflow_dispatch:

permissions:
contents: read

jobs:
repos:
runs-on: ubuntu-latest
outputs:
repos: ${{ steps.repos.outputs.repos }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: bazel-contrib/setup-bazel@f34d6a05eae3c24acab7fa54587492daeaeffdab # 0.19.2
with:
bazelisk-cache: true
disk-cache: ${{ github.workflow }}
repository-cache: true
- id: repos
run: |
bazel build --lockfile_mode=error //:repos
echo "repos=$(jq -c '.managed | keys' bazel-bin/repos.json)" >> "$GITHUB_OUTPUT"

check:
needs: repos
if: >-
github.event_name != 'pull_request' || (github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.user.login != 'dependabot[bot]')
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
secret: [AUTOMATION_TOKEN, ADMIN_TOKEN]
name: ${{ matrix.secret }}
steps:
- env:
GH_TOKEN: ${{ secrets[matrix.secret] }}
SECRET: ${{ matrix.secret }}
OWNER: ${{ github.repository_owner }}
REPOS: ${{ needs.repos.outputs.repos }}
run: |
missing=0
for name in $(jq -r '.[]' <<<"$REPOS"); do
repo="$OWNER/$name"
if ! gh api "repos/$repo" --silent 2>/dev/null; then
echo "::error::$SECRET cannot reach $repo: add it to the token's repository access."
missing=1
else
echo "$SECRET reaches $repo"
fi
done
exit "$missing"
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Run `bazel build //:repos` to compile the list to `bazel-bin/repos.json`. Run
[`schema/repos.schema.json`](schema/repos.schema.json), which documents the
fields and their defaults.

When adding a repository under `managed`, include it in both `ADMIN_TOKEN` and
`AUTOMATION_TOKEN`. [`token-access.yaml`](.github/workflows/token-access.yaml)
checks that each token can reach every managed repository on pull requests and
pushes to `main` that change `repos.jsonnet`, daily at 06:11 UTC and on manual
runs, though it verifies repository access only and not permission levels.

## Repository settings

The OpenTofu module in [`github/`](github/) manages repository settings,
Expand Down