Skip to content

network: support fortinet vpn with saml and password auth - #3384

Merged
bbedward merged 1 commit into
duxlabs-dev:masterfrom
avesst:feat/fortinet-saml-vpn
Sep 10, 2026
Merged

bbedward merged 1 commit into
duxlabs-dev:masterfrom
avesst:feat/fortinet-saml-vpn

Conversation

@avesst

@avesst avesst commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds Fortinet VPN support to the NetworkManager openconnect path, covering both SAML/SSO and password authentication, and lets openfortivpn config files be imported as profiles.

FortiGate gateways configured for SAML can't be used with a username and password — authentication happens in a browser against an external IdP. DMS previously detected that a Fortinet profile needed external browser auth, logged that only GlobalProtect was supported, and fell back to prompting for credentials that don't exist.

Connecting. A Fortinet profile with authtype=saml now runs the login in core:

  1. Probe the gateway certificate and, if it isn't trusted, ask the user once.
  2. Listen on loopback (8020 by default, saml-port overrides) and open /remote/saml/start in the browser.
  3. Wait for the gateway to redirect back with a session id.
  4. Exchange the id for an SVPNCOOKIE over a connection pinned to the probed certificate.

The cookie is handed to the openconnect plugin through the existing secret agent, the same way GlobalProtect already works, so this needs no root and leaves no long-lived process behind. The listener is torn down as soon as the login completes.

A Fortinet profile with authtype=password goes to the openconnect password flow that already existed, unchanged.

Importing. ImportVPN reads openfortivpn configs and builds an openconnect profile from host, port, username, password, realm, trusted-cert and saml-login. A saml-login line selects the browser login; anything else is imported as a password profile carrying whatever credentials the file had, and the connect prompt asks for whichever of username and password is missing. A password alongside saml-login is dropped, since that path never reads one.

openfortivpn configs are conventionally extensionless, so detection reads the contents rather than the extension, and anything that doesn't parse falls through to the existing nmcli importers untouched. For the same reason the two VPN import file browsers now offer * alongside the per-plugin extensions.

Certificates. Trust is stored as the whole-certificate digest that openfortivpn's trusted-cert uses, so an existing config's trust line is honoured on the first connect and a newly approved certificate stays compatible with openfortivpn. Approving a certificate appends to that list rather than replacing it, which keeps gateways that answer from several nodes working. openconnect separately gets the public-key pin it expects for --servercert.

Known limitation. Certificate trust is only persisted when the connection was started from DMS. The approval is queued into the same pending-save slot the existing credential flow uses, and that slot is drained by a handler which returns early unless DMS initiated the activation. Started from nmcli, the applet, or autoconnect, the user approves a certificate and the trust is discarded, so the prompt returns on the next connect. This gap predates the PR and affects saved VPN credentials the same way, so I've left the shared behavior alone rather than changing it from a Fortinet feature. Happy to fix it here or in a follow-up, whichever you prefer.

Notes for reviewers. This path requires the NetworkManager openconnect plugin, which the import checks for up front and reports if missing. The tunnel is openconnect's Fortinet implementation, not openfortivpn — the config file is only a settings source and nothing about openfortivpn runs.

The loopback listener accepts the session id from any request on its port, matching what openfortivpn's own --saml-login server does. A local page racing it during a login costs a retry: the bogus id goes to the real gateway over the pinned connection, is rejected, and the IdP session is still live. Happy to tighten it if you'd rather not carry that.

Implementation written with Claude Code; I directed the design, tested it end to end against a production FortiGate gateway, and reviewed the changes — but Go and VPN internals aren't my area, so I'd appreciate scrutiny of the certificate handling and the secret-agent path.

Type of change

  • New feature (non-breaking change that adds functionality)

Related issues

Closes #1614

Screenshots / video

Certificate trust prompt. Shown once per gateway certificate, before the browser opens. Fingerprint redacted.

image

Loopback completion page. Served by core once the gateway redirects the browser back with the session id. The IdP login in between is whatever the gateway's organisation has configured, so there is nothing DMS-specific to show there.

1789037055483719844

Checklist

  • My code follows the conventions in CONTRIBUTING.md
  • I have tested my changes locally
  • New user-facing strings are wrapped in I18n.tr() with translator context, reusing existing terms where possible
    • No new QML strings. The one new label is a secret-agent field name in Go, added to the existing table alongside GlobalProtect SAML/SSO and following the same pattern.
  • Go changes: ran make fmt, added/updated tests, make test passes, and go mod tidy is clean
  • QML changes: ran make lint-qml with no new warnings
  • I have opened a corresponding pull request in dlx-docs to document any new behaviors: docs(dms): document VPN profiles and Fortinet browser login dux-docs#146
    • Adds a VPN page covering the browser login, the openfortivpn import rules, the openconnect plugin requirement and certificate trust, and corrects the note that said native Fortinet authentication applied only to password profiles. It asks not to be merged until this lands.

Adds Fortinet gateway support to the NetworkManager openconnect path.
A SAML gateway authenticates through the browser, with the loopback
redirect handled in core and the session traded for the cookie
openconnect needs. Certificate trust is confirmed once and stored as
the digest openfortivpn uses.

openfortivpn config files can be imported as profiles. A saml-login
line selects the browser login, anything else imports as a password
profile carrying whatever credentials the file had.

Co-Authored-By: Claude Opus 5 <[email protected]>
@avesst
avesst force-pushed the feat/fortinet-saml-vpn branch from e011e68 to 146bbe5 Compare September 10, 2026 11:01
@bbedward

Copy link
Copy Markdown
Member

/claude review

@claude

claude Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Claude review

No issues found.

Checked: the SAML loopback listener lifecycle (graceful Shutdown so the browser gets the page, no goroutine/listener leak, ctx deadline is the only failure path), certificate handling (certificatePin = sha256(SPKI) base64 matching openconnect --servercert, certificateDigest = sha256(DER) hex matching openfortivpn trusted-cert, TOFU prompt only when the chain fails to verify and the digest is not already trusted, token exchange pinned to the probed leaf), splitGatewayHostPort edge cases against its table test (bare/bracketed/unbracketed IPv6, URLs, out-of-range and non-numeric ports), the secret-agent path (fortinet-saml branch mirrors the existing gp-saml one, only reachable via inferVPNFields when DMS initiated the activation, cached auth consumed once), pendingVPNSave/PersistentData merge in saveVPNCredentials, openfortivpn config sniffing in ImportVPN (wireguard/vpnc/nmconnection are rejected by the section-header guard, .ovpn by the missing host, so the nmcli fallback is intact), and the QML getFileFilter change ("*" is a valid FolderListModel nameFilter, no new user-facing strings, catalogs untouched). Non-standard vpn data keys (saml-port, trusted-cert) follow the existing certificate:<gateway> precedent in this codebase. The loopback listener accepting an id from any local request and the cert-trust persistence gap for non-DMS-initiated activations are both already called out in the PR description as deliberate trade-offs for the maintainer to rule on. Model: claude-opus-5.

@avesst

avesst commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

@bbedward Let me know if your content with the implementation, and I'll add a PR for the docs.

@bbedward

Copy link
Copy Markdown
Member

Looks good, go ahead and add the docs PR if you think its helpful

@avesst

avesst commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

@bbedward PR opened.

@bbedward
bbedward merged commit 5e87317 into duxlabs-dev:master Sep 10, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support openfortivpn

2 participants