Skip to content

Commit c924ee5

Browse files
authored
infra: Minimal permissions for workflow jobs (#565)
Addresses CodeQL scan alerts related to `CWE-275`. New CodeQL scan passes on my fork: https://github.com/michaelnchin/langchain-aws/actions/runs/16740128948/job/47386808821
1 parent ea4b274 commit c924ee5

File tree

7 files changed

+44
-0
lines changed

7 files changed

+44
-0
lines changed

.github/workflows/_compile_integration_test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ jobs:
1717
run:
1818
working-directory: ${{ inputs.working-directory }}
1919
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
actions: write # Needed for actions/cache used by poetry_setup action
2023
strategy:
2124
matrix:
2225
python-version:

.github/workflows/_integration_test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ jobs:
3535
run:
3636
working-directory: ${{ inputs.working-directory }}
3737
runs-on: ubuntu-latest
38+
permissions:
39+
contents: read
40+
id-token: write # Needed for aws-actions/configure-aws-credentials
41+
actions: write # Needed for actions/cache used by poetry_setup action
3842
name: "make integration_test"
3943
steps:
4044
- uses: actions/checkout@v4

.github/workflows/_lint.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ jobs:
1919
build:
2020
name: "make lint #${{ matrix.python-version }}"
2121
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
actions: write # Needed for actions/cache used by poetry_setup action (and directly in this job)
2225
strategy:
2326
matrix:
2427
# Only lint on the min and max supported Python versions.

.github/workflows/_release.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,16 @@ env:
2525
PYTHON_VERSION: "3.11"
2626
POETRY_VERSION: "1.7.1"
2727

28+
permissions:
29+
contents: read
30+
2831
jobs:
2932
build:
3033
if: github.ref == 'refs/heads/main' || inputs.dangerous-nonmaster-release
3134
runs-on: ubuntu-latest
35+
permissions:
36+
contents: read
37+
actions: write # Needed for actions/upload-artifact
3238

3339
outputs:
3440
pkg-name: ${{ steps.check-version.outputs.pkg-name }}
@@ -90,6 +96,9 @@ jobs:
9096
- build
9197
- test-pypi-publish
9298
runs-on: ubuntu-latest
99+
permissions:
100+
contents: read
101+
id-token: write # Needed for aws-actions/configure-aws-credentials
93102
steps:
94103
- uses: actions/checkout@v4
95104

@@ -218,6 +227,8 @@ jobs:
218227
# Trusted publishing has to also be configured on PyPI for each package:
219228
# https://docs.pypi.org/trusted-publishers/adding-a-publisher/
220229
id-token: write
230+
contents: read
231+
actions: read # Needed for actions/download-artifact
221232

222233
defaults:
223234
run:
@@ -258,6 +269,7 @@ jobs:
258269
# This permission is needed by `ncipollo/release-action` to
259270
# create the GitHub release.
260271
contents: write
272+
actions: read # Needed for actions/download-artifact
261273

262274
defaults:
263275
run:

.github/workflows/_test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ jobs:
1717
run:
1818
working-directory: ${{ inputs.working-directory }}
1919
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
actions: write # Needed for actions/cache used by poetry_setup action
2023
strategy:
2124
matrix:
2225
python-version:

.github/workflows/_test_release.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ jobs:
2121
build:
2222
if: github.ref == 'refs/heads/main' || inputs.dangerous-nonmaster-release
2323
runs-on: ubuntu-latest
24+
permissions:
25+
contents: read
26+
actions: write # Needed for actions/upload-artifact
2427

2528
outputs:
2629
pkg-name: ${{ steps.check-version.outputs.pkg-name }}
@@ -77,6 +80,8 @@ jobs:
7780
# Trusted publishing has to also be configured on PyPI for each package:
7881
# https://docs.pypi.org/trusted-publishers/adding-a-publisher/
7982
id-token: write
83+
contents: read
84+
actions: read # Needed for actions/download-artifact
8085

8186
steps:
8287
- uses: actions/checkout@v4

.github/workflows/check_diffs.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ env:
2222
jobs:
2323
build:
2424
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
27+
actions: read # Needed for Ana06/get-changed-files
2528
steps:
2629
- uses: actions/checkout@v4
2730
- uses: actions/setup-python@v5
@@ -39,6 +42,9 @@ jobs:
3942
name: cd ${{ matrix.working-directory }}
4043
needs: [ build ]
4144
if: ${{ needs.build.outputs.dirs-to-lint != '[]' }}
45+
permissions:
46+
contents: read
47+
actions: write # Needed for actions/cache used by poetry_setup action in _lint.yml
4248
strategy:
4349
matrix:
4450
working-directory: ${{ fromJson(needs.build.outputs.dirs-to-lint) }}
@@ -51,6 +57,9 @@ jobs:
5157
name: cd ${{ matrix.working-directory }}
5258
needs: [ build ]
5359
if: ${{ needs.build.outputs.dirs-to-test != '[]' }}
60+
permissions:
61+
contents: read
62+
actions: write # Needed for actions/cache used by poetry_setup action inside _test.yml
5463
strategy:
5564
matrix:
5665
working-directory: ${{ fromJson(needs.build.outputs.dirs-to-test) }}
@@ -63,6 +72,9 @@ jobs:
6372
name: cd ${{ matrix.working-directory }}
6473
needs: [ build ]
6574
if: ${{ needs.build.outputs.dirs-to-test != '[]' }}
75+
permissions:
76+
contents: read
77+
actions: write # Needed for actions/cache used by poetry_setup action inside _compile_integration_test.yml
6678
strategy:
6779
matrix:
6880
working-directory: ${{ fromJson(needs.build.outputs.dirs-to-test) }}
@@ -76,6 +88,8 @@ jobs:
7688
if: |
7789
always()
7890
runs-on: ubuntu-latest
91+
permissions:
92+
contents: read
7993
env:
8094
JOBS_JSON: ${{ toJSON(needs) }}
8195
RESULTS_JSON: ${{ toJSON(needs.*.result) }}

0 commit comments

Comments
 (0)