Fortinet FortiGate connector

The Fortinet FortiGate connector calls the FortiOS REST API (/api/v2) of a FortiGate unit you host yourself. It blocks addresses and domains through a blocklist address group, blocks URLs through a web filter URL filter table, and quarantines addresses. It also reads firewall addresses, address groups, policies, and quarantine entries, so you can confirm a change. It authenticates with the token of a REST API administrator.

You can use this connector in Agent Builder and Workflows.

Warning

This connector changes the configuration of a firewall that filters traffic for everyone behind it. It can do anything the REST API administrator profile allows, in the virtual domains that profile can reach. Use a dedicated REST API administrator with the smallest profile that covers the actions you need, and restrict it with trusted hosts.

FortiGate is an on-premises product, so the management interface of the unit must be reachable over the network from Kibana.

The connector doesn't create the address group, the deny policy, or the URL filter table that blocking relies on. Before you block anything:

  • Create the blocklist address group and the deny policy that uses it, and put the policy above the permit policy it overrides. blockIp, blockDomain, unblockIp, unblockDomain, and updateFirewallAddressGroup fail with the name of the group when it does not exist.
  • For URL blocking, create a URL filter table and bind it to a web filter profile. blockUrl fails and tells you to create one when the profile has no table bound to it.

You can create connectors in Stack Management → Connectors.

  1. In FortiOS, go to System → Administrators and create a REST API Admin.
  2. Assign an administrator profile that grants only the access your actions need. The connector test needs read access on Firewall address.
    • Firewall address: read for listFirewallAddresses and listAddressGroups, write for the address and address group actions.
    • Firewall policy: read for listFirewallPolicies, write for the policy actions.
    • Web filter: read for listUrlFilterEntries, write for blockUrl.
    • Monitor → User: read for listBannedIps, write for banIp and unbanIp.
    • System → VDOM: read for listVdoms.
  3. In the Trusted Hosts field, enter the address Kibana calls from. FortiOS refuses the token from any other address.
  4. Copy the API key FortiOS shows once, at creation time.

Fortinet FortiGate connectors have the following configuration properties:

FortiGate URL
The address of your FortiGate management interface, for example https://fortigate.example.com or https://fortigate.example.com:8443. The address must use https. Leave out the API path, because the connector adds it.
REST API token
The API key of the REST API administrator. Paste the key only, without a Bearer prefix.

If you use the xpack.actions.allowedHosts setting, add the FortiGate host to it. The connector verifies the server certificate, so a unit that presents its factory (self-signed) certificate also needs an entry for that host under xpack.actions.customHostSettings in kibana.yml.

The unit must be reachable from the internet and present a publicly trusted certificate.

You can test connectors when you create or edit the connector in Kibana. The test reads one firewall address to check the URL, the token, and the Firewall address read permission.

If the test fails because of the token, fix the token before you test again. FortiOS locks out the Kibana address after three failed token logins within 60 seconds, and each new lockout lasts twice as long.

The connector has the following actions.

Agents in Agent Builder can't use the policy actions (createFirewallPolicy, updateFirewallPolicy, moveFirewallPolicy, and deleteFirewallPolicy) or the actions that remove enforcement (unblockIp, unblockDomain, unbanIp, updateFirewallAddressGroup, and deleteFirewallAddress). A policy change affects all traffic through the firewall, and removing a block or a ban needs a person's decision. You can run these actions as workflow steps or with the Run a connector API.

This limit applies to agents only. A Kibana user with the Actions and Connectors: Read privilege can run any action of the connector, including the ones that change the firewall. To keep these actions from running, give the REST API administrator a profile with read access only: FortiOS then refuses every change, whatever Kibana sends.

testConnectivity
Check that the unit is reachable and the token works. Returns the FortiOS version, build, serial number, and virtual domain.
listVdoms
List the virtual domains of the unit, so a caller can pick a valid vdom value.
listFirewallAddresses
List firewall address objects, or read one by name.
listAddressGroups
List address groups with their members, or read one group by name. Use it to confirm a membership change.
listFirewallPolicies
List firewall policies in evaluation order, or read one by ID.
listBannedIps
List the quarantine ban entries of a virtual domain, exactly as the unit reports them. Returns at most count entries from start, with the total as matchedCount. For paging, see Usage notes.
listUrlFilterEntries
List web filter URL filter tables with their entries, or read one table with urlFilterId, the same input name blockUrl uses.
blockIp
Block an IPv4 address: create the address object kbn-block-<ip> when it is missing, add it to the blocklist group you name, and read the group back. If the address is already a member, the action reports it as already blocked and writes nothing. For an immediate, memory-only quarantine with no group or policy, use banIp.
blockDomain
Block a domain in the same way, with a domain (fqdn) address object named kbn-block-<domain>.
unblockIp
Remove the address from the blocklist group, read the group back, and delete the address object when its name starts with kbn-block- and nothing else references it. If the address is not a member, the action reports that there is nothing to remove. If the member's address object no longer holds that address, the action fails and changes nothing. Check which group member enforces the block you meant, and leave the mismatched member in place unless what it now blocks should also be unblocked. To clear a quarantine ban made with banIp, use unbanIp.
unblockDomain
Reverse a domain block in the same way: remove the domain address object kbn-block-<domain> from the blocklist group, read the group back, and delete the address object when its name starts with kbn-block- and nothing else references it. If the domain is not a member, the action reports that there is nothing to remove. If the member's address object no longer holds that domain, the action fails and changes nothing. Check which group member enforces the block you meant, and leave the mismatched member in place unless what it now blocks should also be unblocked.
updateFirewallAddressGroup
Add or remove members of an address group one at a time. Returns which names were added, which were already present, which were removed, and which are listed under notFound because they were not members. If the call only removes names and none of them is a member, the action fails and names them.
createFirewallAddress
Create a firewall address object of type ipmask, iprange, fqdn, or geography. If the name already exists, the action reports it as a duplicate and overwrites nothing. Returns the object name with created set to true, or alreadyExists set to true when an object with that name was already there.
deleteFirewallAddress
Delete a firewall address object. If another group or policy still references the object, the action keeps it and returns the reason. If a group still references it, remove it from the group first with updateFirewallAddressGroup.
blockUrl
Add a block entry for a URL to a URL filter table, given urlFilterId or a web filter profile whose bound table is used. Returns the table ID (urlFilterId), the entry ID, alreadyBlocked, and verified.
banIp
Quarantine one or more addresses immediately, with an optional expiry in seconds (0 or no value means until it is cleared). Returns the addresses banned, the expiry, and a note that the ban lasts only until the unit restarts.
unbanIp
Clear the quarantine ban of the addresses you name. The action never clears the whole ban list at once. To reverse a blockIp address-group block, use unblockIp.
createFirewallPolicy
Create a firewall policy. The action defaults to deny, and the connector places the policy at the end of the evaluation order.
updateFirewallPolicy
Update a policy by ID. The action updates only the fields you send, and a list field you send replaces the whole list.
moveFirewallPolicy
Move a policy before or after another policy. Returns the evaluation order before and after the move.
deleteFirewallPolicy
Delete a policy by ID.
  • Virtual domains are case-sensitive. root works, and FortiOS rejects ROOT the same way it rejects an unknown domain (HTTP 424). Use listVdoms for valid values.
  • One page per call. List actions take start and count (at most 1,000) and return one page. A list call that gives no count asks the unit for 100 entries, so one result stays small enough to hand to an Agent Builder agent. Send count to ask for more or fewer entries.
  • Paging. To get the next page, send the nextStart value from the result as start. Don't page with the unit's nextIdx, which the connector returns unchanged. It's the position of the last entry in the unit's table, not a cursor. limitReached is true when a page was cut short. It's false for a read of one object by ID or by name, and for a page shorter than the count you asked for.
  • Nothing is retried. Each action sends its requests once and reports the FortiGate error as it came. The connector never repeats a failed call, because repeated failed token logins lengthen the source-address lockout.
  • Quarantine bans are volatile. Ban entries live in the unit's memory and are lost on a reboot or upgrade unless banned-ip-persistency is enabled on the unit. An address-group block is configuration and survives a restart.
  • Repeating a block or a ban is safe. Blocking an address, domain, or URL that is already blocked, unblocking an address that is not a member, and banning an address that is already banned all change nothing and report what they found. This does not hold for createFirewallPolicy, which creates another policy every time it is called, or for moveFirewallPolicy, which moves the policy again.
  • A delete that found nothing returns null fields. When deleteFirewallAddress or deleteFirewallPolicy reports that the object did not exist, or that the unit kept it because something still references it, the status, vdom, version, and build fields are null. FortiGate's response to a failed delete does not include them, and the connector does not fill them in.
  • An existing URL entry counts as blocked only when it blocks. blockUrl treats an existing entry as already blocked only when its match type is the requested matchType, its action is block, and its status is enable. An entry for the same URL with another match type, or that allows, exempts, or monitors it, or that is disabled, is reported as a conflict naming its entry ID, and is never changed.