Skip to content

Commit

Permalink
Block CI egress (#134)
Browse files Browse the repository at this point in the history
* Block CI egress

* Separate out docs env

* Use alls-green
  • Loading branch information
hynek committed Sep 29, 2022
1 parent d6c3e05 commit 05e6992
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 54 deletions.
94 changes: 80 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ env:
FORCE_COLOR: "1" # Make tools pretty.
TOX_TESTENV_PASSENV: FORCE_COLOR
SETUPTOOLS_SCM_PRETEND_VERSION: "1.0" # avoid warnings about shallow checkout
PIP_DISABLE_PIP_VERSION_CHECK: 1
PIP_NO_PYTHON_VERSION_WARNING: 1
PYTHON_LATEST: "3.10"

jobs:
Expand All @@ -25,26 +27,27 @@ jobs:
- "3.8"
- "3.9"
- "3.10"
- "3.11.0-beta - 3.11"
- "~3.11.0-0"
- "pypy-3.7"
- "pypy-3.8"

steps:
- name: Harden Runner
uses: step-security/harden-runner@v1
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
egress-policy: block
allowed-endpoints: >
api.github.com:443
files.pythonhosted.org:443
github.com:443
objects.githubusercontent.com:443
pypi.org:443
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -VV
python -m site
python -m pip install --upgrade pip setuptools wheel
python -m pip install --upgrade virtualenv tox tox-gh-actions
- run: python -m pip install --upgrade wheel tox tox-gh-actions

- run: python -m tox

Expand All @@ -64,7 +67,11 @@ jobs:
- name: Harden Runner
uses: step-security/harden-runner@v1
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
egress-policy: block
allowed-endpoints: >
files.pythonhosted.org:443
github.com:443
pypi.org:443
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand Down Expand Up @@ -101,7 +108,12 @@ jobs:
- name: Harden Runner
uses: step-security/harden-runner@v1
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
egress-policy: block
allowed-endpoints: >
azure.archive.ubuntu.com:80
files.pythonhosted.org:443
github.com:443
pypi.org:443
- uses: actions/checkout@v3
with:
Expand All @@ -114,11 +126,32 @@ jobs:
sudo apt-get install libargon2-0 libargon2-0-dev
python -VV
python -m site
python -m pip install --upgrade pip setuptools wheel
python -m pip install --upgrade virtualenv tox
python -m pip install --upgrade wheel tox
- run: python -m tox -e system-argon2

docs:
name: Build docs & run doctests
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@v1
with:
egress-policy: block
allowed-endpoints: >
docs.python.org:443
files.pythonhosted.org:443
github.com:443
pypi.org:443
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"

- run: python -m pip install --upgrade wheel tox
- run: tox -e docs

package:
name: Build & verify package
runs-on: ubuntu-latest
Expand All @@ -129,7 +162,11 @@ jobs:
- name: Harden Runner
uses: step-security/harden-runner@v1
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
egress-policy: block
allowed-endpoints: >
files.pythonhosted.org:443
github.com:443
pypi.org:443
- uses: actions/checkout@v3
with:
Expand All @@ -147,11 +184,40 @@ jobs:
- name: Harden Runner
uses: step-security/harden-runner@v1
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
egress-policy: block
allowed-endpoints: >
files.pythonhosted.org:443
github.com:443
pypi.org:443
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{env.PYTHON_LATEST}}
- run: python -m pip install -e .[dev]
- run: python -m argon2 -n 1 -t 1 -m 8 -p 1


# Ensure everything required is passing for branch protection.
required-checks-pass:
if: always()

needs:
- coverage
- docs
- install-dev
- package
- system-package

runs-on: ubuntu-latest

steps:
- name: Harden Runner
uses: step-security/harden-runner@v1
with:
egress-policy: block

- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
44 changes: 9 additions & 35 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: ["main"]
pull_request:
# The branches below must be a subset of the branches above
branches: ["main"]
schedule:
- cron: "24 5 * * 4"

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

jobs:
Expand All @@ -36,44 +24,30 @@ jobs:
fail-fast: false
matrix:
language: ["python"]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Harden Runner
uses: step-security/harden-runner@v1
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
egress-policy: block
allowed-endpoints: >
api.github.com:443
bootstrap.pypa.io:443
files.pythonhosted.org:443
github.com:443
pypi.org:443
uploads.github.com:443
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
2 changes: 1 addition & 1 deletion .readthedocs.yml → readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ formats: all
build:
os: ubuntu-20.04
tools:
# Keep version in sync with tox.ini (docs and gh-actions).
# Keep version in-sync with tox.ini/docs and ci.yml/docs.
python: "3.10"

python:
Expand Down
7 changes: 3 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ ignore =
E203


# Keep docs in sync with docs env and .readthedocs.yml.
# We don't run pre-commit in CI, because we use pre-commit.ci.
[gh-actions]
python =
3.7: py37
3.8: py38, docs
3.8: py38
3.9: py39, mypy
3.10: py310, bindings-main
3.11: py311
Expand All @@ -29,8 +28,8 @@ isolated_build = true

[testenv:docs]
description = Build docs and run doctests.
# Keep basepython in sync with gh-actions and .readthedocs.yml.
basepython = python3.8
# Keep basepython in-sync with .readthedocs.yml and ci.yml/docs.
basepython = python3.10
extras = docs
commands =
python -m doctest README.md
Expand Down

0 comments on commit 05e6992

Please sign in to comment.