CodeCargo logo

Security

Policies

A CargoWall policy is a list of allow rules. A job may connect to what its policies allow, and every other connection is denied: blocked in enforce, recorded as would deny in audit. Policies also carry sudo lockdown and search domains.

How Policies Combine

Policies apply at four levels: the organization, a repository, a workflow, and a job. Each level has its own default policy, and you can assign any number of named policies to it as well.

A job's effective policy is everything every one of those policies allows, from the job up to the organization. Rules only add up: a repository can allow more than the organization, but it can't take away what the organization allows. When two rules have the same hostname or CIDR value, their ports are combined, and a rule with no ports allows every port. A rule for api.github.com beside one for github.com stays separate.

The mode works the other way: the most specific level that sets one wins.

How a CargoWall job's policy is built: organization, repository, workflow, workflow job. Each level has its own default policy and any assigned policies. A job gets every rule from every level, so rules only add up. Only the mode overrides: the most specific level that sets one wins.OrganizationApplies to every jobDefaultAssignedRepositoryAdds to the orgDefaultAssignedWorkflowAdds to the repoDefaultAssignedWorkflow JobAdds to all aboveDefaultAssignedBroadestMostspecificA job gets every rule from each level's default and assigned policies.Only the mode overrides: the most specific level that sets one wins.

The Policy Manager

You manage policies in the Policy Manager. Open it with Policy Manager on any CargoWall tab, or on a repository's or workflow's CargoWall tab. From a run, Open in Policy Manager opens it on the run's workflow. Manage policy, beside a job, opens the Policy Manager with nothing selected. Select the job under Entities.

Its left panel has two tabs:

  • Entities — your organization, then its repositories, their workflows, and their jobs. Select one to see and change its policies and mode.
  • Policies — your named policies.
Policy Manager with the Policies tab selected: the Policies list holds the one named policy, CI tooling, open on the right with three Allow host rules for pypi.org, files.pythonhosted.org and dl-cdn.alpinelinux.org on all ports, Add Rule, Sudo Lockdown with Enable, and Search Domains

Chain and Effective

Select an entity to see it in two views:

  • Chain, the default, shows the selected level expanded and each level above it collapsed and marked Inherited. Each level has its Settings (its CargoWall Mode, and Check Runs for the organization or a repository), its baselines (except on the organization), its Default Policy and its Assigned Policies. Sudo Lockdown and Search Domains appear when a policy at that level has them. With the organization selected, Destination Tags appears below. Expand a level to see what it adds. An inherited level's default rules are read-only here; select that level to change them.
  • Effective shows what the next run gets: the mode, Check Runs, how many rules, sudo lockdown, then the merged rules and search domains. It's the same policy the CargoWall step fetches.

A workflow or job with AI proposals waiting has a third view, Proposed. See AI Policy Advisor.

Policy Manager Chain view for the ledger-service ci workflow: the Entities tree on the left, and on the right the workflow level with its CargoWall Mode set to Inherit (Audit), a stable baseline with Allow buttons for api.stripe.com, sonarcloud.io and hooks.slack.com, an empty default policy, and an Assigned Policies selector
Effective: what the test job's next run gets, merged from every level.
Policy Manager Effective view for the test job of the ledger-service ci workflow: CargoWall Mode Audit, Check Runs Enabled, 7 rules and Sudo lockdown enabled, then the effective rules from api.github.com to repo.maven.apache.org on 443/tcp, sudo lockdown with all sudo commands blocked, and the search domain acme.internal

Named Policies

A named policy is a set of rules you can assign to many entities, such as CI tooling for the package registries every build needs.

  1. In the Policy Manager, open the Policies tab and click +.
  2. Enter a Name and click Submit.
  3. Add rules with Add Rule. See Rules.
  4. Assign the policy where it should apply.

Rename or delete a policy from its options menu (⋯). Deleting a policy removes it from everything it was assigned to.

Only an organization admin can create, rename or delete a named policy. Anyone else doesn't see +.

Assign a Policy

  1. In the Policy Manager, select the organization, a repository, a workflow or a job under Entities.
  2. Under Assigned Policies, choose one or more named policies.

The policies apply to that entity and everything under it. Default policies can't be assigned elsewhere.

Default Policies

Every organization, repository, workflow and job has its own default policy, for rules that belong to just that entity. It's created the first time you add to it:


Rules

Each rule allows a destination, by Hostname or CIDR Block, optionally on some ports. Leave Ports empty on a CIDR block wider than one address. With ports, the current CargoWall release allows nothing inside the range. To add one, click Add Rule on a policy, choose the type, enter the Value, and add any Ports.

TypeValueExample
HostnameA hostname, optionally with wildcardsgithub.com, *.example.com
CIDR BlockAn IP range. For one address, use /32 (IPv4) or /128 (IPv6)10.0.0.0/8, 192.168.1.100/32

Ports takes a comma-separated list, such as 80, 443. With no ports, the rule allows every port. Typed ports cover TCP, UDP and ICMP. The quick picks narrow the protocol where it's usual:

Quick pickPortProtocol
SSH22TCP
DNS53TCP and UDP
HTTP80TCP
HTTPS443TCP and UDP
HTTP Alt8080TCP
HTTPS Alt8443TCP and UDP
ICMP—ICMP

Adding a rule with the same hostname or CIDR value as one the policy already has adds the new ports to the existing rule.

Hostname Matching

  • A plain hostname matches itself and every subdomain. github.com allows github.com, api.github.com and a.b.github.com, but not evil-github.com.
  • One star matches exactly one label. *.github.com allows api.github.com, but not github.com or a.b.github.com.
  • Two stars match one or more labels. **.internal.example.com allows api.internal.example.com and api.dev.internal.example.com.
  • A wildcard must be a whole label: api*.example.com isn't accepted. Matching ignores case.

Tag rules match differently: there, a plain hostname matches only itself.

A hostname rule doesn't take an IP address. Use a CIDR block instead.

Hostnames may contain underscores. _gateway allows the runner's default gateway by the name systemd-resolved gives it, so you don't need a provider's CIDR for it. It opens the gateway's address on the rule's ports, and works only on runners with systemd-resolved, as GitHub's Ubuntu images have. Allow it only on the repository or workflow that needs it.


Allow a Destination

You can allow a destination where you found it, without opening the Policy Manager:

  • From a run: Allow on a denied or would-deny connection on the run's Jobs tab.
  • From the Destinations tab: Add to policy in a destination's actions menu (⋯). Only organization admins see it.

Both open the Allow Destination dialog:

  1. Check the Destination. To widen or correct it, such as api-v2.example.com to *.example.com, click the pencil, edit it, and press Enter (Escape cancels).
  2. Optionally add Ports (optional). With none, the rule allows every port.
  3. Under Add to, choose an existing policy, or a new policy to create. From a run, the dialog also offers the default policies of the run's job, workflow, repository and organization that you can change.
  4. Click Add Rule, or Create Policy for a new one.

The dialog lists only policies you can change, and says why when there are none. An IP address becomes a CIDR block, /32 for IPv4 and /128 for IPv6. From a run, when the job's policy already has an all-ports rule for exactly this destination, the dialog says Already allowed by the current policy.

From a run, Add to also offers the default policies of the run's job, workflow and repository, and your organization's.
The Allow Destination dialog for api.stripe.com, opened from a run: an empty Ports field with quick picks, and the Add to list open on Job default policy, Workflow default policy, Repository default policy, Org default policy, Existing policy and New policy

In the Policy Manager's Chain view, a baseline's entries have Allow too, which keeps the port and protocol the baseline saw. Entries the policy already covers are hidden until you tick Show covered.


Sudo Lockdown

GitHub's runners give a job passwordless sudo, which a step could use to stop the firewall. Sudo lockdown takes that away: the job's user can run only the commands you allow with sudo.

On a policy, click Enable under Sudo Lockdown, then add Allowed Commands by full path, such as /usr/bin/apt-get. With no commands, the job can't use sudo at all.

  • Lockdown is on when any policy in the job's chain turns it on. The allowed commands of every such policy are combined.
  • A policy's lockdown replaces the step's own sudo-lockdown and sudo-allow-commands inputs.
  • Lockdown also takes the job's user out of the docker group, since Docker gives a container root on the runner.

Allowed Commands Can Hand Out Root

A command such as /usr/bin/apt-get or /usr/bin/docker can run anything as root, including a step that turns CargoWall off. Allow only the commands the job needs. Enter each one as a bare full path, such as /usr/bin/apt-get. CodeCargo accepts anything that starts with /, but the step drops arguments, so /usr/bin/apt-get install curl allows apt-get with any arguments. An entry with a wildcard stops lockdown from turning on at all for the job, which keeps passwordless sudo.

Search Domains

On private networks, jobs often reach hosts by short names, such as bastion, that the runner's DNS completes with a search domain, such as internal.example.com. List those domains under Search Domains on a policy, and CargoWall:

  • matches bastion.internal.example.com against a rule for bastion, and
  • resolves any name under the domain through its DNS, even without a hostname rule for it. Connecting still needs a rule, typically a CIDR block with no ports for the private network.

A search domain needs at least two labels, such as internal.example.com, with no wildcards or leading dot, and can't be a public suffix such as co.uk. CodeCargo saves one that breaks these rules, but the CargoWall step then rejects the job's whole policy and falls back as api-failure-mode says, audit by default. See How the Step Gets Its Policy. Search domains from every policy in the chain are combined. The domains your cloud's runners use are added on their own.


Who Can Change Policies

WhatWho can change it
Named policies, the organization's default and assigned policies, and the organization's modeOrganization admins
A repository's, workflow's or job's default policy, assigned policies and modeOrganization admins, and anyone with write access to that repository

CargoWall offers Allow, Add to policy, Manage policy and Open in Policy Manager only for policies you can change. The add-rule dialogs list only those policies as targets, and say why when there are none.

In the Policy Manager, a policy you can't change shows its rules without the controls to edit them, and Rename and Delete are left out of the policy list. Add Rule (or Add Rules on a default policy with no rules yet) stays, turned off, and says who can change the policy: Ask an organization admin to change this policy. for a named policy or the organization's default policy, or that you need write access to the repository for a repository's, workflow's or job's default policy. Sudo Lockdown and Search Domains can't be changed either.