# Filtering behavior

> For the complete documentation index, see [llms.txt](https://docs.ringleader.dev/llms.txt).


> Ringleader filters outbound connections by address and by name, and each way has limits that hold however you write a policy.


Ringleader filters outbound connections by address and by name, and each way has limits that hold
however you write a policy. This page says what a workstation reaches behind an edge instance and
how DNS and the clock behave. It also says what a denied connection looks like and what filtering
cannot stop.

## Destinations by address and by name

An allow entry is a `cidr` or a `host`, and the two are filtered differently.

- A `cidr` is held as an address. Without `ports`, an allow entry covers port 443, and a deny entry
  refuses every port.
- A `host` is a name, and a name is read off the connection itself. That is the TLS server name on
  port 443 and the HTTP `Host` header on port 80. So a `host` can use only ports 80 and 443, and
  an allow entry covers 443 unless `ports` also lists 80. A deny entry for a host refuses both
  unless you list one of the two in `ports`.
- A name that resolves to a private address is refused. To reach another port, or to have your
  cloud's firewall hold the destination directly, declare its address range as a `cidr`.

[Outbound connection restrictions](https://docs.ringleader.dev/reference/resources/workstationconfig/#outbound-connection-restrictions)
has the fields of each entry.

## Traffic behind an edge instance

Behind an edge instance, a workstation reaches the public internet on TCP through the edge
instance, which applies the workstation's policy to each connection. On hcs, vz and qemu, the
network process or edge VM that serves a workstation applies the policy the same way. A denied
connection looks the same there. It carries TCP and DNS alone, and it answers DNS itself. It drops
UDP traffic other than DNS, and a `ping` to an address outside the workstation's own network gets no
answer. Three things change for a workstation behind an edge instance:

- A `cidr` destination in private address space is unreachable. On GCP and Azure that is any
  private range, such as `10.0.0.0/8`. On AWS it is any range inside the workstation's VPC. The
  workstation reports each one with the reason `DestinationUnreachable`.
- A permitted `host` whose name resolves to a private, loopback, link-local or `100.64.0.0/10`
  address is refused. A service inside your network cannot be reached by name.
- UDP traffic other than DNS is dropped, whether or not the policy permits where it was going.

## DNS behind an edge instance

A workstation behind an edge instance keeps using your cloud's own DNS resolver, which it reaches
directly. The edge instance also answers DNS on TCP and UDP port 53, by asking your cloud's resolver
in turn. It answers a query sent to its own address, and a query sent over TCP to any public
resolver. A query sent over UDP to a public resolver is dropped, because the workstation's firewall
rules allow only TCP to public addresses.

Any name resolves, including a name the workstation's policy does not list. That does not weaken
the policy, because the edge instance decides on the connection, not on the lookup. When the
workstation opens a connection, the edge instance reads the name off it, resolves that name itself,
and connects to the address it resolved. Pointing a permitted name at some other address does not
reach that other address.

## Clock sources behind an edge instance

Workstations behind an edge instance keep their clock from the cloud, not from a public time
server:

- On GCP, the metadata server at `169.254.169.254` answers NTP.
- On AWS, the Amazon Time Sync Service answers at `169.254.169.123`.
- On Azure, the supported images read the host's clock directly and need no network time source.

NTP to a public server on UDP port 123 is dropped.

## Denied connections

The edge instance accepts the TCP connection before it decides anything, because it reads the name
or the address off the open connection. So a connect that completes does not prove that a
destination is permitted.

Once the edge instance decides to deny a connection, what you see depends on the port you
connected to:

- A connection to port 80 gets a real `403` response whose body reads `egress policy refused this
  request`. It names no destination and no rule.
- A connection to every other TCP port, including 443, is closed with a TCP reset. Your client
  reports a connection reset by the peer.

On a host Ringleader decrypts, a request whose `Host` header names a different host gets
`421`, as
[Requests to a named host](https://docs.ringleader.dev/security/credentials/injection-effects/#requests-to-a-named-host)
explains.

Only TCP and DNS go through the edge instance. HTTP/3, which runs over UDP, is the case you are most
likely to meet. A client that falls back to TCP gets the behavior above. One that does not fall back
times out without being told anything.

A connection that closes quietly is not a verdict either, because that is also what a connection
dropped for any other reason looks like. To know what is enforced, read `EgressEnforced` on the
workstation.

## Limits of filtering by name

Because any name resolves, DNS is a slow way out of a workstation whose policy otherwise permits
nothing. Your cloud's resolver contacts the nameservers for the names a workstation looks up. So
data encoded into those names can leave the workstation, and whoever runs those nameservers can read
it. This is true of any filtering by name, not only of Ringleader's. If it matters for your
workloads, control it in your cloud's DNS configuration. An `egress` policy cannot.

## Limits of a deny list

A deny list does not stop everything. Keep these limits in mind:

- The workstation reads a denied name off the connection, on ports 80 and 443 only. It still reaches
  the same server by its address on any other port, and over a connection that sends no name. To
  block a server on every port, deny its address range as a `cidr`.
- DNS lookups still leave the workstation, so a denied name still resolves.
  [Connections a policy does not stop](https://docs.ringleader.dev/security/model/protection-limits/#connections-a-policy-does-not-stop)
  says what that means.
- The destinations Ringleader needs to manage the workstation stay reachable whatever the list says,
  including a Ringleader deployment at a private address. Behind an edge VM on hcs, vz or qemu,
  under `privateNetworks: true`, such a destination at a private address is reachable on ports 80
  and 443 only.
- An attached Integration's endpoint is not exempt. If the list covers it, the workstation cannot
  reach it, and `EgressEnforced` names it.

## Cloud metadata endpoints

On a cloud workstation a policy applies to addresses inside your own network as well as to the
public internet. On Google Cloud, an egress policy does not keep a workstation away from its own
cloud credentials. Google Cloud serves the metadata endpoint at `169.254.169.254` underneath the
firewall. Limit what the service account the VM runs as can do, as the
[Onboard Google Cloud](https://docs.ringleader.dev/guides/onboard-gcp/) describes. On AWS and
Azure the same thing is a property of those clouds.

On a local provider, [Enforcement points](https://docs.ringleader.dev/security/outbound/enforcement/) says
what is held and what is not.

## Check why a connection failed

To find out whether a policy refused a connection, ask Ringleader what it enforces and what it
refused.

1. Describe the workstation and read `EgressEnforced`:

   ```bash
   rl workstation describe my-box
   ```

2. List the connections an Edge refused for the workstation in the last 7 days:

   ```bash
   rl workstation egress my-box
   ```

   Each row names a destination, the reason and how many times it happened.

## Next steps

- [Outbound restrictions](https://docs.ringleader.dev/security/outbound/outbound-restrictions/) shows how
  to write a policy that uses these destinations.
- [Enforcement points](https://docs.ringleader.dev/security/outbound/enforcement/) says what holds a
  policy on each provider.
- [`rl workstation egress [workstation]`](https://docs.ringleader.dev/reference/cli/commands/workstation-access/#rl-workstation-egress-workstation)
  lists every flag of the command that reads the records.

