Skip to content
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
40 changes: 40 additions & 0 deletions .github/actions/setup-pmg/action.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions .github/pmg/config.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
31 changes: 17 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand All @@ -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
7 changes: 7 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 12 additions & 18 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand All @@ -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
Comment thread
vignesh2731 marked this conversation as resolved.
Resolved
# 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 }}
Expand Down
Loading