Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cloud/aws-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@
<version>${aws.sdk.v2.version}</version>
<scope>runtime</scope>
</dependency>
<!-- SigV4A signing for Multi-Region Access Points. The SDK looks these up from the classloader that holds
http-auth-aws, which is lib/, so they cannot live in an extension directory -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>http-auth-aws-crt</artifactId>
<version>${aws.sdk.v2.version}</version>
<scope>runtime</scope>
</dependency>
<!-- Keep CRT classes on the shared classpath too: s3 brings crt-core here which relies on the aws-crt-client. -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
Expand Down
21 changes: 20 additions & 1 deletion docs/development/extensions-core/s3.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ To use S3 for Deep Storage, you must supply [connection information](#configurat

|Property|Description|Default|
|--------|-----------|-------|
|`druid.storage.bucket`|Bucket to store in.|Must be set.|
|`druid.storage.bucket`|Bucket to store in. Can also be an S3 Access Point or Multi-Region Access Point ARN. See [Access Points and Multi-Region Access Points](#access-points-and-multi-region-access-points).|Must be set.|
|`druid.storage.baseKey`|A prefix string that will be prepended to the object names for the segments published to S3 deep storage|Must be set.|
|`druid.storage.type`|Global deep storage provider. Must be set to `s3` to make use of this extension.|Must be set (likely `s3`).|
|`druid.storage.disableAcl`|Boolean flag for how object permissions are handled. To use ACLs, set this property to `false`. To use Object Ownership, set it to `true`. The permission requirements for ACLs and Object Ownership are different. For more information, see [S3 permissions settings](#s3-permissions-settings).|false|
Expand Down Expand Up @@ -130,6 +130,25 @@ If you're using Object Ownership, Druid needs the following permissions:
* `s3:PutObject`
* `s3:DeleteObject`

### Access Points and Multi-Region Access Points

You can set `druid.storage.bucket` and `druid.indexer.logs.s3Bucket` to the ARN of an [S3 Access Point](https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-points.html) or a [Multi-Region Access Point](https://docs.aws.amazon.com/AmazonS3/latest/userguide/MultiRegionAccessPoints.html) instead of a bucket name. For example:

```properties
druid.storage.bucket=arn:aws:s3::123456789012:accesspoint/abcdef0123456.mrap
```

Druid accepts both the `accesspoint/<name>` form that AWS documents and the `accesspoint:<name>` form, and converts the first to the second. In the `uris` and `prefixes` of an [S3 input source](../../ingestion/input-sources.md#s3-input-source), and in `druid.export.storage.s3.allowedExportPaths`, use the `accesspoint:<name>` form, for example `s3://arn:aws:s3::123456789012:accesspoint:abcdef0123456.mrap/path/to/file.json`.

When using an ARN:

* Set `druid.storage.disableAcl=true` for a Multi-Region Access Point, and `druid.indexer.logs.disableAcl=true` if task logs use one. With ACLs enabled, Druid looks up the bucket owner using `GetBucketAcl`, which Multi-Region Access Points do not [support](https://docs.aws.amazon.com/AmazonS3/latest/userguide/MrapOperations.html). If ACLs are enabled for a Multi-Region Access Point ARN, Druid rejects the configuration before making any upload or move request. Regional Access Points support `GetBucketAcl`, so ACLs can stay enabled for them.
* Druid sends requests for a regional Access Point to the Region in its ARN, even if that differs from `druid.s3.endpoint.signingRegion`. The ARN and the client must be in the same AWS partition.
Comment thread
vivek807 marked this conversation as resolved.
Resolved
* Leave `druid.s3.enablePathStyleAccess` set to `false`. The AWS SDK rejects ARN buckets with path-style addressing.
* Multi-Region Access Points do not support the multi-object `DeleteObjects` operation. Druid deletes objects behind a Multi-Region Access Point with one `DeleteObject` request per object, so killing segments and cleaning up task logs or durable storage sends more requests than with a bucket.
* Requests to a Multi-Region Access Point are signed with SigV4A. If you use temporary credentials, request them from a regional AWS STS endpoint. Credentials from the global endpoint `sts.amazonaws.com` work only if you set its session tokens to be valid in all AWS Regions. See [Multi-Region Access Point restrictions](https://docs.aws.amazon.com/AmazonS3/latest/userguide/MultiRegionAccessPointRestrictions.html).
* Moving or archiving segments stored behind a Multi-Region Access Point is not supported. S3 accepts a Multi-Region Access Point only as the destination of `CopyObject`, not the source, so Druid fails these move requests. A Multi-Region Access Point can still be the target of a move from a bucket or regional Access Point.

### AWS region

The AWS SDK requires that a target region be specified. You can set these by using the JVM system property `aws.region` or by setting an environment variable `AWS_REGION`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.apache.druid.data.input.impl.systemfield.SystemField;
import org.apache.druid.data.input.impl.systemfield.SystemFields;
import org.apache.druid.java.util.common.RetryUtils;
import org.apache.druid.storage.s3.S3BucketValidator;
import org.apache.druid.storage.s3.S3InputDataConfig;
import org.apache.druid.storage.s3.S3StorageDruidModule;
import org.apache.druid.storage.s3.S3Utils;
Expand Down Expand Up @@ -110,7 +111,15 @@ public S3InputSource(
@JsonProperty("clientConfig") @Nullable AWSClientConfig awsClientConfig
)
{
super(S3StorageDruidModule.SCHEME, uris, prefixes, objects, objectGlob, systemFields);
super(
S3StorageDruidModule.SCHEME,
uris,
prefixes,
objects,
objectGlob,
systemFields,
S3BucketValidator.INSTANCE
);
this.inputDataConfig = Preconditions.checkNotNull(inputDataConfig, "S3DataSegmentPusherConfig");
Preconditions.checkNotNull(s3Client, "s3Client");
this.s3InputSourceConfig = s3InputSourceConfig;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.druid.storage.s3;

import org.apache.druid.data.input.impl.CloudBucketValidator;
import org.apache.druid.java.util.common.IAE;

/**
* Accepts plain bucket names and S3 Access Point / Multi-Region Access Point ARNs in colon form.
*
* {@link org.apache.druid.data.input.impl.CloudObjectLocation} permits ':' in any bucket, so this rejects colons
* outside a well-formed ARN. That also catches slash-form ARNs inside a URI, such as
* s3://arn:aws:s3::&lt;account&gt;:accesspoint/alias.mrap/key, where {@link java.net.URI} truncates the bucket to
* arn:aws:s3::&lt;account&gt;:accesspoint and moves the access point name into the key.
*/
public class S3BucketValidator implements CloudBucketValidator
{
public static final S3BucketValidator INSTANCE = new S3BucketValidator();

private S3BucketValidator()
{
}

@Override
public void validate(String bucket)
{
if (bucket.indexOf(':') >= 0 && !S3Utils.isS3Arn(bucket)) {
throw new IAE(
"Invalid S3 bucket [%s]. Use a bucket name, or an S3 Access Point or Multi-Region Access Point ARN"
+ " in colon form: arn:<partition>:s3:<region>:<account>:accesspoint:<name>",
bucket
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ public DataSegment move(DataSegment segment, Map<String, Object> targetLoadSpec)
{
try {
Map<String, Object> loadSpec = segment.getLoadSpec();
String s3Bucket = MapUtils.getString(loadSpec, "bucket");
// load specs reach the mover as raw maps, bypassing the normalizing setters on S3 config and S3LoadSpec
String s3Bucket = S3Utils.normalizeBucketName(MapUtils.getString(loadSpec, "bucket"));
String s3Path = MapUtils.getString(loadSpec, "key");

final String targetS3Bucket = MapUtils.getString(targetLoadSpec, "bucket");
final String targetS3Bucket = S3Utils.normalizeBucketName(MapUtils.getString(targetLoadSpec, "bucket"));
final String targetS3BaseKey = MapUtils.getString(targetLoadSpec, "baseKey");
final String targetS3Path;

Expand Down Expand Up @@ -198,6 +199,13 @@ private void moveObject(
log.info("No need to move file[s3://%s/%s] onto itself", s3Bucket, s3Path);
return;
}
if (S3Utils.isMultiRegionAccessPointArn(s3Bucket)) {
throw new SegmentLoadingException(
"Unable to move file %s. Multi-Region Access Points are supported only as a CopyObject destination,"
+ " not as a source.",
copyMsg
);
}
final ServerSideEncryptingAmazonS3 s3Client = this.s3ClientSupplier.get();
final HeadObjectResponse sourceMetadata;
try {
Expand Down Expand Up @@ -241,6 +249,7 @@ private void moveObject(
.sourceKey(s3Path)
.destinationBucket(targetS3Bucket)
.destinationKey(targetS3Path);
S3Utils.checkAclSupported(targetS3Bucket, config.getDisableAcl(), "druid.storage.disableAcl");
if (!config.getDisableAcl()) {
final String headerValue = S3Utils.grantFullControlHeaderValue(
s3Client.getBucketOwnerGrant(targetS3Bucket)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
import org.apache.druid.data.input.impl.CloudObjectLocation;
import org.apache.druid.error.DruidException;
import org.apache.druid.java.util.common.IOE;
import org.apache.druid.java.util.emitter.EmittingLogger;
Expand Down Expand Up @@ -60,6 +61,7 @@ public S3DataSegmentPusher(
DeepStorageSegmentConfig deepStorageConfig
)
{
S3Utils.checkAclSupported(config.getBucket(), config.getDisableAcl(), "druid.storage.disableAcl");
this.s3Client = s3Client;
this.config = config;
this.zip = deepStorageConfig.getEffectiveCompressionFormat(
Expand Down Expand Up @@ -208,7 +210,10 @@ private void deleteStaleObjects(final String s3Path, final Set<String> pushedKey
public Map<String, Object> makeLoadSpec(URI finalIndexZipFilePath)
{
// remove the leading "/"
return makeLoadSpec(finalIndexZipFilePath.getHost(), finalIndexZipFilePath.getPath().substring(1));
return makeLoadSpec(
CloudObjectLocation.extractBucket(finalIndexZipFilePath),
finalIndexZipFilePath.getPath().substring(1)
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ public class S3DataSegmentPusherConfig
@Min(1)
private int maxListingLength = 1024;

// annotated so Jackson routes deserialization through the normalizing setter instead of writing the field directly
@JsonProperty("bucket")
public void setBucket(String bucket)
{
this.bucket = bucket;
this.bucket = S3Utils.normalizeBucketName(bucket);
}

public void setBaseKey(String baseKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public S3LoadSpec(
{
Preconditions.checkNotNull(bucket);
Preconditions.checkNotNull(key);
this.bucket = bucket;
this.bucket = S3Utils.normalizeBucketName(bucket);
this.key = key;
this.rangeable = rangeable;
this.puller = puller;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public S3TaskLogs(
CurrentTimeMillisSupplier timeSupplier
)
{
S3Utils.checkAclSupported(config.getS3Bucket(), config.getDisableAcl(), "druid.indexer.logs.disableAcl");
this.service = service;
this.config = config;
this.inputDataConfig = inputDataConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ public String getS3Bucket()
return s3Bucket;
}

@VisibleForTesting
// annotated so Jackson routes deserialization through the normalizing setter instead of writing the field directly
@JsonProperty("s3Bucket")
void setS3Bucket(String s3Bucket)
{
this.s3Bucket = s3Bucket;
this.s3Bucket = S3Utils.normalizeBucketName(s3Bucket);
}

public String getS3Prefix()
Expand Down
Loading
Loading