Fortinet

Fortinet

Certified
Enterprise Edition

Run guarded upgrades, config backup, diff and apply on FortiGate firewalls through the FortiOS REST API, and manage inventory, objects, policy packages and installs on FortiManager through JSON-RPC.

How to use the Fortinet plugin

Automate FortiGate firewalls through the FortiOS REST API, and FortiManager through its JSON-RPC API: facts, sessions, config backup, diff and apply, guarded firmware upgrades on a FortiGate, and inventory, firewall objects, policy packages and installs on FortiManager. Supported: FortiOS 7.2, 7.4, 7.6 and 8.0, FortiManager 7.2.2 and later. The full API references are on the Fortinet Developer Network (login required).

All traffic goes outbound from the worker to the management interface over HTTPS, so the plugin runs on restricted worker groups.

Authentication

FortiGate (fortigate tasks)

  • host and apiToken are required. The token is the key of a REST API administrator (execute api-user generate-key). Store it as a secret and set it once for all tasks with plugin defaults on Kestra 1.3, or with Policies on Kestra 2.0.
  • The token is sent in the Authorization: Bearer header only, never in the URL. There is no username and password login.
  • Set a trusthost on the API administrator to the egress range of your worker group, otherwise FortiOS answers 403.
  • Config backup, restore and firmware upgrade need an API administrator with the super_admin profile. Facts, sessions, Monitor, Check and DiffConfig work with a read profile, ApplyConfig needs write access to the tables it changes.
  • port defaults to 443, vdom to root. Global tables (system/...) ignore the vdom.
  • When the worker can only reach FortiManager, set fortiManager (same properties as the FortiManager connection below) and device (the FortiGate name in FortiManager). The call is proxied with exec /sys/proxy/json. Reads only: ApplyConfig, RestoreConfig, Reload and the backup mode of GetConfig need a direct connection.

FortiManager (fortimanager tasks)

  • host is required, plus apiKey or username and password. adom defaults to root.
  • apiKey (FortiManager 7.2.2 and later) is sent in the Authorization: Bearer header only. With a password the plugin logs in once per task run and always logs out at the end. An account with multi-factor authentication cannot log in this way: use an apiKey.

TLS and timeouts (both)

  • caCertificate takes the PEM of the CA that signed the device certificate. insecureSkipVerify: true disables certificate and host name validation, for labs with self-signed certificates only. It is false by default.
  • Calls go through Kestra's internal HTTP client. Kestra's HTTP client cannot take a custom CA, so when caCertificate is set the plugin uses a dedicated Java HTTP client for that call: it only targets the configured host, never follows redirects, and does not go through the platform's outbound request guard. To keep the platform client, add your CA to the worker JVM trust store and leave caCertificate empty.
  • The two calls that reboot a FortiGate, system/firmware/upgrade (Reload) and system/config/restore (RestoreConfig), always use the dedicated Java HTTP client, even without caCertificate, because Kestra's HTTP client automatically re-sends a request once on a 503 or 429 and that cannot be turned off. On Kestra 2.0 they therefore skip the platform's outbound request guard. They still only target the configured host and never follow redirects. TLS rules are unchanged: caCertificate, then insecureSkipVerify, otherwise the JVM trust store.
  • connectTimeout (10 s) and requestTimeout (60 s) can be raised.

Tokens, API keys, passwords and session IDs are masked in logs and never part of an output.

Tasks

FortiGate

  • fortigate.Facts: host name, serial, model, version, boot time, VDOM and HA mode, licence entitlements and certificate expiry.
  • fortigate.Monitor: read-only call on any /api/v2/monitor/... path. Returns the FortiOS answer as is.
  • fortigate.ListSessions: paged firewall sessions with filters. fetchType defaults to STORE.
  • fortigate.GetConfig: full backup as text (scope GLOBAL or VDOM), or CMDB tables as JSON (paths). The backup uses GET up to FortiOS 7.4 and POST from 7.6.
  • fortigate.DiffConfig: intended entries per CMDB table (tables) against the running ones. Returns changed, toCreate, toUpdate, toDelete and a diff file. Table keys and defaults come from the FortiOS schema.
  • fortigate.ApplyConfig: applies only that delta (POST new, PUT changed). checkMode writes nothing, prune (off by default) deletes entries not listed, referencing tables first. It stops at the first rejected call and never reverts.
  • fortigate.RestoreConfig: restores a GetConfig backup. Returns rebootExpected and is guarded like Reload when a reboot is expected.

FortiOS applies each change immediately, there is no candidate configuration and no commit: take a GetConfig backup before ApplyConfig. On a FortiGate managed by FortiManager, change configuration with policy packages, otherwise FortiManager reports the device out of sync.

FortiGate firmware upgrade

FortiOS writes the new image to the alternate partition and reboots in the same API call, so activate and reload cannot be fully separated on the device:

Step Task Reboots Retry-safe
Pre-check fortigate.Check with phase: PRE. Checks VERSION, DISK, HA, RESOURCES, LICENSE, writes the snapshot. no yes
Activate fortigate.Activate: validates only, changes nothing. Checks the target is one supported hop (upgrade-paths), resolves the FortiGuard image ID or checks the SHA-256 of a Kestra file. no yes
Reload fortigate.Reload: downloads or uploads the image and reboots. Guarded, never sent twice. yes no, never add a retry
Wait fortigate.WaitForReturn: waits for a newer boot time, the HA checksums and a stabilization delay. no yes
Post-check fortigate.Check with phase: POST. Checks VERSION, HA, INTERFACES, LLDP, RESOURCES against the snapshot. no yes

Check returns version, modelName, bootupTimestamp, status (ok or ko), checksPassed, checksFailed and snapshot, like the Arista and Cisco check tasks. A failed check returns ko, it does not fail the task. The version comparison belongs to the flow.

There is no commit step: the previous image stays on the other partition. There is no rollback task: going back is the CLI command execute set-next-reboot followed by a reboot, and re-flashing an older image can drop configuration. Activate returns currentVersion so a manual rollback knows what to go back to.

A FortiGate HA cluster (FGCP) is upgraded through its primary. With the default uninterruptible upgrade mode the secondary units upgrade first, then a failover happens. The HA check fails on simultaneous mode, a missing member or out-of-sync checksums. Some releases do not support an uninterruptible upgrade: read the release notes. When the image is not available from FortiGuard, or the FortiCare entitlement expired, use source: FILE with the image in Kestra and its sha256.

FortiManager

  • fortimanager.ListAdoms, ListDevices, ListPackages: inventory. ListDevices flags devices that are out of sync (inSync). They support fetchType FETCH, FETCH_ONE and STORE.
  • fortimanager.GetTask, WaitForTask: read or wait for any task by ID.
  • fortimanager.objects.Upsert, Get, List, Delete: firewall objects chosen with objectType (ADDRESS, ADDRESS_GROUP, SERVICE, SERVICE_GROUP, VIP, SCHEDULE_ONETIME, SCHEDULE_RECURRING). The entry is the FortiManager JSON entry.
  • fortimanager.policies.Upsert, Get, List, Delete, Move: firewall policies of a policyPackage.
  • fortimanager.InstallPackage: installs a policy package on a scope of devices. With checkMode: true it runs Fortinet's preview sequence and returns the CLI per device without touching the devices. Returns one result per device, and fails when a device failed unless allowPartialInstall is set.

Upsert is idempotent: it creates the entry, or updates it only when the fields you give differ, and returns changed. Every write task takes checkMode and workspace: AUTO (default) locks the ADOM, commits and unlocks (always unlocking in a finally block) when the workspace mode is on, LOCK_ONLY locks without committing, NONE never locks. With waitForLock the task retries up to lockTimeout when another administrator holds the lock, otherwise it fails naming the lock owner. ADOMs in workflow mode (approval required) are refused: submitting workflow sessions is not supported. InstallPackage uses the install flag auto_lock_ws instead of locking by hand.

Errors

  • DeviceUnreachableException: connection refused, timeout, TLS reset or HTTP 503. Retryable while a device reboots.
  • AuthFailureException: HTTP 401, login refused, invalid session or key. Never retry.
  • PermissionDeniedException: HTTP 403. The profile of the API administrator does not allow the call, or the worker IP is outside its trusthost. Never retry.
  • FortiManager JSON-RPC errors carry the status.code, the message and the URL.

Do not set a task level retry on Reload or RestoreConfig: it does not filter by error type. WaitForReturn retries connection errors itself.