-
Notifications
You must be signed in to change notification settings - Fork 202
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
Add support for AWS security lake sink as a bucket selector mode in S3 sink #4846
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0ec283d
dplive1.yaml
kkondaka 2328e33
Delete .github/workflows/static.yml
kkondaka 9c6c9b0
Add support for AWS security lake sink as a bucket selector mode in S…
kkondaka 85aae00
Fixed tests
kkondaka 4f7ac58
Added javadoc for S3BucketSelector
kkondaka d291289
Added new tests for KeyGenerator
kkondaka e1ade2b
Added new tests and fixed style errors
kkondaka 8606003
Addressed review comments
kkondaka 6d1f366
Fixed test build failure
kkondaka 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 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 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 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
17 changes: 17 additions & 0 deletions
17
...nk/src/main/java/org/opensearch/dataprepper/plugins/sink/s3/PredefinedObjectMetadata.java
This file contains 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,17 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.sink.s3; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
public class PredefinedObjectMetadata { | ||
@JsonProperty("number_of_objects") | ||
private String numberOfObjects; | ||
|
||
public String getNumberOfObjects() { | ||
return numberOfObjects; | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...ns/s3-sink/src/main/java/org/opensearch/dataprepper/plugins/sink/s3/S3BucketSelector.java
This file contains 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,29 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.sink.s3; | ||
|
||
public interface S3BucketSelector { | ||
/** | ||
* initialize - initializes the selector | ||
* @param s3SinkConfig - s3 sink configuration | ||
*/ | ||
void initialize(S3SinkConfig s3SinkConfig); | ||
|
||
/** | ||
* getBucketName - returns the name of the bucket created by the bucket selector | ||
* | ||
* @return - bucket name | ||
*/ | ||
String getBucketName(); | ||
|
||
/** | ||
* getPathPrefix - returns the prefix to be used for the objects created in the bucket | ||
* | ||
* @return path prefix | ||
*/ | ||
String getPathPrefix(); | ||
} | ||
|
This file contains 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 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 |
---|---|---|
|
@@ -6,8 +6,8 @@ | |
package org.opensearch.dataprepper.plugins.sink.s3; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import jakarta.validation.constraints.AssertTrue; | ||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import org.opensearch.dataprepper.aws.validator.AwsAccountId; | ||
|
@@ -36,10 +36,21 @@ public class S3SinkConfig { | |
private AwsAuthenticationOptions awsAuthenticationOptions; | ||
|
||
@JsonProperty("bucket") | ||
@NotEmpty | ||
@Size(min = 3, max = 500, message = "bucket length should be at least 3 characters") | ||
private String bucketName; | ||
|
||
@JsonProperty("bucket_selector") | ||
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. Please add 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. Will do follow up PR |
||
private PluginModel bucketSelector; | ||
|
||
@JsonProperty("predefined_object_metadata") | ||
private PredefinedObjectMetadata predefinedObjectMetadata; | ||
|
||
@AssertTrue(message = "You may not use both bucket and bucket_selector together in one S3 sink.") | ||
private boolean isValidBucketConfig() { | ||
return (bucketName != null && bucketSelector == null) || | ||
(bucketName == null && bucketSelector != null); | ||
} | ||
|
||
/** | ||
* The default bucket to send to if using a dynamic bucket name and failures occur | ||
* for any reason when sending to a dynamic bucket | ||
|
@@ -127,6 +138,18 @@ public ObjectKeyOptions getObjectKeyOptions() { | |
return objectKeyOptions; | ||
} | ||
|
||
public PredefinedObjectMetadata getPredefinedObjectMetadata() { | ||
return predefinedObjectMetadata; | ||
} | ||
|
||
/** | ||
* Bucket selector configuration options. | ||
* @return bucketSelector plugin model. | ||
*/ | ||
public PluginModel getBucketSelector() { | ||
return bucketSelector; | ||
} | ||
|
||
/** | ||
* Sink codec configuration Options. | ||
* @return codec plugin model. | ||
|
@@ -172,4 +195,4 @@ public Map<String, String> getBucketOwners() { | |
public String getDefaultBucketOwner() { | ||
return defaultBucketOwner; | ||
} | ||
} | ||
} |
This file contains 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
80 changes: 80 additions & 0 deletions
80
.../src/main/java/org/opensearch/dataprepper/plugins/sink/s3/SecurityLakeBucketSelector.java
This file contains 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,80 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.sink.s3; | ||
|
||
import org.apache.commons.lang3.RandomStringUtils; | ||
import org.opensearch.dataprepper.model.annotations.DataPrepperPlugin; | ||
import org.opensearch.dataprepper.model.annotations.DataPrepperPluginConstructor; | ||
import software.amazon.awssdk.services.securitylake.SecurityLakeClient; | ||
import software.amazon.awssdk.services.securitylake.model.AwsIdentity; | ||
import software.amazon.awssdk.services.securitylake.model.CreateCustomLogSourceRequest; | ||
import software.amazon.awssdk.services.securitylake.model.CustomLogSourceProvider; | ||
import software.amazon.awssdk.services.securitylake.model.CustomLogSourceConfiguration; | ||
import software.amazon.awssdk.services.securitylake.model.CreateCustomLogSourceResponse; | ||
import software.amazon.awssdk.services.securitylake.model.CustomLogSourceCrawlerConfiguration; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@DataPrepperPlugin(name = "aws_security_lake", pluginType = S3BucketSelector.class, pluginConfigurationType = SecurityLakeBucketSelectorConfig.class) | ||
public class SecurityLakeBucketSelector implements S3BucketSelector { | ||
private static final String EXT_PATH = "/ext/"; | ||
private final SecurityLakeBucketSelectorConfig securityLakeBucketSelectorConfig; | ||
|
||
private S3SinkConfig s3SinkConfig; | ||
|
||
private String pathPrefix; | ||
|
||
private String sourceLocation; | ||
|
||
@DataPrepperPluginConstructor | ||
public SecurityLakeBucketSelector(final SecurityLakeBucketSelectorConfig securityLakeBucketSelectorConfig) { | ||
this.securityLakeBucketSelectorConfig = securityLakeBucketSelectorConfig; | ||
} | ||
|
||
public void initialize(S3SinkConfig s3SinkConfig) { | ||
this.s3SinkConfig = s3SinkConfig; | ||
SecurityLakeClient securityLakeClient = SecurityLakeClient.create(); | ||
String arn = s3SinkConfig.getAwsAuthenticationOptions().getAwsStsRoleArn(); | ||
String principal = arn.split(":")[4]; | ||
String sourceName = securityLakeBucketSelectorConfig.getSourceName() != null ? securityLakeBucketSelectorConfig.getSourceName() : RandomStringUtils.randomAlphabetic(7); | ||
CreateCustomLogSourceResponse response = | ||
securityLakeClient.createCustomLogSource( | ||
CreateCustomLogSourceRequest.builder() | ||
.sourceName(sourceName+RandomStringUtils.randomAlphabetic(4)) | ||
.eventClasses(List.of(securityLakeBucketSelectorConfig.getLogClass())) | ||
.sourceVersion(securityLakeBucketSelectorConfig.getSourceVersion()) | ||
.configuration(CustomLogSourceConfiguration.builder() | ||
.crawlerConfiguration(CustomLogSourceCrawlerConfiguration.builder() | ||
.roleArn(arn) | ||
.build()) | ||
.providerIdentity(AwsIdentity.builder() | ||
.externalId(securityLakeBucketSelectorConfig.getExternalId()) | ||
.principal(principal) | ||
.build()) | ||
.build()) | ||
.build()); | ||
CustomLogSourceProvider provider = response.source().provider(); | ||
this.sourceLocation = provider.location(); | ||
final String region=s3SinkConfig.getAwsAuthenticationOptions().getAwsRegion().toString(); | ||
final String accountId=arn.split(":")[4]; | ||
|
||
final LocalDate now = LocalDate.now(); | ||
final String eventDay = String.format("%d%02d%02d", now.getYear(), now.getMonthValue(), now.getDayOfMonth()); | ||
int locIndex = sourceLocation.indexOf(EXT_PATH); | ||
pathPrefix = String.format("%sregion=%s/accountId=%s/eventDay=%s/",sourceLocation.substring(locIndex+1), region, accountId, eventDay); | ||
} | ||
|
||
public String getPathPrefix() { | ||
return pathPrefix; | ||
} | ||
|
||
@Override | ||
public String getBucketName() { | ||
int locIndex = sourceLocation.indexOf(EXT_PATH); | ||
return sourceLocation.substring(EXT_PATH.length(), locIndex); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...ain/java/org/opensearch/dataprepper/plugins/sink/s3/SecurityLakeBucketSelectorConfig.java
This file contains 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,44 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.sink.s3; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class SecurityLakeBucketSelectorConfig { | ||
static final String DEFAULT_SOURCE_VERSION = "1.0"; | ||
|
||
static final String DEFAULT_EXTERNAL_ID = "extid"; | ||
|
||
@JsonProperty("source_name") | ||
private String sourceName; | ||
|
||
@JsonProperty("source_version") | ||
private String sourceVersion = DEFAULT_SOURCE_VERSION; | ||
|
||
@JsonProperty("external_id") | ||
private String externalId = DEFAULT_EXTERNAL_ID; | ||
|
||
@JsonProperty("log_class") | ||
private String logClass; | ||
|
||
|
||
public String getSourceName() { | ||
return sourceName; | ||
} | ||
|
||
public String getSourceVersion() { | ||
return sourceVersion; | ||
} | ||
|
||
public String getExternalId() { | ||
return externalId; | ||
} | ||
|
||
public String getLogClass() { | ||
return logClass; | ||
} | ||
|
||
} |
This file contains 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
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.
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.
Why is this a String? Sounds like it would be integer with the name
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.
Maybe we should call this
number_of_objects_key
. Will do it in the next PR