From 0133ae419a755d3b28ecd7a31e17a3018ae91568 Mon Sep 17 00:00:00 2001 From: marvinfriede <51965259+marvinfriede@users.noreply.github.com> Date: Sun, 15 Dec 2024 09:25:06 -0600 Subject: [PATCH 1/2] Fix zizmor security issues in GA --- .github/workflows/codeql.yaml | 67 ++++++++++++++++---------------- .github/workflows/macos-arm.yaml | 10 ++++- .github/workflows/macos-x86.yaml | 10 ++++- .github/workflows/release.yaml | 32 ++++++++++----- .github/workflows/ubuntu.yaml | 12 ++++-- .github/workflows/windows.yaml | 10 ++++- 6 files changed, 90 insertions(+), 51 deletions(-) diff --git a/.github/workflows/codeql.yaml b/.github/workflows/codeql.yaml index e280d22..5912558 100644 --- a/.github/workflows/codeql.yaml +++ b/.github/workflows/codeql.yaml @@ -13,11 +13,11 @@ name: "CodeQL" on: push: - branches: [ "main" ] + branches: ["main"] pull_request: - branches: [ "main" ] + branches: ["main"] schedule: - - cron: '31 23 * * 0' + - cron: "31 23 * * 0" jobs: analyze: @@ -37,45 +37,46 @@ jobs: strategy: fail-fast: false matrix: - language: [ 'python' ] + language: ["python"] # CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ] # Use only 'java-kotlin' to analyze code written in Java, Kotlin or both # Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support steps: - - name: Checkout repository - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 + with: + persist-credentials: false - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v3 - 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. - # For more 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 - queries: +security-and-quality + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + 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. + # For more 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 + queries: +security-and-quality + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v3 - # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v3 + # ℹī¸ 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 - # ℹī¸ 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. - # 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 - # - run: | - # echo "Run, Build Application using script" - # ./location_of_script_within_repo/buildscript.sh - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 - with: - category: "/language:${{matrix.language}}" + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:${{matrix.language}}" diff --git a/.github/workflows/macos-arm.yaml b/.github/workflows/macos-arm.yaml index 920b72a..119e804 100644 --- a/.github/workflows/macos-arm.yaml +++ b/.github/workflows/macos-arm.yaml @@ -75,6 +75,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 + with: + persist-credentials: false - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 @@ -90,7 +92,11 @@ jobs: run: echo "TOXENV=py$(echo ${{ matrix.python-version }} | tr -d '.')-torch$(echo ${{ matrix.torch-version }} | tr -d '.')" >> $GITHUB_ENV - name: Print TOXENV - run: echo "TOXENV is set to '${{ env.TOXENV }}'." + run: echo "TOXENV is set to '${TOXENV}'." + env: + TOXENV: ${{ env.TOXENV }} - name: Unittests with tox - run: tox -e ${{ env.TOXENV }} + run: tox -e $TOXENV + env: + TOXENV: ${{ env.TOXENV }} diff --git a/.github/workflows/macos-x86.yaml b/.github/workflows/macos-x86.yaml index f38dd86..b230ed2 100644 --- a/.github/workflows/macos-x86.yaml +++ b/.github/workflows/macos-x86.yaml @@ -86,6 +86,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 + with: + persist-credentials: false - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 @@ -101,7 +103,11 @@ jobs: run: echo "TOXENV=py$(echo ${{ matrix.python-version }} | tr -d '.')-torch$(echo ${{ matrix.torch-version }} | tr -d '.')" >> $GITHUB_ENV - name: Print TOXENV - run: echo "TOXENV is set to '${{ env.TOXENV }}'." + run: echo "TOXENV is set to '${TOXENV}'." + env: + TOXENV: ${{ env.TOXENV }} - name: Unittests with tox - run: tox -e ${{ env.TOXENV }} + run: tox -e $TOXENV + env: + TOXENV: ${{ env.TOXENV }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 379e7d7..c92359a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -20,14 +20,12 @@ on: push: branches: - main - - master tags: - "v*" pull_request: branches: - main - - master workflow_dispatch: @@ -37,6 +35,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 + with: + persist-credentials: false - name: Build wheel (bdist) run: pipx run build --wheel @@ -51,6 +51,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 + with: + persist-credentials: false - name: Build source distribution (sdist) run: pipx run build --sdist @@ -60,9 +62,12 @@ jobs: with: path: dist/*.tar.gz - upload_pypi: - needs: [wheel, sdist] + upload_test_pypi: + needs: [sdist, wheel] runs-on: ubuntu-latest + environment: release + permissions: + id-token: write if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') steps: - name: Download build artifacts @@ -74,12 +79,21 @@ jobs: - name: Publish to Test PyPI uses: pypa/gh-action-pypi-publish@release/v1 with: - user: __token__ - password: ${{ secrets.TEST_PYPI_TOKEN }} repository-url: https://test.pypi.org/legacy/ + upload_pypi: + needs: [sdist, wheel, upload_test_pypi] + runs-on: ubuntu-latest + environment: release + permissions: + id-token: write + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + steps: + - name: Download build artifacts + uses: actions/download-artifact@v3 + with: + name: artifact + path: dist + - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1 - with: - user: __token__ - password: ${{ secrets.PYPI_TOKEN }} diff --git a/.github/workflows/ubuntu.yaml b/.github/workflows/ubuntu.yaml index f12c92e..a969e87 100644 --- a/.github/workflows/ubuntu.yaml +++ b/.github/workflows/ubuntu.yaml @@ -92,6 +92,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 + with: + persist-credentials: false - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 @@ -107,13 +109,17 @@ jobs: run: echo "TOXENV=py$(echo ${{ matrix.python-version }} | tr -d '.')-torch$(echo ${{ matrix.torch-version }} | tr -d '.')" >> $GITHUB_ENV - name: Print TOXENV - run: echo "TOXENV is set to '${{ env.TOXENV }}'." + run: echo "TOXENV is set to '${TOXENV}'." + env: + TOXENV: ${{ env.TOXENV }} - name: Unittests with tox - run: tox -e ${{ env.TOXENV }} + run: tox -e $TOXENV + env: + TOXENV: ${{ env.TOXENV }} - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@7f8b4b4bde536c465e797be725718b88c5d95e0e # 5.1.1 if: > matrix.python-version == '3.11' && matrix.torch-version == '2.2.2' && diff --git a/.github/workflows/windows.yaml b/.github/workflows/windows.yaml index ccc00bf..968ac0c 100644 --- a/.github/workflows/windows.yaml +++ b/.github/workflows/windows.yaml @@ -84,6 +84,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 + with: + persist-credentials: false - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 @@ -99,7 +101,11 @@ jobs: run: echo "TOXENV=py$(echo ${{ matrix.python-version }} | tr -d '.')-torch$(echo ${{ matrix.torch-version }} | tr -d '.')" >> $GITHUB_ENV - name: Print TOXENV - run: echo "TOXENV is set to '${{ env.TOXENV }}'." + run: echo "TOXENV is set to '${TOXENV}'." + env: + TOXENV: ${{ env.TOXENV }} - name: Unittests with tox - run: tox -e ${{ env.TOXENV }} + run: tox -e $TOXENV + env: + TOXENV: ${{ env.TOXENV }} From f644b24d5f23d0498050ed84fd02adaa52ce1d32 Mon Sep 17 00:00:00 2001 From: marvinfriede <51965259+marvinfriede@users.noreply.github.com> Date: Sun, 15 Dec 2024 10:22:30 -0600 Subject: [PATCH 2/2] Add zizmor to pre-commit --- .pre-commit-config.yaml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 096b072..7dc8649 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,7 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. ci: - skip: [mypy] + skip: [mypy] repos: - repo: https://github.com/pre-commit/pre-commit-hooks @@ -40,7 +40,7 @@ repos: --min-py-version, "3.8", --max-py-version, - "3.11", + "3.12", ] - repo: https://github.com/asottile/pyupgrade @@ -62,10 +62,15 @@ repos: - id: black stages: [pre-commit] + - repo: https://github.com/woodruffw/zizmor-pre-commit + rev: v0.9.2 + hooks: + - id: zizmor + - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.13.0 hooks: - id: mypy - # additional_dependencies: [types-all] - args: [--config-file=pyproject.toml, --ignore-missing-imports] + pass_filenames: false + args: [--config-file=pyproject.toml, --ignore-missing-imports, src] exclude: "test|examples/|test/conftest.py"