Skip to content

Commit fe2befc

Browse files
zhukaihanclaude
andcommitted
ci: harden supply chain security for release pipelines
- SHA pin all external GitHub Actions to full commit SHAs - Migrate PyPI publishing from token-based auth to OIDC trusted publishers - Migrate TestPyPI publishing from token-based auth to OIDC trusted publishers - Disable semantic-release's built-in PyPI upload in favor of pypa/gh-action-pypi-publish with OIDC - Add CODEOWNERS file requiring SDK team review for workflows, build config, and package metadata - Add id-token: write permission for OIDC token minting Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b2a70c2 commit fe2befc

7 files changed

Lines changed: 40 additions & 22 deletions

File tree

.github/CODEOWNERS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Workflow and release automation files require review from SDK team
2+
/.github/workflows/ @amplitude/sdk
3+
/.github/CODEOWNERS @amplitude/sdk
4+
5+
# Package metadata and build configuration
6+
/setup.py @amplitude/sdk
7+
/pyproject.toml @amplitude/sdk

.github/workflows/docs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- name: Checkout
10-
uses: actions/checkout@v2
10+
uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2
1111

1212
- name: Set up Python
13-
uses: actions/setup-python@v6
13+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
1414

1515
- name: Set up pdoc
1616
run: pip install pdoc3
@@ -19,7 +19,7 @@ jobs:
1919
run: pdoc ./src/amplitude_experiment -o ./docs --html
2020

2121
- name: Deploy
22-
uses: JamesIves/github-pages-deploy-action@4.1.5
22+
uses: JamesIves/github-pages-deploy-action@0f24da7de3e7e135102609a4c9633b025be8411b # 4.1.5
2323
with:
2424
branch: gh-pages
2525
folder: docs/amplitude_experiment

.github/workflows/jira-issue-create.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ jobs:
1212
name: SDK Bot Jira Issue Creation
1313
steps:
1414
- name: Login
15-
uses: atlassian/gajira-login@master
15+
uses: atlassian/gajira-login@c22a5debd482401472b285de4f6deedf70ddbb92 # master
1616
env:
1717
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
1818
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
1919
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
2020

2121
- name: Create issue
2222
id: create
23-
uses: atlassian/gajira-create@master
23+
uses: atlassian/gajira-create@1c54357fdde9dab6273a0e26d67cb175ffffe498 # master
2424
with:
2525
project: ${{ secrets.JIRA_PROJECT }}
2626
issuetype: Task

.github/workflows/publish-to-pypi.yml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,28 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: ${{ github.actor }} permission check to do a release
17-
uses: "lannonbr/repo-permission-check-action@2.0.2"
17+
uses: lannonbr/repo-permission-check-action@2bb8c89ba8bf115c4bfab344d6a6f442b24c9a1f # 2.0.2
1818
with:
1919
permission: "write"
2020
env:
2121
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2222

2323
build-n-publish:
24-
environment: Unit Test
24+
environment: pypi
2525
name: Build and publish to PyPI
2626
runs-on: ubuntu-latest
2727
needs: [authorize]
28+
permissions:
29+
contents: write
30+
id-token: write
2831
steps:
2932
- name: Checkout for release to PyPI
30-
uses: actions/checkout@v3
33+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
3134
with:
3235
fetch-depth: 0
3336

3437
- name: Set up Python 3.8
35-
uses: actions/setup-python@v6
38+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
3639
with:
3740
python-version: 3.8
3841

@@ -56,13 +59,20 @@ jobs:
5659
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5760
run: |
5861
semantic-release publish --noop
59-
- name: Publish distribution PyPI
62+
63+
- name: Version, tag, and release
6064
if: ${{ github.event.inputs.dryRun == 'false'}}
6165
run: |
6266
git config user.name amplitude-sdk-bot
6367
git config user.email amplitude-sdk-bot@users.noreply.github.com
6468
semantic-release publish
6569
env:
6670
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67-
REPOSITORY_USERNAME: __token__
68-
REPOSITORY_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
71+
72+
- name: Build package
73+
if: ${{ github.event.inputs.dryRun == 'false'}}
74+
run: python -m build
75+
76+
- name: Publish to PyPI
77+
if: ${{ github.event.inputs.dryRun == 'false'}}
78+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0

.github/workflows/publish-to-test-pypi.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- name: ${{ github.actor }} permission check to do a release
11-
uses: "lannonbr/repo-permission-check-action@2.0.2"
11+
uses: lannonbr/repo-permission-check-action@2bb8c89ba8bf115c4bfab344d6a6f442b24c9a1f # 2.0.2
1212
with:
1313
permission: "write"
1414
env:
@@ -18,11 +18,14 @@ jobs:
1818
name: Build and publish to TestPyPI
1919
runs-on: ubuntu-latest
2020
needs: [authorize]
21+
environment: testpypi
22+
permissions:
23+
id-token: write
2124
steps:
22-
- uses: actions/checkout@v3
25+
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
2326

2427
- name: Set up Python 3.8
25-
uses: actions/setup-python@v6
28+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
2629
with:
2730
python-version: 3.8
2831

@@ -33,8 +36,6 @@ jobs:
3336
run: python -m build --sdist --wheel --outdir dist/ .
3437

3538
- name: Publish distribution Test PyPI
36-
uses: pypa/gh-action-pypi-publish@release/v1
39+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
3740
with:
38-
user: __token__
39-
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
40-
repository_url: https://test.pypi.org/legacy/
41+
repository-url: https://test.pypi.org/legacy/

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
python-version: [ "3.8" ]
1212
steps:
1313
- name: Checkout source code
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
1515

1616
- name: Set up Python ${{ matrix.python-version }}
17-
uses: actions/setup-python@v6
17+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
1818
with:
1919
python-version: ${{ matrix.python-version }}
2020
cache: 'pip'

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version_variable = [
44
]
55
major_on_zero = true
66
branch = "main"
7-
upload_to_PyPI = true
7+
upload_to_PyPI = false
88
upload_to_release = true
99
build_command = "pip install build && python -m build"
1010
version_source = "commit"

0 commit comments

Comments
 (0)