feat(chronicle): new Google Chronicle SIEM integration

Chronicle Backstory API, 5 commands: list IOCs, list alerts, list assets,
get IOC details. Service-account RS256 JWT auth (remote engine, PyJWT +
cryptography).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Guillaume BOURGEOIS
2026-07-12 00:25:51 +02:00
parent d0d72c5171
commit aca1db5cad
6 changed files with 482 additions and 0 deletions
+76
View File
@@ -0,0 +1,76 @@
id: chronicle
name: Google Chronicle
version: 1.0.0
description: "Google Chronicle (Backstory API) — SIEM threat context: list IOCs seen in the enterprise, list alerts, list assets, and get IOC details for an artifact. Authenticates with a Google service account (RS256 JWT bearer flow). Runs on a remote engine. Requires the Python 'PyJWT' and 'cryptography' libraries on the engine host (pip install pyjwt cryptography)."
changelog: "1.0.0 — Initial release: list IOCs, list alerts, list assets, get IOC details."
category: siem
# Per-instance configuration. The scripts build a signed RS256 assertion from the
# service account's private_key/client_email and exchange it for an access token
# (scope chronicle-backstory). base_url is the regional Chronicle API host.
config_schema:
properties:
service_account_json:
type: string
description: "Full Chronicle service account key JSON (must contain client_email and private_key)"
x-soar-sensitive: true
base_url:
type: string
description: "Chronicle API base URL (region-specific)"
default: "https://backstory.googleapis.com"
required:
- service_account_json
commands:
- id: list_iocs
name: chronicle-list-iocs
description: "List IOCs (indicators of compromise) observed in the enterprise since a start time."
risk: read
inputs_schema:
properties:
start_time: { type: string, description: "RFC3339 start time (e.g. 2024-01-01T00:00:00Z)" }
page_size: { type: number, description: "Max IOCs (default 100)" }
required: [start_time]
outputs_schema: { properties: {} }
- id: list_alerts
name: chronicle-list-alerts
description: "List alerts in a time window."
risk: read
inputs_schema:
properties:
start_time: { type: string, description: "RFC3339 start time" }
end_time: { type: string, description: "RFC3339 end time" }
page_size: { type: number, description: "Max alerts (default 100)" }
required: [start_time, end_time]
outputs_schema: { properties: {} }
- id: list_assets
name: chronicle-list-assets
description: "List assets that accessed an artifact (domain, IP, or hash) in a time window."
risk: read
inputs_schema:
properties:
artifact_type: { type: string, description: "domain_name, destination_ip_address, or hash_sha256" }
artifact_value: { type: string, description: "The artifact value" }
start_time: { type: string, description: "RFC3339 start time" }
end_time: { type: string, description: "RFC3339 end time" }
required: [artifact_type, artifact_value, start_time, end_time]
outputs_schema: { properties: {} }
- id: ioc_details
name: chronicle-ioc-details
description: "Get IOC details for an artifact (domain, IP, or hash)."
risk: read
inputs_schema:
properties:
artifact_type: { type: string, description: "domain_name, destination_ip_address, or hash_sha256" }
artifact_value: { type: string, description: "The artifact value" }
required: [artifact_type, artifact_value]
outputs_schema: { properties: {} }
- id: test_connection
name: chronicle-test-connection
description: "Verify the service-account token exchange (used by the Test button)."
risk: read
inputs_schema:
properties: {}
required: []
outputs_schema: { properties: {} }
@@ -0,0 +1,82 @@
import json, os, sys, time, urllib.parse, urllib.request, urllib.error
import jwt
TOKEN_URL = "https://oauth2.googleapis.com/token"
SCOPE = "https://www.googleapis.com/auth/chronicle-backstory"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return (str(cfg.get("base_url") or "https://backstory.googleapis.com")).rstrip("/")
def _token(cfg):
raw = cfg.get("service_account_json", "")
sa = json.loads(raw) if isinstance(raw, str) else raw
if not sa.get("client_email") or not sa.get("private_key"):
raise Exception("service_account_json must contain client_email and private_key")
now = int(time.time())
aud = sa.get("token_uri") or TOKEN_URL
payload = {"iss": sa["client_email"], "scope": SCOPE, "aud": aud, "iat": now, "exp": now + 3600}
assertion = jwt.encode(payload, sa["private_key"], algorithm="RS256")
data = urllib.parse.urlencode({
"grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
"assertion": assertion,
}).encode("utf-8")
req = urllib.request.Request(aud, data=data,
headers={"Content-Type": "application/x-www-form-urlencoded"}, method="POST")
with urllib.request.urlopen(req, timeout=60) as r:
tok = json.loads(r.read())
if not tok.get("access_token"):
raise Exception("Token request failed: " + json.dumps(tok))
return tok["access_token"]
def api(method, path, cfg, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
headers = {"Accept": "application/json", "Authorization": "Bearer " + _token(cfg)}
req = urllib.request.Request(url, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=90) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def _artifact_params(inputs):
at = inputs.get("artifact_type")
av = inputs.get("artifact_value")
if not at:
raise Exception("artifact_type is required")
if not av:
raise Exception("artifact_value is required")
return {"artifact." + at: av}
def main(cfg, inputs):
params = _artifact_params(inputs)
return api("GET", "/v1/artifact/listiocdetails", cfg, params)
_run(main)
@@ -0,0 +1,83 @@
import json, os, sys, time, urllib.parse, urllib.request, urllib.error
import jwt
TOKEN_URL = "https://oauth2.googleapis.com/token"
SCOPE = "https://www.googleapis.com/auth/chronicle-backstory"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return (str(cfg.get("base_url") or "https://backstory.googleapis.com")).rstrip("/")
def _token(cfg):
raw = cfg.get("service_account_json", "")
sa = json.loads(raw) if isinstance(raw, str) else raw
if not sa.get("client_email") or not sa.get("private_key"):
raise Exception("service_account_json must contain client_email and private_key")
now = int(time.time())
aud = sa.get("token_uri") or TOKEN_URL
payload = {"iss": sa["client_email"], "scope": SCOPE, "aud": aud, "iat": now, "exp": now + 3600}
assertion = jwt.encode(payload, sa["private_key"], algorithm="RS256")
data = urllib.parse.urlencode({
"grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
"assertion": assertion,
}).encode("utf-8")
req = urllib.request.Request(aud, data=data,
headers={"Content-Type": "application/x-www-form-urlencoded"}, method="POST")
with urllib.request.urlopen(req, timeout=60) as r:
tok = json.loads(r.read())
if not tok.get("access_token"):
raise Exception("Token request failed: " + json.dumps(tok))
return tok["access_token"]
def api(method, path, cfg, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
headers = {"Accept": "application/json", "Authorization": "Bearer " + _token(cfg)}
req = urllib.request.Request(url, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=90) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
start_time = inputs.get("start_time")
if not start_time:
raise Exception("start_time is required")
end_time = inputs.get("end_time")
if not end_time:
raise Exception("end_time is required")
page_size = inputs.get("page_size")
params = {
"start_time": start_time,
"end_time": end_time,
"page_size": int(page_size or 100),
}
return api("GET", "/v1/alert/listalerts", cfg, params)
_run(main)
@@ -0,0 +1,90 @@
import json, os, sys, time, urllib.parse, urllib.request, urllib.error
import jwt
TOKEN_URL = "https://oauth2.googleapis.com/token"
SCOPE = "https://www.googleapis.com/auth/chronicle-backstory"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return (str(cfg.get("base_url") or "https://backstory.googleapis.com")).rstrip("/")
def _token(cfg):
raw = cfg.get("service_account_json", "")
sa = json.loads(raw) if isinstance(raw, str) else raw
if not sa.get("client_email") or not sa.get("private_key"):
raise Exception("service_account_json must contain client_email and private_key")
now = int(time.time())
aud = sa.get("token_uri") or TOKEN_URL
payload = {"iss": sa["client_email"], "scope": SCOPE, "aud": aud, "iat": now, "exp": now + 3600}
assertion = jwt.encode(payload, sa["private_key"], algorithm="RS256")
data = urllib.parse.urlencode({
"grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
"assertion": assertion,
}).encode("utf-8")
req = urllib.request.Request(aud, data=data,
headers={"Content-Type": "application/x-www-form-urlencoded"}, method="POST")
with urllib.request.urlopen(req, timeout=60) as r:
tok = json.loads(r.read())
if not tok.get("access_token"):
raise Exception("Token request failed: " + json.dumps(tok))
return tok["access_token"]
def api(method, path, cfg, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
headers = {"Accept": "application/json", "Authorization": "Bearer " + _token(cfg)}
req = urllib.request.Request(url, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=90) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def _artifact_params(inputs):
at = inputs.get("artifact_type")
av = inputs.get("artifact_value")
if not at:
raise Exception("artifact_type is required")
if not av:
raise Exception("artifact_value is required")
return {"artifact." + at: av}
def main(cfg, inputs):
params = _artifact_params(inputs)
start_time = inputs.get("start_time")
if not start_time:
raise Exception("start_time is required")
end_time = inputs.get("end_time")
if not end_time:
raise Exception("end_time is required")
params["start_time"] = start_time
params["end_time"] = end_time
return api("GET", "/v1/artifact/listassets", cfg, params)
_run(main)
@@ -0,0 +1,79 @@
import json, os, sys, time, urllib.parse, urllib.request, urllib.error
import jwt
TOKEN_URL = "https://oauth2.googleapis.com/token"
SCOPE = "https://www.googleapis.com/auth/chronicle-backstory"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return (str(cfg.get("base_url") or "https://backstory.googleapis.com")).rstrip("/")
def _token(cfg):
raw = cfg.get("service_account_json", "")
sa = json.loads(raw) if isinstance(raw, str) else raw
if not sa.get("client_email") or not sa.get("private_key"):
raise Exception("service_account_json must contain client_email and private_key")
now = int(time.time())
aud = sa.get("token_uri") or TOKEN_URL
payload = {"iss": sa["client_email"], "scope": SCOPE, "aud": aud, "iat": now, "exp": now + 3600}
assertion = jwt.encode(payload, sa["private_key"], algorithm="RS256")
data = urllib.parse.urlencode({
"grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
"assertion": assertion,
}).encode("utf-8")
req = urllib.request.Request(aud, data=data,
headers={"Content-Type": "application/x-www-form-urlencoded"}, method="POST")
with urllib.request.urlopen(req, timeout=60) as r:
tok = json.loads(r.read())
if not tok.get("access_token"):
raise Exception("Token request failed: " + json.dumps(tok))
return tok["access_token"]
def api(method, path, cfg, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
headers = {"Accept": "application/json", "Authorization": "Bearer " + _token(cfg)}
req = urllib.request.Request(url, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=90) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
start_time = inputs.get("start_time")
if not start_time:
raise Exception("start_time is required")
page_size = inputs.get("page_size")
params = {
"start_time": start_time,
"page_size": int(page_size or 100),
}
return api("GET", "/v1/ioc/listiocs", cfg, params)
_run(main)
@@ -0,0 +1,72 @@
import json, os, sys, time, urllib.parse, urllib.request, urllib.error
import jwt
TOKEN_URL = "https://oauth2.googleapis.com/token"
SCOPE = "https://www.googleapis.com/auth/chronicle-backstory"
def _cfg():
return json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
def _inputs():
return json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
def _base(cfg):
return (str(cfg.get("base_url") or "https://backstory.googleapis.com")).rstrip("/")
def _token(cfg):
raw = cfg.get("service_account_json", "")
sa = json.loads(raw) if isinstance(raw, str) else raw
if not sa.get("client_email") or not sa.get("private_key"):
raise Exception("service_account_json must contain client_email and private_key")
now = int(time.time())
aud = sa.get("token_uri") or TOKEN_URL
payload = {"iss": sa["client_email"], "scope": SCOPE, "aud": aud, "iat": now, "exp": now + 3600}
assertion = jwt.encode(payload, sa["private_key"], algorithm="RS256")
data = urllib.parse.urlencode({
"grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
"assertion": assertion,
}).encode("utf-8")
req = urllib.request.Request(aud, data=data,
headers={"Content-Type": "application/x-www-form-urlencoded"}, method="POST")
with urllib.request.urlopen(req, timeout=60) as r:
tok = json.loads(r.read())
if not tok.get("access_token"):
raise Exception("Token request failed: " + json.dumps(tok))
return tok["access_token"]
def api(method, path, cfg, params=None):
url = _base(cfg) + path
if params:
clean = {k: v for k, v in params.items() if v not in (None, "")}
if clean:
url += "?" + urllib.parse.urlencode(clean)
headers = {"Accept": "application/json", "Authorization": "Bearer " + _token(cfg)}
req = urllib.request.Request(url, headers=headers, method=method)
with urllib.request.urlopen(req, timeout=90) as r:
raw = r.read()
return json.loads(raw) if raw else {}
def _run(fn):
try:
print(json.dumps(fn(_cfg(), _inputs())))
except urllib.error.HTTPError as e:
print(json.dumps({"error": "HTTP " + str(e.code), "detail": e.read().decode("utf-8", "replace")}))
sys.exit(1)
except Exception as e:
print(json.dumps({"error": str(e)}))
sys.exit(1)
def main(cfg, inputs):
api("GET", "/v1/ioc/listiocs", cfg, {"page_size": 1})
return {"ok": True}
_run(main)