Repository navigation
auth/cephx: harden service ticket verification - #71231
Conversation
batrick
left a comment
There was a problem hiding this comment.
Overall it seems reasonable.
You should update the cephx documentation.
| // the key server clamps the ttl down and stamps the timestamps at mint | ||
| // time, so a ticket that outlives the configured ttl, or whose created or | ||
| // expires sits far from now, has been tampered with. bounding both ends to | ||
| // now also denies a bit-flip its hiding place: reaching a capability byte | ||
| // scrambles the timestamps in the garbled block, and a scrambled pair almost | ||
| // never lands back inside the window. the slack covers clock skew and a ttl | ||
| // change that has not reached us yet. utime_t normalizes a carry away only | ||
| // once the nanoseconds pass a full second, so a minted timestamp reaches at | ||
| // most 1e9 and a larger one is scrambled rather than skewed. | ||
| { | ||
| const double now = ceph_clock_now(); | ||
| const double created = ticket_info.ticket.created; | ||
| const double expires = ticket_info.ticket.expires; | ||
| const double max_ttl = service_id == CEPH_ENTITY_TYPE_AUTH ? | ||
| cct->_conf->auth_mon_ticket_ttl : cct->_conf->auth_service_ticket_ttl; | ||
| const double slop = 2 * max_ttl + 300; | ||
| if (ticket_info.ticket.created.nsec() > 1000000000ul || | ||
| ticket_info.ticket.expires.nsec() > 1000000000ul || | ||
| expires - created < 0 || expires - created > slop || | ||
| created < now - slop || created > now + slop || | ||
| expires < now - slop || expires > now + slop) { | ||
| ldout(cct, 0) << "verify_authorizer implausible ticket lifetime for " | ||
| << ticket_info.ticket.name << ", rejecting" << dendl; | ||
| return false; | ||
| } | ||
| } |
There was a problem hiding this comment.
This I'm not supported of for two reasons:
- The service daemon should not be enforcing timespans using its own view of the
auth_service_ticket_ttlthat may only be configured for the mon service. - The rotating service keys will naturally invalidate any ticket with timespans outside the validity period of the rotating service key itself (default 3hr).
There was a problem hiding this comment.
Rotation throws the ticket out once the key ages out, but it never checks created/expires inside the ticket, so on aes those bytes are still free space for a bit-flip.
There was a problem hiding this comment.
I've been reviewing this more. The created/expires fields are most likely to absorb corruption if ticket.caps is manipulated.
However, we do not need to check the timestamps relative to the daemon's clock. We can simply check the rotating service key validity period. Something like this is what Gemini suggested:
const double secret_age = service_secret.get_created();
const double ticket_age = ticket_info.ticket.created;
// A generous 7-day hardcoded slop window to catch garbage data without breaking on clock skew
const double generous_slop = 7 * 24 * 3600;
if (ticket_age < secret_age - generous_slop || ticket_age > secret_age + generous_slop) {
ldout(cct, 0) << "verify_authorizer: ticket timestamps decoupled from key creation, rejecting" << dendl;
return false;
}
There was a problem hiding this comment.
Perhaps we could reject any ticket whose created/expires falls outside the sealing key's own rotation window?
I could add a small lookup on the rotating keyring that returns that key's window (it already holds the secrets and their expirations, and the gap between them is the interval), then the verifier just checks created and expires land inside it.
There was a problem hiding this comment.
Yes, I think that's what I'm suggesting. You should add some slop just in case.
There was a problem hiding this comment.
I've been reviewing this more. The created/expires fields are most likely to absorb corruption if
ticket.capsis manipulated.However, we do not need to check the timestamps relative to the daemon's clock. We can simply check the rotating service key validity period. Something like this is what Gemini suggested:
const double secret_age = service_secret.get_created(); const double ticket_age = ticket_info.ticket.created; // A generous 7-day hardcoded slop window to catch garbage data without breaking on clock skew const double generous_slop = 7 * 24 * 3600; if (ticket_age < secret_age - generous_slop || ticket_age > secret_age + generous_slop) { ldout(cct, 0) << "verify_authorizer: ticket timestamps decoupled from key creation, rejecting" << dendl; return false; }
I looked at using the rotating service key’s creation time, but that key can already be about two ticket lifetimes old when it seals a new ticket. A fixed seven-day window can therefore reject valid auth tickets when auth_mon_ticket_ttl exceeds roughly 84 hours.
I used the session key’s creation time instead. The monitor creates the ticket and session key together, so their timestamps should be close. I allow a five-minute difference for clock changes or delays during issuance. This gives us a tighter check for corrupted timestamps without depending on the receiving daemon’s clock or TTL setting.
a0d259a to
22bb216
Compare
| // the key server clamps the ttl down and stamps the timestamps at mint | ||
| // time, so a ticket that outlives the configured ttl, or whose created or | ||
| // expires sits far from now, has been tampered with. bounding both ends to | ||
| // now also denies a bit-flip its hiding place: reaching a capability byte | ||
| // scrambles the timestamps in the garbled block, and a scrambled pair almost | ||
| // never lands back inside the window. the slack covers clock skew and a ttl | ||
| // change that has not reached us yet. utime_t normalizes a carry away only | ||
| // once the nanoseconds pass a full second, so a minted timestamp reaches at | ||
| // most 1e9 and a larger one is scrambled rather than skewed. | ||
| { | ||
| const double now = ceph_clock_now(); | ||
| const double created = ticket_info.ticket.created; | ||
| const double expires = ticket_info.ticket.expires; | ||
| const double max_ttl = service_id == CEPH_ENTITY_TYPE_AUTH ? | ||
| cct->_conf->auth_mon_ticket_ttl : cct->_conf->auth_service_ticket_ttl; | ||
| const double slop = 2 * max_ttl + 300; | ||
| if (ticket_info.ticket.created.nsec() > 1000000000ul || | ||
| ticket_info.ticket.expires.nsec() > 1000000000ul || | ||
| expires - created < 0 || expires - created > slop || | ||
| created < now - slop || created > now + slop || | ||
| expires < now - slop || expires > now + slop) { | ||
| ldout(cct, 0) << "verify_authorizer implausible ticket lifetime for " | ||
| << ticket_info.ticket.name << ", rejecting" << dendl; | ||
| return false; | ||
| } | ||
| } |
There was a problem hiding this comment.
I've been reviewing this more. The created/expires fields are most likely to absorb corruption if ticket.caps is manipulated.
However, we do not need to check the timestamps relative to the daemon's clock. We can simply check the rotating service key validity period. Something like this is what Gemini suggested:
const double secret_age = service_secret.get_created();
const double ticket_age = ticket_info.ticket.created;
// A generous 7-day hardcoded slop window to catch garbage data without breaking on clock skew
const double generous_slop = 7 * 24 * 3600;
if (ticket_age < secret_age - generous_slop || ticket_age > secret_age + generous_slop) {
ldout(cct, 0) << "verify_authorizer: ticket timestamps decoupled from key creation, rejecting" << dendl;
return false;
}
|
@mheler ? |
The verifier accepted every field in a service ticket once it decrypted, so nothing checked that the values inside were the ones the key server put there. Reject unexpected auid, allow_all, malformed capability buffers, and invalid ticket timestamps. Compare ticket creation with session-key creation, allowing five minutes either way for a clock step or scheduling delay between the two stamps. Co-authored-by: Dan van der Ster <[email protected]> Signed-off-by: Dan van der Ster <[email protected]> Signed-off-by: Matthew Heler <[email protected]>
Exercise fixed and rotating tickets through cephx_verify_authorizer. Cover valid and long-lived tickets, allow_all changes, auid corruption, malformed capability buffers, and timestamp corruption. Check symmetric creation-time slack, reversed timestamps, and nanosecond boundaries. Historical timestamps verify that the checks do not depend on the service daemon's clock. Co-authored-by: Dan van der Ster <[email protected]> Signed-off-by: Dan van der Ster <[email protected]> Signed-off-by: Matthew Heler <[email protected]>
22bb216 to
02b616e
Compare
|
This PR has been added to wip-bharath24-testing-20260918.001059-main. |
The verifier took a service ticket at its word once it decrypted, so nothing checked that the fields inside it were the ones the key server put there. A daemon then enforced whatever capabilities the ticket carried.
This tightens what the verifier will accept. It now rejects a ticket that sets allow_all, carries a uid the key server no longer varies, or claims an altered timestamp.
Fixes: https://tracker.ceph.com/issues/80932
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.