id: vendor-ip-range-allowlist-change-watch
namespace: company.team
description: |
Watch the published IP ranges of the vendors your firewalls allowlist (GitHub webhooks, Cloudflare,
Stripe webhooks, AWS CloudFront and others), alert in Slack with the exact CIDRs added and removed,
and produce the updated allowlist file for each vendor.
inputs:
- id: sources
type: JSON
displayName: IP range sources
description: |
List of objects with a `name`, the vendor's published `url`, a `jq` expression that returns the
list of CIDRs or IPs from that document, and an `owner` to mention.
defaults: |
[
{"name": "github-hooks", "url": "https://api.github.com/meta", "jq": ".hooks", "owner": "@platform"},
{"name": "cloudflare", "url": "https://api.cloudflare.com/client/v4/ips", "jq": ".result.ipv4_cidrs + .result.ipv6_cidrs", "owner": "@network"},
{"name": "stripe-webhooks", "url": "https://stripe.com/files/ips/ips_webhooks.json", "jq": ".WEBHOOKS", "owner": "@payments"},
{"name": "aws-cloudfront-origin-facing", "url": "https://ip-ranges.amazonaws.com/ip-ranges.json", "jq": "[.prefixes[] | select(.service == \"CLOUDFRONT_ORIGIN_FACING\") | .ip_prefix]", "owner": "@network"}
]
- id: max_removed_percent
type: INT
displayName: Removal safety limit (%)
description: When a source suddenly drops more than this share of its ranges,
the change is held until the next run sees the same list.
defaults: 50
tasks:
- id: for_each_source
type: io.kestra.plugin.core.flow.Loop
description: Check every vendor independently, four at a time.
values: "{{ inputs.sources }}"
concurrencyLimit: 4
tasks:
- id: fetch_ranges
type: io.kestra.plugin.core.http.Download
description: The vendor's published IP range document (public, no key).
uri: "{{ fromJson(item.value).url }}"
- id: load_previous
type: io.kestra.plugin.core.kv.Get
description: The list recorded at the last run. Missing on the first run.
key: "ip_ranges_{{ fromJson(item.value).name | slugify }}"
errorOnMissing: false
- id: compare
type: io.kestra.plugin.scripts.python.Script
description: Normalize the CIDRs, diff them with the last run, and write the
current allowlist file.
containerImage: python:3.12-slim
inputFiles:
current.json: "{{ read(outputs.fetch_ranges.uri) | jq(fromJson(item.value).jq) |
first | toJson }}"
previous.json: "{{ (outputs.load_previous.value ?? {}) | toJson }}"
source.json: "{{ item.value }}"
outputFiles:
- "*.txt"
script: |
import ipaddress
import json
def load(name):
with open(name, encoding="utf-8") as f:
data = json.load(f)
return json.loads(data) if isinstance(data, str) else data
source = load("source.json")
raw = load("current.json")
stored = load("previous.json") or {}
previous = stored.get("ranges", [])
if not isinstance(raw, list) or not raw:
raise SystemExit(f"The jq expression returned no list of ranges for {source['name']}: {raw!r:.200}")
networks = sorted({ipaddress.ip_network(str(x).strip(), strict=False) for x in raw},
key=lambda n: (n.version, n.network_address, n.prefixlen))
current = [str(n) for n in networks]
added = [c for c in current if c not in previous]
removed = [p for p in previous if p not in current]
removed_percent = round(100 * len(removed) / len(previous)) if previous else 0
# A large drop is held once; the same list on the next run confirms it.
held = removed_percent > {{ inputs.max_removed_percent }} and stored.get("pending") != current
confirmed = removed_percent > {{ inputs.max_removed_percent }} and not held
with open(f"{source['name']}.txt", "w", encoding="utf-8") as f:
f.write("\n".join(current) + "\n")
print(f"{source['name']}: {len(current)} ranges, {len(added)} added, {len(removed)} removed"
+ (" (first run)" if not previous else "") + (" HELD" if held else "") + (" CONFIRMED" if confirmed else ""))
print("::" + json.dumps({"outputs": {
"count": len(current),
"added": added,
"removed": removed,
"first_run": not previous,
"changed": bool(previous) and bool(added or removed),
"held": held,
"confirmed": confirmed,
"removed_percent": removed_percent,
"to_store": {"ranges": previous, "pending": current} if held else {"ranges": current},
}}) + "::")
- id: if_changed
type: io.kestra.plugin.core.flow.If
description: Only post when the vendor's ranges changed.
condition: "{{ outputs.compare.vars.changed }}"
then:
- id: alert_owner
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Post the exact CIDRs to add and remove in the allowlist.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
messageText: |
{{ outputs.compare.vars.held ? ':warning: *Suspicious change, held:*' : ':shield:' }} *{{ fromJson(item.value).name }} IP ranges changed* (owner: {{ fromJson(item.value).owner }})
Add ({{ outputs.compare.vars.added | length }}): {{ outputs.compare.vars.added | length > 0 ? '`' ~ (outputs.compare.vars.added | join('`, `')) ~ '`' : 'none' }}
Remove ({{ outputs.compare.vars.removed | length }}): {{ outputs.compare.vars.removed | length > 0 ? '`' ~ (outputs.compare.vars.removed | join('`, `')) ~ '`' : 'none' }}
{{ outputs.compare.vars.held ? outputs.compare.vars.removed_percent ~ '% of the ranges disappeared at once, which is more often a broken document than a real change. The stored list was kept; if the next run sees the same list, it is accepted.' : (outputs.compare.vars.confirmed ? 'The large removal was seen twice in a row, so it is now accepted. ' : '') ~ 'Now ' ~ outputs.compare.vars.count ~ ' ranges. The full list is in the execution outputs.' }}
Source: {{ fromJson(item.value).url }}
- id: remember_ranges
type: io.kestra.plugin.core.kv.Set
description: Store the list for the next comparison. Runs after the alert; a
suspicious drop keeps the old list until it is seen twice.
key: "ip_ranges_{{ fromJson(item.value).name | slugify }}"
kvType: JSON
overwrite: true
value: "{{ outputs.compare.vars.to_store | toJson }}"
errors:
- id: alert_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: A vendor that cannot be checked must not look unchanged.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
messageText: ":warning: Vendor IP range watch failed in execution {{
execution.id }} ({{ flow.namespace }}.{{ flow.id }}). Open the failed loop
iteration: the vendor may have moved its document, or the jq expression no
longer matches it."
triggers:
- id: every_six_hours
type: io.kestra.plugin.core.trigger.Schedule
description: Vendors announce range changes days ahead; four checks a day is
plenty. Disabled until the Slack secret is set.
cron: "0 */6 * * *"
disabled: true