Skip to main content
A compromised package can send your CI secrets to a host that the attacker controls. A network policy lists the hosts that a job can reach. The PMG proxy refuses every other destination, and the job fails.
This page uses safedep/pmg@v0.34.0 or later. Earlier releases have no job summary and need the stop and proposal steps that their documentation shows. Use the policy with kernel enforcement. Without it, a process can ignore the proxy variables and connect directly.

Build the policy from a run

The proxy records every destination that a job reaches. At the end of the job, the post step of the action proposes a profile from these destinations and shows it in the job summary.
1

Run the job with the action

The job summary proposes a profile for .pmg/network.yml. To propose it for another path, set network-profile to a path that does not exist yet. The proposal comes from the event log, so do not set skip-event-logging: true or baseline: false.
2

Review the proposal

The proposal has one allow rule for each host that the job reached. It inherits the built-in github-actions profile, which allows the hosts of the runner and refuses every host that no rule allows. One run does not reach every host that the job needs. Remove each host that the job does not need.
3

Commit the profile

Save the proposal as .pmg/network.yml, commit it, and set network-profile on the action:
network-mode is audit by default. Each later run lists the destinations that the profile does not allow, in the summary and as a warning on the run. The summary shows the rules to add.
4

Protect the profile

The profile controls what the job can reach, so give it the same review as the workflow file. Add a CODEOWNERS line:
A committed profile looks like this:
.pmg/network.yml
deny_ip_literals refuses a connection to an IP address that is not explicitly allowed. Without it, an allow list of names does not stop a package that sends data to an IP address.

Enforce the policy

Set network-mode: enforce:
The proxy refuses each destination that the profile does not allow. The post step fails the job, and the job summary names the destination, the rule, and the program. The two inputs control different things: Use both. Without enforce: true, a process that ignores the proxy variables connects directly, and the profile never sees the connection. To add a host later, run the job with network-mode: audit and add the rule that the summary shows. Under enforce, the proxy refuses a new destination, so the proposal gets no rule for it.

Hosts of the runner

Make your profile inherit github-actions. This built-in profile allows the hosts of the runner, its agents, GitHub releases, the GitHub container registry, and the cache and artifact storage. To see the hosts, run:
Do not inherit another built-in profile, such as npm-restrictive. It does not allow the hosts of the runner, so the proxy refuses the connections of the runner to GitHub. The runner, actions/cache, and actions/upload-artifact store data in Azure storage. github-actions allows only the storage accounts that the GitHub Meta API lists, not every Azure storage account. When GitHub adds a storage account, a job under network-mode: enforce fails, and the job summary names a denied productionresultssa<N>.blob.core.windows.net host. Add that host to network.allow_outbound in your profile. You do not need a new PMG release. An action that downloads from another host also needs a rule in your profile.

Next steps

For the steps without enforce and the steps with config-file, see Build the profile from a run in the PMG action documentation. For all inputs of the action, see Inputs.

PMG in GitHub Actions

Set up the PMG action and kernel enforcement.

Limit the Hosts a Package Install Can Reach

Apply a network policy on a developer machine.