Skip to content

[improve][offload] Support credentials from offload policies for S3 and Aliyun OSS drivers - #26232

Merged
lhotari merged 2 commits into
apache:masterfrom
KannarFr:improve/s3-offload-config-credentials
Jul 25, 2026
Merged

[improve][offload] Support credentials from offload policies for S3 and Aliyun OSS drivers#26232
lhotari merged 2 commits into
apache:masterfrom
KannarFr:improve/s3-offload-config-credentials

Conversation

@KannarFr

Copy link
Copy Markdown
Contributor

Motivation

The S3 and aliyun-oss offload drivers resolve credentials exclusively from the ACCESS_KEY_ID/ACCESS_KEY_SECRET (or ALIYUN_OSS_ACCESS_KEY_ID/ALIYUN_OSS_ACCESS_KEY_SECRET) environment variables, and throw if they are absent.

However, OffloadPoliciesImpl carries the s3ManagedLedgerOffloadCredentialId/s3ManagedLedgerOffloadCredentialSecret properties for every S3-compatible driver — set either in broker.conf or per namespace/topic via set-offload-policies — and S3_CREDENTIAL_BUILDER silently ignores them. Credentials configured through offload policies therefore never take effect for these drivers, and multi-tenant setups where each namespace offloads to its own bucket with its own credentials cannot work: environment variables are global to the broker process.

The aws-s3 driver already resolves these same configuration properties first (in AWS_CREDENTIAL_BUILDER); this change aligns the S3 and aliyun-oss drivers with that behavior.

Modifications

In JCloudBlobStoreProvider.S3_CREDENTIAL_BUILDER (shared by the S3 and ALIYUN_OSS providers):

  • Return early if credentials are already set on the configuration.
  • If both s3ManagedLedgerOffloadCredentialId and s3ManagedLedgerOffloadCredentialSecret are present and non-blank in the tiered storage configuration, use them (they take precedence over the environment variables).
  • If exactly one of the pair is supplied, throw an IllegalArgumentException naming both keys, instead of silently ignoring the partial pair and failing later with a misleading env-var error.
  • Otherwise, fall back to the environment variables exactly as before (same lookup order, same error messages).

Blank/whitespace-only values are treated as absent rather than being accepted as credentials.

Verifying this change

This change added tests and can be verified as follows:

  • Added s3CredentialsFromConfigTest and aliyunOssCredentialsFromConfigTest verifying that a credential pair supplied via the configuration is used to build the provider credentials for the S3 and aliyun-oss drivers.
  • Added s3PartialCredentialsFromConfigTest verifying that supplying only one of the two keys fails fast with a clear message.
  • Existing JCloudBlobStoreProviderTest validation tests are unaffected (13/13 pass).

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Behavior change for S3/aliyun-oss deployments that have s3ManagedLedgerOffloadCredentialId/Secret set in their configuration while relying on environment variables: those configuration values were previously inert for these drivers and now take precedence. Deployments without these configuration keys keep the exact previous behavior. Additionally, a partial credential pair in the configuration now fails fast at credential-building time instead of being silently ignored.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Tu1LLcX9KGPhnZygeWRZXQ

…nd Aliyun OSS drivers

The S3 and aliyun-oss offload drivers only read credentials from the
ACCESS_KEY_ID/ACCESS_KEY_SECRET (or ALIYUN_OSS_*) environment variables,
ignoring the s3ManagedLedgerOffloadCredentialId/Secret properties that
OffloadPoliciesImpl carries for every S3-compatible driver. Credentials
set in broker.conf or in namespace/topic offload policies therefore never
took effect for these drivers.

S3_CREDENTIAL_BUILDER now uses the credential pair from the tiered
storage configuration when both keys are set (blank values are treated
as absent), throws a clear IllegalArgumentException when only one of the
pair is supplied, and otherwise falls back to the environment variables
unchanged.

Assisted-by: Claude Code (Claude Fable 5)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tu1LLcX9KGPhnZygeWRZXQ

@lhotari lhotari 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.

Reviewed with AI assistance: Claude Code (Claude Fable 5) combined with an OpenAI Codex (gpt-5.6-sol) review of the branch diff.

Overall: The implementation matches the stated intent and looks safe to merge. S3_CREDENTIAL_BUILDER (shared by S3 and aliyun-oss) now gives config-provided credentials the same precedence AWS_CREDENTIAL_BUILDER has always had for aws-s3, and the env-var fallback path is untouched. Verified the wiring: OffloadPoliciesImpl.toProperties() copies the s3-prefixed credential fields by name, so they do land in the TieredStorageConfiguration map for these drivers. Ran JCloudBlobStoreProviderTest locally: 13/13 pass. Codex's verdict: "The change correctly prioritizes complete configured credentials for S3-compatible drivers, rejects incomplete pairs, and preserves the existing environment-variable fallback. The added tests cover both affected drivers and partial configuration."

Two observations, neither blocking:

  1. CLI gap for aliyun-oss (pre-existing): OffloadPoliciesImpl.create(driver, …) — the path used by pulsar-admin namespaces/topics set-offload-policies — only copies credentialId/credentialSecret into the s3-prefixed fields when the driver is S3 or aws-s3. For -d aliyun-oss the CLI silently drops the credentials before they reach the offloader, so this fix is only reachable for Aliyun via broker.conf or a policies object set through the admin API. Worth a follow-up extending the driver check in create() (and isS3Driver()). The new code comment ("…carry credentials under the s3-prefixed keys for every S3-compatible driver") slightly overstates the current CLI behavior.

  2. Behavior change worth a release note: (a) deployments that set both credential keys in config while relying on env vars now use the config values; (b) a partial pair now fails fast with IllegalArgumentException instead of silently falling through to env vars. Both are disclosed in the PR description; flagging so it gets picked up for release notes, since operators with stale/partial keys in broker.conf would see a new failure at credential-build time.

Also checked: the static Credentials supplier is appropriate for fixed config values (matches the existing env-var path), the exception message names the keys but never the values, and the new tests are deterministic regardless of ACCESS_KEY_ID/ACCESS_KEY_SECRET being set in the environment.

@KannarFr

Copy link
Copy Markdown
Contributor Author

@lhotari thanks for the review! Addressed observation #1 in 164fb6f: OffloadPoliciesImpl.create(driver, …) (the set-offload-policies CLI path) now copies credentialId/credentialSecret into the s3-prefixed keys for aliyun-oss too — extended the driver check in both create() and isS3Driver() since aliyun-oss is S3-compatible (shares S3_CREDENTIAL_BUILDER and reads the s3ManagedLedgerOffload* keys). This also makes the code comment you flagged accurate and lets bucketValid() check the s3-prefixed bucket for aliyun-oss. Added testAliyunOssConfiguration covering it; checkstyle + OffloadPoliciesTest pass locally.

For observation #2, the behavior change is already noted in the PR description — flagging here so it gets picked up for release notes.

…a the admin CLI

Address PR review feedback: OffloadPoliciesImpl.create(driver, ...) — the path
used by `pulsar-admin namespaces/topics set-offload-policies` — only copied
credentialId/credentialSecret into the s3-prefixed fields for the `S3` and
`aws-s3` drivers. For `-d aliyun-oss` the CLI silently dropped the credentials
before they reached the offloader, so the new config-provided credential
support was only reachable for Aliyun via broker.conf or the admin API.

aliyun-oss is S3-compatible (shares S3_CREDENTIAL_BUILDER and reads the
s3ManagedLedgerOffload* keys), so extend the driver check in create() and
isS3Driver() to include it. This also makes bucketValid() consistently check
the s3-prefixed bucket for aliyun-oss.

Also refactor driver-name handling per review: introduce a named constant for
each built-in driver (DRIVER_S3, DRIVER_AWS_S3, DRIVER_GOOGLE_CLOUD_STORAGE,
DRIVER_FILESYSTEM, DRIVER_AZUREBLOB, DRIVER_ALIYUN_OSS), build
INTERNAL_SUPPORTED_DRIVER from them, and replace the index-based
DRIVER_NAMES.get(N) lookups in create(), isS3Driver(), isGcsDriver() and
isFileSystemDriver() with the constants.

Assisted-by: Claude Code (Claude Opus 4.8 (1M context))
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SFGLyfqZmcYZgWkBV5MkFs
@KannarFr
KannarFr force-pushed the improve/s3-offload-config-credentials branch from 164fb6f to 7941ebd Compare July 24, 2026 10:03
@lhotari lhotari added this to the 5.0.0-M2 milestone Jul 24, 2026
@lhotari
lhotari merged commit a965f5f into apache:master Jul 25, 2026
43 checks passed
lhotari pushed a commit that referenced this pull request Jul 25, 2026
…nd Aliyun OSS drivers (#26232)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit a965f5f)
lhotari pushed a commit that referenced this pull request Jul 25, 2026
…nd Aliyun OSS drivers (#26232)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit a965f5f)
sandeep-ctds pushed a commit to datastax/pulsar that referenced this pull request Jul 31, 2026
…nd Aliyun OSS drivers (apache#26232)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit a965f5f)
sandeep-ctds pushed a commit to datastax/pulsar that referenced this pull request Jul 31, 2026
…nd Aliyun OSS drivers (apache#26232)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit a965f5f)
sandeep-ctds pushed a commit to datastax/pulsar that referenced this pull request Jul 31, 2026
…nd Aliyun OSS drivers (apache#26232)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
(cherry picked from commit a965f5f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants