Skip to content

Reject partial EC2 metadata results - #176

Merged
bastelfreak merged 1 commit into
OpenVoxProject:mainfrom
djuarezg:atomic_ec2_metadata_resolution
Sep 10, 2026
Merged

bastelfreak merged 1 commit into
OpenVoxProject:mainfrom
djuarezg:atomic_ec2_metadata_resolution

Conversation

@djuarezg

@djuarezg djuarezg commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Resolve EC2 metadata with strict HTTP requests so a timeout, transport exception, or non-200 response aborts the entire recursive lookup. Build metadata separately and publish it only after every request succeeds. Previously, the shared HTTP helper converted failures to empty strings, making them indistinguishable from successful empty responses and allowing partially populated metadata to be cached.

Keep successful 200 responses with empty bodies unchanged. Preserve the existing lenient HTTP helper for other callers, userdata behavior, and the EC2 cache lifetime.

Add regression coverage for successful empty values, failed child requests, timeouts, and atomic publication.

Assisted-by: OpenAI Codex:GPT-5

Fixes #175

Checklist

I have:

Copilot AI lite review requested due to automatic review settings September 8, 2026 08:28
@bastelfreak bastelfreak added the bug Something isn't working label Sep 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The changes align with the issue’s acceptance criteria, preserve intended empty-200 behavior, and add regression coverage for failure/timeout and atomic publication semantics.

Pull request overview

This PR hardens EC2 metadata resolution to prevent partially populated metadata hashes from being returned and cached when any recursive child request fails. It introduces a strict HTTP request helper that differentiates HTTP 200 (including empty bodies) from non-200 responses and transport/timeouts, and updates the EC2 resolver to only publish metadata after the full traversal succeeds.

Changes:

  • Added Facter::Util::Resolvers::Http.get_request! which returns the body for HTTP 200 (including empty) and raises on non-200 or request errors/timeouts.
  • Updated Facter::Resolvers::Ec2 to build metadata in a local hash and only assign it to @fact_list[:metadata] after all recursive requests succeed; metadata resolution no longer triggers userdata retrieval.
  • Added/updated specs to cover successful empty values, rejection on unsuccessful/timeout child requests, and atomic publication (no partial @fact_list[:metadata]).
File summaries
File Description
lib/facter/util/resolvers/http.rb Introduces strict get_request! and refactors request execution to enable raising on non-200/transport errors.
lib/facter/resolvers/ec2.rb Switches EC2 metadata traversal to strict HTTP and publishes metadata atomically only after successful recursion.
spec/facter/util/resolvers/http_spec.rb Adds coverage for get_request! success (including empty body) and failure/timeout/error propagation.
spec/facter/resolvers/ec2_spec.rb Updates behavior expectations to reject partial metadata and ensures userdata isn’t fetched during metadata resolution.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@djuarezg
djuarezg force-pushed the atomic_ec2_metadata_resolution branch from 9371e67 to 3e224f0 Compare September 8, 2026 08:35
Resolve EC2 metadata with strict HTTP requests so a timeout,
transport exception, or non-200 response aborts the entire recursive
lookup. Build metadata separately and publish it only after every
request succeeds. Previously, the shared HTTP helper converted failures
to empty strings, making them indistinguishable from successful empty
responses and allowing partially populated metadata to be cached.

Keep successful 200 responses with empty bodies unchanged. Preserve the
existing lenient HTTP helper for other callers, userdata behavior, and
the EC2 cache lifetime.

Add regression coverage for successful empty values, failed child
requests, timeouts, and atomic publication.

Assisted-by: OpenAI Codex:GPT-5
Signed-off-by: Daniel Juarez <djuarezg@proton.me>
@djuarezg
djuarezg force-pushed the atomic_ec2_metadata_resolution branch from 3e224f0 to aaca858 Compare September 8, 2026 08:39
@djuarezg

djuarezg commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Sorry, had to force-push a few times to get GitHub to get commit verified... a bit messy configuration on my account from past jobs.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The implementation matches the stated requirements and includes focused regression coverage.

Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@bastelfreak
bastelfreak merged commit 90c42fe into OpenVoxProject:main Sep 10, 2026
57 of 59 checks passed
@OpenVoxProjectBot

Copy link
Copy Markdown
Contributor

Successfully created backport PR for 5.x:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 5.x bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: EC2 metadata resolver can return and cache a partially populated fact when a child HTTP request fails

4 participants