Repository navigation
Add regression test for IMDSv2-only availability-zone detection - #107767
Conversation
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]>
|
Workflow [PR], commit [7fddf14] Summary: ✅ AI ReviewSummaryThis PR adds focused integration coverage for IMDSv2-only availability-zone detection in PR Metadata💡 The selected
Final VerdictStatus: ✅ Approve No inline code findings. The metadata cleanup above is non-blocking. |
LLVM Coverage Report
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
|
Closes: #81402
Related: #81323
Related: #103549
Issue #81402 reported that availability-zone detection failed on EC2 instances configured for "IMDSv2 only (token required)":
getAvailabilityZoneOrExceptionissued a plain unauthenticatedGETagainst the instance metadata service, which such instances reject with401 Unauthorized, sotryGetRunningAvailabilityZonefailed.The behavior was already fixed in master by #81323 (
kafka_aws_az_aware), which makesgetAvailabilityZoneOrExceptionacquire an IMDSv2 session token viaPUT /latest/api/tokenand send it with the availability-zoneGET, 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 intest_placement_info.This PR adds that missing regression coverage:
imdsv2_server.pythat issues tokens onPUT /latest/api/tokenand rejectsGETrequests without a validx-aws-ec2-metadata-tokenheader (401);node_imds_v2instance and atest_placement_info_from_imdsv2_onlycase 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_onlyand the existingtest_placement_info_from_imdsboth pass (2 passed).Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Documentation entry for user-facing changes
Version info
26.6.1.942