Skip to content
Merged
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
62 changes: 62 additions & 0 deletions .github/workflows/check-release-secrets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Check release secrets

# Manual, read-only check of the publishing secrets. It publishes nothing and never prints a secret value.
on:
workflow_dispatch:

permissions: {}

jobs:
environment-secrets:
name: Secrets seen by the release environment
runs-on: ubuntu-latest
# Same protected environment as the publishing jobs: needs the maintainer's approval to run.
environment: release
steps:
- name: Check the secrets are present and the winget token works
shell: bash
env:
CHOCOLATEY_API_KEY: ${{ secrets.CHOCOLATEY_API_KEY }}
WINGET_GITHUB_TOKEN: ${{ secrets.WINGET_GITHUB_TOKEN }}
WINGET_FORK_OWNER: ${{ secrets.WINGET_FORK_OWNER }}
run: |
missing=0
{
echo "## Secrets seen by the release environment"
for name in CHOCOLATEY_API_KEY WINGET_GITHUB_TOKEN WINGET_FORK_OWNER; do
if [ -n "${!name}" ]; then echo "- $name: present"; else echo "- $name: MISSING"; missing=1; fi
done
} >> "$GITHUB_STEP_SUMMARY"

if [ -n "$WINGET_GITHUB_TOKEN" ]; then
# Read-only call: who owns the token. Only a yes/no goes to the summary.
login=$(curl -fsS -H "Authorization: Bearer $WINGET_GITHUB_TOKEN" -H "Accept: application/vnd.github+json" https://api.github.com/user | jq -r .login) || login=""
if [ -z "$login" ]; then
echo "- WINGET_GITHUB_TOKEN: rejected by GitHub (expired or revoked)" >> "$GITHUB_STEP_SUMMARY"
missing=1
elif [ "${login,,}" = "${WINGET_FORK_OWNER,,}" ]; then
echo "- WINGET_GITHUB_TOKEN: valid, belongs to WINGET_FORK_OWNER" >> "$GITHUB_STEP_SUMMARY"
else
echo "- WINGET_GITHUB_TOKEN: valid, but its user differs from WINGET_FORK_OWNER" >> "$GITHUB_STEP_SUMMARY"
fi
fi

exit $missing

repository-secrets:
name: Repository-level copies (MISSING once deleted)
runs-on: ubuntu-latest
steps:
- name: Check which repository-level copies still exist
shell: bash
env:
CHOCOLATEY_API_KEY: ${{ secrets.CHOCOLATEY_API_KEY }}
WINGET_GITHUB_TOKEN: ${{ secrets.WINGET_GITHUB_TOKEN }}
WINGET_FORK_OWNER: ${{ secrets.WINGET_FORK_OWNER }}
Comment on lines +52 to +55

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restrict the repository-secret probe to trusted code

While the repository-level copies still exist, this job has no protected environment yet injects all three credentials. Any user with repository write access can manually dispatch a workflow_dispatch workflow against a selected branch (GitHub Docs); such a user can alter this job on their branch to exfiltrate the Chocolatey key or winget token without obtaining the intended release-environment approval. Delete the repository copies before exposing this workflow, or inspect secret metadata through an approved environment/API path instead of materializing the values in this unprotected job.

Useful? React with 👍 / 👎.

run: |
{
echo "## Repository-level copies (outside the environment)"
for name in CHOCOLATEY_API_KEY WINGET_GITHUB_TOKEN WINGET_FORK_OWNER; do
if [ -n "${!name}" ]; then echo "- $name: still present"; else echo "- $name: MISSING"; fi
done
} >> "$GITHUB_STEP_SUMMARY"
1 change: 1 addition & 0 deletions .github/workflows/publish-chocolatey.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ permissions:
jobs:
publish-chocolatey:
runs-on: windows-2022
environment: release

steps:
- name: Resolve release metadata
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ jobs:

release:
runs-on: ubuntu-latest
# Protected environment: waits for the maintainer's approval before it can write the release.
environment: release
needs:
- build
- smoke-test
Expand Down Expand Up @@ -439,6 +441,7 @@ jobs:

publish-winget:
runs-on: windows-2022
environment: release
needs:
- build
- release
Expand Down
Loading