fix(core): remove identity from /meta-data index#3905
Conversation
Signed-off-by: Patrice Breton <pbreton@nvidia.com>
Summary by CodeRabbit
WalkthroughThe ChangesMetadata listing contract
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/fmds/src/rest_server.rs (1)
535-567: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse a table-driven check for both metadata index variants.
The
/meta-dataand/meta-data/assertions duplicate the same logic. Iterate over both paths so future contract changes cannot update one case while leaving the other stale.Suggested refactor
- let (status, body) = get_request(port, "meta-data").await; - assert_eq!(status, StatusCode::OK); - assert_eq!(body, expected); - assert!( - !body - .lines() - .any(|line| line == machine_identity::META_DATA_IDENTITY_CATEGORY), - "identity must not be listed in /meta-data/ (cloud-init EC2 crawl)" - ); - - // Also check with trailing slash (cloud-init compat). - let (status, body) = get_request(port, "meta-data/").await; - assert_eq!(status, StatusCode::OK); - assert_eq!(body, expected); - assert!( - !body - .lines() - .any(|line| line == machine_identity::META_DATA_IDENTITY_CATEGORY), - "identity must not be listed in /meta-data/ (cloud-init EC2 crawl)" - ); + for path in ["meta-data", "meta-data/"] { + let (status, body) = get_request(port, path).await; + assert_eq!(status, StatusCode::OK); + assert_eq!(body, expected); + assert!( + !body + .lines() + .any(|line| line == machine_identity::META_DATA_IDENTITY_CATEGORY), + "identity must not be listed in {path} (cloud-init EC2 crawl)" + ); + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/fmds/src/rest_server.rs` around lines 535 - 567, Refactor test_get_metadata_listing to iterate over both "meta-data" and "meta-data/" paths in a table-driven loop. Keep the shared status, body, and identity-exclusion assertions inside the loop, preserving the existing expected response and cloud-init compatibility checks.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@crates/fmds/src/rest_server.rs`:
- Around line 535-567: Refactor test_get_metadata_listing to iterate over both
"meta-data" and "meta-data/" paths in a table-driven loop. Keep the shared
status, body, and identity-exclusion assertions inside the loop, preserving the
existing expected response and cloud-init compatibility checks.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 0b8c5668-dbab-4fbf-8ae6-120a3fac5a7c
📒 Files selected for processing (2)
crates/agent/src/instance_metadata_endpoint.rscrates/fmds/src/rest_server.rs
💤 Files with no reviewable changes (1)
- crates/agent/src/instance_metadata_endpoint.rs
Scope (not universal): only images whose cloud-init uses the EC2/IMDS datasource that crawls /meta-data/.
Root cause: get_metadata_params (crates/fmds/src/rest_server.rs:179-191) advertises identity, but serve_meta_data_identity (crates/dpu-fmds-shared/src/machine_identity.rs:525-531) returns 400 without a Metadata: true header. cloud-init crawls with plain GETs; a 400 on any advertised key is fatal (404 is tolerated) → empty metadata → KeyError: 'instance-id' (DataSourceEc2.py:242) → datasource rejected → DataSourceNone → no phone-home.
Fix: remove identity from the /meta-data/ index (keep the route for Metadata: true clients). Also add a regression test that the plain /meta-data/ index excludes identity.
Type of Change
Breaking Changes
Testing