Keeping the keys
Whoever can log in to a router or a switch controls your network: they can read what passes through it, open its firewall, or turn it off.
Three locks on the door
The management network is a VLAN that only the people who run the network use. In the single-site network it is mgmt, VLAN 10, 192.168.10.0/24, and it travels only on the trunk between the switch and the router. The three locks are all written in the device's file:
- Where from.
management.allowlists the addresses that may reach the device's services. A computer that is not on the list does not even get a login prompt. - How. Each way in is a service, and a service is on only when it is written:
ssh: {}turns SSH on. Telnet, plain web (http), FTP, and the rest stay off unless you write them. SSH is encrypted. Telnet, FTP, and plain web send your password across the network as readable text, so anyone on the path can read it. - Who.
system.userslists every login, each with a role.adminmay do everything,read-onlymay look but change nothing, andoperatorsits between the two. Exactly whatoperatormay do differs by platform. A user the file does not list is removed from the device.
connection: { host: "192.168.10.1", user: "operator" },
system: {
users: { operator: { role: "admin", password: secret("ROUTER_PASSWORD") } },
},
management: { allow: [home.addresses.management], ssh: {} },connection is how Circuit itself logs in: the address, and which of system.users it logs in as. Circuit logs in over SSH like anyone else, and the same locks apply to it.
To show what each lock does on its own, this router has no input firewall in front of its services.
| Who, from where | What happens | Should |
|---|---|---|
| You, on the admin laptop, as operator 192.168.10.20, SSH | Logged inrightLogged in as operator. | log in |
| The monitoring server, as monitor 192.168.10.30, SSH | Turned awaywrongThere is no user called monitor: a user not in the file is removed. | log in |
| The intern who left last month, from the server room, as intern 192.168.10.40, SSH | Logged inwrongLogged in as intern. | be turned away |
| A guest phone guessing passwords 192.168.30.57, SSH | Can try passwordswrong192.168.30.57 is allowed, so it reaches the login prompt. Only the password stands in the way. | be turned away |
| A stranger on the internet 192.0.2.66, SSH | Turned awayright192.0.2.66 is not in 192.168.0.0/16, so the router does not answer. | be turned away |
| An old script on the admin laptop, as operator 192.168.10.20, Telnet | Logged inwrongLogged in as operator. Telnet is not encrypted: the password crossed the network as plain text. | be turned away |
| A visitor who unplugs the guest access point and plugs in a laptop 192.168.30.110, SSH | Can try passwordswrong192.168.30.110 is allowed, so it reaches the login prompt. Only the password stands in the way. | be turned away |
2 of 7 attempts end the way they should. Change the settings above until all of them do.
connection: { host: "192.168.10.1", user: "operator" },
system: {
users: {
operator: { role: "admin", password: secret("ROUTER_PASSWORD") },
intern: { role: "admin", password: secret("INTERN_PASSWORD") },
},
},
management: { allow: ["192.168.0.0/16"], ssh: {}, telnet: {} },
Each lock stopped someone different. The allowed sources stopped the guest phone, the stranger, and the visitor, whatever password they tried. Turning telnet off stopped the old script. Only removing the intern's user stopped the intern, who was on the management network with a password that still worked.
On a real router, the input chain from the firewall lesson is a fourth lock on the same door. The single-site router's "Management" rule accepts only 192.168.10.0/24 too. Two locks that say the same thing are not wasted: if one of them is changed by mistake, the other still keeps people out.
Removing a user is a change like any other, so Circuit shows it in the plan. Here someone had added a user called intern to the router by hand, and the file does not list it:
router: 1 command(s) in 1 step(s)
/user
- add group=full name=internPasswords stay out of the files
The device files go into git, and git keeps every version forever, for everyone who can read the repository. So a password is never written in a file. You write secret("ROUTER_PASSWORD"), a name. Circuit reads the value only when a command needs it, such as diff or apply. It looks in two places, in this order:
- The environment, such as a variable set in your terminal or by an automated job.
.circuit/secrets, in the project's folder, where each value is encrypted. One password opens it, and that password is never in git.
circuit secrets set ROUTER_PASSWORDCircuit asks for the password without showing it, encrypts it, and writes it to .circuit/secrets. The first time, it asks you to choose the password that opens the file. Keep that one in your password manager. A value can also point to a password manager instead, such as op://Network/router/password for 1Password. See Secrets.
A password typed into the file as plain text is an error in your editor, before anything is run:
Type 'string' is not assignable to type 'Secret'.circuit secrets list shows every secret the files use, and how each is kept, without printing any of them. With ROUTER_PASSWORD set and SWITCH_PASSWORD forgotten:
┌─────────────────┬───────────┐
│ Name │ Stored as │
├─────────────────┼───────────┤
│ ROUTER_PASSWORD │ encrypted │
│ SWITCH_PASSWORD │ missing │
└─────────────────┴───────────┘A device never shows its passwords back, so Circuit cannot see that one changed. To change a password, set it again with circuit secrets set ROUTER_PASSWORD, then run circuit apply router --secrets. The plan sends the password again, and shows only its name:
router: 1 command(s) in 1 step(s)
/user
~ {"name":"operator"} password=<secret:ROUTER_PASSWORD>Keep management off the wall sockets
The management VLAN should only travel on trunks between devices. If an access port is in it, whoever plugs into that socket is on the management network, and the first lock lets them through.
Circuit cannot know which of your VLANs is the management one. So the single-site example says it in a check of its own, in lib/checks.ts, and turns it on in circuit.ts:
// This network's own checks, beside Circuit's built-in ones. circuit.ts turns them on in `checks`.
import type { Check } from "circuit";
/** Someone who plugs into a wall socket must not land on the management network: only a trunk between devices carries it. */
export const managementStaysOnTrunks: Check = (network) =>
network.devices.flatMap((device) =>
Object.entries(device.interfaces?.ethernet ?? {})
.filter(([, port]) => port?.access_vlan === "mgmt")
.map(([name]) => ({
device: device.name,
path: `interfaces.ethernet.${name}`,
message: "gives management to whatever plugs in. Put the port in another VLAN.",
}))
);// circuit.ts
checks: {
same_vlan_ids: true,
management_stays_on_trunks: managementStaysOnTrunks,
},Put the guest access point's port on mgmt, and circuit validate gives the file and line of the port:
sites/home/switch.ts:32: management_stays_on_trunks: switch: interfaces.ethernet.10g-4: gives management to whatever plugs in. Put the port in another VLAN.
1 error(s).An error stops diff and apply, so the mistake never reaches the switch. More on checks in Checks and errors.
Locking yourself out
The most dangerous change is one that cuts off the way in. You might turn SSH off, narrow management.allow so it leaves out your own computer, or remove the user Circuit logs in as. validate catches the last one, because it can see the file. Rename the router's operator user to admin, and it says:
router: connection.user: no user operator
1 error(s).It cannot catch the first two, because it does not know where your computer is or how you meant to log in. Turning SSH off in the single-site router validates with no errors, and its whole plan is one line:
router: 1 command(s) in 1 step(s)
/ip service
~ set ssh disabled=yes address=So Circuit protects you when it applies. After every change, it logs in again in a new session, and keeps the change only if that login works.
Step through how Circuit applies a change to a RouterOS router. Then pick the change that turns SSH off, and step through it again.
Step 1 of 6
Read the router and plan
Circuit logs in over SSH as the user in connection, reads what the router runs right now, and makes the plan against it.
What happens when the new login fails depends on the platform. Make a change says what each platform does.