Skip to content

feat(security): add security settings, suppression and scan rule tasks - #43

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

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

Conversation

@PedroHenrique0713

@PedroHenrique0713 PedroHenrique0713 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What changes are being made and why?

Closes #32 (part of #10). This is the second half of the Security section of #10, after the scans in #31, and the last piece of #10 on my side.

The scans from #31 report findings, but a flow could not act on them: choose which resources each plan tier scans, silence a rule on a resource that is fine by design, or keep a resource out of future scans. This adds a security.settings subgroup on /v2/security/settings, plus the scan rule endpoint next to the scans:

  • security.settings.Get: reads the settings, with the tier coverage, the scheduled plan downgrades and one page of rule suppressions
  • security.settings.UpdatePlan: sets the resources and tags each plan tier scans
  • security.settings.CreateSuppression: suppresses a rule on a list of resources
  • security.settings.DeleteSuppression: removes a suppression
  • security.scan.CreateRule: excludes a resource from future scans

Two choices worth flagging:

  • The API groups everything under /v2/security/settings, so this is one subgroup instead of two, and "List Settings" became Get, since it returns one object. CreateRule lives in security.scan because its endpoint is /v2/security/scans/rules.
  • Get exposes page and perPage (up to 200) for the suppressions instead of paginating on its own: the links.next of the response points to GET /v2/security/settings/suppressions, which is not in the OpenAPI spec, so there is nothing documented to follow.

Endpoints, bodies and scopes taken from DigitalOcean's OpenAPI spec (checked again against today's version), plus the metadata, icon and docs entries for the new subgroup. As with #31, I could not run it against the real API, since I have no account with CSPM enabled.


How the changes have been QAed?

  • 21 new WireMock tests: the settings, the coverage and the created suppressions mapped to the output, the bearer token on every call, the page and page size sent as query params, a page size above 200, an empty coverage and an empty resource list rejected before any request, a list left out of the coverage sent as empty, settings with missing fields, 400 and 404 with the API's reason, and one per task rendering its properties from Pebble expressions. The full suite passes (251/251), and ./gradlew javadoc is clean.
  • Built the jar and ran it on Kestra 2.0.5 against a small local mock of the DigitalOcean API that keeps the settings in memory, with this flow (baseUrl points to the mock; drop it to hit the real API):
id: digitalocean_security_settings
namespace: company.team

variables:
  droplet: "do:droplet:fe3a2fd7-903d-46e6-ada3-3e4f285fb89d"
  backups_rule: "460e09ef-dc84-11e8-981e-3cfdfeaae000"

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

  - id: cover_production
    type: io.kestra.plugin.digitalocean.security.settings.UpdatePlan
    apiToken: "{{ secret('DIGITALOCEAN_TOKEN') }}"
    baseUrl: http://host.docker.internal:18996
    tierCoverage:
      basic:
        resources:
          - "{{ vars.droplet }}"
        tags:
          - production

  - id: exclude_sandbox
    type: io.kestra.plugin.digitalocean.security.scan.CreateRule
    apiToken: "{{ secret('DIGITALOCEAN_TOKEN') }}"
    baseUrl: http://host.docker.internal:18996
    resource: "do:droplet:sandbox-01"

  - id: suppress_backups_rule
    type: io.kestra.plugin.digitalocean.security.settings.CreateSuppression
    apiToken: "{{ secret('DIGITALOCEAN_TOKEN') }}"
    baseUrl: http://host.docker.internal:18996
    ruleId: "{{ vars.backups_rule }}"
    resources:
      - "{{ vars.droplet }}"

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

  - id: report
    type: io.kestra.plugin.core.log.Log
    message: "{{ outputs.settings_after.suppressionsTotal }} suppression(s): {{ outputs.settings_after.suppressions | jq('.[].rule_name') | first }} on {{ outputs.settings_after.suppressions[0].resource_type }} {{ outputs.settings_after.suppressions[0].resource_id }}; basic tier tags {{ outputs.settings_after.tierCoverage.basic.tags }}"

  - id: lift_suppression
    type: io.kestra.plugin.digitalocean.security.settings.DeleteSuppression
    apiToken: "{{ secret('DIGITALOCEAN_TOKEN') }}"
    baseUrl: http://host.docker.internal:18996
    suppressionId: "{{ outputs.suppress_backups_rule.suppressions[0].id }}"

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

  - id: check
    type: io.kestra.plugin.core.execution.Assert
    conditions:
      - "{{ outputs.settings_before.suppressionsTotal == 0 }}"
      - "{{ outputs.settings_after.suppressionsTotal == 1 }}"
      - "{{ outputs.settings_final.suppressionsTotal == 0 }}"

All nine tasks succeeded. The mock received the calls as the spec describes them: PUT /v2/security/settings/plan with the tier_coverage, POST /v2/security/scans/rules with the resource, POST /v2/security/settings/suppressions with the rule_uuid and resources, and the DELETE on the suppression ID returned by CreateSuppression. The report task logged 1 suppression(s): Droplet Backups Not Enabled on Droplet fe3a2fd7-903d-46e6-ada3-3e4f285fb89d; basic tier tags ["production"], and the Assert at the end checked 0, 1 and 0 suppressions before, after and once the suppression was lifted.

Before / after

Editor: the plugin before this PR rejects security.settings.Get, this branch validates the flow.

Before: the editor rejects security.settings.Get After: the flow validates

Screenshots

The new Security Settings group in the plugin docs.

Security Settings group in the plugin docs

The demo flow running end to end, and its logs.

Demo flow execution, all tasks succeeded Demo flow logs


Setup Instructions

A DigitalOcean API token in a DIGITALOCEAN_TOKEN secret, on an account with CSPM enabled, with the security:read scope for Get, security:update for UpdatePlan, security:create for CreateSuppression and CreateRule, and security:delete for DeleteSuppression.


Contributor Checklist ✅

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

@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 listed in #32 are present (security.settings.Get, UpdatePlan, CreateSuppression, DeleteSuppression, security.scan.CreateRule). Paths, methods, request bodies, response shapes and the per_page/page parameters match DigitalOcean's current OpenAPI spec. No build, dependency or CI changes.

Kestra Guidelines: 3 findings

  • 🟢 CreateRule.java:30 [Guidelines] Schema descriptions not in text blocks
  • 🟢 SuppressionPage.java:23 [Guidelines] Explicit local type where var works
  • 🟢 CreateSuppression.java:118 [Guidelines] Output count named differently from Get

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

✅ No issues found

Performance: 0 findings

✅ No issues found

Local check at f5c8659: the 5 new test classes ran, 21/21 passed. CI (Main, Security scan) is green.

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

Confidence: 97% (100 - 1 Nit - 1 Nit - 1 Nit)

@NoArgsConstructor
@Schema(
title = "Exclude a resource from DigitalOcean security scans",
description = "Creates a scan rule that excludes a resource from future security (CSPM) scans, e.g. to mark the " +

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.

🟢 [Guidelines] Schema descriptions not in text blocks
Problem: The new @Schema(description = ...) values use single-line strings or + concatenation, while the guidelines ask for """ text blocks for documentation; this applies to all new classes in this PR (Get, UpdatePlan, CreateSuppression, DeleteSuppression, TierCoverage).
Fix: Switch the descriptions to text blocks, e.g. description = """ followed by the text on its own lines. Optional, the existing classes in the repo use the same style.

.filter(Objects::nonNull)
.toList();
var meta = asMap(block.get("meta"));
long total = meta != null && meta.get("total") instanceof Number number ? number.longValue() : rows.size();

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.

🟢 [Guidelines] Explicit local type where var works
Problem: long total = ... declares an explicit type although the ternary already resolves to long, against the var for all locals rule.
Fix: var total = meta != null && meta.get("total") instanceof Number number ? number.longValue() : rows.size();

private final List<Map<String, Object>> suppressions;

@Schema(title = "Total suppressions", description = "Number of suppressions reported by the DigitalOcean API (meta.total).")
private final Long total;

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.

🟢 [Guidelines] Output count named differently from Get
Problem: The same meta.total value is exposed as total here and as suppressionsTotal on security.settings.Get, so a flow using both tasks has to remember two names for the same thing.
Fix: Rename to suppressionsTotal (and the builder call at line 103) so both tasks match.

@fdelbrayelle

Copy link
Copy Markdown
Member

QA report: plugin-digitalocean PR 43 (security settings, suppressions, scan rule)

Commit: f5c8659
Edition: OSS | Docker tag: kestra/kestra:v1.3.44 (PR kestraVersion 1.3.39 line, highest 1.3.x), then same JAR on kestra/kestra:v2.0.7 (latest 2.0.x)
Instance: http://localhost:8143 (container qa-do43-kestra, currently v2.0.7, left running; docker rm -f qa-do43-kestra qa-do43-mock to stop)
Screenshots: https://claude.ai/artifact/3Qg6qTya2Lw4ow5c6BRZba
Confidence: 100% (9 PASS of 9 scenarios, no deductions; mock API only, see limits)

Setup: shadow JAR built from the PR head (build files unchanged vs main, no qa/ folder, no Gradle test task run). DigitalOcean is replaced by a local Python HTTP mock that requires Authorization: Bearer fake-do-token-qa (fake token, no cloud, no secrets), records method, path, auth and body, and serves the response shapes of the DigitalOcean OpenAPI spec (settings wrapper with suppressions {resources, meta, links}, tier_coverage, plan_downgrades, create returning the suppression root, DELETE 204, scan rule 201). All flows set baseUrl to the mock.

Results

# Flow Task(s) Expected 1.3.44 2.0.7
1 get_defaults Get defaults per_page=200&page=1, outputs tierCoverage, planDowngrades, suppressions, suppressionsTotal PASS PASS
2 get_paged Get perPage=2 pages 1, 3, 4 send matching query, rows 2/2/0 PASS PASS
3 suppression_lifecycle CreateSuppression, DeleteSuppression, UpdatePlan, CreateRule correct method, path and JSON body; ids chained from create to delete PASS PASS
4 bad_token Get HTTP 401 mapped to a clear "invalid or missing API token" error PASS PASS
5 delete_missing DeleteSuppression HTTP 404 mapped to a clear "resource not found" error PASS PASS
6 per_page_invalid Get perPage: 201 rejected before any request PASS PASS
7 empty_resources CreateSuppression resources: [] rejected before any request PASS PASS
8 path_injection DeleteSuppression ../../v2/droplets/123?x=1 is percent-encoded inside one path segment PASS PASS
9 droplet_get_regression (non-regression) droplet.Get existing task still works PASS PASS

Flows 4 to 8 are negative scenarios: PASS means the task failed as intended.

Requests recorded by the mock (2.0.7 run)

GET    /v2/security/settings?per_page=200&page=1        auth ok
GET    /v2/security/settings?per_page=2&page=1|3|4      auth ok
POST   /v2/security/settings/suppressions               {"rule_uuid":"...","resources":["do:droplet:...","do:droplet:..."]}
DELETE /v2/security/settings/suppressions/<id>          auth ok
PUT    /v2/security/settings/plan                       {"tier_coverage":{"basic":{"resources":[...],"tags":["production"]},"advanced":{"resources":[],"tags":["staging"]}}}
POST   /v2/security/scans/rules                         {"resource":"do:droplet:..."}
GET    /v2/security/settings (wrong token)              auth rejected -> 401
DELETE /v2/security/settings/suppressions/..%2F..%2Fv2%2Fdroplets%2F123%3Fx%3D1

All requests carried Authorization: Bearer <token>. UpdatePlan sends an omitted list as [] (documented in the task).

Flow 3: suppression_lifecycle (SUCCESS, 0.55s on 1.3.44, 0.35s on 2.0.7)

Flow YAML
id: suppression_lifecycle
namespace: qa.do43
tasks:
  - id: suppress
    type: io.kestra.plugin.digitalocean.security.settings.CreateSuppression
    apiToken: fake-do-token-qa
    baseUrl: http://qa-do43-mock:8099
    ruleId: bbbbbbbb-0000-4000-8000-000000000009
    resources:
      - do:droplet:11111111-2222-4333-8444-555555555555
      - do:droplet:66666666-2222-4333-8444-555555555555
  - id: delete
    type: io.kestra.plugin.digitalocean.security.settings.DeleteSuppression
    apiToken: fake-do-token-qa
    baseUrl: http://qa-do43-mock:8099
    suppressionId: "{{ outputs.suppress.suppressions[0].id }}"
  - id: update_plan
    type: io.kestra.plugin.digitalocean.security.settings.UpdatePlan
    apiToken: fake-do-token-qa
    baseUrl: http://qa-do43-mock:8099
    tierCoverage:
      basic:
        tags: [production]
        resources: [do:droplet:fe3a2fd7-903d-46e6-ada3-3e4f285fb89d]
      advanced:
        tags: [staging]
  - id: rule
    type: io.kestra.plugin.digitalocean.security.scan.CreateRule
    apiToken: fake-do-token-qa
    baseUrl: http://qa-do43-mock:8099
    resource: do:droplet:fe3a2fd7-903d-46e6-ada3-3e4f285fb89d
  - id: log
    type: io.kestra.plugin.core.log.Log
    message: "created {{ outputs.suppress.suppressions | length }} total={{ outputs.suppress.total }} plan={{ outputs.update_plan.tierCoverage }}"

Gantt (1.3.44, 2.0.7)

Task Status
suppress SUCCESS
delete SUCCESS
update_plan SUCCESS
rule SUCCESS
log SUCCESS

Logs synthesis: "Suppressing ... on 2 resource(s)", "Removing ... suppression ", "Updating ... tier(s) [basic, advanced]", "Excluding do:droplet:... from DigitalOcean security scans".

Outputs synthesis: suppress returned 2 suppressions (id, rule_uuid, rule_name, resource_id, resource_type) and total: 2; update_plan returned the applied tierCoverage; delete and rule have no output.

Flow 2: get_paged (SUCCESS)

Flow YAML
id: get_paged
namespace: qa.do43
tasks:
  - id: p1
    type: io.kestra.plugin.digitalocean.security.settings.Get
    apiToken: fake-do-token-qa
    baseUrl: http://qa-do43-mock:8099
    perPage: 2
    page: 1
  - id: p3   # same task, page: 3
  - id: p4   # same task, page: 4
  - id: log
    type: io.kestra.plugin.core.log.Log
    message: "p1={{ outputs.p1.suppressions | length }} p3={{ outputs.p3.suppressions | length }} p4={{ outputs.p4.suppressions | length }} total={{ outputs.p1.suppressionsTotal }}"

(p3 and p4 repeat the p1 block with page changed.)

Logs (1.3.44, 2.0.7): "Read 2 of 5 suppression(s) on page 1", page 3 returns 2 rows, page 4 returns 0 rows. On 1.3.44 the totals shown (5, 7, 6) differ between pages only because the mock state was being changed by flow 3 running at the same time. That is a mock artifact, not a plugin issue; on 2.0.7 the runs were sequential and consistent.

Flow 1: get_defaults (outputs)

SUCCESS. Output keys: tierCoverage, planDowngrades, suppressions, suppressionsTotal. Log: "Read 6 of 6 suppression(s) on page 1".

Flows 4 to 8 (negative)

  • bad_token (logs): FAILED with "DigitalOcean API returned HTTP 401: invalid or missing API token. Create a personal access token ...". The token value is not logged.
  • delete_missing (logs): FAILED with "HTTP 404: resource not found. Verify baseUrl ... and the id used in the request are correct".
  • per_page_invalid: FAILED with "perPage must be between 1 and 200, got 201", mock saw no request.
  • empty_resources: FAILED with "resources needs at least one resource URN", mock saw no request.
  • path_injection: the id was sent as one encoded segment (..%2F..%2Fv2%2Fdroplets%2F123%3Fx%3D1), mock returned 404, no traversal to /v2/droplets/123.

Flow 9: droplet_get_regression (SUCCESS, gantt)

droplet.Get returned id: 123, name: web-1, status: active, region: nyc3, sizeSlug: s-1vcpu-1gb.

Findings

Introduced by this PR: none found at any severity.

Pre-existing: none observed.

Observation (LOW, informational, not a defect): on a 4xx the task logs the failing response at ERROR and a TRACE stack trace; the user-facing message is clear.

Not testable / limits

  • NOT TESTABLE: behavior against the real DigitalOcean API (needs a real account and token). Real paging semantics, real rule UUIDs, the real 201 body of POST /v2/security/scans/rules, rate limit (429) handling and security:* scope errors (403) were not exercised. Request and response shapes follow the published OpenAPI spec as read from the digitalocean/openapi repository.
  • Topology/plugin artifact views: out of scope (no custom UI in this change).
  • Timeouts: none, every execution finished in under 1s.
  • Unit tests were not run (skill forbids Gradle test tasks; CI is green).

@fdelbrayelle
fdelbrayelle merged commit 471fbee into kestra-io:main Oct 27, 2026
4 checks passed
@github-project-automation github-project-automation Bot moved this from To review to Done in Pull Requests Oct 27, 2026
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 settings and suppression tasks (part of #10)

2 participants