Skip to content

Add regression test for IMDSv2-only availability-zone detection - #107767

Merged
alexey-milovidov merged 1 commit into
masterfrom
ci/test-imdsv2-only-availability-zone
Jun 17, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
ci/test-imdsv2-only-availability-zone

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jun 17, 2026 •

Copy link
Copy Markdown
Member

Closes: #81402
Related: #81323
Related: #103549

Issue #81402 reported that availability-zone detection failed on EC2 instances configured for "IMDSv2 only (token required)": getAvailabilityZoneOrException issued a plain unauthenticated GET against the instance metadata service, which such instances reject with 401 Unauthorized, so tryGetRunningAvailabilityZone failed.

The behavior was already fixed in master by #81323 (kafka_aws_az_aware), which makes getAvailabilityZoneOrException acquire an IMDSv2 session token via PUT /latest/api/token and send it with the availability-zone GET, falling back to the token-less IMDSv1 request when the metadata service does not implement the token endpoint. That change did not, however, add a test covering the IMDSv2-only scenario in test_placement_info.

This PR adds that missing regression coverage:

  • a new mock metadata server imdsv2_server.py that issues tokens on PUT /latest/api/token and rejects GET requests without a valid x-aws-ec2-metadata-token header (401);
  • a node_imds_v2 instance and a test_placement_info_from_imdsv2_only case asserting the availability zone is still loaded against such an endpoint.

The test originates from #103549, which proposed an equivalent production fix before #81323 was merged; that pull request is now superseded for the code change, so only its regression test is kept here (credit retained via Co-authored-by).

Verified locally: test_placement_info_from_imdsv2_only and the existing test_placement_info_from_imds both pass (2 passed).

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Documentation entry for user-facing changes

  • Documentation is not required (test-only change).

Version info

  • Merged into: 26.6.1.942

Issue #81402 reported that availability-zone detection failed on EC2
instances configured for "IMDSv2 only (token required)", because
`getAvailabilityZoneOrException` issued a plain unauthenticated `GET`
against the instance metadata service, which such instances reject with
`401 Unauthorized`.

The behavior was fixed in master by #81323 (`kafka_aws_az_aware`), which
makes `getAvailabilityZoneOrException` acquire an IMDSv2 session token via
`PUT /latest/api/token` and send it with the availability-zone `GET`,
falling back to the token-less IMDSv1 request when the metadata service
does not implement the token endpoint. That change did not add a test
covering the IMDSv2-only scenario in `test_placement_info`.

This adds that missing coverage: a new mock metadata server
`imdsv2_server.py` that issues tokens on `PUT /latest/api/token` and
rejects `GET` requests without a valid `x-aws-ec2-metadata-token` header
(`401`), plus a `node_imds_v2` instance and a
`test_placement_info_from_imdsv2_only` case that asserts the availability
zone is still loaded against such an endpoint.

The test originates from #103549, which proposed an equivalent fix before
#81323 was merged; that pull request is now superseded for the production
change, so only its regression test is kept here.

Co-Authored-By: ashrithb <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7fddf14]

Summary: ✅


AI Review

Summary

This PR adds focused integration coverage for IMDSv2-only availability-zone detection in PlacementInfo: the mock metadata server requires a valid x-aws-ec2-metadata-token, and the new test exercises the startup path that would have failed with the old unauthenticated GET behavior. I found no code-level blockers.

PR Metadata

💡 The selected Changelog category is Build/Testing/Packaging Improvement, but the Changelog entry is Not for changelog (test-only change). With that category, release tooling can treat the literal Not for changelog text as a changelog item. For this test-only PR, replace the category with:

- Not for changelog (changelog entry is not required)

Final Verdict

Status: ✅ Approve

No inline code findings. The metadata cleanup above is non-blocking.

@clickhouse-gh clickhouse-gh Bot added the pr-build Pull request with build/testing/packaging improvement label Jun 17, 2026
@thevar1able thevar1able self-assigned this Jun 17, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.30% 85.20% -0.10%
Functions 92.30% 92.30% +0.00%
Branches 77.50% 77.40% -0.10%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 354 line(s), 18 function(s) across 106 file(s) · Details

Top files
  • src/Backups/BackupEntriesCollector.cpp: 31 line(s), 2 function(s)
  • src/Storages/StorageReplicatedMergeTree.cpp: 23 line(s)
  • src/Interpreters/DDLWorker.cpp: 17 line(s)
  • src/Common/ZooKeeper/ZooKeeperImpl.cpp: 15 line(s)
  • src/Storages/MergeTree/ReplicatedMergeTreePartCheckThread.cpp: 13 line(s)

Full report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jun 17, 2026
Merged via the queue into master with commit ecb4ddf Jun 17, 2026
165 checks passed
@alexey-milovidov
alexey-milovidov deleted the ci/test-imdsv2-only-availability-zone branch June 17, 2026 21:54
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-build Pull request with build/testing/packaging improvement pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

avaliability zone detection (getRunningAvailabilityZone) may not work on aws sometimes

3 participants