Skip to content

Default S3 endpoint scheme to HTTPS when not specified #127489

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

Merged
merged 12 commits into from
May 5, 2025

Conversation

nicktindall
Copy link
Contributor

@nicktindall nicktindall commented Apr 29, 2025

The protocol configuration option was removed in the AWS v2 client

Our interpretation of that was that we could provide a host name and the scheme would be defaulted/derived. The code appears to contradict that. While you can't specify the protocol using the setProtocol anymore, it seems if you want to specify an endpoint override, it must include a scheme in the URI.

See validation here

This PR just appends https:// when no scheme is specified. This seemed to match the defaulting of the new builder now that setProtocol has been removed.

We used to have code that used our s3.client.{client-name}.protocol setting to prepend a scheme if it were missing:

String endpoint = Strings.hasLength(clientSettings.endpoint) ? clientSettings.endpoint : Constants.S3_HOSTNAME;
if ((endpoint.startsWith("http://") || endpoint.startsWith("https://")) == false) {
// Manually add the schema to the endpoint to work around https://github.com/aws/aws-sdk-java/issues/2274
// TODO: Remove this once fixed in the AWS SDK
endpoint = clientSettings.protocol.toString() + "://" + endpoint;
}
final String region = Strings.hasLength(clientSettings.region) ? clientSettings.region : null;
LOGGER.debug("using endpoint [{}] and region [{}]", endpoint, region);
// If the endpoint configuration isn't set on the builder then the default behaviour is to try
// and work out what region we are in and use an appropriate endpoint - see AwsClientBuilder#setRegion.
// In contrast, directly-constructed clients use s3.amazonaws.com unless otherwise instructed. We currently
// use a directly-constructed client, and need to keep the existing behaviour to avoid a breaking change,
// so to move to using the builder we must set it explicitly to keep the existing behaviour.
//
// We do this because directly constructing the client is deprecated (was already deprecated in 1.1.223 too)
// so this change removes that usage of a deprecated API.
builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, region));

I thought it was better to match the new client behaviour (defaulting to HTTPS) rather than resurrecting the s3.client.{client-name}.protocol setting (which was deprecated in the client upgrade). It seems the linked issue is not relevant to the v2 client behaviour.

You can still use a HTTP server by setting the scheme explicitly in the s3.client.{client-name}.endpoint

Relates: CP-10914

@nicktindall nicktindall added >bug :Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs v8.19.0 labels Apr 29, 2025
@elasticsearchmachine elasticsearchmachine added Team:Distributed Coordination Meta label for Distributed Coordination team v9.1.0 labels Apr 29, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-distributed-coordination (Team:Distributed Coordination)

@elasticsearchmachine
Copy link
Collaborator

Hi @nicktindall, I've created a changelog YAML for you.

@ywangd
Copy link
Member

ywangd commented Apr 29, 2025

The change makes sense to me. Just a minor comment on the label: Since #126843 is not released, this PR should be a >non-issue.

Comment on lines 258 to 261
if ((endpoint.startsWith("http://") || endpoint.startsWith("https://")) == false) {
// Default protocol to https if not specified
// See https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/client-configuration.html#client-config-other-diffs
endpoint = "https://" + endpoint;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another minor comment: It might be useful to have an INFO log here? If the cluster was relying on an explicit http protocol setting and default to https here would not work for them. In that case, it feels useful to see a log message to indicate this have happened? Since #126843 is a breaking change, I am not entirely sure what the expectation is for end-users. It would be a moot point if they are expected to fix the protocol and endpoint settings before upgrade.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, I'll add one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in d3836c4

// Default protocol to https if not specified
// See https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/client-configuration.html#client-config-other-diffs
endpoint = "https://" + endpoint;
LOGGER.info("Defaulting to https for endpoint with no scheme [{}]", clientSettings.endpoint);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For other backward compatibility issues that we handle gracefully, we added a WARN log message. Since AWS requires a scheme on the endpoint, I'm leaning towards a WARN here, too.

IIUC, this is a stop-gap for CP-10914 to fix the issue? If the downstream teams intend to change this, then their warning message would eventually be fixed, and that sounds reasonable to me. I think I ideally we wouldn't want to support this forever?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, perhaps we need to update documentation for the setting also to indicate that scheme is required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0365fda

Copy link
Contributor Author

@nicktindall nicktindall May 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation still has an example without a scheme in it. It also still talks about the protocol property. I don't know where that documentation lives now, but it's not in this repo. We should create a ticket to update it to reflect the upgrade at some point, if that work is not already planned.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! TIL. I'll add a second PR to address these changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicktindall nicktindall requested a review from DiannaHohensee May 1, 2025 04:59
Copy link
Contributor

@DiannaHohensee DiannaHohensee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with a typo fix and a suggestion. Thanks for fixing this!

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to this quick fix to address the ECH use case, but then I think we should follow-up with one that chooses between http and https according to the .protocol client setting to preserve the SDKv1 behaviour. I still think .protocol should be deprecated, we don't need to support both ways to set the URL scheme; I will be opening a breaking-change proposal to recommend the removal of all the SDK-bwc shims in v10, including this one.

@nicktindall nicktindall merged commit 8dc6bf8 into elastic:main May 5, 2025
16 of 17 checks passed
@nicktindall nicktindall deleted the default_protocol_to_https branch May 5, 2025 08:47
nicktindall added a commit to nicktindall/elasticsearch that referenced this pull request May 5, 2025
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request May 6, 2025
The `s3.client.CLIENT_NAME.protocol` setting became unused in elastic#126843 as
it is inapplicable in the v2 SDK. However, the v2 SDK requires the
`s3.client.CLIENT_NAME.endpoint` setting to be a URL that includes a
scheme, so in elastic#127489 we prepend a `https://` to the endpoint if needed.
This commit generalizes this slightly so that we prepend `http://` if
the endpoint has no scheme and the `.protocol` setting is set to `http`.
DaveCTurner added a commit that referenced this pull request May 7, 2025
The `s3.client.CLIENT_NAME.protocol` setting became unused in #126843 as
it is inapplicable in the v2 SDK. However, the v2 SDK requires the
`s3.client.CLIENT_NAME.endpoint` setting to be a URL that includes a
scheme, so in #127489 we prepend a `https://` to the endpoint if needed.
This commit generalizes this slightly so that we prepend `http://` if
the endpoint has no scheme and the `.protocol` setting is set to `http`.
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request May 7, 2025
The `s3.client.CLIENT_NAME.protocol` setting became unused in elastic#126843 as
it is inapplicable in the v2 SDK. However, the v2 SDK requires the
`s3.client.CLIENT_NAME.endpoint` setting to be a URL that includes a
scheme, so in elastic#127489 we prepend a `https://` to the endpoint if needed.
This commit generalizes this slightly so that we prepend `http://` if
the endpoint has no scheme and the `.protocol` setting is set to `http`.

Backport of elastic#127744 to `8.19`
elasticsearchmachine pushed a commit that referenced this pull request May 7, 2025
* Reinstate use of S3 `protocol` client setting

The `s3.client.CLIENT_NAME.protocol` setting became unused in #126843 as
it is inapplicable in the v2 SDK. However, the v2 SDK requires the
`s3.client.CLIENT_NAME.endpoint` setting to be a URL that includes a
scheme, so in #127489 we prepend a `https://` to the endpoint if needed.
This commit generalizes this slightly so that we prepend `http://` if
the endpoint has no scheme and the `.protocol` setting is set to `http`.

Backport of #127744 to `8.19`

* Fix up warning assertions
ywangd pushed a commit to ywangd/elasticsearch that referenced this pull request May 9, 2025
ywangd pushed a commit to ywangd/elasticsearch that referenced this pull request May 9, 2025
The `s3.client.CLIENT_NAME.protocol` setting became unused in elastic#126843 as
it is inapplicable in the v2 SDK. However, the v2 SDK requires the
`s3.client.CLIENT_NAME.endpoint` setting to be a URL that includes a
scheme, so in elastic#127489 we prepend a `https://` to the endpoint if needed.
This commit generalizes this slightly so that we prepend `http://` if
the endpoint has no scheme and the `.protocol` setting is set to `http`.
afoucret pushed a commit to afoucret/elasticsearch that referenced this pull request May 9, 2025
The `s3.client.CLIENT_NAME.protocol` setting became unused in elastic#126843 as
it is inapplicable in the v2 SDK. However, the v2 SDK requires the
`s3.client.CLIENT_NAME.endpoint` setting to be a URL that includes a
scheme, so in elastic#127489 we prepend a `https://` to the endpoint if needed.
This commit generalizes this slightly so that we prepend `http://` if
the endpoint has no scheme and the `.protocol` setting is set to `http`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Coordination/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs >non-issue Team:Distributed Coordination Meta label for Distributed Coordination team v8.19.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants