Skip to content

Commit d6e23e9

Browse files
Provide an Option to Use Path-Style-Access with S3 Repo (#41966)
* Provide an Option to Use Path-Style-Access with S3 Repo * As discussed, added the option to use path style access back again and deprecated it. * Defaulted to `false` * Added warning to docs * Closes #41816
1 parent b38b3ea commit d6e23e9

File tree

6 files changed

+56
-10
lines changed

6 files changed

+56
-10
lines changed

docs/plugins/repository-s3.asciidoc

+14-4
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,20 @@ settings belong in the `elasticsearch.yml` file.
145145
Whether retries should be throttled (i.e. should back off). Must be `true`
146146
or `false`. Defaults to `true`.
147147

148+
`path_style_access`::
149+
150+
Whether to force the use of the path style access pattern. If `true`, the
151+
path style access pattern will be used. If `false`, the access pattern will
152+
be automatically determined by the AWS Java SDK (See
153+
https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/AmazonS3Builder.html#setPathStyleAccessEnabled-java.lang.Boolean-[AWS
154+
documentation] for details). Defaults to `false`.
155+
156+
[[repository-s3-path-style-deprecation]]
157+
NOTE: In versions `7.0`, `7.1`, `7.2` and `7.3` all bucket operations used the
158+
https://aws.amazon.com/blogs/aws/amazon-s3-path-deprecation-plan-the-rest-of-the-story/[now-deprecated]
159+
path style access pattern. If your deployment requires the path style access
160+
pattern then you should set this setting to `true` when upgrading.
161+
148162
[float]
149163
[[repository-s3-compatible-services]]
150164
===== S3-compatible services
@@ -381,10 +395,6 @@ bucket, in this example, named "foo".
381395
The bucket needs to exist to register a repository for snapshots. If you did not
382396
create the bucket then the repository registration will fail.
383397

384-
Note: Starting in version 7.0, all bucket operations are using the path style
385-
access pattern. In previous versions the decision to use virtual hosted style or
386-
path style access was made by the AWS Java SDK.
387-
388398
[[repository-s3-aws-vpc]]
389399
[float]
390400
==== AWS VPC Bandwidth Settings

docs/reference/migration/migrate_8_0/snapshots.asciidoc

+15
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,18 @@ This change will affect both newly created repositories and existing repositorie
8181
explicitly specified.
8282

8383
For more information on the compress option, see <<modules-snapshots>>
84+
85+
[float]
86+
==== The S3 repository plugin uses the DNS style access pattern by default
87+
88+
Starting in version 7.4 the `repository-s3` plugin does not use the
89+
now-deprecated path-style access pattern by default. In versions 7.0, 7.1, 7.2
90+
and 7.3 the `repository-s3` plugin always used the path-style access pattern.
91+
This is a breaking change for deployments that only support path-style access
92+
but which are recognized as supporting DNS-style access by the AWS SDK. If your
93+
deployment only supports path-style access and is affected by this change then
94+
you must configure the S3 client setting `path_style_access` to `true`. This
95+
breaking change was made necessary by
96+
https://aws.amazon.com/blogs/aws/amazon-s3-path-deprecation-plan-the-rest-of-the-story/[AWS's
97+
announcement] that the path-style access pattern is deprecated and will be
98+
unsupported on buckets created after September 30th 2020.

plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3ClientSettings.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ final class S3ClientSettings {
9595
static final Setting.AffixSetting<Boolean> USE_THROTTLE_RETRIES_SETTING = Setting.affixKeySetting(PREFIX, "use_throttle_retries",
9696
key -> Setting.boolSetting(key, ClientConfiguration.DEFAULT_THROTTLE_RETRIES, Property.NodeScope));
9797

98+
/** Whether the s3 client should use path style access. */
99+
static final Setting.AffixSetting<Boolean> USE_PATH_STYLE_ACCESS = Setting.affixKeySetting(PREFIX, "path_style_access",
100+
key -> Setting.boolSetting(key, false, Property.NodeScope));
101+
98102
/** Credentials to authenticate with s3. */
99103
final S3BasicCredentials credentials;
100104

@@ -127,9 +131,13 @@ final class S3ClientSettings {
127131
/** Whether the s3 client should use an exponential backoff retry policy. */
128132
final boolean throttleRetries;
129133

134+
/** Whether the s3 client should use path style access. */
135+
final boolean pathStyleAccess;
136+
130137
private S3ClientSettings(S3BasicCredentials credentials, String endpoint, Protocol protocol,
131138
String proxyHost, int proxyPort, String proxyUsername, String proxyPassword,
132-
int readTimeoutMillis, int maxRetries, boolean throttleRetries) {
139+
int readTimeoutMillis, int maxRetries, boolean throttleRetries,
140+
boolean pathStyleAccess) {
133141
this.credentials = credentials;
134142
this.endpoint = endpoint;
135143
this.protocol = protocol;
@@ -140,6 +148,7 @@ private S3ClientSettings(S3BasicCredentials credentials, String endpoint, Protoc
140148
this.readTimeoutMillis = readTimeoutMillis;
141149
this.maxRetries = maxRetries;
142150
this.throttleRetries = throttleRetries;
151+
this.pathStyleAccess = pathStyleAccess;
143152
}
144153

145154
/**
@@ -162,6 +171,7 @@ S3ClientSettings refine(RepositoryMetaData metadata) {
162171
getRepoSettingOrDefault(READ_TIMEOUT_SETTING, normalizedSettings, TimeValue.timeValueMillis(readTimeoutMillis)).millis());
163172
final int newMaxRetries = getRepoSettingOrDefault(MAX_RETRIES_SETTING, normalizedSettings, maxRetries);
164173
final boolean newThrottleRetries = getRepoSettingOrDefault(USE_THROTTLE_RETRIES_SETTING, normalizedSettings, throttleRetries);
174+
final boolean usePathStyleAccess = getRepoSettingOrDefault(USE_PATH_STYLE_ACCESS, normalizedSettings, pathStyleAccess);
165175
final S3BasicCredentials newCredentials;
166176
if (checkDeprecatedCredentials(repoSettings)) {
167177
newCredentials = loadDeprecatedCredentials(repoSettings);
@@ -183,7 +193,8 @@ S3ClientSettings refine(RepositoryMetaData metadata) {
183193
proxyPassword,
184194
newReadTimeoutMillis,
185195
newMaxRetries,
186-
newThrottleRetries
196+
newThrottleRetries,
197+
usePathStyleAccess
187198
);
188199
}
189200

@@ -270,7 +281,8 @@ static S3ClientSettings getClientSettings(final Settings settings, final String
270281
proxyPassword.toString(),
271282
Math.toIntExact(getConfigValue(settings, clientName, READ_TIMEOUT_SETTING).millis()),
272283
getConfigValue(settings, clientName, MAX_RETRIES_SETTING),
273-
getConfigValue(settings, clientName, USE_THROTTLE_RETRIES_SETTING)
284+
getConfigValue(settings, clientName, USE_THROTTLE_RETRIES_SETTING),
285+
getConfigValue(settings, clientName, USE_PATH_STYLE_ACCESS)
274286
);
275287
}
276288
}

plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3RepositoryPlugin.java

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public List<Setting<?>> getSettings() {
105105
S3ClientSettings.READ_TIMEOUT_SETTING,
106106
S3ClientSettings.MAX_RETRIES_SETTING,
107107
S3ClientSettings.USE_THROTTLE_RETRIES_SETTING,
108+
S3ClientSettings.USE_PATH_STYLE_ACCESS,
108109
S3Repository.ACCESS_KEY_SETTING,
109110
S3Repository.SECRET_KEY_SETTING);
110111
}

plugins/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Service.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,10 @@ AmazonS3 buildClient(final S3ClientSettings clientSettings) {
153153
//
154154
// We do this because directly constructing the client is deprecated (was already deprecated in 1.1.223 too)
155155
// so this change removes that usage of a deprecated API.
156-
builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, null))
157-
.enablePathStyleAccess();
158-
156+
builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, null));
157+
if (clientSettings.pathStyleAccess) {
158+
builder.enablePathStyleAccess();
159+
}
159160
return builder.build();
160161
}
161162

plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/S3ClientSettingsTests.java

+7
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,11 @@ public void testRefineWithRepoSettings() {
144144
assertThat(credentials.getSessionToken(), is("session_token"));
145145
}
146146
}
147+
148+
public void testPathStyleAccessCanBeSet() {
149+
final Map<String, S3ClientSettings> settings = S3ClientSettings.load(
150+
Settings.builder().put("s3.client.other.path_style_access", true).build());
151+
assertThat(settings.get("default").pathStyleAccess, is(false));
152+
assertThat(settings.get("other").pathStyleAccess, is(true));
153+
}
147154
}

0 commit comments

Comments
 (0)