Repository navigation
mgr/MgrCap: clear grants on profile-evaluation parse failure - #72346
stzuraski898 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
@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
capthat 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
| // "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)"; |
There was a problem hiding this comment.
we already have parse_bad why do we want to retest it here as well?
There was a problem hiding this comment.
I removed this test, and instead added to ParseBad. ParseBad now asserts grants.empty() and get_str() == "" after each failed parse.
| << "Current: grants retained after failed profile parse; " | ||
| << "Expected: grants cleared (empty cap)"; | ||
| ASSERT_EQ("", stringify(cap)) | ||
| << "Current: grants retained after failed profile parse; " |
There was a problem hiding this comment.
Assert already print that, just noise
There was a problem hiding this comment.
This test was removed (see above)
| 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; " |
There was a problem hiding this comment.
Assert already print that, just noise
There was a problem hiding this comment.
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]>
ffa9867 to
c11a36f
Compare
NitzanMordhai
left a comment
There was a problem hiding this comment.
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()); | |||
There was a problem hiding this comment.
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]>
c11a36f to
5a39382
Compare
|
This PR has been added to wip-bharath37-testing-20261124.044935-main. |
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
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job DefinitionYou must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.