Skip to content

Improve testing of STS credentials reloading#140114

Merged
DaveCTurner merged 6 commits intoelastic:mainfrom
DaveCTurner:2026/01/02/s3-web-identity-token-reload-tests
Jan 12, 2026
Merged

Improve testing of STS credentials reloading#140114
DaveCTurner merged 6 commits intoelastic:mainfrom
DaveCTurner:2026/01/02/s3-web-identity-token-reload-tests

Conversation

@DaveCTurner
Copy link
Contributor

Today CustomWebIdentityTokenCredentialsProviderTests verifies that a
S3 repository will reload credentials from STS, but fakes out the
interactions with the environment variables and system properties via
special test-only abstractions in the production code. This makes it
hard to be confident that the real system behaves as expected.

This commit replaces this suite with ones that verify the behaviour of a
real Elasticsearch node, removing the need for the extra abstractions in
the production code.

Today `CustomWebIdentityTokenCredentialsProviderTests` verifies that a
S3 repository will reload credentials from STS, but fakes out the
interactions with the environment variables and system properties via
special test-only abstractions in the production code. This makes it
hard to be confident that the real system behaves as expected.

This commit replaces this suite with ones that verify the behaviour of a
real Elasticsearch node, removing the need for the extra abstractions in
the production code.
@DaveCTurner DaveCTurner requested a review from mhl-b January 2, 2026 09:14
@DaveCTurner DaveCTurner added >test Issues or PRs that are addressing/adding tests :Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs v9.4.0 labels Jan 2, 2026
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine elasticsearchmachine added the Team:Distributed Coordination (obsolete) Meta label for Distributed Coordination team. Obsolete. Please do not use. label Jan 2, 2026
@mhl-b
Copy link
Contributor

mhl-b commented Jan 2, 2026

Is there third party test with real S3?

@DaveCTurner
Copy link
Contributor Author

No I don't think so, this is beyond what we have the tools to orchestrate in CI right now.

Comment on lines 118 to 129
// doesn't matter if the current credentials all become invalid, because they're so close to expiry that the SDK is refreshing them
// (as confirmed by the success of the verify command)
dynamicCredentials.clearValidCredentials();
assertVerifySuccess(repositoryName);

// if the refresh fails (incorrect token file contents) we keep on re-using the last good credentials
expectedWebIdentityTokenFileContents = randomAlphanumericOfLength(100);
assertVerifySuccess(repositoryName);

// if the last good credentials stop working then verification starts to fail
dynamicCredentials.clearValidCredentials();
assertVerifyFailure(repositoryName);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get it. First you clear creds and make verify call to refresh them. How come after second clear creds call refresh stops working?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh wait, AWS client should refresh creds on the background, isn't it? Even clearing creds should issue a refresh on next s3 operation?

Copy link
Contributor Author

@DaveCTurner DaveCTurner Jan 6, 2026

Choose a reason for hiding this comment

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

Yes, it's refreshing these creds each time. The second one has an incorrect expectedWebIdentityTokenFileContents so the STS request fails (but the old creds remain valid)

Copy link
Contributor

Choose a reason for hiding this comment

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

I see now... expectedWebIdentityTokenFileContents is hooked into the fixture. It does look magical.

Do you mind to add another comment line saying how expectedWebIdentityTokenFileContents = randomAlphanumericOfLength(100) manipulates test?

@DaveCTurner DaveCTurner requested a review from mhl-b January 6, 2026 16:59
Copy link
Contributor

@mhl-b mhl-b left a comment

Choose a reason for hiding this comment

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

LGTM, would be nice to have additional comment

Comment on lines 118 to 129
// doesn't matter if the current credentials all become invalid, because they're so close to expiry that the SDK is refreshing them
// (as confirmed by the success of the verify command)
dynamicCredentials.clearValidCredentials();
assertVerifySuccess(repositoryName);

// if the refresh fails (incorrect token file contents) we keep on re-using the last good credentials
expectedWebIdentityTokenFileContents = randomAlphanumericOfLength(100);
assertVerifySuccess(repositoryName);

// if the last good credentials stop working then verification starts to fail
dynamicCredentials.clearValidCredentials();
assertVerifyFailure(repositoryName);
Copy link
Contributor

Choose a reason for hiding this comment

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

I see now... expectedWebIdentityTokenFileContents is hooked into the fixture. It does look magical.

Do you mind to add another comment line saying how expectedWebIdentityTokenFileContents = randomAlphanumericOfLength(100) manipulates test?

@DaveCTurner DaveCTurner enabled auto-merge (squash) January 8, 2026 13:37
@DaveCTurner DaveCTurner merged commit f4bb553 into elastic:main Jan 12, 2026
35 checks passed
szybia added a commit to szybia/elasticsearch that referenced this pull request Jan 12, 2026
…i-project-tests

* upstream/main: (23 commits)
  Fix `testAckListenerReceivesNacksIfPublicationTimesOut` (elastic#140514)
  Reduce priority of clear-cache tasks (elastic#139685)
  Add docs and tests about `StreamOutput` to memory (elastic#140365)
  ES|QL - dense_vector support for COUNT, PRESENT, ABSENT aggregator functions (elastic#139914)
  Add release notes for v9.2.4 release (elastic#140487)
  Add release notes for v9.1.10 release (elastic#140488)
  Add conncectors release notes for 9.1.10, 9.2.4 (elastic#140499)
  Add parameter support in PromQL query durations (elastic#139873)
  Improve testing of STS credentials reloading (elastic#140114)
  Fix zstd native binary publishing script to support newer versions (elastic#140485)
  Add FlattenedFieldBinaryVsSortedSetDocValuesSyntheticSourceIT (elastic#140489)
  Store fallback match only text fields in binary doc values (elastic#140189)
  [DiskBBQ] Use the new merge executor for intra-merge parallelism (elastic#139942)
  ESQL: introduce support for mapping-unavailable fields (elastic#140463)
  Add ESNextOSQVectorsScorerTests (elastic#140436)
  Disable high cardinality tests on release builds (elastic#140503)
  ESQL: TRange timezone support (elastic#139911)
  Directly compressing `StreamOutput` (elastic#140502)
  ES|QL - fix dense vector enrich bug (elastic#139774)
  Use CrossProjectModeDecider in RemoteClusterService (elastic#140481)
  ...
spinscale pushed a commit to spinscale/elasticsearch that referenced this pull request Jan 21, 2026
Today `CustomWebIdentityTokenCredentialsProviderTests` verifies that a
S3 repository will reload credentials from STS, but fakes out the
interactions with the environment variables and system properties via
special test-only abstractions in the production code. This makes it
hard to be confident that the real system behaves as expected.

This commit replaces this suite with ones that verify the behaviour of a
real Elasticsearch node, removing the need for the extra abstractions in
the production code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Distributed/Snapshot/Restore Anything directly related to the `_snapshot/*` APIs Team:Distributed Coordination (obsolete) Meta label for Distributed Coordination team. Obsolete. Please do not use. >test Issues or PRs that are addressing/adding tests v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants