-
Notifications
You must be signed in to change notification settings - Fork 321
feat: vendor-pluggable S3 credentials for native scans #4309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mbutrovich
wants to merge
37
commits into
apache:main
Choose a base branch
from
mbutrovich:credential_provider
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
e877e7e
cloud credential provider JVM side
mbutrovich 892697b
cloud credential provider native side
mbutrovich 67b6f9b
hook up iceberg-rust, had to bump iceberg-rust
mbutrovich 22e30b0
docs
mbutrovich 58b1364
tests
mbutrovich 858f901
cleanup
mbutrovich 92b0416
cleanup
mbutrovich 2da7184
Merge branch 'main' into credential_provider
mbutrovich 4d03053
fix native test failure in CI
mbutrovich a8cbe8e
update contributor guide about multiple providers
mbutrovich 9d07ff0
add access mode to the SPI since a provider might have different cred…
mbutrovich 9b1e622
clean up iceberg path discrepancy
mbutrovich 08afb7d
run prettier on the docs
mbutrovich 0cd8a36
Merge branch 'main' into credential_provider
mbutrovich d9596de
cleanup to get ready for review
mbutrovich 7050069
Merge branch 'main' into credential_provider
mbutrovich de5d5c2
Replaced the ServiceLoader-based S3 credential SPI with config-driven…
mbutrovich 17825c0
Cleanup.
mbutrovich cc2648a
Merge branch 'main' into credential_provider
mbutrovich d806ef6
try to incorporate changes from #4335 and add IcebergRESTVendedS3Prov…
mbutrovich 581739e
Merge branch 'main' into credential_provider
mbutrovich c5a4a72
Merge branch 'main' into credential_provider
mbutrovich 8551aca
change IcebergRESTVendedS3Provider and its test to Spark 4.0+
mbutrovich 55c3b6d
Merge branch 'main' into credential_provider
mbutrovich 9f58cb0
Update file structure after #4325.
mbutrovich 176ff52
Merge branch 'main' into credential_provider
mbutrovich 0c13ae6
Merge branch 'main' into credential_provider
mbutrovich 5853dff
Update docs, add contributor guide page about credential provider.
mbutrovich c776613
fix format
mbutrovich 6738ca0
rename docs
mbutrovich b85d645
Merge branch 'main' into credential_provider
mbutrovich 1895a17
Address PR feedback.
mbutrovich e37d61e
Clean up docs trying to get line count on the diff down.
mbutrovich f08805e
fix format.
mbutrovich 6b0c853
Address PR feedback.
mbutrovich 43d5d45
Merge branch 'main' into credential_provider
mbutrovich acd6cdb
Merge branch 'main' into credential_provider
mbutrovich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
common/src/main/java/org/apache/comet/cloud/CometAccessMode.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.comet.cloud; | ||
|
|
||
| /** | ||
| * Access intent for a credential request issued by Comet's native code, passed to {@link | ||
| * CometCloudCredentialProvider#getCredentialsForPath}. | ||
| * | ||
| * <p>Granularity is intentionally binary. Vendors that issue WRITE-scoped credentials are expected | ||
| * to include READ permissions when their workflows require it (multipart-completion HEAD, Iceberg | ||
| * manifest reads on the write path, etc.) — the SPI does not promise that a WRITE credential is | ||
| * also read-capable; the vendor's IAM policy does. | ||
| */ | ||
| public enum CometAccessMode { | ||
| /** GET / HEAD / LIST and equivalent. All Comet native scan paths request this today. */ | ||
| READ, | ||
| /** PUT / POST / DELETE / multipart and equivalent. Reserved for future native write paths. */ | ||
| WRITE | ||
| } |
176 changes: 176 additions & 0 deletions
176
common/src/main/java/org/apache/comet/cloud/CometCloudCredentialDispatcher.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.comet.cloud; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.ServiceLoader; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| // spotless:off | ||
| /* | ||
| * Architecture Overview: | ||
| * | ||
| * JVM Side | Native Side | ||
| * ┌──────────────────────────────────────────┐ | ┌──────────────────────────────────────────┐ | ||
| * │ CometCloudCredentialDispatcher │ | │ S3 Object Reading │ | ||
| * │ │ | │ │ | ||
| * │ ┌────────────────────────────────────┐ │ | │ ┌────────────────────────────────────┐ │ | ||
| * │ │ ServiceLoader discovery: │ │ | │ │ DataFusion iceberg-rust │ │ | ||
| * │ │ META-INF/services/ │ │ | │ │ object_store opendal │ │ | ||
| * │ │ o.a.c.cloud.CometCloudCred... │ │ | │ └────────────────────────────────────┘ │ | ||
| * │ └────────────────────────────────────┘ │ | │ │ │ │ | ||
| * │ │ │ | │ ▼ ▼ │ | ||
| * │ ▼ │ | │ ┌────────────────────────────────────┐ │ | ||
| * │ ┌────────────────────────────────────┐ │ | │ │ CometCredentialBridge (Rust) │ │ | ||
| * │ │ CometCloudCredentialProvider │ │ | │ │ impl object_store:: │ │ | ||
| * │ │ (single instance, cached) │ │ | │ │ CredentialProvider │ │ | ||
| * │ └────────────────────────────────────┘ │ | │ │ impl reqsign_core:: │ │ | ||
| * │ │ │ | │ │ ProvideCredential │ │ | ||
| * │ ▼ │ | │ └────────────────────────────────────┘ │ | ||
| * │ ┌────────────────────────────────────┐ │ | │ │ │ | ||
| * │ │ .getCredentialsForPath(...) │◄─┼───────┼─────┼──╗ ▼ │ | ||
| * │ └────────────────────────────────────┘ │ | │ ╔════════════════════════════════════╗ │ | ||
| * │ │ │ | │ ║ JNI CALL: ║ │ | ||
| * │ ▼ │ | │ ║ getCredentialsForPath( ║ │ | ||
| * │ ┌────────────────────────────────────┐ │ | │ ║ bucket, path, mode) ║ │ | ||
| * │ │ return CometCredentials POJO │──┼───────┼─────┼─►║ ║ │ | ||
| * │ │ (access key, secret, token, │ │ | │ ╚════════════════════════════════════╝ │ | ||
| * │ │ region, expiration) │ │ | │ │ │ | ||
| * │ └────────────────────────────────────┘ │ | │ ▼ │ | ||
| * │ │ | │ ┌────────────────────────────────────┐ │ | ||
| * │ │ | │ │ AwsCredential │ │ | ||
| * │ │ | │ │ used to sign S3 requests │ │ | ||
| * │ │ | │ └────────────────────────────────────┘ │ | ||
| * └──────────────────────────────────────────┘ | └──────────────────────────────────────────┘ | ||
| * | | ||
| * JNI Boundary | ||
| * | ||
| * Setup Phase (one-time per executor): | ||
| * 1. Vendor JAR ships an impl of CometCloudCredentialProvider via META-INF/services. | ||
| * 2. CometCloudCredentialDispatcher resolves it via ServiceLoader on first class-load. | ||
| * 3. Native side caches dispatcher class + static method ID in OnceCell. | ||
| * | ||
| * Runtime Phase (per S3 request): | ||
| * 4. object_store / opendal calls its async credential trait on CometCredentialBridge. | ||
| * 5. Bridge enters JNI, invokes dispatcher.getCredentialsForPath(bucket, path, mode). | ||
| * 6. Provider returns a CometCredentials POJO; vendor may call its own STS / authorization service. | ||
| * 7. Rust reads fields via JNI accessors, returns AwsCredential for request signing. | ||
| */ | ||
| // spotless:on | ||
|
|
||
| /** | ||
| * Static entry point invoked from Comet's native code (via JNI) to fetch AWS credentials for an S3 | ||
| * request. | ||
| * | ||
| * <p>Resolution rules at first class-load: | ||
| * | ||
| * <ul> | ||
| * <li>Zero impls registered via {@code ServiceLoader} → {@link #isProviderRegistered()} returns | ||
| * false; native callers fall through to the existing AWS credential chain. | ||
| * <li>Exactly one impl registered → cached and used for every credential request. | ||
| * <li>Multiple impls registered → throws {@link IllegalStateException} at class-load, failing the | ||
| * executor loudly. Operators should remove all but one bridge jar. | ||
| * </ul> | ||
| * | ||
| * <p>Discovery is via classpath only; there is no Comet-specific config knob for selecting a | ||
| * provider. This keeps the credentials Comet uses identical to whatever the same JVM would use if a | ||
| * query fell back to Spark execution mid-flight. | ||
| */ | ||
| public final class CometCloudCredentialDispatcher { | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(CometCloudCredentialDispatcher.class); | ||
|
|
||
| /* | ||
| * Process-lifetime singleton, justified per the contributor guide's "Global singletons" | ||
| * section. | ||
| * | ||
| * Why static is the right lifetime: ServiceLoader discovers the impl from the executor | ||
| * classpath, which is fixed once Spark has launched the JVM. The same instance must serve | ||
| * every credential request from native code so that a query falling back from Comet to | ||
| * Spark mid-execution sees identical credentials. | ||
| * | ||
| * Bounded: a single reference, not a cache. | ||
| * | ||
| * Credential refresh: this dispatcher does NOT cache credentials. Each call to | ||
| * getCredentialsForPath delegates straight to the provider, which is responsible for any | ||
| * STS / token refresh logic. Stale-credential failure modes therefore live in the provider | ||
| * impl, not here. | ||
| */ | ||
| private static final CometCloudCredentialProvider PROVIDER = resolve(); | ||
|
|
||
| private CometCloudCredentialDispatcher() {} | ||
|
|
||
| public static boolean isProviderRegistered() { | ||
| return PROVIDER != null; | ||
| } | ||
|
|
||
| /** | ||
| * Invoked by native code via JNI. Delegates to the registered provider. | ||
| * | ||
| * <p>{@code mode} is passed as a {@code String} (the {@link CometAccessMode} name) rather than | ||
| * the enum itself to keep the JNI signature trivial — Rust passes a Java string, this method | ||
| * parses to the enum and forwards. | ||
| * | ||
| * @throws IllegalStateException if no provider is registered (callers should check {@link | ||
| * #isProviderRegistered()} first) | ||
| * @throws IllegalArgumentException if {@code mode} is not a recognized {@link CometAccessMode} | ||
| * name | ||
| */ | ||
| public static CometCredentials getCredentialsForPath(String bucket, String path, String mode) | ||
| throws Exception { | ||
| if (PROVIDER == null) { | ||
| throw new IllegalStateException( | ||
| "No CometCloudCredentialProvider registered; check META-INF/services on the classpath"); | ||
| } | ||
| CometAccessMode accessMode = CometAccessMode.valueOf(mode); | ||
| if (LOG.isDebugEnabled()) { | ||
| LOG.debug("Fetching credentials for bucket={} path={} mode={}", bucket, path, accessMode); | ||
| } | ||
| return PROVIDER.getCredentialsForPath(bucket, path, accessMode); | ||
| } | ||
|
|
||
| private static CometCloudCredentialProvider resolve() { | ||
| List<CometCloudCredentialProvider> impls = new ArrayList<>(); | ||
| for (CometCloudCredentialProvider impl : | ||
| ServiceLoader.load(CometCloudCredentialProvider.class)) { | ||
| impls.add(impl); | ||
| } | ||
| if (impls.isEmpty()) { | ||
| LOG.info( | ||
| "No CometCloudCredentialProvider registered; native S3 readers will use the default " | ||
| + "AWS credential chain"); | ||
| return null; | ||
| } | ||
| if (impls.size() > 1) { | ||
| List<String> names = | ||
| impls.stream().map(p -> p.getClass().getName()).collect(Collectors.toList()); | ||
| LOG.error("Multiple CometCloudCredentialProvider impls on classpath: {}", names); | ||
| throw new IllegalStateException( | ||
| "Multiple CometCloudCredentialProvider impls on classpath: " + names); | ||
| } | ||
| CometCloudCredentialProvider provider = impls.get(0); | ||
| LOG.info("Registered CometCloudCredentialProvider: {}", provider.getClass().getName()); | ||
| return provider; | ||
| } | ||
| } | ||
56 changes: 56 additions & 0 deletions
56
common/src/main/java/org/apache/comet/cloud/CometCloudCredentialProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.comet.cloud; | ||
|
|
||
| /** | ||
| * SPI for supplying AWS credentials to Comet's native S3 readers. | ||
| * | ||
| * <p>Comet's native scan paths ({@code object_store} for raw Parquet, {@code opendal} via {@code | ||
| * iceberg-rust} for Iceberg) bypass Spark's Hadoop S3A code path. The standard {@code | ||
| * AWSCredentialsProvider.getCredentials()} contract has no path argument, so vendors that issue | ||
| * per-path STS credentials cannot expose them through that interface. This SPI fills the gap. | ||
| * | ||
| * <p>Vendors register an implementation via {@code | ||
| * META-INF/services/org.apache.comet.cloud.CometCloudCredentialProvider}. Comet discovers it at | ||
| * executor startup and routes every per-request credential fetch through it. | ||
| * | ||
| * <p>Implementations must be thread-safe; {@link #getCredentialsForPath} may be invoked | ||
| * concurrently from many native tokio tasks. | ||
| * | ||
| * <p>Contract: returns credentials or throws. There is no "fall through to the default chain" | ||
| * return value; if a provider is registered, it is responsible for every credential fetch on the | ||
| * paths it sees. See the contributor guide section on cloud credential providers for the rationale | ||
| * and patterns for vendors that need to defer to a default credential chain on a subset of paths. | ||
| */ | ||
| public interface CometCloudCredentialProvider { | ||
|
|
||
| /** | ||
| * Returns credentials usable to sign an S3 request for the given path. | ||
| * | ||
| * @param bucket the S3 bucket name (no scheme, no path) | ||
| * @param path the object key or prefix being accessed; the URL path of the store, leading slash | ||
| * included | ||
| * @param mode the access intent for this credential request | ||
| * @return non-null credentials | ||
| * @throws Exception any failure surfaces to the native caller and aborts the request | ||
| */ | ||
| CometCredentials getCredentialsForPath(String bucket, String path, CometAccessMode mode) | ||
| throws Exception; | ||
| } |
74 changes: 74 additions & 0 deletions
74
common/src/main/java/org/apache/comet/cloud/CometCredentials.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.comet.cloud; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Credentials returned by a {@link CometCloudCredentialProvider}, consumed by Comet's native code | ||
| * via JNI field accessors. | ||
| * | ||
| * <p>{@code sessionToken} is null for non-STS credentials; {@code region} is null when the provider | ||
| * has no opinion (the native side falls back to its configured region). {@code | ||
| * expirationEpochMillis} is {@code 0} when the provider does not track expiration; in that case | ||
| * Comet will not pre-emptively refresh and relies on the provider to return fresh credentials on | ||
| * each call. | ||
| */ | ||
| public final class CometCredentials { | ||
|
|
||
| private final String accessKeyId; | ||
| private final String secretAccessKey; | ||
| private final String sessionToken; | ||
| private final String region; | ||
| private final long expirationEpochMillis; | ||
|
|
||
| public CometCredentials( | ||
| String accessKeyId, | ||
| String secretAccessKey, | ||
| String sessionToken, | ||
| String region, | ||
| long expirationEpochMillis) { | ||
| this.accessKeyId = Objects.requireNonNull(accessKeyId, "accessKeyId"); | ||
| this.secretAccessKey = Objects.requireNonNull(secretAccessKey, "secretAccessKey"); | ||
| this.sessionToken = sessionToken; | ||
| this.region = region; | ||
| this.expirationEpochMillis = expirationEpochMillis; | ||
| } | ||
|
|
||
| public String getAccessKeyId() { | ||
| return accessKeyId; | ||
| } | ||
|
|
||
| public String getSecretAccessKey() { | ||
| return secretAccessKey; | ||
| } | ||
|
|
||
| public String getSessionToken() { | ||
| return sessionToken; | ||
| } | ||
|
|
||
| public String getRegion() { | ||
| return region; | ||
| } | ||
|
|
||
| public long getExpirationEpochMillis() { | ||
| return expirationEpochMillis; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.