The KeytabLookup field in spnego.Config expects a function that returns a *keytab.Keytab and an error. This allows you to fetch keytabs from databases, secrets managers, or remote services.
Important Performance Note: KeytabLookup is called on every request (authenticated or not). If your lookup involves network calls or database queries, you must cache the result and refresh it out-of-band (e.g., via a TTL or rotation event) to avoid adding significant latency to every request.
Security Warning: Do not return sensitive key material in the error returned by your lookup function. Errors are logged and passed to OnError. If you are reading a file, separate the file-reading error from the parsing error to avoid logging the key buffer.
// Example: Retrieve keytab from a database
func dbKeytabLookup() (*keytab.Keytab, error) {
// Your database lookup logic here
// ...
return keytabFromDatabase, nil
}
// Example: Retrieve keytab from a remote service
func remoteKeytabLookup() (*keytab.Keytab, error) {
// Your remote service call logic here
// ...
return keytabFromRemote, nil
}