Skip to content

feat(mmds): Add flag for making MMDS operate like EC2 IMDS #5310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 24, 2025

Conversation

zulinx86
Copy link
Contributor

@zulinx86 zulinx86 commented Jul 17, 2025

Changes

Added an optional imds_compat field (default to false if not provided) to PUT requests to /mmds/config to enforce MMDS to always respond plain text contents in the IMDS format regardless of the Accept header in requests.

Reason

While EC2 IMDS only supports text/plain content type and ignores Accept header, Firecracker MMDS supports not only text/plain but also application/json. If users don't have the control of libraries that set "Accept: application/json" but expect MMDS to behave like EC2 IMDS, the above difference becomes a problem.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following Developer
Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.

PR Checklist

  • I have read and understand CONTRIBUTING.md.
  • I have run tools/devtool checkbuild --all to verify that the PR passes
    build checks on all supported architectures.
  • I have run tools/devtool checkstyle to verify that the PR passes the
    automated style checks.
  • I have described what is done in these changes, why they are needed, and
    how they are solving the problem in a clear and encompassing way.
  • I have updated any relevant documentation (both in code and in the docs)
    in the PR.
  • I have mentioned all user-facing changes in CHANGELOG.md.
  • [ ] If a specific issue led to this PR, this PR closes the issue.
  • When making API changes, I have followed the
    Runbook for Firecracker API changes.
  • I have tested all new and changed functionalities in unit tests and/or
    integration tests.
  • [ ] I have linked an issue to every new TODO.

  • This functionality cannot be added in rust-vmm.

Copy link

codecov bot commented Jul 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.03%. Comparing base (70745e1) to head (dd1410e).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5310      +/-   ##
==========================================
+ Coverage   82.96%   83.03%   +0.06%     
==========================================
  Files         250      250              
  Lines       26828    26828              
==========================================
+ Hits        22259    22276      +17     
+ Misses       4569     4552      -17     
Flag Coverage Δ
5.10-c5n.metal 83.48% <100.00%> (+0.01%) ⬆️
5.10-m5n.metal 83.48% <100.00%> (+0.02%) ⬆️
5.10-m6a.metal 82.69% <100.00%> (+<0.01%) ⬆️
5.10-m6g.metal 79.14% <100.00%> (+0.01%) ⬆️
5.10-m6i.metal 83.47% <100.00%> (+0.01%) ⬆️
5.10-m7a.metal-48xl 82.68% <100.00%> (?)
5.10-m7g.metal 79.14% <100.00%> (+0.01%) ⬆️
5.10-m7i.metal-24xl 83.43% <100.00%> (?)
5.10-m7i.metal-48xl 83.44% <100.00%> (?)
5.10-m8g.metal-24xl 79.13% <100.00%> (?)
5.10-m8g.metal-48xl 79.13% <100.00%> (?)
6.1-c5n.metal 83.52% <100.00%> (+0.01%) ⬆️
6.1-m5n.metal 83.52% <100.00%> (+0.02%) ⬆️
6.1-m6a.metal 82.74% <100.00%> (+0.01%) ⬆️
6.1-m6g.metal 79.13% <100.00%> (+<0.01%) ⬆️
6.1-m6i.metal 83.52% <100.00%> (+0.01%) ⬆️
6.1-m7a.metal-48xl 82.72% <100.00%> (?)
6.1-m7g.metal 79.14% <100.00%> (+0.01%) ⬆️
6.1-m7i.metal-24xl 83.54% <100.00%> (?)
6.1-m7i.metal-48xl 83.54% <100.00%> (?)
6.1-m8g.metal-24xl 79.13% <100.00%> (?)
6.1-m8g.metal-48xl 79.13% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zulinx86 zulinx86 force-pushed the mmds_accept branch 2 times, most recently from ce0ed24 to c2c67c3 Compare July 17, 2025 16:35
@zulinx86 zulinx86 changed the title [DRAFT] feat(mmds): Add flag for making MMDS operate like EC2 IMDS feat(mmds): Add flag for making MMDS operate like EC2 IMDS Jul 17, 2025
@zulinx86 zulinx86 marked this pull request as ready for review July 17, 2025 16:54
@zulinx86 zulinx86 added the Status: Awaiting review Indicates that a pull request is ready to be reviewed label Jul 18, 2025
@zulinx86 zulinx86 enabled auto-merge (rebase) July 18, 2025 07:58
Copy link
Contributor

@Manciukic Manciukic left a comment

Choose a reason for hiding this comment

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

Nice work! Mostly lgtm, just a couple of nits.

nit: commit message cccfe86 s/oeprate/operate/

@zulinx86 zulinx86 force-pushed the mmds_accept branch 2 times, most recently from 7833b2b to 27ab7ab Compare July 18, 2025 12:52
@zulinx86 zulinx86 requested review from Manciukic and roypat July 18, 2025 12:53
zulinx86 added 3 commits July 22, 2025 07:25
The snapshot versioning follows the semantic versioning (i.e. snapshot
restore is allowed only if the restore major version is same as the
snapshot major version and the restore minor version is greater than or
equal to the snapshot minor version). We already bumped the major
version up multiple times since we added `mmds_version` state. That
means snapshots taken when `mmds_version` didn't exist are not able to
be restored in the current version. The code to restore such snapshots
is no longer needed.

Signed-off-by: Takahiro Itazuri <[email protected]>
Currently the only MMDS-related state saved in the snapshot is the
version info. To enable persisting more MMDS-related state, generalize
the struct for MMDS state.

Bumped up the snapshot major version since it is a breaking change.

Signed-off-by: Takahiro Itazuri <[email protected]>
The method sets not only the version but also the AAD.

Signed-off-by: Takahiro Itazuri <[email protected]>
roypat
roypat previously approved these changes Jul 22, 2025
Manciukic
Manciukic previously approved these changes Jul 22, 2025
While EC2 IMDS only supports text/plain and ignores Accept header,
Firecracker MMDS supports not only text/plain but also application/json.
If users don't have the control of libraries that set "Accept:
application/json" but expect MMDS to behave like EC2 IMDS, the above
difference becomes a problem. Not to break existing workloads, add a new
flag `imds_compat` (default to false) to PUT /mmds/config API.

Signed-off-by: Takahiro Itazuri <[email protected]>
@zulinx86 zulinx86 dismissed stale reviews from Manciukic and roypat via 8577d09 July 23, 2025 10:40
Manciukic
Manciukic previously approved these changes Jul 23, 2025
Copy link
Contributor

@Manciukic Manciukic left a comment

Choose a reason for hiding this comment

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

Ship it 🚢

         /|\
       /__| )
     /____| ))
   /______| )))
 /________|  )))
         _|____))
 \======| o o /
~~~~~~~~~~~~~~~~~~~

@zulinx86 zulinx86 requested a review from roypat July 23, 2025 11:57
`_validate_mmds_snapshot()` is used only once.

Signed-off-by: Takahiro Itazuri <[email protected]>
@zulinx86
Copy link
Contributor Author

@Manciukic Sorry, I needed to fix a style error (unused import)...

@zulinx86 zulinx86 merged commit ba13237 into firecracker-microvm:main Jul 24, 2025
7 checks passed
@zulinx86 zulinx86 deleted the mmds_accept branch July 24, 2025 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting review Indicates that a pull request is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants