Skip to content
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

Harden Workflow Security #1577

Merged
merged 6 commits into from
Jan 8, 2024
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
17 changes: 14 additions & 3 deletions .github/workflows/actions-versions-updater.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,31 @@ on:
- cron: '0 0 1 * *'
workflow_dispatch:

permissions: # added using https://github.com/step-security/secure-repo
contents: read

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/[email protected]
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
with:
egress-policy: audit

- name: Checkout
uses: actions/[email protected]
with:
token: ${{ secrets.BUMPVERSION_TOKEN }}
token: ${{ secrets.ACTIONS_VERSION_UPDATER_TOKEN }}
persist-credentials: true

- name: Run GitHub Actions Version Updater
uses: saadmk11/[email protected]
with:
token: ${{ secrets.BUMPVERSION_TOKEN }}
token: ${{ secrets.ACTIONS_VERSION_UPDATER_TOKEN }}
committer_email: 'bumpversion[bot]@ouranos.ca'
committer_username: 'update-github-actions[bot]'
pull_request_title: '[bot] Update GitHub Action Versions'
pull_request_team_reviewers: "xclim-core"
update_version_with: "release-commit-sha"
3 changes: 3 additions & 0 deletions .github/workflows/add-to-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
types:
- opened

permissions: # added using https://github.com/step-security/secure-repo
contents: read

jobs:
add-to-project:
name: Add Issue to xclim Project
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ on:
- tox.ini
- xclim/__init__.py

permissions: # added using https://github.com/step-security/secure-repo
contents: read

jobs:
bump_patch_version:
name: Bumpversion Patch
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
with:
egress-policy: audit
- uses: actions/[email protected]
with:
persist-credentials: false
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/cache-cleaner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ on:
types:
- closed

permissions: # added using https://github.com/step-security/secure-repo
contents: read

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
with:
egress-policy: audit

- name: Check out code
uses: actions/[email protected]

Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ on:
schedule:
- cron: '30 23 * * 5'

permissions: # added using https://github.com/step-security/secure-repo
actions: read

jobs:
analyze:
name: Analyze
Expand All @@ -33,6 +36,10 @@ jobs:
language:
- 'python'
steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
with:
egress-policy: audit
- name: Checkout repository
uses: actions/[email protected]
# Initializes the CodeQL tools for scanning.
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/first_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ jobs:
name: Welcome
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
with:
egress-policy: audit

- uses: actions/[email protected]
with:
script: |
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

permissions:
contents: read
pull-requests: read

jobs:
lint:
name: Black (Python${{ matrix.python-version }})
Expand All @@ -39,6 +43,10 @@ jobs:
python-version:
- "3.8"
steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
with:
egress-policy: audit
- uses: actions/[email protected]
- name: Set up Python${{ matrix.python-version }}
uses: actions/[email protected]
Expand All @@ -65,6 +73,10 @@ jobs:
- tox-env: "py39" # "py39-coverage"
python-version: "3.9"
steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
with:
egress-policy: audit
- uses: actions/[email protected]
- name: Set up Python${{ matrix.python-version }}
uses: actions/[email protected]
Expand Down Expand Up @@ -109,6 +121,10 @@ jobs:
python-version: "3.11"
markers: -m 'not slow and not requires_internet'
steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
with:
egress-policy: audit
- uses: actions/[email protected]
- name: Install Eigen3
if: contains(matrix.tox-env, 'sbck')
Expand Down Expand Up @@ -148,6 +164,10 @@ jobs:
run:
shell: bash -l {0}
steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
with:
egress-policy: audit
- uses: actions/[email protected]
- name: Setup Conda (Micromamba) with Python${{ matrix.python-version }}
uses: mamba-org/[email protected]
Expand Down Expand Up @@ -202,6 +222,10 @@ jobs:
runs-on: ubuntu-latest
container: python:3-slim
steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
with:
egress-policy: audit
- name: Coveralls Finished
run: |
python -m pip install --upgrade coveralls
Expand Down
92 changes: 48 additions & 44 deletions .github/workflows/publish-mastodon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,57 +20,61 @@ jobs:
runs-on: ubuntu-latest
environment: production
steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
with:
egress-policy: audit

- name: Checkout
uses: actions/[email protected]
- name: Checkout
uses: actions/[email protected]

- name: Current Version
if: ${{ !github.event.inputs.version-tag }}
run: |
CURRENT_VERSION="$(grep -E '__version__' xclim/__init__.py | cut -d ' ' -f3)"
echo "version=v${CURRENT_VERSION}" >> $GITHUB_ENV
- name: Set Version from Input
if: ${{ github.event.inputs.version-tag }}
run: |
echo "version=${{ github.event.inputs.version-tag }}" >> $GITHUB_ENV
- name: Current Version
if: ${{ !github.event.inputs.version-tag }}
run: |
CURRENT_VERSION="$(grep -E '__version__' xclim/__init__.py | cut -d ' ' -f3)"
echo "version=v${CURRENT_VERSION}" >> $GITHUB_ENV
- name: Set Version from Input
if: ${{ github.event.inputs.version-tag }}
run: |
echo "version=${{ github.event.inputs.version-tag }}" >> $GITHUB_ENV

- name: Get Release Description
if: ${{ !endsWith(env.current_version, '-dev') }}
id: get_release_description
run: |
# Fetch the release information using the GitHub API
RELEASE_INFO=$(curl -sH "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ env.version }}")
- name: Get Release Description
if: ${{ !endsWith(env.current_version, '-dev') }}
id: get_release_description
run: |
# Fetch the release information using the GitHub API
RELEASE_INFO=$(curl -sH "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ env.version }}")

# Extract the release description from the response
RELEASE_DESCRIPTION=$(echo "$RELEASE_INFO" | jq -r .body)
# Extract the release description from the response
RELEASE_DESCRIPTION=$(echo "$RELEASE_INFO" | jq -r .body)

# Remove Markdown links and the space preceding them
CLEANED_DESCRIPTION=$(echo "$RELEASE_DESCRIPTION" | sed -E 's/\ \(\[[^]]+\]\([^)]+\)\)//g')
# Remove Markdown links and the space preceding them
CLEANED_DESCRIPTION=$(echo "$RELEASE_DESCRIPTION" | sed -E 's/\ \(\[[^]]+\]\([^)]+\)\)//g')

# Extract the first line of the release description
CONTRIBUTORS=$(echo "$CLEANED_DESCRIPTION" | head -n 1)
# Extract the first line of the release description
CONTRIBUTORS=$(echo "$CLEANED_DESCRIPTION" | head -n 1)

echo "contributors=${CONTRIBUTORS}" >> $GITHUB_ENV
echo "contributors=${CONTRIBUTORS}" >> $GITHUB_ENV

- name: Prepare Message
id: render_template
uses: chuhlomin/[email protected]
with:
template: .github/publish-mastodon.template.md
vars: |
version: ${{ env.version }}
- name: Prepare Message
id: render_template
uses: chuhlomin/[email protected]
with:
template: .github/publish-mastodon.template.md
vars: |
version: ${{ env.version }}

- name: Message Preview
run: |
echo "${{ steps.render_template.outputs.result }}${{ env.contributors }}"
- name: Message Preview
run: |
echo "${{ steps.render_template.outputs.result }}${{ env.contributors }}"

- name: Send toot to Mastodon
if: ${{ github.event.inputs.dry-run != 'true' }} || ${{ github.event_name == 'release' }}
uses: cbrgm/[email protected]
with:
message: "${{ steps.render_template.outputs.result }}${{ env.contributors }}"
visibility: "public"
env:
MASTODON_URL: ${{ secrets.MASTODON_URL }}
MASTODON_ACCESS_TOKEN: ${{ secrets.MASTODON_ACCESS_TOKEN }}
- name: Send toot to Mastodon
if: ${{ github.event.inputs.dry-run != 'true' }} || ${{ github.event_name == 'release' }}
uses: cbrgm/[email protected]
with:
message: "${{ steps.render_template.outputs.result }}${{ env.contributors }}"
visibility: "public"
env:
MASTODON_URL: ${{ secrets.MASTODON_URL }}
MASTODON_ACCESS_TOKEN: ${{ secrets.MASTODON_ACCESS_TOKEN }}
7 changes: 7 additions & 0 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
types:
- published

permissions: # added using https://github.com/step-security/secure-repo
contents: read

jobs:
build-n-publish-pypi:
name: Build and publish Python 🐍 distributions 📦 to PyPI
Expand All @@ -14,6 +17,10 @@ jobs:
id-token: write
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
with:
egress-policy: audit
- uses: actions/[email protected]
- name: Set up Python3
uses: actions/[email protected]
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/tag-testpypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
tags:
- 'v*'

permissions: # added using https://github.com/step-security/secure-repo
contents: read

jobs:
build-n-publish-testpypi:
name: Build and publish Python 🐍 distributions 📦 to TestPyPI
Expand All @@ -14,6 +17,10 @@ jobs:
id-token: write
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
with:
egress-policy: audit
- uses: actions/[email protected]
- name: Set up Python3
uses: actions/[email protected]
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/testdata_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ on:
paths:
- .github/workflows/main.yml

permissions: # added using https://github.com/step-security/secure-repo
contents: read

jobs:
use-latest-tag:
name: Check Latest xclim-testdata Tag
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/[email protected]
- name: Find xclim-testdata Tag and CI Testing Branch
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/upstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions: # added using https://github.com/step-security/secure-repo
contents: read

jobs:
upstream-dev:
name: test-upstream-dev (Python${{ matrix.python-version }})
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
if: |
(github.event_name == 'schedule') ||
(github.event_name == 'workflow_dispatch') ||
Expand All @@ -33,6 +39,10 @@ jobs:
run:
shell: bash -l {0}
steps:
- name: Harden Runner
uses: step-security/harden-runner@eb238b55efaa70779f274895e782ed17c84f2895 # v2.6.1
with:
egress-policy: audit
- uses: actions/[email protected]
with:
fetch-depth: 0 # Fetch all history for all branches and tags.
Expand Down
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Internal changes
^^^^^^^^^^^^^^^^
* The `flake8` configuration has been migrated from `setup.cfg` to `.flake8`; `setup.cfg` has been removed. (:pull:`1569`)
* The `bump-version.yml` workflow has been adjusted to bump the `patch` version when the last version is determined to have been a `release` version; otherwise, the `build` version is bumped. (:issue:`1557`, :pull:`1569`).
* The GitHub Workflows now use the `step-security/harden-runner` action to monitor source code, actions, and dependency safety. All workflows now employ more constrained permissions rule sets to prevent security issues. (:pull:`1577`).

v0.47.0 (2023-12-01)
--------------------
Expand Down