Skip to content

feat(security): add security scan and affected resources tasks - #31

Merged
fdelbrayelle merged 1 commit into
kestra-io:mainfrom
PedroHenrique0713:feat/security-scans
Oct 14, 2026
Merged

fdelbrayelle merged 1 commit into
kestra-io:mainfrom
PedroHenrique0713:feat/security-scans

Conversation

@PedroHenrique0713

@PedroHenrique0713 PedroHenrique0713 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What changes are being made and why?

Closes #30 (part of #10). This is the Security scans slice, after Snapshots (#17), Billing (#18), Block Storage Actions (#23) and Spaces keys (#25).

DigitalOcean's security (CSPM) scans could not be started or read from a flow, e.g. to run a scan on a schedule and fail or alert when it reports critical findings. This adds a security.scan subgroup on /v2/security/scans:

  • security.scan.Create: starts a scan and returns it without waiting
  • security.scan.Get: reads a scan by ID with its findings, optionally filtered by severity or type
  • security.scan.GetLatest: the same, for the most recent scan
  • security.scan.List: lists the scans
  • security.scan.ListAffectedResources: lists the resources a finding applies to

Create follows the same pattern as the other asynchronous tasks in the plugin: it returns the scan's initial status, and Get inside a LoopUntil waits for it (see the flow below).

Three choices worth flagging:

  • Get and GetLatest return one page of findings (up to 200) and expose page, instead of paginating on their own: the scan response has no links or meta in the OpenAPI spec, so there is nothing documented to follow.
  • List drops the findings from each row, so its output doesn't grow with scans times findings. Findings are read with Get.
  • The spec doesn't say where the finding_uuid of the affected resources endpoint comes from, and a finding only carries a rule_uuid. ListAffectedResources takes it as a plain findingId; the demo below passes the rule_uuid, which is what my mock expects. I could not check this against the real API, since I have no account with CSPM enabled.

The settings and suppressions endpoints of the Security API are left for a follow-up PR.

Endpoints and fields taken from DigitalOcean's OpenAPI spec, plus the metadata, icon and docs entries for the new subgroup.


How the changes have been QAed?

  • 18 new WireMock tests: the scan and its findings mapped to the output, the severity, type, page size and page sent as query params, a page size above 200 rejected before any request, the empty create body, the latest scan with CSPM not enabled, findings removed from the list rows, 400, 404 and 429, and one per task rendering its properties from Pebble expressions. The full suite passes (201/201). Leaving the findings in the list rows, lowercasing the severity, ignoring page, skipping the page size check, sending a different create body, swapping the scan and finding IDs in the path or pointing GetLatest elsewhere each makes a test fail.
  • Built the jar and ran it on Kestra 2.0.5 against a small local mock of the DigitalOcean API that completes the scan after a few seconds, with this flow (baseUrl points to the mock; drop it to hit the real API):
id: digitalocean_security_scan
namespace: company.team

tasks:
  - id: start_scan
    type: io.kestra.plugin.digitalocean.security.scan.Create
    apiToken: "{{ secret('DIGITALOCEAN_TOKEN') }}"
    baseUrl: http://host.docker.internal:18996

  - id: wait_for_scan
    type: io.kestra.plugin.core.flow.LoopUntil
    condition: "{{ outputs.get_scan.status != 'IN_PROGRESS' }}"
    checkFrequency:
      interval: PT2S
      maxDuration: PT5M
    tasks:
      - id: get_scan
        type: io.kestra.plugin.digitalocean.security.scan.Get
        apiToken: "{{ secret('DIGITALOCEAN_TOKEN') }}"
        baseUrl: http://host.docker.internal:18996
        scanId: "{{ outputs.start_scan.id }}"
        severity: CRITICAL

  - id: affected_resources
    type: io.kestra.plugin.digitalocean.security.scan.ListAffectedResources
    apiToken: "{{ secret('DIGITALOCEAN_TOKEN') }}"
    baseUrl: http://host.docker.internal:18996
    scanId: "{{ outputs.start_scan.id }}"
    findingId: "{{ outputs.get_scan.findings[0].rule_uuid }}"

  - id: list_scans
    type: io.kestra.plugin.digitalocean.security.scan.List
    apiToken: "{{ secret('DIGITALOCEAN_TOKEN') }}"
    baseUrl: http://host.docker.internal:18996

  - id: summary
    type: io.kestra.plugin.core.log.Log
    message: >
      Scan {{ outputs.get_scan.status }} with {{ outputs.get_scan.findings | length }} critical finding(s):
      "{{ outputs.get_scan.findings[0].name }}" affects {{ outputs.affected_resources.total }} resource(s),
      first one {{ outputs.affected_resources.rows[0].urn }}. {{ outputs.list_scans.total }} scan(s) on the account.

The loop polled the scan three times until it was COMPLETED, and the summary logged Scan COMPLETED with 1 critical finding(s): "All Firewall Ports Exposed to a Source" affects 2 resource(s), first one do:droplet:3164444. 3 scan(s) on the account. The mock sends findings inside every scan of the list, and the list_scans rows came out with id, status and created_at only. A second flow with GetLatest and a Fail task failed as intended with 1 critical finding(s), first one: All Firewall Ports Exposed to a Source.

Before / after

Plugin list: the new Security Scans group shows up. The "before" side is the released plugin, so it also lacks the Snapshots and Billing groups merged this week.

Before: plugin list After: plugin list with the Security Scans group

Editor: the released plugin rejects security.scan.Create, this branch validates it.

Before: the editor rejects security.scan.Create After: the flow validates

The demo flow running end to end.

After: demo flow execution

Setup Instructions

A DigitalOcean API token in a DIGITALOCEAN_TOKEN secret, with the security:create scope for Create and security:read for the other tasks, on an account with CSPM enabled.


Contributor Checklist ✅

@github-project-automation github-project-automation Bot moved this to To review in Pull Requests Oct 13, 2026
@Coding-with-Adam
Coding-with-Adam requested review from a team and fdelbrayelle October 14, 2026 12:29
@Coding-with-Adam Coding-with-Adam added area/plugin Plugin-related issue or feature request kind/external Pull requests raised by community contributors labels Oct 14, 2026

@fdelbrayelle fdelbrayelle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kestra Plugin Code Review

Business Requirements — met

All five tasks from #30 (Create, Get, GetLatest, List, ListAffectedResources) are added under security.scan, with the severity and type filters, metadata, icon, docs, README and AGENTS.md entries. Settings and suppressions are out of scope as stated in the issue.

Kestra Guidelines — 0 findings

✅ No violations. Lombok annotations, Property<T> inputs, property groups, @Schema, full runnable @Example flows, @PluginSubGroup, metadata yaml, how-to doc and AGENTS.md are all in place. perPage and page bounds are enforced at runtime with requireInRange and documented in @Schema. Path segments are encoded with encodePathSegment. Tests are WireMock-based and run unconditionally, with a happy path for every task.

Security (OWASP Top 10:2025 + KPS) — 0 findings

✅ No issues found. The token goes through the shared base class and the internal HTTP client, and nothing user-supplied is concatenated unencoded into the URL.

Performance — 0 findings

✅ No issues found. List drops findings from each row so the output does not grow with scans times findings, and Get/GetLatest cap the findings at one page of at most 200.

Notes for maintainers (non-blocking)

  • ListAffectedResources.findingId: the PR says the OpenAPI spec does not state where finding_uuid comes from, and the demo passes a finding's rule_uuid. This was only checked against a local mock, never the real API. Worth a check on a CSPM-enabled account before release, and if rule_uuid is not accepted, the @Schema description of findingId should say where to find the right value.

Verdict: APPROVE; recommendation only, posted as COMMENT, a maintainer decides.

@fdelbrayelle

Copy link
Copy Markdown
Member

QA report: feat(security): add security scan and affected resources tasks (#31)

Commit: b178950
Edition: OSS | Docker tag: v1.3.43 (plugin kestraVersion 1.3.39 line), then v2.0.6 with the same JAR
Instance: http://localhost:18231 (left running, currently v2.0.6; docker rm -f qa-do31-kestra qa-do31-mock && docker network rm qa-do31-net to stop)
Screenshots: https://claude.ai/artifact/MDzPNnP2sHoc3R4NpV82CD
API: DigitalOcean mocked locally (64 MB Python container serving the /v2/security/scans routes, 5 scans, 3 findings, 5 affected resources, paginated through links.pages.next) and reached through the tasks' baseUrl. No real account or credential used. Flows were created and started through the Kestra API, then every execution was inspected in the UI (Gantt, Logs, Outputs tabs).

Result: PASS. No HIGH or MEDIUM issue found. Bundled plugin-digitalocean was removed from each QA container so only the PR JAR is loaded; the five task docs resolve under "Security Scans" in the Plugins page (screenshot).

Flow v1.3.43 v2.0.6
do31_lifecycle (Create, Get, GetLatest, List, ListAffectedResources) SUCCESS SUCCESS
do31_filters (severity, findingType, page/perPage) SUCCESS SUCCESS
do31_pagination (List and ListAffectedResources over 3 pages) SUCCESS SUCCESS
do31_notenabled (GetLatest, CSPM_NOT_ENABLED) SUCCESS SUCCESS
do31_notfound (Get unknown scan) FAILED as expected FAILED as expected
do31_badtoken (HTTP 401) FAILED as expected FAILED as expected
do31_badperpage (perPage 500) FAILED as expected FAILED as expected
do31_regression (droplet.List, existing task) SUCCESS SUCCESS

Checked against the request log of the mock: Create sends POST /v2/security/scans with body {}; Get and GetLatest send per_page, page, severity and type as set; List and ListAffectedResources follow links.pages.next (3 requests each with perPage 2); every call carries the Bearer header; the bad perPage case sends no request at all. v2.0.6 produced the identical request sequence.

Flow 1: do31_lifecycle (SUCCESS)

Flow YAML
id: do31_lifecycle
namespace: qa.do31
tasks:
  - id: create_scan
    type: io.kestra.plugin.digitalocean.security.scan.Create
    apiToken: "fake-token-for-mock"
    baseUrl: "http://mock:8080"
  - id: get_scan
    type: io.kestra.plugin.digitalocean.security.scan.Get
    apiToken: "fake-token-for-mock"
    baseUrl: "http://mock:8080"
    scanId: "{{ outputs.create_scan.id }}"
  - id: latest_scan
    type: io.kestra.plugin.digitalocean.security.scan.GetLatest
    apiToken: "fake-token-for-mock"
    baseUrl: "http://mock:8080"
  - id: list_scans
    type: io.kestra.plugin.digitalocean.security.scan.List
    apiToken: "fake-token-for-mock"
    baseUrl: "http://mock:8080"
  - id: affected
    type: io.kestra.plugin.digitalocean.security.scan.ListAffectedResources
    apiToken: "fake-token-for-mock"
    baseUrl: "http://mock:8080"
    scanId: "{{ outputs.get_scan.id }}"
    findingId: "{{ outputs.latest_scan.findings[0].rule_uuid }}"
  - id: summary
    type: io.kestra.plugin.core.log.Log
    message: "create={{ outputs.create_scan.status }} get_findings={{ outputs.get_scan.findings | length }} scans={{ outputs.list_scans.total }} affected={{ outputs.affected.total }}"

Gantt (1.3.43, 2.0.6)

Task Status Duration
create_scan SUCCESS 0.02s
get_scan SUCCESS 0.03s
latest_scan SUCCESS 0.04s
list_scans SUCCESS 0.03s
affected SUCCESS 0.03s
summary SUCCESS 0.03s
Total SUCCESS 0.31s

Logs synthesis (1.3.43): "Started security scan ... with status IN_PROGRESS", "Scan ... is COMPLETED with 3 finding(s) on page 1" for Get and GetLatest, then List and ListAffectedResources counts. No token in any log line.

Outputs synthesis (1.3.43, 2.0.6): Create returns id, status: IN_PROGRESS, createdAt, findings: []. Get and GetLatest return 3 findings each with rule_uuid, name, severity, type, details, mitigation_steps, affected_resources_count. List returns 5 rows (size: 5, total: 5) with only id, status, created_at: the findings array is stripped from the rows. ListAffectedResources returns 5 rows (urn, name, type). On 2.0.6 the Input/Output tab lists the objects but does not expand values in the UI; the same tasks produced the same requests.

Flow 2: do31_filters (SUCCESS)

Flow YAML
id: do31_filters
namespace: qa.do31
tasks:
  - id: critical_only
    type: io.kestra.plugin.digitalocean.security.scan.GetLatest
    apiToken: "fake-token-for-mock"
    baseUrl: "http://mock:8080"
    severity: CRITICAL
  - id: by_type
    type: io.kestra.plugin.digitalocean.security.scan.Get
    apiToken: "fake-token-for-mock"
    baseUrl: "http://mock:8080"
    scanId: "22222222-2222-2222-2222-222222222222"
    findingType: firewall
  - id: page_two
    type: io.kestra.plugin.digitalocean.security.scan.Get
    apiToken: "fake-token-for-mock"
    baseUrl: "http://mock:8080"
    scanId: "22222222-2222-2222-2222-222222222222"
    perPage: 2
    page: 2
  - id: check
    type: io.kestra.plugin.core.log.Log
    message: "critical={{ outputs.critical_only.findings | length }} firewall={{ outputs.by_type.findings | length }} page2={{ outputs.page_two.findings | length }}"

Gantt (1.3.43, 2.0.6): all 4 tasks SUCCESS, each under 0.05s.
Logs synthesis (screenshot): CRITICAL filter gives 1 finding, findingType: firewall gives 1 finding, perPage: 2, page: 2 gives the 3rd finding "on page 2".
Outputs synthesis (screenshot): findings match the filter in each task (Public Spaces bucket, Firewall open on SSH, Droplet without backups).

Flow 3: do31_pagination (SUCCESS)

Flow YAML
id: do31_pagination
namespace: qa.do31
tasks:
  - id: list_paged
    type: io.kestra.plugin.digitalocean.security.scan.List
    apiToken: "fake-token-for-mock"
    baseUrl: "http://mock:8080"
    perPage: 2
  - id: affected_paged
    type: io.kestra.plugin.digitalocean.security.scan.ListAffectedResources
    apiToken: "fake-token-for-mock"
    baseUrl: "http://mock:8080"
    scanId: "22222222-2222-2222-2222-222222222222"
    findingId: "aaaaaaaa-0000-0000-0000-000000000001"
    perPage: 2
    fetchType: FETCH
  - id: check
    type: io.kestra.plugin.core.log.Log
    message: "scans={{ outputs.list_paged.size }}/{{ outputs.list_paged.total }} has_findings={{ outputs.list_paged.rows[0] | keys | join(',') }} affected={{ outputs.affected_paged.size }}"

Gantt (1.3.43, 2.0.6): 3 tasks SUCCESS, 0.2s total.
Logs synthesis (screenshot): "Found 5 security scan(s)", "Found 5 affected resource(s)", check line scans=5/5 has_findings=id,status,created_at affected=5 (row keys confirm findings are dropped).
Outputs synthesis (screenshot): size: 5, total: 5 for both tasks.

Flow 4: do31_notenabled (SUCCESS)

Flow YAML
id: do31_notenabled
namespace: qa.do31
tasks:
  - id: latest
    type: io.kestra.plugin.digitalocean.security.scan.GetLatest
    apiToken: "notenabled"
    baseUrl: "http://mock:8080"
  - id: log
    type: io.kestra.plugin.core.log.Log
    message: "status={{ outputs.latest.status }} findings={{ outputs.latest.findings | length }}"

Gantt (screenshot): both tasks SUCCESS.
Outputs synthesis (screenshot): status: CSPM_NOT_ENABLED, findings: [], empty id. The task does not fail when CSPM is off.

Flow 5: do31_notfound (FAILED, expected)

Flow YAML
id: do31_notfound
namespace: qa.do31
tasks:
  - id: get_missing
    type: io.kestra.plugin.digitalocean.security.scan.Get
    apiToken: "fake-token-for-mock"
    baseUrl: "http://mock:8080"
    scanId: "missing"

Gantt (1.3.43, 2.0.6): get_missing FAILED in 0.03s.
Logs synthesis (screenshot): "DigitalOcean API returned HTTP 404: resource not found. Verify baseUrl (e.g. https://api.digitalocean.com) and the id used in the request are correct." Clear and actionable.

Flow 6: do31_badtoken (FAILED, expected)

Flow YAML
id: do31_badtoken
namespace: qa.do31
tasks:
  - id: unauthorized
    type: io.kestra.plugin.digitalocean.security.scan.GetLatest
    apiToken: "bad"
    baseUrl: "http://mock:8080"

Logs synthesis (screenshot): "HTTP 401: invalid or missing API token. Create a personal access token (prefixed dop_v1_) ... and set it as apiToken". The token value is not printed.

Flow 7: do31_badperpage (FAILED, expected)

Flow YAML
id: do31_badperpage
namespace: qa.do31
tasks:
  - id: too_many
    type: io.kestra.plugin.digitalocean.security.scan.Get
    apiToken: "fake-token-for-mock"
    baseUrl: "http://mock:8080"
    scanId: "22222222-2222-2222-2222-222222222222"
    perPage: 500

Logs synthesis (screenshot): "perPage must be between 1 and 200, got 500". Validated before any HTTP call.

Flow 8: do31_regression (SUCCESS, non-regression)

Flow YAML
id: do31_regression
namespace: qa.do31
tasks:
  - id: droplets
    type: io.kestra.plugin.digitalocean.droplet.List
    apiToken: "fake-token-for-mock"
    baseUrl: "http://mock:8080"

Outputs synthesis (screenshot): existing droplet.List still returns 3 rows, size: 3, total: 3 with the PR JAR loaded.

Timeout notes: none, every execution finished in under 2s. Topology checks skipped: the PR adds no custom UI or topology node, and the repo has no ui/ folder. Not testable here: behavior against the real DigitalOcean CSPM API (real finding payloads, scan status transitions over time), since no account is available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/plugin Plugin-related issue or feature request kind/external Pull requests raised by community contributors

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

DigitalOcean: add Security scan tasks (part of #10)

3 participants