A routine maintenance release on a lab KVM FortiGate — pre-checks, three install paths, rollback, and a companion REST helper script.
Lab case study — routine maintenance release. KVM FortiGate VM. Not a production procedure.
Disclaimer: Performed on a lab VM with no FortiGuard subscription. Validate in your own environment before any production use. Provided as-is, no warranty.
Sanitized record. No real IPs, hostnames, serial numbers, or credential values appear in this post — placeholders stand in where a value is needed.
A lab FortiGate VM running FortiOS 7.4.12 (build 2902) was upgraded in place to the current 7.4 maintenance build, 7.4.13 (build 2933), as routine maintenance. Configuration, interfaces, policies and license carried over unchanged. Downtime ≈ 8 minutes (warm reboot). The VM has no FortiGuard subscription, so its AV/IPS databases are frozen and provide no real protection — this is a firmware refresh, not an endpoint-security fix.
FortiOS 7.4.13 (build 2933) is the current maintenance release for the 7.4 branch, published 22 Oct 2026. Moving the lab VM to the current maintenance build keeps it current and is the normal patching step.
Advisory note: As of this writing (26 Oct 2026), the official 7.4.13 release notes list one CVE — CVE-2025-54821 (FG-IR-25-545), Low severity (CVSSv3 1.7), not exploited in the wild. Fortinet's broader FortiOS 7.4 advisories for the October 2026 release are embargoed on FortiGuard PSIRT until 10 Nov 2026 and will be added to the table below when published.
| CVE | Severity | Exploited in the wild? | Notes |
|---|---|---|---|
| CVE-2025-54821 (FG-IR-25-545) | Low (CVSSv3 1.7) | No | Authenticated, CLI component. PSIRT: "Migrate to a fixed release"; 7.4.13 release notes: no longer vulnerable. |
| (Oct 2026 hardening advisories) | unverified | unverified | Embargoed until 10 Nov 2026 — to be added after publication. |
Before upgrading, read the 7.4.13 release notes (known issues, upgrade path) and confirm 7.4.12 → 7.4.13 is a supported in-branch path.
.out for in-place upgrades; .kvm.zip is for fresh deployments only.Option A: GUI. System > Firmware, upload the .out, confirm. Simplest, recommended.
Option B: CLI. execute restore image tftp <filename> <tftp_ipv4> is the documented form. Other transports (FTP/SCP) — check execute restore image ? in the CLI help for your build.
Option C: REST API (what was used here). Multipart POST to /api/v2/monitor/system/firmware/upgrade with file (the .out) and source=upload; Bearer token (generated from the API key). The device writes the inactive partition and reboots itself.
If using the API:
trusthost limited to the admin workstation.curl -k) outside a lab.| Item | Before | After |
|---|---|---|
| Version | 7.4.12 build 2902 | 7.4.13 build 2933 |
| Interfaces | up | up, unchanged |
| Policies | present | present, unchanged |
| Mode / HA | NAT, standalone | unchanged |
| License / serial | valid | unchanged, no re-import |
| Downtime | — | ~8 minutes (warm reboot) |
The system automatically saved a config revision as part of the upgrade, alongside the manual pre-upgrade backup.
.out image, then restore the off-box config backup.execute restore image). The REST route was a workaround, not a requirement.fgt-upgrade.sh — REST-method helper (precheck → snapshot → apikey → upgrade → wait → verify → cleanup). The script is a cleaned-up rewrite of the manual steps used in this lab; it has been syntax-checked but not yet run end to end. Full listing in the code block below.
#!/usr/bin/env bash
# fgt-upgrade.sh - in-place FortiOS upgrade helper (REST API method)
#
# STATUS: DRAFT FOR REVIEW. Test on a lab VM before any production use.
# Intended path: FortiGate-VM64-KVM, FortiOS 7.4.x. Not yet run end to end.
#
# Steps (each can run alone, or use "run" for all of them):
# precheck verify image checksum, SSH access, save baseline + off-box config
# snapshot optional libvirt disk snapshot (VM only)
# apikey create a temp, IP-restricted API user and store its key (0600)
# upgrade upload the .out image via REST (device reboots itself)
# wait poll until the target build is running
# verify post-upgrade checks, diffed against baseline
# cleanup delete temp API user and key (also runs automatically on error)
#
# Secrets: no passwords in this script. Use SSH key auth for the admin user.
# The API key is written to a 0600 file and is never printed.
set -euo pipefail
umask 077
# ---------- configuration (override via environment) ----------
: "${FGT_HOST:?set FGT_HOST (management IP or FQDN)}"
FGT_USER="${FGT_USER:-admin}"
FGT_SSH_KEY="${FGT_SSH_KEY:-$HOME/.ssh/id_ed25519}"
IMAGE="${IMAGE:-}" # path to FGT_VM64_KVM-*.out
EXPECTED_SHA256="${EXPECTED_SHA256:-}" # from Fortinet support portal
EXPECTED_BUILD="${EXPECTED_BUILD:-}" # e.g. 2933
TRUSTHOST="${TRUSTHOST:-}" # admin workstation IP, e.g. 192.0.2.10
VIRSH_DOMAIN="${VIRSH_DOMAIN:-}" # libvirt domain name (optional)
FGT_CACERT="${FGT_CACERT:-}" # CA/cert PEM to verify the GUI cert
FGT_INSECURE="${FGT_INSECURE:-0}" # 1 = skip TLS verify (LAB ONLY)
WAIT_TIMEOUT="${WAIT_TIMEOUT:-1200}" # seconds to wait for reboot
API_USER="temp-api-upgrade"
WORKDIR="${WORKDIR:-./fgt-upgrade-$(date +%Y%m%d-%H%M%S)}"
KEY_FILE="$WORKDIR/.api_key"
HDR_FILE="$WORKDIR/.api_hdr"
mkdir -p "$WORKDIR"
SSH_OPTS=(-i "$FGT_SSH_KEY" -o BatchMode=yes -o StrictHostKeyChecking=accept-new
-o ConnectTimeout=8)
log() { printf '[%s] %s\n' "$(date +%T)" "$*"; }
die() { log "ERROR: $*" >&2; exit 1; }
fgt() { ssh "${SSH_OPTS[@]}" "$FGT_USER@$FGT_HOST" "$@"; }
curl_tls() {
if [[ -n "$FGT_CACERT" ]]; then
curl --cacert "$FGT_CACERT" "$@"
elif [[ "$FGT_INSECURE" == "1" ]]; then
log "WARNING: TLS verification disabled (FGT_INSECURE=1). Lab use only."
curl -k "$@"
else
curl "$@"
fi
}
need() { command -v "$1" >/dev/null || die "missing required tool: $1"; }
# ---------- steps ----------
precheck() {
need ssh; need curl; need sha256sum
[[ -f "$IMAGE" ]] || die "IMAGE not found: '$IMAGE'"
[[ -n "$EXPECTED_SHA256" ]] || die "set EXPECTED_SHA256 from the Fortinet portal"
[[ -n "$EXPECTED_BUILD" ]] || die "set EXPECTED_BUILD (target build number)"
local actual
actual="$(sha256sum "$IMAGE" | awk '{print $1}')"
[[ "${actual,,}" == "${EXPECTED_SHA256,,}" ]] \
|| die "SHA256 mismatch. expected=$EXPECTED_SHA256 actual=$actual"
log "image checksum OK"
log "SSH check + baseline"
fgt 'get system status' > "$WORKDIR/baseline_status.txt"
fgt 'get system interface' > "$WORKDIR/baseline_interfaces.txt"
fgt 'get firewall policy' > "$WORKDIR/baseline_policy.txt"
# Disable paging so the full config is returned in one go.
fgt 'config system console
set output standard
end
show full-configuration' > "$WORKDIR/config_backup_offbox.conf"
[[ -s "$WORKDIR/config_backup_offbox.conf" ]] || die "config backup is empty"
log "off-box config saved: $WORKDIR/config_backup_offbox.conf"
log "REVIEW: baseline_status.txt for current version and upgrade path."
}
snapshot() {
[[ -n "$VIRSH_DOMAIN" ]] || { log "VIRSH_DOMAIN not set, skipping snapshot"; return; }
need virsh
local name="pre-upgrade-$(date +%Y%m%d-%H%M)"
virsh snapshot-create-as "$VIRSH_DOMAIN" "$name" --disk-only --atomic
log "snapshot '$name' created."
log "NOTE: libvirt may not revert external snapshots. After the change is"
log " accepted, merge it: virsh blockcommit $VIRSH_DOMAIN <disk> --active --pivot"
}
apikey() {
[[ -n "$TRUSTHOST" ]] || die "set TRUSTHOST (admin workstation IP) to restrict the API key"
log "creating temp API user (trusthost $TRUSTHOST)"
# api-user trusthost uses the nested form (FortiOS 7.4.1+). The flat "trusthost1" is for admin users.
# The optional "config vdom" sub-block is a parse error on FGT-VM 7.4 and is omitted.
local out
out="$(fgt "config system api-user
edit \"$API_USER\"
set accprofile \"super_admin\"
config trusthost
edit 1
set ipv4-trusthost $TRUSTHOST 255.255.255.255
next
end
next
end
execute api-user generate-key $API_USER")"
local key
key="$(printf '%s\n' "$out" | sed -n 's/.*New API key:[[:space:]]*\([^[:space:]]*\).*/\1/p' | head -1)"
[[ -n "$key" ]] || die "could not capture API key"
printf '%s' "$key" > "$KEY_FILE"
printf 'Authorization: Bearer %s\n' "$key" > "$HDR_FILE" # keeps key off the process list
unset out key
local code
code="$(curl_tls -s -o /dev/null -w '%{http_code}' -H "@$HDR_FILE" \
"https://$FGT_HOST/api/v2/monitor/system/status")"
[[ "$code" == "200" ]] || die "API auth test failed (HTTP $code)"
log "API key works (HTTP 200)"
}
upgrade() {
[[ -f "$HDR_FILE" ]] || die "no API key; run: apikey"
log "uploading image; the device will write the inactive partition and reboot"
local resp
resp="$(curl_tls -s --max-time 900 -H "@$HDR_FILE" \
-F "file=@$IMAGE" -F "source=upload" \
-w '\nHTTP %{http_code}' \
"https://$FGT_HOST/api/v2/monitor/system/firmware/upgrade")"
printf '%s\n' "$resp" > "$WORKDIR/upgrade_response.txt"
grep -q 'HTTP 20[02]' <<<"$resp" || die "upgrade call failed: $resp"
log "upgrade accepted"
}
wait_for_build() {
log "waiting up to ${WAIT_TIMEOUT}s for build $EXPECTED_BUILD"
local start now out
start="$(date +%s)"
while :; do
sleep 20
now="$(date +%s)"
(( now - start > WAIT_TIMEOUT )) && die "timed out waiting for build $EXPECTED_BUILD"
if out="$(fgt 'get system status' 2>/dev/null)"; then
if grep -Eq "build:?${EXPECTED_BUILD}" <<<"$out"; then
log "device is up on build $EXPECTED_BUILD after $((now - start))s"
printf '%s\n' "$out" > "$WORKDIR/post_status.txt"
return
fi
log "up, but not on target build yet"
else
log "device down (rebooting)"
fi
done
}
verify() {
fgt 'get system status' > "$WORKDIR/post_status.txt"
fgt 'get system interface' > "$WORKDIR/post_interfaces.txt"
fgt 'get firewall policy' > "$WORKDIR/post_policy.txt"
log "version:"; grep -i '^Version' "$WORKDIR/post_status.txt" || true
diff -q "$WORKDIR/baseline_interfaces.txt" "$WORKDIR/post_interfaces.txt" >/dev/null \
&& log "interfaces: unchanged" || log "interfaces: DIFFERENT, review diff"
diff -q "$WORKDIR/baseline_policy.txt" "$WORKDIR/post_policy.txt" >/dev/null \
&& log "policies: unchanged" || log "policies: DIFFERENT, review diff"
log "MANUAL: test real traffic, DNS, VPN tunnels, and logging."
log "A matching config is not proof that traffic works."
}
cleanup() {
set +e
if ssh "${SSH_OPTS[@]}" "$FGT_USER@$FGT_HOST" 'get system status' >/dev/null 2>&1; then
fgt "config system api-user
delete \"$API_USER\"
end" >/dev/null 2>&1 \
&& log "temp API user removed" \
|| log "WARNING: remove '$API_USER' manually (config system api-user)"
else
log "WARNING: device unreachable; remove '$API_USER' manually once it is back"
fi
[[ -f "$KEY_FILE" ]] && { shred -u "$KEY_FILE" 2>/dev/null || rm -f "$KEY_FILE"; }
[[ -f "$HDR_FILE" ]] && { shred -u "$HDR_FILE" 2>/dev/null || rm -f "$HDR_FILE"; }
}
run_all() {
log "Target: $FGT_HOST image: $IMAGE build: $EXPECTED_BUILD"
read -r -p "Type 'upgrade' to proceed (maintenance window + approval in place?): " ans
[[ "$ans" == "upgrade" ]] || die "aborted"
trap cleanup EXIT
precheck
snapshot
apikey
upgrade
# Device reboots; the API user is deleted after the wait via trap/cleanup.
wait_for_build
verify
}
usage() { sed -n '2,20p' "$0"; exit 1; }
case "${1:-}" in
precheck) precheck ;;
snapshot) snapshot ;;
apikey) apikey ;;
upgrade) upgrade ;;
wait) wait_for_build ;;
verify) verify ;;
cleanup) cleanup ;;
run) run_all ;;
*) usage ;;
esac
execute restore image — FortiGate 7.4 Admin Guide, "Upgrading individual device firmware" — https://docs.fortinet.com/document/fortigate/7.4.2/administration-guide/596131/upgrading-individual-device-firmwaretrusthost — FortiOS 7.4.12 Admin Guide, "REST API administrator" — https://docs.fortinet.com/document/fortigate/7.4.12/administration-guide/399023/rest-api-administrator