-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat(kinesis) Cross-account Kinesis source support via STS assume-role in JsonKinesisSource #19383
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
suryadanny
wants to merge
1
commit into
apache:master
Choose a base branch
from
suryadanny:ENG-45358-cross-account-kinesis
base: master
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 all commits
Commits
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
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
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -76,6 +76,17 @@ public class KinesisSourceConfig extends HoodieConfig { | |||||
| .withDocumentation("AWS secret key for Kinesis. Used when connecting to custom endpoints (e.g., LocalStack). " | ||||||
| + "If not set with endpoint, uses the default AWS credential chain."); | ||||||
|
|
||||||
| public static final ConfigProperty<String> KINESIS_ROLE_ARN = ConfigProperty | ||||||
| .key(PREFIX + "role.arn") | ||||||
| .noDefaultValue() | ||||||
| .sinceVersion("1.2.0") | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| .markAdvanced() | ||||||
| .withDocumentation("IAM role ARN to assume (via STS) when the Kinesis stream lives in a different " | ||||||
| + "AWS account than the application. When set, the Kinesis client uses an auto-refreshing " | ||||||
| + "StsAssumeRoleCredentialsProvider whose base credentials come from the default credential chain. " | ||||||
| + "When empty/absent, the stream is read from the application's own AWS account using the default " | ||||||
| + "credential chain (legacy behavior). No external ID is used."); | ||||||
|
|
||||||
| public static final ConfigProperty<Long> MAX_EVENTS_FROM_KINESIS_SOURCE = ConfigProperty | ||||||
| .key(PREFIX + "max.events") | ||||||
| .defaultValue(5000000L) | ||||||
|
|
||||||
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
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
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
73 changes: 73 additions & 0 deletions
73
...s/src/test/java/org/apache/hudi/utilities/sources/helpers/TestKinesisOffsetGenClient.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,73 @@ | ||
| /* | ||
| * 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 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.hudi.utilities.sources.helpers; | ||
|
|
||
| import org.apache.hudi.common.config.TypedProperties; | ||
| import org.apache.hudi.utilities.config.KinesisSourceConfig; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import software.amazon.awssdk.services.kinesis.KinesisClient; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
|
||
| /** | ||
| * Covers the credential-provider branches of {@link KinesisOffsetGen#createKinesisClient}. AWS SDK v2 | ||
| * clients resolve credentials lazily (only on the first request), so a client can be built for each | ||
| * branch without any AWS environment or network access. | ||
| */ | ||
| class TestKinesisOffsetGenClient { | ||
|
|
||
| private static final String REGION = "us-west-2"; | ||
| private static final String ROLE_ARN = "arn:aws:iam::123456789012:role/kinesis-cross-account-read"; | ||
|
|
||
| @Test | ||
| void buildsClientWithAssumeRoleProviderWhenArnPresent() { | ||
| try (KinesisClient client = KinesisOffsetGen.createKinesisClient(REGION, null, null, null, ROLE_ARN)) { | ||
| assertNotNull(client); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void buildsClientWithDefaultChainWhenNoArnOrKeys() { | ||
| try (KinesisClient client = KinesisOffsetGen.createKinesisClient(REGION, null, null, null, null)) { | ||
| assertNotNull(client); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void staticKeysTakePrecedenceOverAssumeRole() { | ||
| // Both static keys and an ARN set: the static-credentials branch wins (no STS assume-role). | ||
| try (KinesisClient client = | ||
| KinesisOffsetGen.createKinesisClient(REGION, null, "access", "secret", ROLE_ARN)) { | ||
| assertNotNull(client); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void instanceClientReadsRoleArnFromProps() { | ||
| TypedProperties props = new TypedProperties(); | ||
| props.setProperty(KinesisSourceConfig.KINESIS_STREAM_NAME.key(), "test-stream"); | ||
| props.setProperty(KinesisSourceConfig.KINESIS_REGION.key(), REGION); | ||
| props.setProperty(KinesisSourceConfig.KINESIS_ROLE_ARN.key(), ROLE_ARN); | ||
|
|
||
| try (KinesisClient client = new KinesisOffsetGen(props).createKinesisClient()) { | ||
| assertNotNull(client); | ||
| } | ||
| } | ||
| } |
82 changes: 82 additions & 0 deletions
82
...lities/src/test/java/org/apache/hudi/utilities/sources/helpers/TestKinesisReadConfig.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,82 @@ | ||
| /* | ||
| * 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 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.hudi.utilities.sources.helpers; | ||
|
|
||
| import org.apache.hudi.utilities.config.KinesisSourceConfig; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.io.ByteArrayInputStream; | ||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.ObjectInputStream; | ||
| import java.io.ObjectOutputStream; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
|
||
| /** | ||
| * Config-plumbing tests for the cross-account Kinesis role ARN: the config-key contract and the ARN | ||
| * surviving transport to Spark executors via the serializable {@link KinesisReadConfig}. | ||
| */ | ||
| class TestKinesisReadConfig { | ||
|
|
||
| private static final String ROLE_ARN = "arn:aws:iam::123456789012:role/kinesis-cross-account-read"; | ||
|
|
||
| @Test | ||
| void roleArnKeyMatchesExpectedContract() { | ||
| assertEquals("hoodie.streamer.source.kinesis.role.arn", | ||
| KinesisSourceConfig.KINESIS_ROLE_ARN.key()); | ||
| // No default: an absent key must read as null so the client falls back to the default chain. | ||
| assertFalse(KinesisSourceConfig.KINESIS_ROLE_ARN.hasDefaultValue()); | ||
| } | ||
|
|
||
| @Test | ||
| void readConfigRoundTripsRoleArn() { | ||
| assertEquals(ROLE_ARN, newReadConfig(ROLE_ARN).getRoleArn()); | ||
| // Legacy same-account path: null ARN is preserved (not coerced to empty). | ||
| assertNull(newReadConfig(null).getRoleArn()); | ||
| } | ||
|
|
||
| /** | ||
| * The client is rebuilt on executors from a deserialized KinesisReadConfig, so the ARN must | ||
| * survive Java serialization for cross-account reads to work outside the driver. | ||
| */ | ||
| @Test | ||
| void roleArnSurvivesSerialization() throws Exception { | ||
| KinesisReadConfig deserialized = serializeRoundTrip(newReadConfig(ROLE_ARN)); | ||
| assertEquals(ROLE_ARN, deserialized.getRoleArn()); | ||
| } | ||
|
|
||
| private static KinesisReadConfig newReadConfig(String roleArn) { | ||
| return new KinesisReadConfig("test-stream", "us-west-2", null, null, null, roleArn, | ||
| KinesisSourceConfig.KinesisStartingPositionStrategy.LATEST, false, true, | ||
| 10000, 200L, 5000L, 1000L, 10000L, 600000L); | ||
| } | ||
|
|
||
| private static KinesisReadConfig serializeRoundTrip(KinesisReadConfig config) throws Exception { | ||
| ByteArrayOutputStream bytes = new ByteArrayOutputStream(); | ||
| try (ObjectOutputStream out = new ObjectOutputStream(bytes)) { | ||
| out.writeObject(config); | ||
| } | ||
| try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()))) { | ||
| return (KinesisReadConfig) in.readObject(); | ||
| } | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be shaded in
hudi-utilities-bundle?