Skip to content

Security/422 restrict GitHub token in workflows #423

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

Merged
merged 3 commits into from
May 12, 2025
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
3 changes: 2 additions & 1 deletion .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ jobs:
cd-job:
name: Continuous Delivery
runs-on: ubuntu-24.04
permissions:
contents: write
steps:

- name: SCM Checkout
uses: actions/checkout@v4

Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@ jobs:
check-tag-version-job:
name: Check Release Tag
uses: ./.github/workflows/check-release-tag.yml
permissions:
contents: read

cd-job:
name: Continuous Delivery
uses: ./.github/workflows/build-and-publish.yml
permissions:
contents: write
secrets:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}

publish-docs:
needs: [ cd-job ]
name: Publish Documentation
uses: ./.github/workflows/gh-pages.yml
permissions:
contents: read
pages: write
id-token: write

7 changes: 4 additions & 3 deletions .github/workflows/check-release-tag.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
name: Check Release Tag

on: workflow_call
on:
workflow_call:

jobs:

check-tag-version-job:

name: Check Tag Version
runs-on: ubuntu-24.04

permissions:
contents: read
steps:
- name: SCM Checkout
uses: actions/checkout@v4
Expand Down
23 changes: 18 additions & 5 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ jobs:
Version-Check:
name: Version
runs-on: ubuntu-24.04

permissions:
contents: read
steps:
- name: SCM Checkout
uses: actions/checkout@v4
Expand All @@ -25,7 +26,8 @@ jobs:
name: Docs
needs: [ Version-Check ]
runs-on: ubuntu-24.04

permissions:
contents: read
steps:
- name: SCM Checkout
uses: actions/checkout@v4
Expand All @@ -40,8 +42,9 @@ jobs:
Changelog:
name: Changelog Update Check
runs-on: ubuntu-24.04
permissions:
contents: read
if: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/master' }}

steps:
- name: SCM Checkout
uses: actions/checkout@v4
Expand All @@ -55,11 +58,15 @@ jobs:
build-matrix:
name: Generate Build Matrix
uses: ./.github/workflows/matrix-python.yml
permissions:
contents: read

Lint:
name: Linting (Python-${{ matrix.python-version }})
needs: [ Version-Check, build-matrix ]
runs-on: ubuntu-24.04
permissions:
contents: read
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.build-matrix.outputs.matrix) }}
Expand Down Expand Up @@ -89,6 +96,8 @@ jobs:
name: Type Checking (Python-${{ matrix.python-version }})
needs: [ Version-Check, build-matrix ]
runs-on: ubuntu-24.04
permissions:
contents: read
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.build-matrix.outputs.matrix) }}
Expand All @@ -109,10 +118,11 @@ jobs:
name: Security Checks (Python-${{ matrix.python-version }})
needs: [ Version-Check, build-matrix ]
runs-on: ubuntu-24.04
permissions:
contents: read
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.build-matrix.outputs.matrix) }}

steps:
- name: SCM Checkout
uses: actions/checkout@v4
Expand All @@ -135,7 +145,8 @@ jobs:
Format:
name: Format Check
runs-on: ubuntu-24.04

permissions:
contents: read
steps:
- name: SCM Checkout
uses: actions/checkout@v4
Expand All @@ -150,6 +161,8 @@ jobs:
name: Unit-Tests (Python-${{ matrix.python-version }})
needs: [ Documentation, Lint, Type-Check, Security, Format, build-matrix ]
runs-on: ubuntu-24.04
permissions:
contents: read
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
strategy:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ jobs:
CI:
uses: ./.github/workflows/merge-gate.yml
secrets: inherit
permissions:
contents: read

Metrics:
needs: [ CI ]
uses: ./.github/workflows/report.yml
permissions:
contents: read
4 changes: 2 additions & 2 deletions .github/workflows/matrix-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ on:

jobs:
all_versions:

runs-on: ubuntu-24.04

permissions:
contents: read
steps:
- name: SCM Checkout
uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/matrix-exasol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ on:

jobs:
exasol_versions:

runs-on: ubuntu-24.04

permissions:
contents: read
steps:
- name: SCM Checkout
uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/matrix-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ on:

jobs:
python_versions:

permissions:
contents: read
runs-on: ubuntu-24.04

steps:
- name: SCM Checkout
uses: actions/checkout@v4
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/merge-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ jobs:
fast-checks:
name: Fast
uses: ./.github/workflows/checks.yml
permissions:
contents: read

slow-checks:
name: Slow
uses: ./.github/workflows/slow-checks.yml
permissions:
contents: read

# This job ensures inputs have been executed successfully.
approve-merge:
name: Allow Merge
runs-on: ubuntu-24.04
permissions:
contents: read
# If you need additional jobs to be part of the merge gate, add them below
needs: [ fast-checks, slow-checks ]

Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/pr-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ jobs:
ci-job:
name: Checks
uses: ./.github/workflows/checks.yml
permissions:
contents: read

publish-docs:
name: Publish Documentation
uses: ./.github/workflows/gh-pages.yml
permissions:
contents: read
pages: write
id-token: write

metrics:
needs: [ ci-job ]
uses: ./.github/workflows/report.yml
permissions:
contents: read
2 changes: 2 additions & 0 deletions .github/workflows/report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ jobs:

Report:
runs-on: ubuntu-24.04
permissions:
contents: read
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/slow-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ jobs:
build-matrix:
name: Generate Build Matrix
uses: ./.github/workflows/matrix-all.yml
permissions:
contents: read

Tests:
name: Integration-Tests (Python-${{ matrix.python-version }}, Exasol-${{ matrix.exasol-version}})
needs: [ build-matrix ]
runs-on: ubuntu-24.04
permissions:
contents: read
# Even though the environment "manual-approval" will be created automatically,
# it still needs to be configured to require interactive review.
# See project settings on GitHub (Settings / Environments / manual-approval).
Expand Down
21 changes: 20 additions & 1 deletion doc/changes/unreleased.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
# Unreleased

## Summary

With #420, any GitHub repos using the PTB for **documentation** will also need to
reconfigure the GitHub Pages settings for each repo:
1. Go to the affected repo's GitHub page
2. Select 'Settings'
3. Scroll down & select 'Pages'
4. Within the 'Build and deployment' section, change 'Source' to 'GitHub Actions'.

This should also create a 'github-pages' environment, if it does not yet exist.
For most repos using the PTB, the updating of the github pages only happens when a
PR is merged to main, so please check post-merge that it worked as expected.

With #422, we have hardened the security in our GitHub workflows by explicitly
setting permissions to the default GitHub token. In a few repos who greatly differ
from the default PTB setup, this might lead to small issues which require the allowed
permissions to be increased for specific jobs.

## ⚒️ Refactorings

* [#412](https://github.com/exasol/python-toolbox/issues/392): Refactored pre commit hook package version.py into nox task

## Security

* [#420](https://github.com/exasol/python-toolbox/issues/420): Replaced 3rd party action with GitHub actions for gh-pages
* [#420](https://github.com/exasol/python-toolbox/issues/420): Replaced 3rd party action with GitHub actions for gh-pages
* [#422](https://github.com/exasol/python-toolbox/issues/422): Set permissions within the GitHub workflows to restrict usage of the default GitHub token
12 changes: 11 additions & 1 deletion doc/user_guide/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,17 @@ forward, and you just can use the example *noxfile.py* below.

.. _toolbox tasks:

7. Go 🥜
7. Setup for deploying documentation (optional)
+++++++++++++++++++++++++++++++++++++++++++++++
Within the `gh-pages.yml`, we use the GitHub `upload-pages-artifact` and `deploy-pages`
actions. In order to properly deploy your pages, you'll need to reconfigure the GitHub
Pages settings for the repo:
1. Go to the affected repo's GitHub page
2. Select 'Settings'
3. Scroll down & select 'Pages'
4. Within the 'Build and deployment' section, change 'Source' to 'GitHub Actions'.

8. Go 🥜
+++++++++++++
You are ready to use the toolbox. With *nox -l* you can list all available tasks.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ jobs:
cd-job:
name: Continuous Delivery
runs-on: ubuntu-24.04
permissions:
contents: write
steps:

- name: SCM Checkout
uses: actions/checkout@v4

Expand Down
8 changes: 8 additions & 0 deletions exasol/toolbox/templates/github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@ jobs:
check-tag-version-job:
name: Check Release Tag
uses: ./.github/workflows/check-release-tag.yml
permissions:
contents: read

cd-job:
name: Continuous Delivery
uses: ./.github/workflows/build-and-publish.yml
permissions:
contents: write
secrets:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}

publish-docs:
needs: [ cd-job ]
name: Publish Documentation
uses: ./.github/workflows/gh-pages.yml
permissions:
contents: read
pages: write
id-token: write

Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
name: Check Release Tag

on: workflow_call
on:
workflow_call:

jobs:

check-tag-version-job:

name: Check Tag Version
runs-on: ubuntu-24.04

permissions:
contents: read
steps:
- name: SCM Checkout
uses: actions/checkout@v4
Expand Down
Loading