Skip to content

fix(http): preserve bearer token when options are set - #29

Merged
jymaire merged 2 commits into
kestra-io:mainfrom
NaomiiAP:fix/options-bearer-auth
Oct 13, 2026
Merged

jymaire merged 2 commits into
kestra-io:mainfrom
NaomiiAP:fix/options-bearer-auth

Conversation

@NaomiiAP

@NaomiiAP NaomiiAP commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

What changes are being made and why?

DigitalOcean tasks and droplet.Trigger copied HTTP options with toBuilder() before building the client. On Kestra 1.3 that call installs basic auth null:null, so the request sends Authorization: Basic instead of Bearer <apiToken> and DigitalOcean returns HTTP 401 whenever options is set.

AbstractDigitalOceanTask now passes options through unchanged when it is set, and builds an empty HttpConfiguration otherwise. request(), fetchAllPages() (used by every list task and droplet.Trigger), and the droplet create activation poll all use that path. Timeouts, proxy, and the other client settings are unchanged. Every request still sends Authorization: Bearer <apiToken>.

close #21


How the changes have been QAed?

WireMock tests in volume.GetTest, droplet.ListTest, and droplet.CreateTest run those tasks with options.timeout.readIdleTimeout set and assert that the request carries only Authorization: Bearer <token>. volume.GetTest also sets a 500ms read idle timeout against a delayed response and asserts the call fails with SocketTimeoutException, so the timeout from options is still applied.

id: do_options_auth
namespace: company.team

tasks:
  - id: get_volume
    type: io.kestra.plugin.digitalocean.volume.Get
    apiToken: "{{ secret('DIGITALOCEAN_TOKEN') }}"
    volumeId: "<existing-volume-id>"
    options:
      timeout:
        readIdleTimeout: PT5S

DIGITALOCEAN_TOKEN is a DigitalOcean personal access token. volumeId is an existing volume. options is set on purpose. The task should succeed. Before this fix it failed with HTTP 401.


Setup Instructions

  • Create a Kestra secret named DIGITALOCEAN_TOKEN containing a personal access token (prefixed dop_v1_) from the DigitalOcean control panel under API > Tokens.
  • The token needs permission to read the volume.
  • Replace volumeId with a volume that exists on that account.

Contributor Checklist ✅

Kestra 1.3 HttpConfiguration.toBuilder() installs basic auth null:null, so any task that sets options sends Basic instead of the API token.

Fixes kestra-io#21
@MilosPaunovic MilosPaunovic added the area/plugin Plugin-related issue or feature request label Oct 12, 2026
@MilosPaunovic
MilosPaunovic requested review from a team and jymaire October 12, 2026 07:43
@MilosPaunovic MilosPaunovic added the kind/external Pull requests raised by community contributors label Oct 12, 2026

@jymaire jymaire left a comment

Copy link
Copy Markdown
Contributor

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

Issue #21 asks that setting options only changes HTTP client settings and every request still sends Authorization: Bearer <apiToken>. Passing options through unchanged does that. I confirmed the root cause in core: on v1.3.39 HttpConfiguration still has the deprecated basicAuthUser/basicAuthPassword builder methods, which replace auth with a BasicAuthConfiguration holding null values, and Lombok's toBuilder() calls them. On v2.0.5 those fields and methods are gone, so toBuilder() no longer injects basic auth and 2.0 is unaffected. The fix is safe on both lines: HttpConfiguration.builder().build() and TimeoutConfiguration.builder().readIdleTimeout(Property) exist in both. Every HTTP path goes through clientConfiguration(options): request(), fetchAllPages() (list tasks and droplet.Trigger) and the droplet.Create activation poll. No toBuilder() is left in src/main. I ran volume.GetTest, droplet.ListTest and droplet.CreateTest on the PR head and all 19 pass. With src/main reverted to main, the new GetTest options tests fail, so the tests do reproduce the bug.

Kestra Guidelines — 1 finding

  • 🟢 src/main/java/io/kestra/plugin/digitalocean/AbstractDigitalOceanTask.java:112 [Guidelines] Javadoc longer than needed

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

✅ No issues found. The token is still set explicitly on every request and never logged or output. If a user sets options.auth, the explicit Authorization: Bearer header the plugin adds is the one that is sent. The PR changes nothing about proxy, redirect or TLS handling.

Performance — 0 findings

✅ No issues found. One client is still reused across pages and across the activation poll.

Verdict: APPROVE (recommendation only). I have no blocking findings, and the one nit is optional. I'd suggest a maintainer QA run on Kestra 1.3.x and 2.0.x with options set.

@NaomiiAP
NaomiiAP requested a review from jymaire October 12, 2026 10:29
@jymaire

jymaire commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

QA report: plugin-digitalocean #29 (head fd86932)

Edition: OSS | Docker tags: v1.3.42 (latest on the PR's kestraVersion=1.3.39 line) and v2.0.5 (latest 2.0.x)
Instance: container qa-digitalocean29-kestra on network qa-digitalocean29-net, Kestra 2.0.5 with the PR JAR, at http://127.0.0.1:50919 on the QA host. It is left running for manual review; stop it with docker rm -f qa-digitalocean29-kestra && docker network rm qa-digitalocean29-net.
Screenshots: https://claude.ai/artifact/MXZbTyYGvUuZNsn8PgLAfE

Result: ✅ PASS. With options set, every request the PR JAR sent carried exactly one Authorization: Bearer <apiToken> header, on 1.3.42 and on 2.0.5. That covers request(), fetchAllPages() (list tasks and droplet.Trigger), the droplet.Create activation poll and the non-JSON kubeconfig download. Requests without options behave as before. options.timeout is still applied: a 1s read timeout fails after 1s against an endpoint that answers after 5s.

Setup

  • I built the shadow JAR of the PR head. For comparison I also built one at the PR's base commit 188a292.
  • The DigitalOcean API is a stateful Python mock on the QA network, aliased api.digitalocean.com with port 443 closed, so nothing can reach the real API. Every flow sets baseUrl: http://api.digitalocean.com:8080. The mock logs the Authorization header(s) of each request and returns 401 unless it gets exactly one Bearer fake-qa-token header. It also delays one volume (slow-volume) by 5s, and it reports a created droplet as new on the first poll and active on the second.
  • The token is a fake value stored as the Kestra secret DIGITALOCEAN_TOKEN.
  • Real DigitalOcean: NOT TESTABLE (needs a real account).

Bug reproduction: base 188a292 vs PR fd86932

Scenario Base JAR on 1.3.42 PR JAR on 1.3.42 Base JAR on 2.0.5 PR JAR on 2.0.5
volume.Get with options.timeout ❌ FAILED, HTTP 401: sent Basic bnVsbDpudWxs (null:null) instead of Bearer ✅ Bearer ✅ Bearer ✅ Bearer
droplet.List (2 pages) with options ❌ 401, Basic null:null ✅ Bearer on both pages ✅ Bearer ✅ Bearer
droplet.Create with options ❌ 401 on the POST ✅ Bearer on POST and both polls not run ✅ Bearer
billing.GetBalance with options: {} ❌ 401 ✅ Bearer not run ✅ Bearer
droplet.Trigger with options (polls) ❌ every poll sent Basic null:null ✅ Bearer, fired for each new droplet not run ✅ Bearer, fired
volume.Get without options ✅ Bearer ✅ Bearer not run ✅ Bearer

Totals from the mock's request log with the PR JAR: 21/21 requests on 1.3.42 (flow runs plus 5 trigger polls) and 50/50 on 2.0.5 (flow runs, a second create run and 31 trigger polls) carried ["Bearer fake-qa-token"] and nothing else. As the code review said, 2.0 was not affected by the original bug.

Summary

# Flow 1.3.42 2.0.5 Checks
1 qa_volume_get_options (scenario from the PR body) ✅ SUCCESS ✅ SUCCESS Bearer sent with options.timeout set
2 qa_volume_get_default (plugin example) ✅ SUCCESS ✅ SUCCESS Default options unchanged
3 qa_droplet_create_options ✅ SUCCESS ✅ SUCCESS POST and activation polls send Bearer, ip output set
4 digitalocean_create_droplet (plugin example) ✅ SUCCESS ✅ SUCCESS Create without options, log_ip renders the IP
5 qa_droplet_list_paged_options ✅ SUCCESS ✅ SUCCESS Pagination with options, total 3
6 qa_timeout_slow_short ✅ FAILED as expected after 1.06s ✅ FAILED as expected after 1.05s readIdleTimeout: PT1S applied (SocketTimeoutException: Read timed out)
7 qa_timeout_slow_long ✅ SUCCESS in 5.05s ✅ SUCCESS in 5.06s Control: readIdleTimeout: PT10S
8 qa_other_options ✅ SUCCESS ✅ SUCCESS options: {}, followRedirects, defaultCharset, connectTimeout, kubeconfig (non-JSON)
9 qa_options_logs ✅ SUCCESS ✅ SUCCESS options.logs header logging: Bearer sent, token masked as Bearer ****** in the logs
10 qa_droplet_trigger_options ✅ fired twice ✅ fired Trigger polls with options send Bearer

Flow 1: qa_volume_get_options (✅ SUCCESS on 1.3.42 and 2.0.5)

Flow YAML
id: qa_volume_get_options
namespace: qa.digitalocean
description: PR body scenario - volume.Get with options.timeout set must still send the Bearer token.
tasks:
  - id: get_volume
    type: io.kestra.plugin.digitalocean.volume.Get
    apiToken: "{{ secret('DIGITALOCEAN_TOKEN') }}"
    baseUrl: http://api.digitalocean.com:8080
    volumeId: "3fa85f64-5717-4562-b3fc-2c963f66afa6"
    options:
      timeout:
        readIdleTimeout: PT5S
  - id: log_size
    type: io.kestra.plugin.core.log.Log
    message: "Volume {{ outputs.get_volume.name }} is {{ outputs.get_volume.sizeGigabytes }} GiB"

Gantt (1.3.42, 2.0.5)

Task 1.3.42 2.0.5
get_volume SUCCESS, 0.14s SUCCESS, 0.56s
log_size SUCCESS, 0.03s SUCCESS, 0.07s
Total SUCCESS, 0.36s SUCCESS, 0.79s

Logs synthesis: Fetching DigitalOcean volume 3fa85f64-…, then Volume data-01 is 100 GiB. The mock got a single request with Authorization: Bearer <token>. With the base JAR on 1.3.42 the same flow failed with DigitalOcean API returned HTTP 401: invalid or missing API token because the request carried Basic null:null.

Outputs synthesis (1.3.42, 2.0.5): id: 3fa85f64-5717-4562-b3fc-2c963f66afa6, name: data-01, region: nyc3, sizeGigabytes: 100, filesystemType: ext4.

Flow 2: qa_volume_get_default (✅ SUCCESS on 1.3.42 and 2.0.5)

Flow YAML
id: qa_volume_get_default
namespace: qa.digitalocean
description: Non-regression - plugin example for volume.Get, no options (default HTTP configuration).
tasks:
  - id: get_volume
    type: io.kestra.plugin.digitalocean.volume.Get
    apiToken: "{{ secret('DIGITALOCEAN_TOKEN') }}"
    baseUrl: http://api.digitalocean.com:8080
    volumeId: "3fa85f64-5717-4562-b3fc-2c963f66afa6"
  - id: log_size
    type: io.kestra.plugin.core.log.Log
    message: "Volume {{ outputs.get_volume.name }} is {{ outputs.get_volume.sizeGigabytes }} GiB"

Gantt (1.3.42, 2.0.5): get_volume SUCCESS (0.06s / 0.05s), log_size SUCCESS. Total 0.20s / 0.19s.

Logs synthesis: Volume data-01 is 100 GiB. One request, Bearer only. Without options, behaviour is unchanged.

Outputs synthesis: same values as flow 1.

Flow 3: qa_droplet_create_options (✅ SUCCESS on 1.3.42 and 2.0.5)

Flow YAML
id: qa_droplet_create_options
namespace: qa.digitalocean
description: droplet.Create with options set - POST and every activation poll must carry the Bearer token.
tasks:
  - id: create_droplet
    type: io.kestra.plugin.digitalocean.droplet.Create
    apiToken: "{{ secret('DIGITALOCEAN_TOKEN') }}"
    baseUrl: http://api.digitalocean.com:8080
    name: "web-options"
    region: "nyc3"
    size: "s-1vcpu-1gb"
    image: "ubuntu-22-04-x64"
    tags:
      - "web"
    pollInterval: PT1S
    waitTimeout: PT20S
    options:
      timeout:
        connectTimeout: PT5S
        readIdleTimeout: PT10S
  - id: log_ip
    type: io.kestra.plugin.core.log.Log
    message: "Droplet is up at {{ outputs.create_droplet.ip }}"

Gantt (1.3.42, 2.0.5)

Task 1.3.42 2.0.5
create_droplet SUCCESS, 1.10s SUCCESS, 1.08s
log_ip SUCCESS, 0.02s SUCCESS, 0.02s
Total SUCCESS, 1.21s SUCCESS, 1.19s

Logs synthesis (1.3.42): Creating DigitalOcean droplet 'web-options' in nyc3, Waiting up to PT20S for droplet 900001 to become active, Droplet 900001 is active with IP 198.51.100.1, Droplet is up at 198.51.100.1. Mock log: POST /v2/droplets then GET /v2/droplets/900001 twice, all Bearer. The activation poll goes through clientConfiguration(options) too. With the base JAR the POST failed with 401.

Outputs synthesis (1.3.42, 2.0.5): id: 900001, name: web-options, status: active, region: nyc3, sizeSlug: s-1vcpu-1gb, ip: 198.51.100.1.

Flow 4: digitalocean_create_droplet (✅ SUCCESS on 1.3.42 and 2.0.5)

Flow YAML
id: digitalocean_create_droplet
namespace: company.team
tasks:
  - id: create_droplet
    type: io.kestra.plugin.digitalocean.droplet.Create
    apiToken: "{{ secret('DIGITALOCEAN_TOKEN') }}"
    baseUrl: http://api.digitalocean.com:8080
    name: "web-01"
    region: "nyc3"
    size: "s-1vcpu-1gb"
    image: "ubuntu-22-04-x64"
    pollInterval: PT1S
    tags:
      - "web"
  - id: log_ip
    type: io.kestra.plugin.core.log.Log
    message: "Droplet is up at {{ outputs.create_droplet.ip }}"

This is the plugin's droplet.Create example, plus baseUrl and pollInterval: PT1S to suit the mock.

Gantt (1.3.42, 2.0.5): create_droplet SUCCESS (1.07s / 1.04s), log_ip SUCCESS. Total 1.18s / 1.15s.

Logs synthesis: Droplet 900002 is active with IP 198.51.100.2, Droplet is up at 198.51.100.2. POST and 2 polls, all Bearer.

Outputs synthesis (1.3.42, 2.0.5): id: 900002, name: web-01, status: active, ip: 198.51.100.2.

Flow 5: qa_droplet_list_paged_options (✅ SUCCESS on 1.3.42 and 2.0.5)

Flow YAML
id: qa_droplet_list_paged_options
namespace: qa.digitalocean
description: droplet.List over several pages with options set - every page request must carry the Bearer token.
tasks:
  - id: list_droplets
    type: io.kestra.plugin.digitalocean.droplet.List
    apiToken: "{{ secret('DIGITALOCEAN_TOKEN') }}"
    baseUrl: http://api.digitalocean.com:8080
    perPage: 2
    options:
      timeout:
        readIdleTimeout: PT5S
  - id: log_total
    type: io.kestra.plugin.core.log.Log
    message: "Found {{ outputs.list_droplets.total }} droplet(s)"

Gantt (1.3.42, 2.0.5): list_droplets SUCCESS (0.11s / 0.09s), log_total SUCCESS. Total 0.22s / 0.21s.

Logs synthesis: Found 3 droplet(s). Mock log: GET /v2/droplets?per_page=2 then GET /v2/droplets?page=2&per_page=2, both Bearer, so the shared client in fetchAllPages keeps the token across pages.

Outputs synthesis (1.3.42, 2.0.5): total: 3, 3 rows (web-01, web-02, web-03).

Flow 6: qa_timeout_slow_short (✅ FAILED as expected on 1.3.42 and 2.0.5)

Flow YAML
id: qa_timeout_slow_short
namespace: qa.digitalocean
description: The mock answers this volume after 5s; readIdleTimeout PT1S must make the task fail after about 1s.
tasks:
  - id: get_slow_volume
    type: io.kestra.plugin.digitalocean.volume.Get
    apiToken: "{{ secret('DIGITALOCEAN_TOKEN') }}"
    baseUrl: http://api.digitalocean.com:8080
    volumeId: slow-volume
    options:
      timeout:
        readIdleTimeout: PT1S

Gantt (1.3.42, 2.0.5): get_slow_volume FAILED after 1.06s / 1.05s. The mock only answers after 5s.

Logs synthesis (2.0.5): Fetching DigitalOcean volume slow-volume, then ERROR java.net.SocketTimeoutException: Read timed out. The request still carried Bearer. The timeout from options is applied.

Outputs synthesis: none (task failed).

Flow 7: qa_timeout_slow_long (✅ SUCCESS on 1.3.42 and 2.0.5)

Flow YAML
id: qa_timeout_slow_long
namespace: qa.digitalocean
description: Control - same 5s endpoint with readIdleTimeout PT10S must succeed after about 5s.
tasks:
  - id: get_slow_volume
    type: io.kestra.plugin.digitalocean.volume.Get
    apiToken: "{{ secret('DIGITALOCEAN_TOKEN') }}"
    baseUrl: http://api.digitalocean.com:8080
    volumeId: slow-volume
    options:
      timeout:
        readIdleTimeout: PT10S

Gantt (1.3.42, 2.0.5): get_slow_volume SUCCESS in 5.05s / 5.06s. This is the control for flow 6: the 5s delay is real and a longer timeout lets it through.

Logs synthesis: Fetching DigitalOcean volume slow-volume, no warning.

Outputs synthesis: id: slow-volume, name: slow.

Flow 8: qa_other_options (✅ SUCCESS on 1.3.42 and 2.0.5)

Flow YAML
id: qa_other_options
namespace: qa.digitalocean
description: Other client options (empty object, followRedirects, defaultCharset, connectTimeout) on a JSON and a non-JSON endpoint.
tasks:
  - id: balance_empty_options
    type: io.kestra.plugin.digitalocean.billing.GetBalance
    apiToken: "{{ secret('DIGITALOCEAN_TOKEN') }}"
    baseUrl: http://api.digitalocean.com:8080
    options: {}
  - id: balance_misc_options
    type: io.kestra.plugin.digitalocean.billing.GetBalance
    apiToken: "{{ secret('DIGITALOCEAN_TOKEN') }}"
    baseUrl: http://api.digitalocean.com:8080
    options:
      followRedirects: false
      defaultCharset: UTF-8
      timeout:
        connectTimeout: PT3S
  - id: kubeconfig_options
    type: io.kestra.plugin.digitalocean.kubernetes.GetKubeconfig
    apiToken: "{{ secret('DIGITALOCEAN_TOKEN') }}"
    baseUrl: http://api.digitalocean.com:8080
    clusterId: "bd5f5959-5e1e-4205-a714-a914373942af"
    options:
      timeout:
        readIdleTimeout: PT5S

Gantt (1.3.42, 2.0.5)

Task 1.3.42 2.0.5
balance_empty_options SUCCESS, 0.06s SUCCESS, 0.06s
balance_misc_options SUCCESS, 0.05s SUCCESS, 0.05s
kubeconfig_options SUCCESS, 0.08s SUCCESS, 0.05s
Total SUCCESS, 0.30s SUCCESS, 0.32s

Logs synthesis: 3 requests, all Bearer. The kubeconfig call sends a non-JSON Accept header and goes through the same request() path. With the base JAR on 1.3.42, options: {} alone was enough to get a 401.

Outputs synthesis: balance monthToDateBalance: 23.44, accountBalance: 12.23, monthToDateUsage: 11.21. Kubeconfig uri: kestra:///qa/digitalocean/qa-other-options/executions/…/14882233955884139312.yaml.

Flow 9: qa_options_logs (✅ SUCCESS on 1.3.42 and 2.0.5)

Flow YAML
id: qa_options_logs
namespace: qa.digitalocean
description: options.logs set (request headers logging) - check the Bearer token is still sent.
tasks:
  - id: get_volume
    type: io.kestra.plugin.digitalocean.volume.Get
    apiToken: "{{ secret('DIGITALOCEAN_TOKEN') }}"
    baseUrl: http://api.digitalocean.com:8080
    volumeId: "3fa85f64-5717-4562-b3fc-2c963f66afa6"
    options:
      logs:
        - REQUEST_HEADERS
        - RESPONSE_HEADERS

Gantt (1.3.42, 2.0.5): get_volume SUCCESS (0.04s on both).

Logs synthesis (2.0.5, DEBUG level): the request headers logged at DEBUG show Authorization: Bearer ******, so the token is masked and the header is Bearer, not Basic. The same holds on 1.3.42.

Outputs synthesis: same values as flow 1.

Flow 10: qa_droplet_trigger_options (✅ fired on 1.3.42 and 2.0.5)

Flow YAML
id: qa_droplet_trigger_options
namespace: qa.digitalocean
description: droplet.Trigger with options set - every poll must carry the Bearer token and a new droplet must fire.
triggers:
  - id: on_new_droplet
    type: io.kestra.plugin.digitalocean.droplet.Trigger
    apiToken: "{{ secret('DIGITALOCEAN_TOKEN') }}"
    baseUrl: http://api.digitalocean.com:8080
    interval: PT10S
    options:
      timeout:
        readIdleTimeout: PT5S
tasks:
  - id: handle_new_droplet
    type: io.kestra.plugin.core.log.Log
    message: "New droplet: {{ trigger.name }} ({{ trigger.id }}) in {{ trigger.region }}"

Gantt (1.3.42, 2.0.5): handle_new_droplet SUCCESS.

Logs synthesis (1.3.42, 2.0.5):

  • On 1.3.42 the trigger fired once for each droplet created by flows 3 and 4: New droplet: web-options (900001) in nyc3 and web-01 (900002).
  • On 2.0.5 its first poll ran after flows 3 and 4, so the baseline already held those droplets. It fired for the next droplet created: New droplet: web-options (900003) in nyc3.
  • Every GET /v2/droplets?per_page=200 poll carried Bearer: 5 logged on 1.3.42 and 31 on 2.0.5. With the base JAR on 1.3.42, every poll sent Basic null:null.

Outputs synthesis: trigger variables id, name, region: nyc3, status: active, createdAt.

Notes

  • No new finding. The PR fixes the bug described in All DigitalOcean tasks: setting options sends Basic null:null auth and gets HTTP 401 on Kestra 1.3.x #21 on 1.3.x, and nothing changes on 2.0.x.
  • A read timeout surfaces as a raw java.net.SocketTimeoutException: Read timed out. HTTP errors get the plugin's rewritten message, but timeouts don't. This is the same before and after the PR and is outside its scope.
  • No scenario hit the 30s timeout rule.
  • The mock container has been removed. The qa_droplet_trigger_options trigger on the instance that was left running will log connection errors from now on. That is expected.

@jymaire jymaire left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All good for me, thanks for the contribution!

@jymaire
jymaire merged commit e172496 into kestra-io:main Oct 13, 2026
@github-project-automation github-project-automation Bot moved this from To review to Done in Pull Requests Oct 13, 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.

All DigitalOcean tasks: setting options sends Basic null:null auth and gets HTTP 401 on Kestra 1.3.x

3 participants