# Edge management

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


> An Edge enforces a workstation's outbound rules by host name and adds injected credentials, in your cloud account or on your computer.


An Edge enforces a workstation's outbound rules by host name, and adds injected credentials to
requests, in your cloud account or on your computer. Your cloud's firewall matches addresses, not
names. An Edge reads the host name off each outbound connection. A workstation's
egress policy (see [outbound restrictions](https://docs.ringleader.dev/security/outbound/outbound-restrictions/)) can then name `github.com` instead of an
address range. It is also where Ringleader adds a key to a request, as
[Injected credentials](https://docs.ringleader.dev/security/credentials/injected-credentials/) shows.

An **Edge** resource declares one **edge instance**: a VM that Ringleader builds in your cloud
account, in one cloud and region. For hcs, vz and qemu workstations, an Edge runs a small VM on
each member's own computer instead. A namespace administrator declares an Edge once. From then
on, every workstation in that namespace that it serves, in its region or on its provider, sends
its outbound connections through it. Declare one Edge for each provider and region in a namespace.
[Workstations an Edge serves](#workstations-an-edge-serves) says
what a second one does.

## Workstations an Edge serves

A workstation is served by the Edge in its own namespace whose provider and region match the
workstation's. No field on a workstation or an Integration names an Edge.

- A namespace may hold one Edge per provider and region. A second is refused when you apply
  it, and the refusal names the Edge that already serves that region. The regions an Edge
  lists in `additionalRegions` count as its own.
- All the workstations an Edge serves in its own `region` must be in one subnet. If two are
  not, the Edge builds nothing, and its message names both. Move the workstations into one
  subnet, or give the others a namespace and an Edge of their own.
- Once an Edge exists for a region, every workstation there with an `egress` policy goes
  through it, including one whose policy lists only `cidr` destinations. See
  [Traffic behind an edge instance](https://docs.ringleader.dev/security/outbound/filtering/#traffic-behind-an-edge-instance).

[Held-closed workstations](https://docs.ringleader.dev/security/outbound/enforcement/#held-closed-workstations)
and [A policy that names a host](https://docs.ringleader.dev/security/outbound/enforcement/#a-policy-that-names-a-host)
say what a workstation reaches while no edge instance serves it.


## Cases that need an Edge

A cloud workstation needs an Edge in three cases. Its policy names a `host` or is `audit`. Its deny
list names a `host` or, on AWS, has any entry. Or an Integration injects a credential into it.
[Enforcement by provider](https://docs.ringleader.dev/security/outbound/enforcement/#enforcement-by-provider)
says which policies need one on each cloud. An hcs, vz or qemu workstation needs no Edge, and
[Network processes and edge VMs](https://docs.ringleader.dev/security/outbound/enforcement/#network-processes-and-edge-vms)
says what an optional one changes. While an Edge that a workstation needs is missing or not serving
yet, [Held-closed workstations](https://docs.ringleader.dev/security/outbound/enforcement/#held-closed-workstations)
says what the workstation reaches.

## Cost of an Edge

An edge instance is a VM that your organization pays for. Traffic from another region to the VM is
billed per gigabyte by your cloud, where it is possible at all. An administrator lists each extra
region in `additionalRegions` to accept that cost, and it is never filled in for you.
[Additional regions](https://docs.ringleader.dev/reference/resources/edge/#additional-regions) says what each cloud
needs.

## Subnet ownership

On AWS and Azure, a route replaces the default route for every VM in a subnet. So an edge instance
routes a whole subnet, and only one edge instance can route a given subnet.
[Subnet routing](#subnet-routing) says what that asks of your network.

- A namespace administrator can claim a subnet for their namespace, on any of the three clouds, by
  naming it in a [CloudIdentity](https://docs.ringleader.dev/reference/resources/cloudidentity/)'s `spec.subnet`. See
  [Subnet claims](https://docs.ringleader.dev/cloud-accounts/cloud-identities/subnet-claims/) for how a claim
  works, what is refused and who may use a claimed subnet.
- Before an edge instance first routes a subnet, it lists every VM in it. A VM it does not serve,
  such as one Ringleader did not create, holds that routing back. The subnet's entry in the
  Edge's `status.subnetHolds` names the VM, and the workstations in the subnet report `SteeringHeld`.
  Move the VM out of the subnet, or, if it is a workstation in this namespace, give it an egress
  policy.
- When another edge instance already routes the subnet, the workstation reports
  `SubnetSteeredElsewhere`. The subnet's entry in `status.subnetHolds` has `steeredElsewhere: true`,
  and its message names the other Edge when that Edge is in your organization.
- The Edge keeps routing the subnet after its last workstation there is gone. A workstation whose
  policy you remove, or any other VM left in the subnet, reaches nothing and reports
  `SteeredWithoutServing` until you delete the Edge.

## Subnet routing

Subnet routing asks two things of your network on AWS and Azure, and neither is a subnet per policy. One edge instance serves many policies from one subnet, telling them apart by source address. The onboarding module or stack reserves both subnets for you.

- A routed subnet may hold only workstations the edge instance serves, because the edge instance refuses a source address it has no rule for. The edge instance does not start routing a subnet while a VM it does not serve is in it. A VM created there later is routed anyway, because a route applies to the whole subnet, and loses its outbound access. The Edge lists it in `status.neighbours`, and a workstation in that position reports the `SteeredWithoutServing` condition. The setting `create_governed_subnet` (Terraform) or `CREATE_GOVERNED_SUBNET` (ARM on Azure, CloudFormation on AWS) reserves a subnet for this. Put the workstations that have an egress policy in the subnet it outputs: `governed_subnet_id` (Terraform), `governedSubnetId` (ARM) or `GovernedSubnetId` (CloudFormation). The workstations subnet the module creates is never routed. It is for every workstation in the virtual network (Azure) or VPC (AWS), with a policy or without one.
- The edge instance is never in the subnet it routes. A route table replaces the default route for everything in its subnet. An edge instance in the subnet it routes would send its own traffic back into itself. Its VM goes in the subnet that `create_gateway_subnet` (Terraform) or `CREATE_GATEWAY_SUBNET` (ARM or CloudFormation) reserves. Give that subnet's id to the [Edge](https://docs.ringleader.dev/reference/resources/edge/) as its `subnet`: `gateway_subnet_id` (Terraform), `gatewaySubnetId` (ARM) or `GatewaySubnetId` (CloudFormation).

## Access to a workstation behind an Edge

Routing a workstation's traffic through an edge instance also routes the replies to
connections opened *to* the workstation, so its own public address stops answering. The edge
instance gives it a new way in instead. Each workstation it serves that has a public address
of its own gets a TCP port on the edge instance's public address, forwarded to the
workstation's port 22.

- The workstation publishes that endpoint as `status.managementAddress`. `rl shell`, `rl code`
  and the rest of Ringleader use it with no change on your side. The workstation's own SSH
  server still checks who is connecting.
- Ports come from the range 10000 to 32767. Ringleader writes the firewall rule that admits
  them, open to any address unless the
  [CloudAccount](https://docs.ringleader.dev/reference/resources/cloudaccount/) lists `sshSourceRanges`. When
  Ringleader cannot write that rule, it uses ports from 30000 to 32767, which your cloud
  onboarding's own rule admits.
- On Azure, the workstation sees each such connection as coming from the edge instance's
  address, not from the caller's.
- The first time an edge instance routes a workstation that was reachable before, it waits
  until the workstation's port is in place. The workstation reports `SteeringHeld` meanwhile.
  On GCP it waits for each workstation for as long as it takes. On AWS and Azure it routes a
  whole subnet at once and waits at most 30 minutes. After that, a workstation still without a
  port reports `InboundUnreachable`.

To keep the management ports off the internet, set `inboundManagement: false`, or on GCP and
Azure `publicAddress: false`. The edge instance then forwards no ports, and on GCP and Azure it
takes no public address. The workstations it serves that have a public address of their own
report `EgressEnforced` `True` with reason `InboundUnreachable`. Reach them over your own
private network instead.

## Edges for local workstations

`provider` also accepts `hcs`, `vz` and `qemu`. An Edge for one of these runs on each
member's own computer instead of in a cloud. It takes no `region`, refuses every cloud field, and a
namespace holds one per provider.

A local Edge reports `Ready` `False` with reason `LocalVMPlacement`. Whether a workstation is
served shows on the workstation itself, on its `EgressEnforced` condition.
[Providers and where the key is added](https://docs.ringleader.dev/security/credentials/injected-credentials/#providers-and-where-the-key-is-added) says
what each local provider can inject.

## Final records before deletion

Before Ringleader deletes or replaces an edge instance, it stops routing workstations through it
and stops it from serving connections. It then waits up to five minutes for the instance to send
the records it still holds. It deletes the VM whether or not they all arrived. `status.drain` on the Edge shows
the wait: when it began (`since`), when it ends (`deadline`), and, once it is over, its `outcome`,
`shipped` or `timed-out`. An edge instance whose agent has gone silent is deleted without the
wait.

On your own computer, Ringleader does the same before it deletes an edge VM for hcs, vz or qemu
workstations. It does the same before it stops a workstation's own network process.

## Labels and namespaces

One Edge serves several teams in a namespace, because it applies each workstation's own policy to
each of its connections. To see it serve two teams step by step, follow
[Set up one Edge for two teams](https://docs.ringleader.dev/guides/set-up-edge/).

A workstation's owner writes its labels. Within one namespace, a label chooses which workstations
get an allowlist or a token, and it does not keep a member out:

- A member can add `team: platform` to their own workstation, and the Edge then adds the token to
  its requests.
- A member can remove `team: data` from their own workstation, and the data team's allowlist no
  longer applies to it. A Policy refuses any destination outside its list. It does not make a
  workstation declare an egress policy, and a workstation with none is not limited to an
  allowlist.

To keep a token or a host away from some people, give the people who need it a namespace of their
own. A layer never reaches a workstation in another namespace, as
[Workstations a layer reaches](https://docs.ringleader.dev/workstations/configuration/configuration-layers/#workstations-a-layer-reaches)
says, and an Integration is a layer. The namespace needs an Edge of its own. On AWS and Azure,
read [Subnet routing](#subnet-routing) first, because an edge instance routes a whole subnet.

## Workstations that depend on an Edge

Deleting an Edge changes what the workstations it serves can reach, so Ringleader refuses the
delete while a workstation in the namespace depends on it. Each of these workstations depends on
it:

- One the Edge serves whose policy names a `host` or is `audit`.
- One the Edge serves only to add a credential.
- One with a `strict` policy naming a `host`, or with an `audit` policy, when no other Edge for its
  provider would serve it.

An hcs, vz or qemu workstation depends on the Edge only when its own network process cannot serve
it. Otherwise it moves to that process once the Edge is gone.

A workstation cannot be served that way when it was created before its provider gave each
workstation its own address. On qemu, neither can one created before Ringleader could set up the
network cards its own Edge needs. A workstation on a computer whose `rl` is too old to say whether
it can be served that way is counted too. The refusal names these causes. Recreate a workstation
created that early, or update `rl` on a computer that is too old, and the delete goes through
without `rl edge force-delete`. On qemu, a computer that runs neither Linux nor macOS cannot serve a
workstation this way at all, so the delete needs `rl edge force-delete`.

The refusal lists those workstations, grouped by what each would lose:

- A cloud workstation with a `bestEffort` policy keeps the rule set it was given while it was
  routed, which permits the whole public internet. Its policy still reads the same.
- A `bestEffort` workstation on hcs, vz or qemu whose own network process cannot serve it runs on
  the open network.
- A workstation with a `strict` or `audit` policy is held closed until another edge instance serves
  it.
- A workstation that only had an injected credential stops getting the credential. It was never
  restricted.

## Declare an Edge

On Google Cloud, the provider and the region are all an Edge needs:

```yaml
apiVersion: core.ringleader.dev/v1
kind: Edge
metadata:
  name: gcp-us-east4
  namespace: platform
spec:
  provider: gcp
  region: us-east4
```

On AWS and Azure, also name the subnet your onboarding reserved for the edge instance.
Without it, no VM is built. The onboarding publishes it as `gateway_subnet_id` (Terraform),
`GatewaySubnetId` (CloudFormation) or `gatewaySubnetId` (Azure's ARM template):

```yaml
apiVersion: core.ringleader.dev/v1
kind: Edge
metadata:
  name: aws-us-east-1
  namespace: platform
spec:
  provider: aws
  region: us-east-1
  subnet: subnet-0abc1234def567890
```

On AWS and Azure, the workstations the Edge serves also go in a subnet of their own. The
onboarding publishes it as `governed_subnet_id` (Terraform), `GovernedSubnetId` (CloudFormation)
or `governedSubnetId` (ARM). A namespace admin sets it on the
[CloudIdentity](https://docs.ringleader.dev/reference/resources/cloudidentity/) that selects those workstations, in its
`spec.subnet`. Another way is `subnetId` under `aws` or `azure` in its `defaultProviderConfig` or
`overrideProviderConfig`. A workstation's own author cannot name a subnet. An author with the
`cloudconfig` right can name one, and so can an author whose CloudIdentity allows the key.
[Keys you set and keys an administrator sets](https://docs.ringleader.dev/workstations/providers/cloud/#keys-you-set-and-keys-an-administrator-sets)
says how. The edge instance cannot route a subnet that already has a route table of its own, and the
onboarding's general workstations subnet has one.

Apply the Edge with `rl apply -f edge.yaml`. The VM is built when the first workstation in the
Edge's region that needs it reports in. Until then `rl edge get` shows `Ready` `False` with reason
`NoMachine`, and the message says it is waiting for a workstation. Once the VM is serving, `Ready`
reads `True` with reason `Serving`. If that is all you need, you are done.

## Delete an Edge

To delete an Edge, an administrator runs `rl delete edge`. If a workstation depends on the Edge,
the delete is refused, and the steps below clear it.

1. Delete the Edge:

   ```bash
   rl delete edge <name>
   ```

   Ringleader deletes the Edge's VM, as [Final records before deletion](#final-records-before-deletion)
   describes. If the command is refused, it lists the workstations that depend on the Edge. Go on
   to the next step.
2. Change those workstations so they no longer need the Edge, then run the command again. On a
   cloud, replace their `host` destinations with `cidr` ones, which your cloud's firewall holds
   without an Edge. Or replace an `audit` policy with one that names only `cidr` destinations, or
   remove their policies. Detach the Integrations that inject credentials into them. Or declare
   another Edge for the same provider, which serves them in its place. Adding a `cidr` beside a
   `host` does not help, because the `host` still needs an edge instance.
3. Optional: to delete the Edge anyway, run `rl edge force-delete`, typing the Edge's name again
   after `--acknowledge-unrestricted-workstations`:

   ```bash
   rl edge force-delete <name> --acknowledge-unrestricted-workstations <name>
   ```

   This overrides the refusal and nothing else. The VM is deleted the way a plain delete deletes
   it, and the command prints what each group of workstations lost.

## Remove an Edge that stays in Terminating

Deleting an Edge deletes its VM first, after up to five minutes for the VM to
[send its last records](#final-records-before-deletion). The Edge is not removed until the VM is
confirmed gone. While it waits, its provider and region stay taken, so you cannot declare a
replacement.

If the VM cannot be deleted, and you will delete it yourself in your cloud console, an administrator
can remove the Edge without it:

```bash
rl edge release-finalizer <name> --acknowledge-orphaned-machine <machine-name>
```

`<machine-name>` is the VM's name, from `status.machine`. The VM is left running and billing, and
Ringleader no longer tracks it.

## Next steps

- [Set up one Edge for two teams](https://docs.ringleader.dev/guides/set-up-edge/) walks through one Edge that
  serves two teams.
- [Edge](https://docs.ringleader.dev/reference/resources/edge/) lists the spec, the status and the conditions of an Edge.
- [Enforcement points](https://docs.ringleader.dev/security/outbound/enforcement/) says what happens
  while no edge instance serves a workstation.
- [Filtering behavior](https://docs.ringleader.dev/security/outbound/filtering/) says what a workstation
  reaches behind an edge instance.
- [Outbound restrictions](https://docs.ringleader.dev/security/outbound/outbound-restrictions/) shows the
  egress policy an Edge enforces.

