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
1 change: 1 addition & 0 deletions .github/workflows/backport.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}
token: ${{ steps.app-token.outputs.token }}
persist-credentials: false

- name: Log current API rate limits
env:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
sparse-checkout: .github/actions
- name: Checkout the merge commit
uses: ./.github/actions/checkout
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
path: trusted
sparse-checkout: |
ci/github-script
Expand Down Expand Up @@ -73,6 +74,7 @@ jobs:
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
sparse-checkout: .github/actions
- name: Checkout merge and target commits
uses: ./.github/actions/checkout
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/eval.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ jobs:
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
path: trusted
sparse-checkout: |
ci/supportedVersions.nix

- name: Check out the PR at the test merge commit
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
ref: ${{ inputs.mergedSha }}
path: untrusted
sparse-checkout: |
Expand Down Expand Up @@ -84,6 +86,7 @@ jobs:

- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
sparse-checkout: .github/actions
- name: Check out the PR at merged and target commits
uses: ./.github/actions/checkout
Expand Down Expand Up @@ -155,6 +158,7 @@ jobs:
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
sparse-checkout: .github/actions
- name: Check out the PR at the target commit
uses: ./.github/actions/checkout
Expand All @@ -181,8 +185,9 @@ jobs:
- name: Compare against the target branch
env:
AUTHOR_ID: ${{ github.event.pull_request.user.id }}
TARGET_SHA: ${{ inputs.mergedSha }}
run: |
git -C nixpkgs/trusted diff --name-only ${{ inputs.mergedSha }} \
git -C nixpkgs/trusted diff --name-only "$TARGET_SHA" \
| jq --raw-input --slurp 'split("\n")[:-1]' > touched-files.json

# Use the target branch to get accurate maintainer info
Expand Down Expand Up @@ -318,6 +323,7 @@ jobs:
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
sparse-checkout: .github/actions
- name: Checkout the merge commit
uses: ./.github/actions/checkout
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
sparse-checkout: |
ci/github-script

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
sparse-checkout: .github/actions
- name: Checkout the merge commit
uses: ./.github/actions/checkout
Expand Down Expand Up @@ -60,6 +61,7 @@ jobs:
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
sparse-checkout: .github/actions
- name: Checkout the merge commit
uses: ./.github/actions/checkout
Expand Down Expand Up @@ -87,6 +89,7 @@ jobs:
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
sparse-checkout: .github/actions
- name: Checkout merge and target commits
uses: ./.github/actions/checkout
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/merge-group.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
sparse-checkout: |
ci/supportedSystems.json

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/periodic-merge-24h.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ jobs:
from: ${{ matrix.pairs.from }}
into: ${{ matrix.pairs.into }}
name: ${{ matrix.pairs.name || format('{0} → {1}', matrix.pairs.from, matrix.pairs.into) }}
secrets: inherit
secrets:
NIXPKGS_CI_APP_PRIVATE_KEY: ${{ secrets.NIXPKGS_CI_APP_PRIVATE_KEY }}
3 changes: 2 additions & 1 deletion .github/workflows/periodic-merge-6h.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ jobs:
from: ${{ matrix.pairs.from }}
into: ${{ matrix.pairs.into }}
name: ${{ format('{0} → {1}', matrix.pairs.from, matrix.pairs.into) }}
secrets: inherit
secrets:
NIXPKGS_CI_APP_PRIVATE_KEY: ${{ secrets.NIXPKGS_CI_APP_PRIVATE_KEY }}
5 changes: 5 additions & 0 deletions .github/workflows/periodic-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ on:
description: Target branch to merge into.
required: true
type: string
secrets:
NIXPKGS_CI_APP_PRIVATE_KEY:
required: true

defaults:
run:
Expand All @@ -32,6 +35,8 @@ jobs:
permission-pull-requests: write

- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false

- name: Find merge base between two branches
if: contains(inputs.from, ' ')
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
sparse-checkout-cone-mode: true # default, for clarity
sparse-checkout: |
ci/github-script
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/reviewers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
- name: Check out the PR at the base commit
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
path: trusted
sparse-checkout: ci

Expand Down Expand Up @@ -146,6 +147,7 @@ jobs:
if: ${{ steps.app-token.outputs.token }}
env:
GH_TOKEN: ${{ github.token }}
APP_GH_TOKEN: ${{ steps.app-token.outputs.token }}
REPOSITORY: ${{ github.repository }}
NUMBER: ${{ github.event.number }}
AUTHOR: ${{ github.event.pull_request.user.login }}
Expand All @@ -156,7 +158,7 @@ jobs:
# There appears to be no API to request reviews based on GitHub IDs
jq -r 'keys[]' comparison/maintainers.json \
| while read -r id; do gh api /user/"$id" --jq .login; done \
| GH_TOKEN=${{ steps.app-token.outputs.token }} result/bin/request-reviewers.sh "$REPOSITORY" "$NUMBER" "$AUTHOR"
| GH_TOKEN="$APP_GH_TOKEN" result/bin/request-reviewers.sh "$REPOSITORY" "$NUMBER" "$AUTHOR"

- name: Log current API rate limits (app-token)
if: ${{ steps.app-token.outputs.token }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
sparse-checkout-cone-mode: true # default, for clarity
sparse-checkout: |
ci/github-script
Expand Down
12 changes: 12 additions & 0 deletions .github/zizmor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file defines the ignore rules for zizmor.
#
# For rules that contain a high number of false positives, prefer listing them here
# instead of adding ignore comments. Note that zizmor cannot ignore by line-within-a-string, so
# there are some ignore items that encompass multiple problems within one `run` block. An issue
# tracking this is at https://github.com/woodruffw/zizmor/issues/648.
#
# For more info, see the documentation: https://woodruffw.github.io/zizmor/usage/#ignoring-results

rules:
dangerous-triggers:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This was the source of https://ptrpa.ws/nixpkgs-actions-abuse, correct?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One of the 3 factors, yes. Since we can not get rid of pull_request_target, we must focus on the other two instead. That trigger being dangerous means we must use it in the safest way possible. We do use explicit trusted/ and untrusted/ folders for all the checkouts to make it obvious when untrusted code is executed. And we committed to move away from Bash recently. I think we're in a good spot.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can't we disable this on a per-usage basis? Globally disabling it whilst this is a thing we actually got pwned by seems to kind of defeat the purpose of the tool. I want this to fail hard in CI and have people add a #zizmor-ignore comment if they really want to use dangerous triggers

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We decided to disable it globally in #396451 (comment). The exclusion list was almost every workflow file back then - so there was really no point in doing it differently.

This is different by now - since we rely much more on re-usable workflows which are triggered in a single parent workflow. Still, we have pull_request_target 4x, and pull_request only a single time. The latter is an exception for a very specific use-case.

Due to the way that the workflows are structured:

  • New jobs will not be added in new workflow files, so people are not going to write new triggers the majority of time. When they do, they are likely implementing something that needs permissions, because it's something outside the regular PR workflow - which means it's some kind of automation. But even for more automation, it's unlikely that anyone will actually write a new workflow with pull_request_target or pull_request.
  • Contributors to those files will need to know that they are actually in a pull_request_target context - despite this trigger being written in a separate file. So they can't really tell from the on: part of the workflow file they are in anyway, due to those re-usable workflows. Also, these workflows are designed to be run in both triggers, depending on the parent workflow.

a thing we actually got pwned by

Again, no. We were not pwned by using this trigger. We were pwned by using it wrong. The idea of marking this trigger "dangerous" is kinda stupid to begin with. If you were to never use this kind of trigger, then, sure, you have fewer risks. But also, you can't make use of any secrets or elevated permissions in CI. So once you start putting secrets into GHA configuration, you'll have to start thinking about this. Is putting secrets in via GHA's configuration specifically designed for that considered "bad practice"? I don't think so.


I won't oppose somebody changing this to put these comments in these 4 places - but I'll also say that this won't make any meaningful difference for security. If you feel better when removing this global option, but adding individual disable comments - then I'm afraid you are not seeing the real threats that we have to deal with for CI: Injection and running untrusted code. These are far more likely to mess up.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Side note, I also noticed we have one usage of workflow_run which can also be problematic

Maybe we should also add a note in .github/workflows/README.md?

https://securitylab.github.com/resources/github-actions-new-patterns-and-mitigations/#security-boundaries-and-workflow_run-event

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We will very likely have more workflow_run and also issue_comment soon. All of which are giving access to secrets, yes.

The default assumption for everything in CI must be that it will run in these contexts, where elevated permissions are possible and secrets are available.

To put it differently: Of the 16 workflow files we have, only two workflow files can be considered "safe" according to the "dangerous triggers" definition. All other 14 workflow files have access to secrets and permissions.

disable: true
2 changes: 2 additions & 0 deletions ci/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ let
[ "--config=${config}" ];
includes = [ "*.md" ];
};

programs.zizmor.enable = true;
};
fs = pkgs.lib.fileset;
nixFilesSrc = fs.toSource {
Expand Down
Loading