# Zones and firewall rules

_For tartan 0.9.36._

A firewall runs on every device, default deny.

A firewall runs on every device, default deny. Zones set what the organization's own devices reach; rules open the rest, by tag, not by address.

Rules follow the device's certificate, not its IP address. Nothing reaches a device unless a zone setting or a
rule opens it.

## 1. Know the zones

Every device sits in one zone. A new organization starts with four:

| Zone | Your devices reach it on | Notes |
|---|---|---|
| `user` | ping | Where a new device lands by default. |
| `resource-internal` | ping and the device's profile ports | |
| `resource-external` | ping and the device's profile ports | Set `--shareable`. |
| `infra` | nothing | Techs only. |

Your organization's techs reach every zone. An Admin can change the zones, so read what your organization has.

```sh
tartan fwzone list --org acme
```

In the console: **Firewall**.

## 2. Open a service with a port profile

A port profile is a named list of ports. These ship with every organization:

| Profile | Ports |
|---|---|
| `rdp` | 3389 |
| `ssh` | 22 |
| `web` | 80, 443 |
| `file-sharing` | 445 |
| `printing` | 9100, 631, 515 |
| `sql-server` | 1433 |
| `vnc` | 5900 |
| `cameras` | 554 |

Give a device its profiles and a zone that takes them. When it steps up, your passkey approves it.

```sh
tartan device set --org acme --device <device id> --zone resource-internal --profiles rdp,web --dry-run
tartan device set --org acme --device <device id> --zone resource-internal --profiles rdp,web
```

Your own port profile. Not the sign-in profile. When it steps up, your passkey approves it.

```sh
tartan profile set --org acme --name label-printers --ports 9100,631,5000-5100
```

See a profile's ports and what carries it, by name: its devices and NAT resources, and how many join codes and
reservations name it. A profile of your own can be removed once nothing carries it.

```sh
tartan profile show --org acme --name rdp
```

Moving a device to another zone is a config reload, not a new certificate. In the console:
**Firewall**, then **Move** on the device's row.

## 3. Narrow it with a rule

A rule opens one port or range, to devices by zone, tag or kind, from devices that carry all the tags you name.
When it steps up, your passkey approves it.

```sh
tartan group create --org acme --name finance
tartan group create --org acme --name sql
tartan rule add --org acme --id finance-sql --ports 1433 --proto tcp --from_groups finance --to_groups sql --dry-run
tartan rule add --org acme --id finance-sql --ports 1433 --proto tcp --from_groups finance --to_groups sql
```

`--ports` takes `any`, `profiles`, one port or `lo-hi`; `--proto` takes `any`, `tcp`, `udp` or `icmp`. A Tech's rule
change alerts the organization's Admins. In the console: **Firewall** › **Add a custom rule**.

Putting a tag on a device shows first which rules start or stop applying to it:

```sh
tartan group add --org acme --name finance --device <device id> --dry-run
```

## 4. Add your own zone

An Admin adds a zone. Your passkey approves it. In the console: **Firewall** › **Add a zone**.

```sh
tartan fwzone add --org acme --name lab --colour zone.resourceInternal --ping --takes_profiles --dry-run
tartan fwzone add --org acme --name lab --colour zone.resourceInternal --ping --takes_profiles
```

Settings you leave out are off. `--techs_only` makes a zone that nothing but your techs reach. `--shareable` lets
its devices be offered to a partner ([Share with a partner org](partner-org.md)); to turn it on for a zone you have
(your passkey approves it):

```sh
tartan fwzone set --org acme --name lab --shareable
```

`tartan fwzone remove` removes a zone; one that holds devices or rules needs `--move_to <zone>`. Your passkey
approves it.

## Check it worked

- `tartan rule list --org acme` shows your rules in order.
- `tartan device show --org acme --device <device id> --schema tartan.device.v1` shows the device's `zone`,
  `groups` and `profiles`.
- From a `finance` device, port 1433 on a `sql` device answers.

## Next

- [Names and certificates](names-certificates.md)
- [Share with a partner org](partner-org.md)
- [Techs, just in time](techs-just-in-time.md)
