Skip to content

auth/cephx: harden service ticket verification - #71231

Merged
mheler merged 2 commits into
ceph:mainfrom
mheler:wip-cephx-ticket-tamper-checks
Sep 27, 2026
Merged

mheler merged 2 commits into
ceph:mainfrom
mheler:wip-cephx-ticket-tamper-checks

Conversation

@mheler

@mheler mheler commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

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 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.

@batrick batrick left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall it seems reasonable.

You should update the cephx documentation.

Comment thread src/auth/cephx/CephxProtocol.cc Outdated
Comment on lines +533 to +558
// 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;
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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_ttl that 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).

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.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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;
}

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.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, I think that's what I'm suggesting. You should add some slop just in case.

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'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;
}

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.

@mheler
mheler force-pushed the wip-cephx-ticket-tamper-checks branch 2 times, most recently from a0d259a to 22bb216 Compare August 21, 2026 22:06
Comment thread src/auth/cephx/CephxProtocol.cc Outdated
Comment on lines +533 to +558
// 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;
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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;
}

@batrick

batrick commented Sep 10, 2026

Copy link
Copy Markdown
Member

@mheler ?

mheler and others added 2 commits September 16, 2026 06:38
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]>
@mheler
mheler force-pushed the wip-cephx-ticket-tamper-checks branch from 22bb216 to 02b616e Compare September 16, 2026 11:48
@mheler
mheler requested a review from batrick September 16, 2026 12:01

@batrick batrick left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like it!

@mheler
mheler marked this pull request as ready for review September 17, 2026 20:14
@mheler
mheler requested review from a team as code owners September 17, 2026 20:14
@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath24-testing-20260918.001059-main.

@NitzanMordhai

Copy link
Copy Markdown
Contributor

@mheler
mheler merged commit 986f3c8 into ceph:main Sep 27, 2026
18 checks passed
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