Documentation
¶
Overview ¶
Package kdc issues Kerberos tickets from a go-authn/directory.
It is the other half of github.com/go-authn/krb5, which accepts them. A service that verifies tickets needs no KDC and should not import this; a site that wants its own realm, backed by the same people its LDAP and its NFS already know, does.
What it can and cannot be backed by ¶
A KDC must DECRYPT the client's pre-authentication with that person's long-term key. It follows that only a directory source holding the PASSWORD can back one: sqldir and hcldir can, and a directory.Verifier — a bind against somebody else's LDAP, or a hash comparison — CANNOT, however well it answers "is this the right password".
That is a property of Kerberos rather than a limitation here, and this package refuses at configuration time rather than at the first kinit.
What it implements ¶
AS-REQ and TGS-REQ over UDP and TCP, with encrypted-timestamp pre-authentication required. It does not implement cross-realm referrals, PKINIT, FAST, renewable or postdated tickets, or a kadmin protocol: keys come from the directory and from a keytab, and change where they live.
One encryption type ¶
Tickets and keys are made with aes256-cts-hmac-sha1-96 (etype 18) and nothing else is issued: a request whose etype list lacks 18 is answered KDC_ERR_ETYPE_NOSUPP (RFC 4120 §3.1.3). The KRB-ERROR that demands pre-authentication carries an ETYPE-INFO2 hint naming that etype and the salt, so a client learns what to derive its key with rather than guessing. A client that encrypts its timestamp under another type is answered KDC_ERR_PREAUTH_FAILED, the same code a wrong password gets; with Config.Logf set, the log records both etypes so an operator can tell the two apart.
Index ¶
Constants ¶
const DefaultMintedRID uint32 = 1 << 30
DefaultMintedRID is the RID of the SID that marks a minted TGT when PAC.MintedRID is zero. RIDs of users and groups are their uidNumber and gidNumber, so this sits above any plausible one; a directory that uses it must set another.
const MaxMintLifetime = 10 * time.Hour
MaxMintLifetime is the longest TGT a mint request can get, whatever the caller asks and whatever Config.Lifetime says.
const MaxUnmarkedWindow = MaxMintLifetime
MaxUnmarkedWindow is the longest an unmarked TGT is accepted after the KDC started: the longest TGT a Mint can have made (MaxMintLifetime), so none older than the window can still be alive.
Variables ¶
var ( // ErrMintRefused reports a request that is not allowed: a bad name, a // principal this realm does not know. ErrMintRefused = errors.New("kdc: mint refused") // ErrMintDisabled reports a realm configured with no MintCallers. ErrMintDisabled = errors.New("kdc: minting is not enabled") )
Errors Mint reports.
var ( // ErrNoRealm reports a configuration with no realm name. ErrNoRealm = errors.New("kdc: no realm") // ErrNoPeople reports one with nowhere to look up users. ErrNoPeople = errors.New("kdc: no directory") // ErrNoServices reports one with no keytab, which means no krbtgt key // and therefore nothing to sign a TGT with. ErrNoServices = errors.New("kdc: no keytab") // ErrNoTGTKey reports a keytab without krbtgt/REALM@REALM. A KDC without // it can authenticate somebody and then have nothing to hand them. ErrNoTGTKey = errors.New("kdc: the keytab has no krbtgt key for this realm") )
Errors a configuration can have.
var ( // ErrBadDomainSID reports a PAC.DomainSID that is not S-1-5-21-a-b-c. ErrBadDomainSID = errors.New("kdc: PAC.DomainSID is not S-1-5-21-a-b-c") )
Errors of PAC configuration and issuance.
var ErrClosed = errors.New("kdc: server closed")
ErrClosed is returned by ServeUDP and ServeTCP after Close.
var ErrMintBadMethod = errors.New("kdc: mint: method must be one of passkey, federated, machine")
ErrMintBadMethod reports a MintRequest.Method that is missing (with a PAC configured) or not one of passkey, federated, machine.
var ErrNotAPerson = errors.New("kdc: not a user principal")
ErrNotAPerson reports a principal that is not a single name — a service like nfs/host asking for a TGT of its own. Services authenticate from a keytab, not from this directory.
Functions ¶
func NewDomainSID ¶ added in v0.12.0
NewDomainSID returns a random domain SID, S-1-5-21-a-b-c.
Types ¶
type Config ¶
type Config struct {
// Realm is the realm name, conventionally the DNS domain in capitals.
Realm string
// People is where users come from. It must publish passwords; see the
// package comment for why a verifier cannot serve Kerberos.
People directory.Source
// Services holds the keys for service principals, including the
// krbtgt/REALM@REALM this KDC issues its own tickets under.
//
// ⛔ It is the KDC's file alone. The krbtgt key forges a ticket for anyone
// and the other services' keys forge theirs, so a service (an NFS server)
// must be given a keytab holding ONLY its own key, extracted from this one,
// never this file. A service that reads this file can mint tickets for the
// whole realm, and one without a pinned Principal would also accept a TGT
// as a service ticket (go-authn/krb5 refuses that since v0.5.0).
Services *keytab.Keytab
// Lifetime caps a ticket. Zero means ten hours, which is MIT's default.
Lifetime time.Duration
// MaxSkew is how far a client's clock may be from this one. Zero means
// five minutes, which is what every Kerberos implementation assumes.
MaxSkew time.Duration
// MintCallers lists who may ask [Server.MintHandler] for a TGT on behalf of
// a person they authenticated elsewhere (a passkey login at bridge): the
// URI subjectAltNames of their TLS client certificates, matched exactly,
// e.g. "https://login.example.org". Empty, the default, disables minting.
MintCallers []string
// AllowPasswordDerivedAS enables the AS exchange this KDC runs: a client
// proves a password by encrypting a timestamp under a key the KDC derives
// from the password the directory holds (RFC 3962 string-to-key). False, the
// default, refuses an AS-REQ for a person whose directory entry holds a
// password with KDC_ERR_POLICY (RFC 4120 §7.5.9), and Logf names this
// option.
//
// ⛔ It is opt-in because the derivation needs the password itself, in the
// clear, in the directory. Keys of services and krbtgt (the keytab), TGS and
// the mint endpoint do not depend on it.
AllowPasswordDerivedAS bool
// Logf, when set, is told why a request was refused.
//
// It exists because the protocol cannot say: a client is given an error
// CODE, and "pre-authentication failed" covers a wrong password, a wrong
// salt, a clock an hour out and a malformed message. Only this side can
// tell them apart, and only to an operator.
//
// ⛔ It is never given a password, a key, or a decrypted anything.
Logf func(format string, args ...any)
// PAC, when set, makes tickets for the listed services carry a Microsoft
// PAC (MS-PAC) so that a service which insists on one (Samba as a domain
// member) can build a token. Nil, the default, issues none: a standalone
// Samba refuses a ticket whose PAC carries LOGON_INFO.
PAC *PAC
}
Config describes one realm.
type Finder ¶ added in v0.6.0
Finder is a directory.Source that can find one person by name without handing over everybody. Config.People may implement it; when it does, Server asks it instead of walking directory.Source.Identities.
Find reports the identity whose Name is EXACTLY name — a Kerberos principal is case-sensitive (RFC 4120 6.2), so a source indexed by a folded name must compare the original — found false when there is none, and an error when the source cannot be read, which is answered KDC_ERR_SVC_UNAVAILABLE.
It exists because the walk is the cost of a request: with 10,000 people it was half of an AS-REQ's CPU (go-authn/kdc#31), and it grows with the directory. The source owns the index, so it is as fresh as the source is.
type MintRequest ¶ added in v0.8.0
type MintRequest struct {
// Principal is the person's name exactly as the directory holds it.
Principal string `json:"principal"`
// LifetimeSeconds is how long the caller wants the TGT to last; zero means
// as long as allowed. It is capped, never extended.
LifetimeSeconds int64 `json:"lifetime_seconds,omitempty"`
// Method is how the person logged in, which the KDC cannot know: passkey,
// federated or machine. It is required when [Config.PAC] is set (it becomes
// the TGT's authentication indicator and the PAC's minted SID), never
// defaulted; optional, but checked, otherwise.
Method string `json:"method,omitempty"`
}
MintRequest is what a trusted caller sends.
type PAC ¶ added in v0.12.0
type PAC struct {
// DomainSID is the domain's SID, S-1-5-21-a-b-c, generated once with
// [NewDomainSID] and then kept: changing it changes every user's SID.
DomainSID string
// Services lists the service principals ("cifs/host.example.org") whose
// tickets carry a PAC. Any other service gets none.
Services []string
// NetBIOSDomain is LogonDomainName; empty, the realm's first label.
NetBIOSDomain string
// MintedRID is the RID, under DomainSID, of the SID that marks a TGT a
// bridge minted (a passkey, federated or machine logon); zero means
// [DefaultMintedRID]. It must not be a uidNumber or gidNumber in use.
MintedRID uint32
// UnmarkedWindow is how long after the KDC started a TGT issued BEFORE the
// upgrade (one with no authentication marking) is still accepted; zero
// means [MaxUnmarkedWindow], and none is longer.
UnmarkedWindow time.Duration
// RefuseUnmarked refuses every unmarked TGT at once, ignoring
// UnmarkedWindow: for a realm whose TGTs were all issued by this version.
RefuseUnmarked bool
}
PAC configures the Privilege Attribute Certificate ([MS-PAC]) that service tickets can carry. The zero Config.PAC (nil) issues none, which is what a standalone Samba needs: it refuses a ticket whose PAC holds LOGON_INFO.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server answers Kerberos requests for one realm.
The zero value is not usable; use New.
func New ¶
New checks a configuration and returns a server for it.
It refuses a realm it could not serve -- no realm, no directory, no keytab, a keytab without the krbtgt key -- rather than starting and failing at the first kinit, where the error reaches a person who cannot fix it. A person whose source holds no password (a verifier) is refused per request, with KDC_ERR_NULL_KEY: whether a source holds passwords is known only per person.
func (*Server) KKDCPHandler ¶ added in v0.9.0
KKDCPHandler is the HTTP face of the realm for [MS-KKDCP]: POST a KDC-PROXY-MESSAGE, receive the KDC's reply in one. It is meant to sit behind a reverse proxy that terminates TLS (Windows requires HTTPS), on a path such as /KdcProxy, which is where both clients look by default.
It refuses what it cannot answer instead of guessing:
- any method but POST: 405;
- a body over the bound: 413;
- bytes that are not exactly one KDC-PROXY-MESSAGE (DER, nothing after it), a kerb-message whose length prefix does not match, or one that is not a request: 400. The specification says to drop the connection on a malformed Kerberos message; a status line costs the proxy nothing and tells a person debugging a client what happened;
- a missing target-domain: 400 (the specification's ERROR_BAD_FORMAT);
- another realm: 403. A Windows client reports 403 as a firewall refusal and any other error as "no logon servers"; either way it tries its next proxy.
Nothing here authenticates the caller: like port 88, it answers anyone, and what it answers is what the KDC answers (a KRB-ERROR for an unknown person, a ticket only to whoever proves a key).
func (*Server) Mint ¶ added in v0.8.0
func (s *Server) Mint(req MintRequest) ([]byte, error)
Mint makes a TGT for req.Principal and returns it as a KRB-CRED. It does NOT authenticate the caller: Server.MintHandler does, and is what to expose. It exists as a method so that an in-process caller (a test, a supervisor holding both services) has no HTTP in between.
func (*Server) MintHandler ¶ added in v0.8.0
MintHandler is the HTTP face of Server.Mint: POST a JSON MintRequest, receive the KRB-CRED (application/octet-stream).
Serve it ONLY on a listener that demands and verifies client certificates (tls.RequireAndVerifyClientCert, ClientCAs = the callers' CA), on a unix socket or an internal interface, never on the KDC's public address. The handler refuses a request whose connection was not verified that way, so a listener that forgot mints nothing rather than minting for everybody.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
cammac
Package cammac writes and reads the Container of Authentication-Marking Authorization Data a ticket-granting ticket carries (RFC 7751, the container MIT krb5 calls CAMMAC; RFC 8129 for the authentication indicator in it).
|
Package cammac writes and reads the Container of Authentication-Marking Authorization Data a ticket-granting ticket carries (RFC 7751, the container MIT krb5 calls CAMMAC; RFC 8129 for the authentication indicator in it). |
|
pac
Package pac builds, signs and reads the Privilege Attribute Certificate of [MS-PAC] that a Kerberos ticket carries in its authorization data.
|
Package pac builds, signs and reads the Privilege Attribute Certificate of [MS-PAC] that a Kerberos ticket carries in its authorization data. |
|
interop
|
|
|
automount
Package automount is the harness of an end-to-end proof: a Linux client that AUTOMOUNTS a Samba share with Kerberos and no human kinit.
|
Package automount is the harness of an end-to-end proof: a Linux client that AUTOMOUNTS a Samba share with Kerberos and no human kinit. |
|
samba
Package samba is an interoperability harness: it puts a Samba file server, configured as a non-AD server, behind three KDCs (go-authn/kdc, MIT krb5kdc, Heimdal kdc) and records whether each one's tickets are accepted.
|
Package samba is an interoperability harness: it puts a Samba file server, configured as a non-AD server, behind three KDCs (go-authn/kdc, MIT krb5kdc, Heimdal kdc) and records whether each one's tickets are accepted. |