Configuration as code (YAML, Git, CI)
Under System › Configuration as code (or via opnexus export / opnexus apply)
all centrally maintained objects can be exported as a single YAML file and
imported again: device groups, hierarchy groups, aliases, filter rules,
port forwards, 1:1 NAT, outbound NAT, hierarchy rules and the values of the
site variables. For Git management, reviews, CI checks and
restoring onto a new instance.
What is not included: hosts themselves (address, API key, pinning), users, tokens, SSO, settings, notifications, maintenance windows and rollouts, network objects, VPN and certificates. The file contains no credentials, keys or passwords; hosts appear only with their name.
The import changes only the drafts in OPNexus. Nothing reaches firewalls without preview → deploy → confirm. The import code calls no firewall command (a test enforces this) and never deletes an object that has ever been deployed.
Flow:
- Plan: OPNexus compares the file with the current state and shows per object new, changed (with fields before/after), removed or unchanged, plus notes. The plan writes nothing and may also be retrieved by read-only accounts and with a "Read" token (for example for a check in a pull request).
- Apply: only administrators (session or admin token). Applying writes everything in one transaction or nothing. It requires the token of exactly this plan: if something changed since the plan (even just a group member or a new object in the interface), OPNexus answers "outdated" and you plan again. Finally OPNexus verifies that the database corresponds exactly to the plan; otherwise everything is reverted.
- Afterwards the changes appear as drafts and are deployed per object as usual. Changed objects that are already deployed are named by the plan ("deployed to N firewalls").
Partial files: if a section is missing in the file, that kind remains untouched. If a
section is present, even an empty one, and prune is on, that kind is fully
reconciled: what is missing in the file is removed from OPNexus. Without prune, objects are only
created and changed. Prune is powerful and therefore an explicit switch
(--prune, in the interface with confirmation).
Blocked (the plan cannot be applied, nothing is changed):
- An object with an open deployment (waiting for confirmation or rollback) is to be changed or removed.
- Prune of an object that has already been deployed (also rolled back or failed). Remove it in the interface first, where there is a preview and a way back.
- Prune of a group, an alias name or a hierarchy group that is still in use after the import (by rules, VPN, rollout waves, hosts, child groups).
- Errors in the file itself (unknown host, group or hierarchy group, duplicate
key, cycle in the hierarchy tree, a host in two hierarchy groups, placeholders
{{…}}in hierarchy rules) reject the plan already, with line and path.
Keys: aliases, groups and hierarchy groups are recognised by their name,
rules, NAT objects and hierarchy rules by a key
(lowercase letters, digits, . _ -, at most 64 characters, unique per kind). Existing
objects automatically received one on update (r-…, pf-…, nat1-…, out-…, ph-…);
in the file you may assign your own (allow-dns-lan), and the import stores them. A
rename counts as removing and recreating; a deployed object then blocks
with prune. The order of hierarchy rules is the order in the file.
Notes in the plan: a value that looks like an alias but is not a central alias in OPNexus (aliases created by hand on the firewall are fine; OPNexus queries no firewall when planning); a variable that is removed
although an object uses it (deployment to this host then fails safely);
a disabled target host; new objects with targets without a link to objects already present on the
firewalls. The latter is important for an import into a new
instance with the same firewalls: deploying creates duplicates there. Better restore a
full backup (opnexus backup --full) or assign the objects beforehand via
"Link with existing central object".
Format: one file opnexus-config.yaml, opnexus_config: 1, fixed order of the
sections, objects sorted by key, all fields always, no timestamp: Git
shows only real changes. The JSON schema is in
backend/app/config_code/opnexus-config-v1.schema.json (for editor validation). Descriptions
may be multi-line, names and keys may not; ports may be a number or text.
The file may be at most 1 MiB (5000 objects per kind, 200 variables per host).
Strict validation: the file is read only as data. Anchors and aliases (&, *),
merge keys (<<), explicit tags (!!python/…, !!binary), directives, multiple
documents, duplicate keys, control characters and invalid UTF-8 are rejected.
on, yes, dates and 1:30 remain text (no "YAML 1.1" behaviour). Errors
name line and path (rules[3].destination_port).
On the server (CLI):
opnexus export [--out DIRECTORY] [--kinds rules,aliases]
opnexus apply FILE [--dry-run] [--prune] [--yes] [--json]apply shows the plan first and asks [y/N] (without a terminal only with --yes). With
--dry-run nothing is applied. Exit codes for CI: 0 applied or no
differences, 2 differences (--dry-run only), 3 file invalid, 4
blocked or outdated, 1 other error. Whoever operates the server console needs
no token; the audit log shows cli (host console).
Git recipe (cron or systemd timer on the OPNexus server):
opnexus export --out /srv/opnexus-config \
&& git -C /srv/opnexus-config add -A \
&& git -C /srv/opnexus-config commit -m "OPNexus state $(date -u +%F)" \
&& git -C /srv/opnexus-config pushOPNexus itself never connects to a Git server and needs no credentials for it.
CI without access to the server: via API with a token. The plan is enough for checks in pull requests (token "Read"), applying needs "Admin":
curl -s -H "Authorization: Bearer opx_…" -H "Content-Type: application/json" \
-d "$(jq -n --rawfile y opnexus-config.yaml '{yaml:$y, prune:false}')" \
https://opnexus.example/api/config/import/planThe response contains summary, items, warnings, applicable and token; this
token belongs to POST /api/config/import/apply ({"yaml", "prune", "plan_token"}). Export:
GET /api/config/export (?kinds=rules,aliases). In the audit log every apply leaves a
summary entry (SHA-256 of the file, counters, prune) and one entry per changed object; the content
of the file is not in it.