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.
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.
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.
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.
- In the Policy Manager, open the Policies tab and click +.
- Enter a Name and click Submit.
- Add rules with Add Rule. See Rules.
- 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
- In the Policy Manager, select the organization, a repository, a workflow or a job under Entities.
- 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:
- Add Rules under Default Policy in the Chain view
- Allow on a run's connection, with a default policy as the target. See Allow a Destination.
- Applying an AI Policy Advisor proposal
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.
| Type | Value | Example |
|---|---|---|
| Hostname | A hostname, optionally with wildcards | github.com, *.example.com |
| CIDR Block | An 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 pick | Port | Protocol |
|---|---|---|
| SSH | 22 | TCP |
| DNS | 53 | TCP and UDP |
| HTTP | 80 | TCP |
| HTTPS | 443 | TCP and UDP |
| HTTP Alt | 8080 | TCP |
| HTTPS Alt | 8443 | TCP 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.comallowsgithub.com,api.github.comanda.b.github.com, but notevil-github.com. - One star matches exactly one label.
*.github.comallowsapi.github.com, but notgithub.comora.b.github.com. - Two stars match one or more labels.
**.internal.example.comallowsapi.internal.example.comandapi.dev.internal.example.com. - A wildcard must be a whole label:
api*.example.comisn'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:
- Check the Destination. To widen or correct it, such as
api-v2.example.comto*.example.com, click the pencil, edit it, and press Enter (Escape cancels). - Optionally add Ports (optional). With none, the rule allows every port.
- 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.
- 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.
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-lockdownandsudo-allow-commandsinputs. - Lockdown also takes the job's user out of the
dockergroup, 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.comagainst a rule forbastion, 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
| What | Who can change it |
|---|---|
| Named policies, the organization's default and assigned policies, and the organization's mode | Organization admins |
| A repository's, workflow's or job's default policy, assigned policies and mode | Organization 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.
