-
Notifications
You must be signed in to change notification settings - Fork 2k
Actions: Fix dominates() false positive in reusable workflows #21986
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| category: fix | ||
| --- | ||
| * GitHub Actions support for reusable workflows was improved. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,15 @@ string actor_not_attacker_event() { | |
| ] | ||
| } | ||
|
|
||
| /** | ||
| * Gets the outer caller of `ej`, i.e. the `ExternalJob` that calls the | ||
| * reusable workflow containing `ej`. Used with transitive closure to | ||
| * walk up nested reusable workflow chains. | ||
| */ | ||
| private ExternalJob getAnOuterCaller(ExternalJob ej) { | ||
| result = ej.getEnclosingWorkflow().(ReusableWorkflow).getACaller() | ||
| } | ||
|
|
||
| /** An If node that contains an actor, user or label check */ | ||
| abstract class ControlCheck extends AstNode { | ||
| ControlCheck() { | ||
|
|
@@ -60,7 +69,12 @@ abstract class ControlCheck extends AstNode { | |
| this.getATriggerEvent() = event | ||
| } | ||
|
|
||
| /** | ||
| * Holds if this control check must execute and pass before `node` can run. | ||
| */ | ||
| predicate dominates(AstNode node) { | ||
| // Step-level: the check is an `if:` on the step containing `node`, | ||
| // or on the enclosing job, or on a needed job/step. | ||
| this instanceof If and | ||
| ( | ||
| node.getEnclosingStep().getIf() = this or | ||
|
|
@@ -69,21 +83,48 @@ abstract class ControlCheck extends AstNode { | |
| node.getEnclosingJob().getANeededJob().(LocalJob).getIf() = this | ||
| ) | ||
| or | ||
| // Job-level: the check is an environment on the enclosing job or a needed job. | ||
| this instanceof Environment and | ||
| ( | ||
| node.getEnclosingJob().getEnvironment() = this | ||
| or | ||
| node.getEnclosingJob().getANeededJob().getEnvironment() = this | ||
| ) | ||
| or | ||
| // Step-level: the check is a Run/UsesStep that precedes `node`'s step | ||
| // in the same job, or is a step in a needed job. | ||
| ( | ||
| this instanceof Run or | ||
| this instanceof UsesStep | ||
| ) and | ||
| ( | ||
| this.(Step).getAFollowingStep() = node.getEnclosingStep() | ||
| or | ||
| node.getEnclosingJob().getANeededJob().(LocalJob).getAStep() = this.(Step) | ||
| node.getEnclosingJob().getANeededJob().(LocalJob).getAStep() = this | ||
| ) | ||
| or | ||
| // When the node is inside a (possibly nested) reusable workflow, | ||
| // check if the control check dominates any caller job in the chain. | ||
| exists(ExternalJob directCaller, ExternalJob caller | | ||
| directCaller = node.getEnclosingWorkflow().(ReusableWorkflow).getACaller() and | ||
| caller = getAnOuterCaller*(directCaller) and | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this might be too broad when the same reusable workflow has multiple callers. Since I've cooked up a scratch qltest with two callers to the same |
||
| ( | ||
| this instanceof If and | ||
| ( | ||
| caller.getIf() = this or | ||
| caller.getANeededJob().(LocalJob).getIf() = this or | ||
| caller.getANeededJob().(LocalJob).getAStep().getIf() = this | ||
| ) | ||
| or | ||
| this instanceof Environment and | ||
| ( | ||
| caller.getEnvironment() = this or | ||
| caller.getANeededJob().getEnvironment() = this | ||
| ) | ||
| or | ||
| (this instanceof Run or this instanceof UsesStep) and | ||
| caller.getANeededJob().(LocalJob).getAStep() = this | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| COMMIT_SHA: | ||
| type: string | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| ref: ${{ inputs.COMMIT_SHA }} | ||
| - run: | | ||
| npm install | ||
| npm run lint | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| COMMIT_SHA: | ||
| type: string | ||
|
|
||
| jobs: | ||
| build: | ||
| uses: TestOrg/TestRepo/.github/workflows/build.yml@main | ||
| with: | ||
| COMMIT_SHA: ${{ inputs.COMMIT_SHA }} | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| on: | ||
| pull_request_target: | ||
|
|
||
| jobs: | ||
| is-collaborator: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Get User Permission | ||
| id: checkAccess | ||
| uses: actions-cool/check-user-permission@cd622002ff25c2311d2e7fb82107c0d24be83f9b | ||
| with: | ||
| require: write | ||
| username: ${{ github.actor }} | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Check User Permission | ||
| if: steps.checkAccess.outputs.require-result == 'false' | ||
| run: | | ||
| echo "${{ github.actor }} does not have permissions on this repo." | ||
| echo "Current permission level is ${{ steps.checkAccess.outputs.user-permission }}" | ||
| exit 1 | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| #needs: is-collaborator Mistake, doesn't wait for the collaborator - no security check | ||
| steps: | ||
| - name: Checkout repo | ||
| uses: actions/checkout@4 | ||
| with: | ||
| ref: ${{ github.event.pull_request.head.sha }} # should alert | ||
| fetch-depth: 2 | ||
| - run: yarn test |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| on: | ||
| pull_request_target: | ||
|
|
||
| jobs: | ||
| is-collaborator: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Get User Permission | ||
| id: checkAccess | ||
| uses: actions-cool/check-user-permission@cd622002ff25c2311d2e7fb82107c0d24be83f9b | ||
| with: | ||
| require: write | ||
| username: ${{ github.actor }} | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Check User Permission | ||
| if: steps.checkAccess.outputs.require-result == 'false' | ||
| run: | | ||
| echo "${{ github.actor }} does not have permissions on this repo." | ||
| echo "Current permission level is ${{ steps.checkAccess.outputs.user-permission }}" | ||
| exit 1 | ||
| build: | ||
| needs: is-collaborator | ||
| uses: TestOrg/TestRepo/.github/workflows/build.yml@main | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we also add a regression for the mixed-caller case? Something like this protected caller plus another job in the same triggering workflow that calls the same reusable workflow without That seems to be the tricky case here, because otherwise the reusable workflow node can look protected just because one of its callers is protected. |
||
| with: | ||
| COMMIT_SHA: ${{ github.event.pull_request.head.sha }} # shouldn't alert since permission check | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| on: | ||
| pull_request_target: | ||
|
|
||
| jobs: | ||
| is-collaborator: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Get User Permission | ||
| id: checkAccess | ||
| uses: actions-cool/check-user-permission@cd622002ff25c2311d2e7fb82107c0d24be83f9b | ||
| with: | ||
| require: write | ||
| username: ${{ github.actor }} | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Check User Permission | ||
| if: steps.checkAccess.outputs.require-result == 'false' | ||
| run: | | ||
| echo "${{ github.actor }} does not have permissions on this repo." | ||
| echo "Current permission level is ${{ steps.checkAccess.outputs.user-permission }}" | ||
| exit 1 | ||
| build: | ||
| needs: is-collaborator | ||
| uses: TestOrg/TestRepo/.github/workflows/build_nested.yml@main | ||
| with: | ||
| COMMIT_SHA: ${{ github.event.pull_request.head.sha }} # shouldn't alert since permission check |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| on: | ||
| pull_request_target: | ||
|
|
||
| jobs: | ||
| is-collaborator: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Get User Permission | ||
| id: checkAccess | ||
| uses: actions-cool/check-user-permission@cd622002ff25c2311d2e7fb82107c0d24be83f9b | ||
| with: | ||
| require: write | ||
| username: ${{ github.actor }} | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Check User Permission | ||
| if: steps.checkAccess.outputs.require-result == 'false' | ||
| run: | | ||
| echo "${{ github.actor }} does not have permissions on this repo." | ||
| echo "Current permission level is ${{ steps.checkAccess.outputs.user-permission }}" | ||
| exit 1 | ||
| build: | ||
| # needs: is-collaborator | ||
| uses: TestOrg/TestRepo/.github/workflows/build_nested.yml@main | ||
| with: | ||
| COMMIT_SHA: ${{ github.event.pull_request.head.sha }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| on: | ||
| pull_request_target: | ||
|
|
||
| jobs: | ||
| is-collaborator: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Get User Permission | ||
| id: checkAccess | ||
| uses: actions-cool/check-user-permission@cd622002ff25c2311d2e7fb82107c0d24be83f9b | ||
| with: | ||
| require: write | ||
| username: ${{ github.actor }} | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Check User Permission | ||
| if: steps.checkAccess.outputs.require-result == 'false' | ||
| run: | | ||
| echo "${{ github.actor }} does not have permissions on this repo." | ||
| echo "Current permission level is ${{ steps.checkAccess.outputs.user-permission }}" | ||
| exit 1 | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| needs: is-collaborator | ||
| steps: | ||
| - name: Checkout repo | ||
| uses: actions/checkout@4 | ||
| with: | ||
| ref: ${{ github.event.pull_request.head.sha }} # shouldn't alert since permission check | ||
| fetch-depth: 2 | ||
| - run: yarn test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe we could make this a little tighter? This sounds like a general reusable-workflow support improvement, while the change is more specifically about recognizing control checks around jobs that call reusable workflows.
Maybe something like: