Repository navigation
fix(http): preserve bearer token when options are set - #29
Conversation
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
jymaire
left a comment
There was a problem hiding this comment.
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.
QA report: plugin-digitalocean #29 (head
|
| 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"| 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 }}"| 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: PT1SGantt (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: PT10SGantt (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| 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_HEADERSGantt (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 nyc3andweb-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=200poll carried Bearer: 5 logged on 1.3.42 and 31 on 2.0.5. With the base JAR on 1.3.42, every poll sentBasic 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
optionssends 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_optionstrigger on the instance that was left running will log connection errors from now on. That is expected.
jymaire
left a comment
There was a problem hiding this comment.
All good for me, thanks for the contribution!
What changes are being made and why?
DigitalOcean tasks and
droplet.Triggercopied HTTPoptionswithtoBuilder()before building the client. On Kestra 1.3 that call installs basic authnull:null, so the request sendsAuthorization: Basicinstead ofBearer <apiToken>and DigitalOcean returns HTTP 401 wheneveroptionsis set.AbstractDigitalOceanTasknow passesoptionsthrough unchanged when it is set, and builds an emptyHttpConfigurationotherwise.request(),fetchAllPages()(used by every list task anddroplet.Trigger), and the droplet create activation poll all use that path. Timeouts, proxy, and the other client settings are unchanged. Every request still sendsAuthorization: Bearer <apiToken>.close #21
How the changes have been QAed?
WireMock tests in
volume.GetTest,droplet.ListTest, anddroplet.CreateTestrun those tasks withoptions.timeout.readIdleTimeoutset and assert that the request carries onlyAuthorization: Bearer <token>.volume.GetTestalso sets a 500ms read idle timeout against a delayed response and asserts the call fails withSocketTimeoutException, so the timeout fromoptionsis still applied.DIGITALOCEAN_TOKENis a DigitalOcean personal access token.volumeIdis an existing volume.optionsis set on purpose. The task should succeed. Before this fix it failed with HTTP 401.Setup Instructions
DIGITALOCEAN_TOKENcontaining a personal access token (prefixeddop_v1_) from the DigitalOcean control panel under API > Tokens.volumeIdwith a volume that exists on that account.Contributor Checklist ✅