-
Notifications
You must be signed in to change notification settings - Fork 96
SPN selection fails for keytabs with multiple keys when validating Windows AD Kerberos tickets #392
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
Comments
I've been meaning to deal with this problem for a while now, so thanks for opening the bug and giving me an excuse to do it. |
Thank you very much for your swift response and action! Would it be helpful if I throw together a test setup for PR #393 in the scenario I described above? (To keep the test realistic, I'd need access to the system we first noticed the issue on; I think that should be doable next week after the Easter holidays) |
It would absolutely be helpful and would be much appreciated. That said, if you want to just grab the change and try it out manually that also works. It's a relatively simple change so it should theoretically "just" work. |
So, today I finally managed to have a test session with the person maintaining the system in question. We found that there is still a problem with the current changes: While they solve the problem on the decryption side of things, there's a separate signature check that's still behaving like before (and, thus, failing). I've applied a similar patch to the signature check here: With this patch also included, our tests were successful. |
Oh yeah, that makes sense. Let me merge those changes in. |
As an aside: I tried to adapt the existing web example into a simple test server executable to perform our tests, but had trouble simply building the project (it's still written for an old .NET Core version and you'd have to wrangle the project setup to get it to build). So, I quickly sketched out a very basic example using .NET 8.0 in the newer "Minimal API" style instead: It's very bare bones (no middleware etc., which certainly is what one would do in a production setting), but I think it doesn't do too bad of a job outlining how the HTTP SPNEGO dance for Kerberos auth works from a protocol perspective. Might this be an interesting example to keep in the official repo? If so, I could prepare a PR… |
Absolutely. Always willing to accept these sorts of things. I haven't done a good job keeping the samples up to date. Everything tends to fall into the |
Describe the bug
I'm in the process of writing a service that uses Kerberos.NET to process and validate Windows AD-issued Kerberos tickets without the service being part of the ticket issuing domain. My service must have the ability to accept tickets for multiple SPNs (for multiple hostnames), which is why I'm dealing with multiple keys exported through Windows'
ktpass
command (one for each SPN, all of which have a dedicated service user for the secret in the ticket issuing domain). I've merged all of these keytab entries into a single keytab file using the MIT kerberos tooling (i.e.ktutil
).What I'm observing with this setup is that the Kerberos.NET validator (created with the
KeyTable
from said file) fails to select the appropriate key for the ticket I want to validate (see here). This causesKeyTable.GetKey()
to fall back to the first key with the requiredEncryptionType
or simply to the first key in the keytab file. In a keytab file where all keys have the same encryption type and the right key isn't the first entry, this leads to the validator complaining about an "invalid checksum":Splitting the
KeyTable
into its entries, creating dedicated validators (one for each key) and selecting the right one for a given ticket (with some ugly workaround code to determine the ticket's SPN) works as expected and the validator for the right key also accepts the provided ticket.To Reproduce
ktpass
ktutil
binaryExpected behavior
The validator should pick the right key for the specified SPN and succeed in validating a valid ticket.
Additional context
I dug into the matching logic that decides whether a
KeyTable
entry corresponds to the SPN of a given ticket and found that the approach of KrbPrincipalName.Matches() doesn't work properly for Windows AD keytab entries and Windows AD tickets:The method compares the output of KrbPrincipalName.MakeFullName() applied to both principal names being compared.
MakeFullName
replaces the "service" portion of the principal name (as dubbed by RFC4120, i.e. the protocol such asHTTP/
) with the stringhost/
ONLY IF the principal name was split into two or more segments already. Upon inspecting the keytab entries and tickets issued by Windows AD servers, I noticed that the tickets specified aName
that has been split into its components (i.e.HTTP
and themyhost.mydomain.com
) whereas the keytab entry exported by Windows'ktpass
utility contains theName
as a single, concatenated string (i.e.HTTP/myhost.mydomain.com
).This means that the
Matches()
call will end up comparing"host/myhost.mydomain.com"
to"HTTP/myhost.mydomain.com"
and deducing that the keytab entry and ticket aren't compatible. I'm adding two screenshots frombruce
'skdecode
utility to illustrate the issue in the keytab/ticket structure.Screenshots
Keytab entry:

Note that this depicts the decoded keytab file as exported by Windows'
ktpass
utility. This keytab entry hasn't been passed intoktutil
yet, so I'm quite certain that the MIT Kerberos implementation is not to blame.Ticket:

The text was updated successfully, but these errors were encountered: