Skip to content

tunnet policy

Manage Tunnet access policy as code from the CLI: validate and test offline, then diff, apply, export, detect drift, and roll back against Managed Tunnet.

Direct mode

For Direct (P2P) coordinator firewall rules, use tunnet coordinator-policy. That is separate from Managed Policy as Code.

Authentication

Remote commands need a management API endpoint and credentials:

bash
export TUNNET_API_URL=https://management.example.com
export TUNNET_API_KEY=tt_...
ScopeCommands
policy:readdiff, export, drift, history, live simulate
policy:applyapply, rollback

Offline commands (validate, test, local simulate, fmt) need no credentials.

You can also authenticate with OAuth2 client credentials or OIDC federation from CI. See Policy as Code → Authentication.

Commands

CommandOfflineDescription
tunnet policy validate <path>YesSchema, references, and conflicts
tunnet policy test <path>YesRun embedded test blocks
tunnet policy simulate --file <path> --src … --dst …Yes*Traffic verdict and matching rules
tunnet policy fmt <path>YesFormat policy JSON
tunnet policy diff <path>NoSemantic diff vs live state
tunnet policy apply <path>NoApply document (--force overwrites drift)
tunnet policy export --remoteNoExport live policy (--format hcl|json|yaml|terraform)
tunnet policy drift <path>NoDetect dashboard vs document drift
tunnet policy historyNoList policy revisions
tunnet policy rollback --revision-id <id>NoRestore a prior revision

* Local simulation uses only the document on disk. Pointing at live state for simulation requires policy:read.

Examples

bash
# Before opening a PR
tunnet policy validate .tunnet
tunnet policy test .tunnet
tunnet policy simulate \
  --file .tunnet \
  --src usergroup:engineering \
  --dst tag:staging \
  --port 443

# Against production
tunnet policy diff .tunnet
tunnet policy apply .tunnet
tunnet policy apply .tunnet --force

# Export and recover
tunnet policy export --remote --format hcl --out .tunnet
tunnet policy export --remote --format terraform --out ./infra/tunnet
tunnet policy history
tunnet policy rollback --revision-id <revision-id>

Formats

Pass a file or a directory (multi-file .tunnet/ tree with include blocks). Supported formats: HCL, JSON, and YAML.

See also

Released under the AGPL-3.0 License.