Skip to content

Commit dcf0394

Browse files
dishaprakashdumians
authored andcommitted
chore(ci): secure tests and lint workflow against RCE (googleapis#2671)
## Description Due to a RCE Vulnerability, we can safely change the workflow to run on pull_request while still maintaining it's run on PRs from forks. Changes: - Remove usage of pull_request_target - Remove write permissions from the workflow as these workflows will move from the labeled runs ## PR Checklist > Thank you for opening a Pull Request! Before submitting your PR, there are a > few things you can do to make sure it goes smoothly: - [ ] Make sure you reviewed [CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md) - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) - [ ] Make sure to add `!` if this involve a breaking change 🛠️ Fixes #<issue_number_goes_here>
1 parent 3355ff9 commit dcf0394

2 files changed

Lines changed: 3 additions & 64 deletions

File tree

.github/workflows/lint.yaml

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,62 +21,34 @@ on:
2121
- "!**.md"
2222
- "!.github/**"
2323
- ".github/workflows/lint.yaml"
24-
pull_request_target:
25-
types: [labeled]
26-
paths:
27-
- "**"
28-
- "!docs/**"
29-
- "!**.md"
30-
- "!.github/**"
31-
- ".github/workflows/lint.yaml"
3224

3325
# Declare default permissions as read only.
3426
permissions: read-all
3527

3628
jobs:
3729
lint:
38-
if: "${{ github.event.action != 'labeled' || github.event.label.name == 'tests: run' }}"
3930
name: lint
4031
runs-on: ubuntu-latest
4132
concurrency:
4233
group: ${{ github.workflow }}-${{ github.ref }}
4334
cancel-in-progress: true
4435
permissions:
4536
contents: 'read'
46-
issues: 'write'
47-
pull-requests: 'write'
4837
steps:
49-
- name: Remove PR Label
50-
if: "${{ github.event.action == 'labeled' && github.event.label.name == 'tests: run' }}"
51-
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
52-
with:
53-
github-token: ${{ secrets.GITHUB_TOKEN }}
54-
script: |
55-
try {
56-
await github.rest.issues.removeLabel({
57-
name: 'tests: run',
58-
owner: context.repo.owner,
59-
repo: context.repo.repo,
60-
issue_number: context.payload.pull_request.number
61-
});
62-
} catch (e) {
63-
console.log('Failed to remove label. Another job may have already removed it!');
64-
}
6538
- name: Setup Go
6639
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
6740
with:
6841
go-version: "1.25"
42+
6943
- name: Checkout code
7044
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
71-
with:
72-
ref: ${{ github.event.pull_request.head.sha }}
73-
repository: ${{ github.event.pull_request.head.repo.full_name }}
74-
token: ${{ secrets.GITHUB_TOKEN }}
45+
7546
- name: >
7647
Verify go mod tidy. If you're reading this and the check has
7748
failed, run `goimports -w . && go mod tidy && golangci-lint run`
7849
run: |
7950
go mod tidy && git diff --exit-code
51+
8052
- name: golangci-lint
8153
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
8254
with:

.github/workflows/tests.yaml

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,12 @@ on:
3030
- "!**.md"
3131
- "!.github/**"
3232
- ".github/workflows/tests.yaml"
33-
pull_request_target:
34-
types: [labeled]
35-
paths:
36-
- "**"
37-
- "!docs/**"
38-
- "!**.md"
39-
- "!.github/**"
40-
- ".github/workflows/tests.yaml"
4133

4234
# Declare default permissions as read only.
4335
permissions: read-all
4436

4537
jobs:
4638
integration:
47-
# run job on proper workflow event triggers (skip job for pull_request event from forks and only run pull_request_target for "tests: run" label)
48-
if: "${{ (github.event.action != 'labeled' && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name) || github.event.label.name == 'tests: run' }}"
4939
name: unit tests
5040
runs-on: ${{ matrix.os }}
5141
strategy:
@@ -54,37 +44,14 @@ jobs:
5444
fail-fast: false
5545
permissions:
5646
contents: "read"
57-
issues: "write"
58-
pull-requests: "write"
5947
steps:
60-
- name: Remove PR label
61-
if: "${{ github.event.action == 'labeled' && github.event.label.name == 'tests: run' }}"
62-
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
63-
with:
64-
github-token: ${{ secrets.GITHUB_TOKEN }}
65-
script: |
66-
try {
67-
await github.rest.issues.removeLabel({
68-
name: 'tests: run',
69-
owner: context.repo.owner,
70-
repo: context.repo.repo,
71-
issue_number: context.payload.pull_request.number
72-
});
73-
} catch (e) {
74-
console.log('Failed to remove label. Another job may have already removed it!');
75-
}
76-
7748
- name: Setup Go
7849
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
7950
with:
8051
go-version: "1.24"
8152

8253
- name: Checkout code
8354
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
84-
with:
85-
ref: ${{ github.event.pull_request.head.sha }}
86-
repository: ${{ github.event.pull_request.head.repo.full_name }}
87-
token: ${{ secrets.GITHUB_TOKEN }}
8855

8956
- name: Install dependencies
9057
run: go get .

0 commit comments

Comments
 (0)