diff --git a/.agents/skills/playbook-template/SKILL.md b/.agents/skills/playbook-template/SKILL.md new file mode 100644 index 0000000..9bc4d88 --- /dev/null +++ b/.agents/skills/playbook-template/SKILL.md @@ -0,0 +1,83 @@ +--- +name: playbook-template +description: Use when adding, changing, exporting, checking or reviewing a Sekoia playbook template under playbooks/templates/ in SEKOIA-IO/Community, or when a user wants to share one of their Sekoia playbooks as a template. +--- + +# Sekoia playbook templates + +Every file in `playbooks/templates/` is published in the Sekoia playbook editor (**Start from a template** on a new playbook) for every customer, with the next release of the Sekoia playbook service. A template the platform refuses never appears, and an existing template that stops passing its validation is removed from the editor. Work as if each change ships to production. + +The human guide is [`playbooks/README.md`](../../../playbooks/README.md). This file adds what an agent must do and must not do. + +## 1. Start from a playbook that ran + +A template is a playbook that worked in a real Sekoia community. Do not write one from scratch. + +- Ask the user for the playbook UUID: the last part of its address in Sekoia, `.../playbooks/`. +- Ask which region their community is in. The API URL is in `playbooks/tools/export_template.py` (FRA1 is the default). +- Export it. The API key must come from the environment, with the "View playbooks" permission: + + ```bash + python playbooks/tools/export_template.py .json [--base-url ] + ``` + + `SEKOIA_API_KEY` must already be set in the environment the agent was started from. If it is not, ask the user to run the export command above themselves in their terminal (`read -s SEKOIA_API_KEY && export SEKOIA_API_KEY` first), then continue from the exported file. Never write the key in a command, a file or a script, and never ask for it in the conversation. +- If the user only has an idea, do not invent a template: suggest an issue with the "Playbook template idea" form. +- If the user asks you to edit an existing template, keep its `uuid`: the platform updates the published template in place. A new template always gets a new `uuid` (the export script sets one). + +Never type an `action_uuid`, `trigger_uuid` or `module_uuid` from memory. They come from the export, or from the manifests of [automation-library](https://github.com/SEKOIA-IO/automation-library) (`/manifest.json`, `action_*.json`, `trigger_*.json`) on the `production` branch. + +## 2. Remove everything that belongs to the user's environment + +The export removes the accounts (module and trigger configurations) and nothing else: until this step is done, the exported file holds the playbook's arguments as they are, so do not commit it before. Look for the rest in the arguments, conditions and store operators, and replace each value with `_to_update_`: + +- URLs and host names (`atlassian.net`, `webhook.office.com`, `hooks.slack.com`, internal domains); +- identifiers of the community: IOC collection ids (`ioc-collection--...`), asset, rule, case or community UUIDs, project keys; +- email addresses, user or team names, customer or company names; +- anything that looks like a secret, even partly. + +Then say in the description which values the reader must change. Show the user every value you replaced, with its node and field; for a secret, give the node and field only, never the value. + +## 3. Complete the file + +- `name`: what the playbook does, e.g. "Enrich an alert with AbuseIPDB". Not "AbuseIPDB playbook". +- `description`: what it does, then what it needs (integration and its account, a licence if any, the event fields it reads, the values to change). +- `tags`: reuse the tags of the other templates, with the same spelling (they are case sensitive), plus the vendor name. +- File name: lower case with underscores, ending in `.json`. +- Do not create or edit `playbooks/templates/playbooks.json`: the platform does not read it any more. + +## 4. Check what the platform checks, and what it cannot + +Run the check from the repository root: + +```bash +pip install "jsonschema==4.26.0" "jinja2==3.1.6" +git clone --depth 1 --filter=blob:none --sparse --branch production \ + https://github.com/SEKOIA-IO/automation-library.git /tmp/automation-library +git -C /tmp/automation-library sparse-checkout set --no-cone '/*/manifest.json' '/*/action_*.json' '/*/trigger_*.json' +python playbooks/tools/check_templates.py --automation-library /tmp/automation-library --changed playbooks/templates/.json +``` + +- Fix every error (`x`). Each one is refused by the platform or makes every run fail. +- Read every warning (`!`). Fix it unless you can explain why it is wrong. A field that an action "does not declare in its result" may still be returned by the integration: check the action's documentation before changing it. +- Never silence the check, edit `playbooks/tools/` to make a template pass, or change other templates in the same pull request. + +Then review what no static check sees. Read the playbook as a run would: + +- **The trigger fits the use case.** A manual trigger for an analyst action, "Alert Created" for something that must run on every alert. An expensive step (sandbox, paid API) on every alert needs a condition before it. +- **The data exists.** Event fields must be fields of the Sekoia event taxonomy that the expected intakes produce (`source.ip`, `url.original`, `file.hash.sha256`...). A field no intake produces makes every run fail. +- **All the data is read.** `$.events[0]` reads the first event only. To use every value of a field across the alert's events, use the action "Get Event Field Common Values" and `jsonpath("$.fields[*].common_values[*]['name']", True)`, as the IOC collection templates do. +- **Loops keep their results.** A store operator that collects results across a foreach's iterations must `append`; `set` keeps only the last value. `set` stays right for a value used within one iteration. +- **Every branch ends somewhere useful.** No placeholder node that does nothing, and no branch named after an output the action does not have. +- **The description matches the playbook.** + +## 5. Open the pull request + +- One template, or one coherent set for the same integration, per pull request. +- Fill in the pull request checklist. Ask the user for a screenshot of the playbook or of a successful run: you cannot produce it. +- Write the description for a reviewer: the use case, who it helps, what the reader must configure. +- Before committing, search the diff once more for secrets and environment values (section 2). + +## 6. When asked to review a template pull request + +Run the check on the changed files, then go through section 2 and the review list of section 4, and report each problem with the node id and name, what happens at run time, and the fix. Distinguish what blocks the merge (errors, secrets, environment values, wrong behaviour) from suggestions. diff --git a/.claude/skills b/.claude/skills new file mode 120000 index 0000000..2b7a412 --- /dev/null +++ b/.claude/skills @@ -0,0 +1 @@ +../.agents/skills \ No newline at end of file diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..dfe0097 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,15 @@ +# Instructions for AI agents working on SEKOIA-IO/Community + +This public repository holds content shared with the users of the Sekoia platform: playbook templates, detection rules (Sigma, YARA), hunting queries, IOCs, reports, dashboards and scripts. Anyone can read it and open a pull request. + +## Rules for every change + +- **It is public.** Never write an API key, a token, a password, a webhook URL, an internal host name, a customer name or customer data in a file, a commit, a pull request or an issue. Read secrets from environment variables (for Sekoia: `SEKOIA_API_KEY`) and never print them. If the user pastes a secret in the conversation, do not reuse it in a file or a command that is saved, and tell them to revoke it once done. +- **Some files are live product content.** Changing them changes what every Sekoia customer sees: + - `playbooks/templates/`: published in the playbook editor with the next release of the Sekoia playbook service; + - `events/lookups.json`: read by the Sekoia web app straight from `main`. +- **One topic per pull request**, with a description that says what changes and why. + +## Playbook templates + +Before adding, changing, exporting or reviewing anything under `playbooks/`, read and follow [`.agents/skills/playbook-template/SKILL.md`](.agents/skills/playbook-template/SKILL.md). The human guide is [`playbooks/README.md`](playbooks/README.md). diff --git a/CLAUDE.md b/CLAUDE.md new file mode 120000 index 0000000..47dc3e3 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1 @@ +AGENTS.md \ No newline at end of file diff --git a/playbooks/README.md b/playbooks/README.md index 625b960..6b48f9b 100644 --- a/playbooks/README.md +++ b/playbooks/README.md @@ -26,6 +26,8 @@ A template merged on `main` is published with the next release of the Sekoia pla ``` 5. **Open a pull request** and fill in the checklist. The same check runs on the pull request. +Working with an AI coding agent? It finds its instructions in [`AGENTS.md`](../AGENTS.md) and [`.agents/skills/playbook-template`](../.agents/skills/playbook-template/SKILL.md): the same steps, plus what it must never do (write a secret, invent identifiers, silence the check). + Not ready to build it? [Open an idea](https://github.com/SEKOIA-IO/Community/issues/new?template=playbook-template-request.yml): someone else may pick it up. ## What makes a good template