diff --git a/.github/actions/setup-pmg/action.yml b/.github/actions/setup-pmg/action.yml new file mode 100644 index 0000000..8a76d3d --- /dev/null +++ b/.github/actions/setup-pmg/action.yml @@ -0,0 +1,40 @@ +name: Set up PMG +description: >- + Starts the PMG proxy as root with kernel enforcement, so every process of the + job goes through it. Call it right after the checkout. At the end of the job, + the post step of safedep/pmg stops PMG, fails the job when PMG blocked a + package, and writes a job summary with a proposed network profile. See + https://github.com/safedep/pmg/blob/main/docs/github-action.md. + +inputs: + api-key: + description: SafeDep Cloud API key for the audit events. Empty sends none. + required: false + default: "" + tenant-id: + description: SafeDep Cloud tenant of the API key. + required: false + default: "" + network-profile: + description: >- + The network profile of the job, a path under .github/pmg/network/. While + the file does not exist, PMG applies no network policy, and the job + summary proposes a profile for this path. + required: true + +runs: + using: composite + steps: + - uses: safedep/pmg@ee9c6ccfb8c7cc31280fb91f1fa5031ec1c6ff18 # v0.34.0 + with: + api-key: ${{ inputs.api-key }} + tenant-id: ${{ inputs.tenant-id }} + endpoint-id: CICD_GHA_SAFEDEP_CLI + enforce: true + # The cooldown and its skip list. The path is relative to the checkout. + config-file: .github/pmg/config.yml + network-profile: ${{ inputs.network-profile }} + # audit lets every connection through and reports each destination + # that the profile does not allow. Change it to enforce when each job + # has a reviewed profile. + network-mode: audit diff --git a/.github/pmg/config.yml b/.github/pmg/config.yml index 13b5622..d3ab58f 100644 --- a/.github/pmg/config.yml +++ b/.github/pmg/config.yml @@ -1,6 +1,6 @@ -# PMG settings for the CI jobs of this repository. ci.yml and goreleaser.yml -# pass this file to safedep/pmg as config-file. PMG reads the keys that this -# file does not set from its own template. +# PMG settings for the CI jobs of this repository. setup-pmg passes this file +# to safedep/pmg as config-file. PMG reads the keys that this file does not set +# from its own template. dependency_cooldown: enabled: true days: 2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d1823e..8f1e089 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,10 +8,20 @@ on: jobs: build-test-lint: runs-on: ubuntu-latest + # Under PMG the traffic of the runner goes through the proxy. A proxy that + # hangs makes the job hang until this timeout. + timeout-minutes: 30 steps: # actions/checkout v6.0.2 - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd + - name: Set up PMG + uses: ./.github/actions/setup-pmg + with: + api-key: ${{ secrets.SAFEDEP_CLOUD_API_KEY }} + tenant-id: ${{ secrets.SAFEDEP_CLOUD_TENANT_DOMAIN }} + network-profile: .github/pmg/network/ci-build-test-lint.yml + # actions/setup-go v6.4.0 - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c with: @@ -45,6 +55,13 @@ jobs: with: fetch-depth: 0 + - name: Set up PMG + uses: ./.github/actions/setup-pmg + with: + api-key: ${{ secrets.SAFEDEP_CLOUD_API_KEY }} + tenant-id: ${{ secrets.SAFEDEP_CLOUD_TENANT_DOMAIN }} + network-profile: .github/pmg/network/ci-release-preflight.yml + - name: Set up Go uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 with: @@ -60,16 +77,6 @@ jobs: node-version: "24" cache: "pnpm" - - name: Install and configure PMG - uses: safedep/pmg@5ac0f275b83d9d5a9342c6aae977ec32fa330daa # v1 - with: - server-mode: true - api-key: ${{ secrets.SAFEDEP_CLOUD_API_KEY }} - tenant-id: ${{ secrets.SAFEDEP_CLOUD_TENANT_DOMAIN }} - endpoint-id: CICD_GHA_SAFEDEP_CLI - # The cooldown and its skip list. The path is relative to the checkout. - config-file: .github/pmg/config.yml - - name: Install dependencies run: pnpm install --frozen-lockfile @@ -81,7 +88,3 @@ jobs: - name: Release preflight run: pnpm nx run safedep-cli:release-preflight - - - name: Stop PMG proxy - if: always() - run: pmg proxy stop --fail-on-violation diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index e4ce5e3..f6192d4 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -21,6 +21,13 @@ jobs: steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 + - name: Set up PMG + uses: ./.github/actions/setup-pmg + with: + api-key: ${{ secrets.SAFEDEP_CLOUD_API_KEY }} + tenant-id: ${{ secrets.SAFEDEP_CLOUD_TENANT_DOMAIN }} + network-profile: .github/pmg/network/golangci-lint-golangci.yml + - uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6 with: go-version-file: go.mod diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index 95ddc09..f8eae2d 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -25,6 +25,13 @@ jobs: with: fetch-depth: 0 + - name: Set up PMG + uses: ./.github/actions/setup-pmg + with: + api-key: ${{ secrets.SAFEDEP_CLOUD_API_KEY }} + tenant-id: ${{ secrets.SAFEDEP_CLOUD_TENANT_DOMAIN }} + network-profile: .github/pmg/network/goreleaser-release.yml + - name: Set up Go uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 with: @@ -41,16 +48,6 @@ jobs: registry-url: "https://registry.npmjs.org" cache: "pnpm" - - name: Install and configure PMG - uses: safedep/pmg@5ac0f275b83d9d5a9342c6aae977ec32fa330daa # v1 - with: - server-mode: true - api-key: ${{ secrets.SAFEDEP_CLOUD_API_KEY }} - tenant-id: ${{ secrets.SAFEDEP_CLOUD_TENANT_DOMAIN }} - endpoint-id: CICD_GHA_SAFEDEP_CLI - # The cooldown and its skip list. The path is relative to the checkout. - config-file: .github/pmg/config.yml - - name: Install dependencies run: pnpm install --frozen-lockfile @@ -75,20 +72,17 @@ jobs: with: subject-checksums: dist/checksums.txt + # Limitation: the post step of PMG gives its verdict at the end of the + # job, after the GitHub release and the npm publish. So it alerts but + # cannot stop a release. A block of a required dependency already fails + # its install step. The gap is an optional dependency. pnpm skips the + # block, exits 0 and reaches publish. - name: Publish npm packages (sync + build + publish via Nx) run: pnpm nx run safedep-cli:publish-npm env: VERSION: ${{ steps.version.outputs.version }} NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - # Limitation: runs after publish, so it alerts but cannot stop a - # release. A required dep block already fails the earlier install step. The - # gap is an optional dep: pnpm skips the block and exits 0, reaching - # publish. - - name: Stop PMG proxy - if: always() - run: pmg proxy stop --fail-on-violation - test-installation: needs: release runs-on: ${{ matrix.os }}