[improve][offload] Support credentials from offload policies for S3 and Aliyun OSS drivers - #26232
Conversation
…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
left a comment
There was a problem hiding this comment.
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:
-
CLI gap for
aliyun-oss(pre-existing):OffloadPoliciesImpl.create(driver, …)— the path used bypulsar-admin namespaces/topics set-offload-policies— only copiescredentialId/credentialSecretinto the s3-prefixed fields when the driver isS3oraws-s3. For-d aliyun-ossthe CLI silently drops the credentials before they reach the offloader, so this fix is only reachable for Aliyun viabroker.confor a policies object set through the admin API. Worth a follow-up extending the driver check increate()(andisS3Driver()). The new code comment ("…carry credentials under the s3-prefixed keys for every S3-compatible driver") slightly overstates the current CLI behavior. -
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
IllegalArgumentExceptioninstead 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 inbroker.confwould 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.
|
@lhotari thanks for the review! Addressed observation #1 in 164fb6f: 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
164fb6f to
7941ebd
Compare
…nd Aliyun OSS drivers (apache#26232) Co-authored-by: Claude Fable 5 <noreply@anthropic.com> (cherry picked from commit a965f5f)
…nd Aliyun OSS drivers (apache#26232) Co-authored-by: Claude Fable 5 <noreply@anthropic.com> (cherry picked from commit a965f5f)
…nd Aliyun OSS drivers (apache#26232) Co-authored-by: Claude Fable 5 <noreply@anthropic.com> (cherry picked from commit a965f5f)
Motivation
The
S3andaliyun-ossoffload drivers resolve credentials exclusively from theACCESS_KEY_ID/ACCESS_KEY_SECRET(orALIYUN_OSS_ACCESS_KEY_ID/ALIYUN_OSS_ACCESS_KEY_SECRET) environment variables, and throw if they are absent.However,
OffloadPoliciesImplcarries thes3ManagedLedgerOffloadCredentialId/s3ManagedLedgerOffloadCredentialSecretproperties for every S3-compatible driver — set either inbroker.confor per namespace/topic viaset-offload-policies— andS3_CREDENTIAL_BUILDERsilently 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-s3driver already resolves these same configuration properties first (inAWS_CREDENTIAL_BUILDER); this change aligns theS3andaliyun-ossdrivers with that behavior.Modifications
In
JCloudBlobStoreProvider.S3_CREDENTIAL_BUILDER(shared by theS3andALIYUN_OSSproviders):s3ManagedLedgerOffloadCredentialIdands3ManagedLedgerOffloadCredentialSecretare present and non-blank in the tiered storage configuration, use them (they take precedence over the environment variables).IllegalArgumentExceptionnaming both keys, instead of silently ignoring the partial pair and failing later with a misleading env-var error.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:
s3CredentialsFromConfigTestandaliyunOssCredentialsFromConfigTestverifying that a credential pair supplied via the configuration is used to build the provider credentials for theS3andaliyun-ossdrivers.s3PartialCredentialsFromConfigTestverifying that supplying only one of the two keys fails fast with a clear message.JCloudBlobStoreProviderTestvalidation 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
Behavior change for
S3/aliyun-ossdeployments that haves3ManagedLedgerOffloadCredentialId/Secretset 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