Skip to content

mgr/MgrCap: clear grants on profile-evaluation parse failure - #72346

Open
stzuraski898 wants to merge 2 commits into
ceph:mainfrom
stzuraski898:wip-sz-81015-mgrcap-clear-grants-on-profile-failure
Open

stzuraski898 wants to merge 2 commits into
ceph:mainfrom
stzuraski898:wip-sz-81015-mgrcap-clear-grants-on-profile-failure

Conversation

@stzuraski898

@stzuraski898 stzuraski898 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

MgrCap::parse cleared grants only on the grammar-parse failure path,
violating the "no grants are kept after parsing failed" invariant
(6350bee) when a grammar-valid capability failed profile evaluation.
This was introduced in 9193d87 ("mgr: validate that profile caps
are actually valid"), which added the profile-evaluation failure return
without a matching grants.clear(); the result was that an authorization
object retained unvalidated grammar-parsed grants after parse() returned
false (e.g. "profile does-not-exist" or "profile rbd badkey=x").

Restructure parse() so both failure paths fall through to a single
grants.clear()/return false, without weakening profile validation.

Fixes: https://tracker.ceph.com/issues/81015
Assisted-by: Claude Code (Claude Opus 4.8)

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The focused fix preserves profile validation and comprehensively tests the authorization invariant.

Review effort: Balanced
Findings: None

What changed in this PR

Ensures failed MGR capability profile evaluation cannot retain unauthorized grants.

Changes:

  • Unifies parse-failure cleanup.
  • Adds regression tests for invalid profiles and arguments.
File Description
src/​mgr/​MgrCap.cc Clears grants after all parse failures.
src/​test/​mgr/​test_mgrcap.cc Verifies failed profile parsing leaves no grants.

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

@NitzanMordhai NitzanMordhai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@stzuraski898 please rewrite the commit message. This is not a security issue at all.
Every caller checks parse()'s return value and stops right there:

  • AuthMonitor::_was_parsing_fine() parses into a function-local cap that is
    thrown away when parse() returns false (src/mon/AuthMonitor.cc:1464).
  • DaemonServer::ms_handle_authentication() returns false as soon as
    s->caps.parse() fails, so the session is rejected and s->caps is never
    passed to is_capable() (src/mgr/DaemonServer.cc:341).

So no authorization object with leftover grants is ever used. The wording
"an authorization object retained unvalidated grammar-parsed grants" reads
like a privilege bypass.

The change is still worth having, just describe it for what it is: restoring
the "no grants are kept after parsing failed" invariant so the object is
consistent on every failure path. Please drop the impact claim and keep the
tracker reference.

please fix the rest of the code comment that i added

Comment thread src/mgr/MgrCap.cc Resolved
Comment thread src/test/mgr/test_mgrcap.cc Outdated
Comment on lines +347 to +352
// "profile does-not-exist" is grammar-valid but names an unrecognized
// profile, so expand_profile() reports an error and parse() must fail.
ASSERT_FALSE(cap.parse("profile does-not-exist", &cout));
ASSERT_TRUE(cap.grants.empty())
<< "Current: grants retained after failed profile parse; "
<< "Expected: grants cleared (empty cap)";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we already have parse_bad why do we want to retest it here as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed this test, and instead added to ParseBad. ParseBad now asserts grants.empty() and get_str() == "" after each failed parse.

Comment thread src/test/mgr/test_mgrcap.cc Outdated
<< "Current: grants retained after failed profile parse; "
<< "Expected: grants cleared (empty cap)";
ASSERT_EQ("", stringify(cap))
<< "Current: grants retained after failed profile parse; "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Assert already print that, just noise

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This test was removed (see above)

Comment thread src/test/mgr/test_mgrcap.cc Outdated
MgrCap rbd_cap;
ASSERT_FALSE(rbd_cap.parse("profile rbd badkey=x", &cout));
ASSERT_TRUE(rbd_cap.grants.empty())
<< "Current: grants retained after failed profile parse; "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Assert already print that, just noise

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This test was removed (see above)

MgrCap::parse cleared grants only on the grammar-parse failure path,
violating the "no grants are kept after parsing failed" invariant
(6350bee) when a grammar-valid capability failed profile evaluation.
This was introduced in 9193d87 ("mgr: validate that profile caps
are actually valid"), which added the profile-evaluation failure return
without a matching grants.clear(); the result was that grants (and the
cap text) were left populated after parse() returned false (e.g.
"profile does-not-exist" or "profile rbd badkey=x").

Restructure parse() so both failure paths fall through to a single
grants.clear()/text.clear()/return false, without weakening profile
validation. The object is now consistent on every failure path.

Fixes: https://tracker.ceph.com/issues/81015
Assisted-by: Claude Code (Claude Opus 4.8)
Signed-off-by: Steven Zuraski <[email protected]>
@stzuraski898
stzuraski898 force-pushed the wip-sz-81015-mgrcap-clear-grants-on-profile-failure branch from ffa9867 to c11a36f Compare November 10, 2026 19:07

@NitzanMordhai NitzanMordhai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, please check the suggestion and maybe you can add it to the test

@@ -179,6 +179,9 @@ TEST(MgrCap, ParseBad)
MgrCap cap;
std::cout << "Testing bad input: '" << unparseable << "'" << std::endl;
ASSERT_FALSE(cap.parse(unparseable, &cout));
// a failed parse must leave the object empty
ASSERT_TRUE(cap.grants.empty());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: each input gets a fresh MgrCap, so the empty get_str() check only matters for the profile cases.
Could you add a test that parses a good cap and then a bad one on the same object? That covers the old-text-left-behind case that text.clear() fixes.

maybe:

MgrCap cap;
ASSERT_TRUE(cap.parse("allow *", nullptr));
ASSERT_EQ("allow *", cap.get_str());

 ASSERT_FALSE(cap.parse(unparseable, &cout));
 // a failed parse must leave the object empty
 ASSERT_TRUE(cap.grants.empty());
 ASSERT_EQ("", cap.get_str());

MgrCap.ParseBad only checked that parse() returned false, so a failed
parse that left grants or text behind went unnoticed. Also assert that
grants and the cap text are empty after every failed parse. The inputs
already include grammar-valid capabilities that fail profile evaluation
(e.g. "profile unknown" and "profile rbd invalid-key=value"), which
exercises the path fixed in the previous commit.

Fixes: https://tracker.ceph.com/issues/81015
Assisted-by: Claude Code (Claude Opus 4.8)
Signed-off-by: Steven Zuraski <[email protected]>
@stzuraski898
stzuraski898 force-pushed the wip-sz-81015-mgrcap-clear-grants-on-profile-failure branch from c11a36f to 5a39382 Compare November 23, 2026 22:27
@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath37-testing-20261124.044935-main.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants