-
Couldn't load subscription status.
- Fork 25.6k
Make S3 custom query parameter optional #128043
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
Changes from 8 commits
6814d98
88c4c77
81cef8c
3f1a8f4
6cca2b3
2512826
b9da53e
36cb13d
c148ba1
6b91e9b
0e58906
f38515d
9bfb6f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| pr: 128043 | ||
| summary: Make S3 custom query parameter optional | ||
| area: Snapshot/Restore | ||
| type: breaking | ||
| issues: [] | ||
| breaking: | ||
| title: Make S3 custom query parameter optional | ||
| area: Cluster and node setting | ||
| details: >- | ||
| Earlier versions of Elasticsearch would record the purpose of each S3 API | ||
| call using the `?x-purpose=` custom query parameter. This isn't believed to | ||
| be necessary outside of the ECH/ECE/ECK/... managed services, and it adds | ||
| rather a lot to the request logs, so with this change we make the feature | ||
| optional and disabled by default. | ||
| impact: >- | ||
| If you wish to reinstate the old behaviour on a S3 repository, set | ||
| `s3.client.${CLIENT_NAME}.add_purpose_custom_query_parameter` to `true` | ||
| for the relevant client. | ||
| notable: false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| package org.elasticsearch.repositories.s3; | ||
|
|
||
| import fixture.s3.S3HttpFixture; | ||
| import fixture.s3.S3HttpHandler; | ||
|
|
||
| import com.sun.net.httpserver.HttpExchange; | ||
| import com.sun.net.httpserver.HttpHandler; | ||
|
|
||
| import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest; | ||
| import org.elasticsearch.action.admin.cluster.repositories.put.TransportPutRepositoryAction; | ||
| import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest; | ||
| import org.elasticsearch.action.admin.cluster.snapshots.create.TransportCreateSnapshotAction; | ||
| import org.elasticsearch.common.settings.MockSecureSettings; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.common.util.CollectionUtils; | ||
| import org.elasticsearch.core.SuppressForbidden; | ||
| import org.elasticsearch.plugins.Plugin; | ||
| import org.elasticsearch.snapshots.SnapshotState; | ||
| import org.elasticsearch.test.ESSingleNodeTestCase; | ||
| import org.hamcrest.Matcher; | ||
| import org.junit.runner.Description; | ||
| import org.junit.runners.model.Statement; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
|
|
||
| import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
| import static org.hamcrest.Matchers.hasItem; | ||
| import static org.hamcrest.Matchers.not; | ||
|
|
||
| public class AddPurposeCustomQueryParameterTests extends ESSingleNodeTestCase { | ||
|
|
||
| @Override | ||
| protected Collection<Class<? extends Plugin>> getPlugins() { | ||
| return CollectionUtils.appendToCopyNoNullElements(super.getPlugins(), S3RepositoryPlugin.class); | ||
| } | ||
|
|
||
| @Override | ||
| protected Settings nodeSettings() { | ||
| final var secureSettings = new MockSecureSettings(); | ||
| for (final var clientName : List.of("default", "with_purpose", "without_purpose")) { | ||
| secureSettings.setString( | ||
| S3ClientSettings.ACCESS_KEY_SETTING.getConcreteSettingForNamespace(clientName).getKey(), | ||
| randomIdentifier() | ||
| ); | ||
| secureSettings.setString( | ||
| S3ClientSettings.SECRET_KEY_SETTING.getConcreteSettingForNamespace(clientName).getKey(), | ||
| randomSecretKey() | ||
| ); | ||
| } | ||
|
|
||
| return Settings.builder() | ||
| .put(super.nodeSettings()) | ||
| .put(S3ClientSettings.REGION.getConcreteSettingForNamespace("default").getKey(), randomIdentifier()) | ||
| .put(S3ClientSettings.ADD_PURPOSE_CUSTOM_QUERY_PARAMETER.getConcreteSettingForNamespace("with_purpose").getKey(), "true") | ||
| .put(S3ClientSettings.ADD_PURPOSE_CUSTOM_QUERY_PARAMETER.getConcreteSettingForNamespace("without_purpose").getKey(), "false") | ||
| .setSecureSettings(secureSettings) | ||
| .build(); | ||
| } | ||
|
|
||
| private static final Matcher<Iterable<? super String>> HAS_CUSTOM_QUERY_PARAMETER = hasItem(S3BlobStore.CUSTOM_QUERY_PARAMETER_PURPOSE); | ||
| private static final Matcher<Iterable<? super String>> NO_CUSTOM_QUERY_PARAMETER = not(HAS_CUSTOM_QUERY_PARAMETER); | ||
|
|
||
| public void testCustomQueryParameterConfiguration() throws Throwable { | ||
| final var indexName = randomIdentifier(); | ||
| createIndex(indexName); | ||
| prepareIndex(indexName).setSource("foo", "bar").get(); | ||
|
|
||
| final var bucket = randomIdentifier(); | ||
| final var basePath = randomIdentifier(); | ||
|
|
||
| runCustomQueryParameterTest(bucket, basePath, null, Settings.EMPTY, NO_CUSTOM_QUERY_PARAMETER); | ||
| runCustomQueryParameterTest(bucket, basePath, "default", Settings.EMPTY, NO_CUSTOM_QUERY_PARAMETER); | ||
| runCustomQueryParameterTest(bucket, basePath, "without_purpose", Settings.EMPTY, NO_CUSTOM_QUERY_PARAMETER); | ||
| runCustomQueryParameterTest(bucket, basePath, "with_purpose", Settings.EMPTY, HAS_CUSTOM_QUERY_PARAMETER); | ||
|
|
||
| final var falseRepositorySetting = Settings.builder().put("add_purpose_custom_query_parameter", false).build(); | ||
| final var trueRepositorySetting = Settings.builder().put("add_purpose_custom_query_parameter", true).build(); | ||
| for (final var clientName : new String[] { null, "default", "with_purpose", "without_purpose" }) { | ||
| // client name doesn't matter if repository setting specified | ||
| runCustomQueryParameterTest(bucket, basePath, clientName, falseRepositorySetting, NO_CUSTOM_QUERY_PARAMETER); | ||
| runCustomQueryParameterTest(bucket, basePath, clientName, trueRepositorySetting, HAS_CUSTOM_QUERY_PARAMETER); | ||
| } | ||
| } | ||
|
|
||
| private void runCustomQueryParameterTest( | ||
| String bucket, | ||
| String basePath, | ||
| String clientName, | ||
| Settings extraRepositorySettings, | ||
| Matcher<Iterable<? super String>> queryParamMatcher | ||
| ) throws Throwable { | ||
| final var httpFixture = new S3HttpFixture(true, bucket, basePath, (key, token) -> true) { | ||
|
|
||
| @SuppressForbidden(reason = "this test uses a HttpServer to emulate an S3 endpoint") | ||
| class AssertingHandler extends S3HttpHandler { | ||
| AssertingHandler() { | ||
| super(bucket, basePath); | ||
| } | ||
|
|
||
| @SuppressForbidden(reason = "this test uses a HttpServer to emulate an S3 endpoint") | ||
| @Override | ||
| public void handle(HttpExchange exchange) throws IOException { | ||
| assertThat(parseRequest(exchange).queryParameters().keySet(), queryParamMatcher); | ||
| super.handle(exchange); | ||
| } | ||
| } | ||
|
|
||
| @SuppressForbidden(reason = "this test uses a HttpServer to emulate an S3 endpoint") | ||
| @Override | ||
| protected HttpHandler createHandler() { | ||
| return new AssertingHandler(); | ||
| } | ||
| }; | ||
| httpFixture.apply(new Statement() { | ||
|
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. Do we need to stop the fixture explicitly especially when the test fails? 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. That's handled within |
||
| @Override | ||
| public void evaluate() { | ||
| final var repoName = randomIdentifier(); | ||
| assertAcked( | ||
| client().execute( | ||
| TransportPutRepositoryAction.TYPE, | ||
| new PutRepositoryRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT, repoName).type(S3Repository.TYPE) | ||
| .settings( | ||
| Settings.builder() | ||
| .put("bucket", bucket) | ||
| .put("base_path", basePath) | ||
| .put("endpoint", httpFixture.getAddress()) | ||
| .put(clientName == null ? Settings.EMPTY : Settings.builder().put("client", clientName).build()) | ||
| .put(extraRepositorySettings) | ||
| ) | ||
| ) | ||
| ); | ||
|
|
||
| assertEquals( | ||
| SnapshotState.SUCCESS, | ||
| client().execute( | ||
| TransportCreateSnapshotAction.TYPE, | ||
| new CreateSnapshotRequest(TEST_REQUEST_TIMEOUT, repoName, randomIdentifier()).waitForCompletion(true) | ||
| ).actionGet(SAFE_AWAIT_TIMEOUT).getSnapshotInfo().state() | ||
| ); | ||
| } | ||
| }, Description.EMPTY).evaluate(); | ||
| } | ||
|
|
||
| } | ||
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 we make
AssertingHandlerdelegate to the handler returned bysuper.createHandler()so that we don't miss the fix from #102976?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.
Sure see 6b91e9b. It doesn't really matter here, the test fails either way.