id: darkmoon-pentest-gate-slack-triage
namespace: company.security
inputs:
- id: target
type: STRING
displayName: Target
description: Host or URL of an asset you own or are explicitly authorized in
writing to test. Darkmoon sends real attack traffic to it.
defaults: staging.example.com
validator: '^[A-Za-z0-9][A-Za-z0-9.:/_-]{0,252}$'
- id: fail_on
type: STRING
displayName: Fail On Severities
description: Comma-separated severities that fail the gate when at least one
finding has them.
defaults: critical,high
validator: '^(critical|high|medium|low|info)(,(critical|high|medium|low|info))*$'
- id: timeout_seconds
type: INT
displayName: Campaign Timeout (seconds)
description: Hard timeout for the autonomous campaign before the CLI gives up waiting.
defaults: 3600
- id: notify_slack
type: BOOL
displayName: Notify Slack
description: Post the triage digest to Slack when the gate trips. Requires the
SLACK_WEBHOOK_URL secret.
defaults: true
concurrency:
limit: 1
triggers:
- id: weekly_pentest
type: io.kestra.plugin.core.trigger.Schedule
description: Run the pentest gate every Sunday at 02:00 UTC against the default
target. Disabled by default so nothing attacks a host until you opt in.
cron: "0 2 * * 0"
disabled: true
tasks:
- id: run_campaign
type: io.kestra.plugin.scripts.shell.Commands
description: Launch an autonomous Darkmoon campaign through the darkmoon-ci CLI,
wait for it, apply the fail policy, then export the findings as JSON. Exit
code 2 (policy tripped) is recorded and handled downstream; any other
non-zero exit is a real tool error.
containerImage: node:20-slim
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
timeout: PT2H
env:
DARKMOON_PRO_URL: "{{ secret('DARKMOON_PRO_URL') }}"
DARKMOON_PRO_USER: "{{ secret('DARKMOON_PRO_USER') }}"
DARKMOON_PRO_PASS: "{{ secret('DARKMOON_PRO_PASS') }}"
DARKMOON_MODE: pro
outputFiles:
- gate.json
- findings.json
commands:
- |
set -uo pipefail
CLI="npx -y -p @darkmoon_ai/client@0.2.0 darkmoon-ci"
$CLI run \
--target "{{ inputs.target }}" \
--fail-on "{{ inputs.fail_on }}" \
--timeout "{{ inputs.timeout_seconds }}" \
--json > gate.json
GATE_EXIT=$?
if [ "$GATE_EXIT" -ne 0 ] && [ "$GATE_EXIT" -ne 2 ]; then
echo "darkmoon-ci failed with exit code ${GATE_EXIT}" >&2
exit "$GATE_EXIT"
fi
CAMPAIGN_ID=$(node -e "console.log(JSON.parse(require('fs').readFileSync('gate.json','utf8')).campaignId)")
$CLI findings "$CAMPAIGN_ID" --json > findings.json
echo "::{\"outputs\":{\"gate_exit\":${GATE_EXIT},\"campaign_id\":\"${CAMPAIGN_ID}\"}}::"
- id: triage_findings
type: io.kestra.plugin.scripts.python.Script
description: Count findings by severity and status, and build a short digest
ordered by CVSS score. Only summary fields are read; evidence is never
copied into the digest.
containerImage: python:3.12-slim
taskRunner:
type: io.kestra.plugin.scripts.runner.docker.Docker
beforeCommands:
- pip install --no-cache-dir kestra
inputFiles:
findings.json: "{{ outputs.run_campaign.outputFiles['findings.json'] }}"
script: |
import json
from kestra import Kestra
with open("findings.json") as f:
findings = json.load(f)
order = ["critical", "high", "medium", "low", "info"]
by_severity = {s: 0 for s in order}
by_status = {}
for item in findings:
sev = (item.get("severity") or "info").lower()
by_severity[sev] = by_severity.get(sev, 0) + 1
status = item.get("status") or "unknown"
by_status[status] = by_status.get(status, 0) + 1
def rank(item):
sev = (item.get("severity") or "info").lower()
return (order.index(sev) if sev in order else len(order), -(item.get("cvssScore") or 0))
lines = [
"Target: {{ inputs.target }}",
"Campaign: {{ outputs.run_campaign.vars.campaign_id }}",
"Findings: %d (%s)" % (
len(findings),
", ".join("%s %d" % (s, by_severity[s]) for s in order if by_severity[s]) or "none",
),
"Exploited: %d, confirmed: %d, unconfirmed: %d" % (
by_status.get("exploited", 0), by_status.get("confirmed", 0), by_status.get("unconfirmed", 0)
),
"",
"Top findings:",
]
for item in sorted(findings, key=rank)[:8]:
score = item.get("cvssScore")
lines.append("- [%s/%s] %s (%s)%s" % (
(item.get("severity") or "info").upper(),
item.get("status") or "unknown",
item.get("title") or "untitled",
item.get("endpoint") or "n/a",
" CVSS %s" % score if score is not None else "",
))
if len(findings) > 8:
lines.append("... and %d more in the Darkmoon dashboard." % (len(findings) - 8))
lines.append("")
lines.append("Findings can include false positives: a qualified human must review them before action.")
digest = "\n".join(lines)
print(digest)
Kestra.outputs({
"total": len(findings),
"critical": by_severity["critical"],
"high": by_severity["high"],
"exploited": by_status.get("exploited", 0),
"digest": digest,
})
- id: evaluate_gate
type: io.kestra.plugin.core.flow.If
description: Branch on the fail policy result recorded by darkmoon-ci (exit code
2 means a severity in fail_on was found).
condition: "{{ outputs.run_campaign.vars.gate_exit == 2 }}"
then:
- id: notify_slack_if_enabled
type: io.kestra.plugin.core.flow.If
condition: "{{ inputs.notify_slack }}"
then:
- id: slack_digest
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Post the triage digest to the security channel.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": "Darkmoon pentest gate tripped for `{{ inputs.target }}` (fail on: {{ inputs.fail_on }}).\n```\n{{ outputs.triage_findings.vars.digest }}\n```\nExecution: {{ execution.id }}"
}
- id: fail_gate
type: io.kestra.plugin.core.execution.Fail
description: Fail the execution so downstream flows and alerting see the gate as
red.
errorMessage: "Darkmoon gate failed for {{ inputs.target }}: {{
outputs.triage_findings.vars.critical }} critical and {{
outputs.triage_findings.vars.high }} high findings in campaign {{
outputs.run_campaign.vars.campaign_id }}."
else:
- id: log_gate_passed
type: io.kestra.plugin.core.log.Log
message: "Darkmoon gate passed for {{ inputs.target }}. {{
outputs.triage_findings.vars.total }} findings, none at severity {{
inputs.fail_on }}."
errors:
- id: alert_on_tool_error
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Tell the team the campaign could not run (unreachable Darkmoon Pro
API, bad credentials, timeout).
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": "Darkmoon pentest flow `{{ flow.id }}` errored for `{{ inputs.target }}`. Check the Pro API URL and credentials. Execution {{ execution.id }}."
}
outputs:
- id: campaign_id
type: STRING
description: Darkmoon campaign id the gate evaluated.
value: "{{ outputs.run_campaign.vars.campaign_id }}"
- id: total_findings
type: INT
description: Total number of findings in the campaign.
value: "{{ outputs.triage_findings.vars.total }}"
- id: digest
type: STRING
description: Plain text triage digest.
value: "{{ outputs.triage_findings.vars.digest }}"