Documentation
¶
Overview ¶
Package audit defines the security events a cedar server reports: the handshake, each authentication attempt, sessions as they are created, resumed, imported and ended, and the authorization decision for each command.
cedar reports events through a Hook and records nothing itself. The embedding program decides what to keep, where, and for how long. A Hook is called synchronously on the connection's goroutine (or, for sessions ending, on whichever goroutine touched the cache), so it must be quick, must not block, and must be safe for concurrent use. A program that writes events to disk queues them in the Hook and writes them elsewhere.
An Event carries no secret: no session key, no token signature, no whole token. It does carry the session id, which a peer presents in the clear to resume a session; record SessionRef(key, id) rather than the id itself.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SessionRef ¶
SessionRef returns a stable reference to a session id that does not reveal it: the first 16 bytes of HMAC-SHA256(key, id), in hex. Events with the same id and key share a reference. Keep key secret and stable across restarts so references join over time.
Types ¶
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter is a Hook that only counts events, by type, outcome and reason. It records nothing else, so it is cheap enough to run on a busy daemon to learn how many events of each kind a full recorder would have to keep.
type Credential ¶
type Credential struct {
// Tokens (IDTOKENS, TOKEN, SCITOKENS).
Issuer string
Subject string
KeyID string // the signing key's id ("kid")
ID string // the token's own id ("jti")
Scopes []string
Expires time.Time
// X.509 (SSL).
CertSubject string
CertIssuer string
CertSerial string
CertSHA256 string // hex SHA-256 of the DER certificate
}
Credential is what an identity rests on, as the authentication method verified it. Only the fields the method provides are set.
type Direction ¶
type Direction string
Direction is which side of the connection this process was on.
type Event ¶
type Event struct {
Time time.Time
Type Type
Outcome Outcome
Reason Reason
Direction Direction
// Err is the error, for people. It can quote what the peer sent.
Err error
// Peer is the peer's "host:port".
Peer string
// Stage is how far a failed handshake got.
Stage Stage
// SessionID is the session's id. Record SessionRef(key, SessionID), not
// the id: a peer that knows a session's id can try to resume it.
SessionID string
// SessionPeer is the address the session was created with, for a resumed
// or ended session.
SessionPeer string
// Command is the command a command event is about. For DC_SEC_QUERY and
// DC_AUTHENTICATE it is the command the peer asked about.
Command int
// Levels are the authorization levels Command is registered at.
Levels []string
// Limits are the authorization levels the session's credential is
// limited to; nil when it has no such limit.
Limits []string
// AuthMethod is the authentication method: the one attempted, for
// AuthAttempt; the one the session authenticated with, otherwise.
AuthMethod string
// CryptoMethod is the session's cipher.
CryptoMethod string
// Authenticated and Encrypted describe the session.
Authenticated bool
Encrypted bool
// AuthenticatedAs is the identity the authentication method produced,
// before any mapping. User is the identity the session runs as.
AuthenticatedAs string
User string
// Credential is what the identity rests on, when the method verified
// one.
Credential *Credential
// Expires and Lease are a session's absolute expiry and idle lease.
Expires time.Time
Lease time.Duration
// ValidCommands is how many commands a new session may run.
ValidCommands int
}
Event is one audit event. Fields that do not apply to its Type are zero.
type Reason ¶
type Reason string
Reason is a stable code for why. Match on it, never on Event.Err's text.
const ( // Any failure. ReasonIO Reason = "io" // the connection failed or closed ReasonCanceled Reason = "canceled" // the connection's context ended ReasonProtocol Reason = "protocol" // the peer sent something malformed or unexpected // HandshakeFailed at StageNegotiate. ReasonAuthPolicyMismatch Reason = "auth_policy_mismatch" // one side requires authentication, the other forbids it ReasonEncryptionPolicyMismatch Reason = "encryption_policy_mismatch" // likewise for encryption or integrity ReasonNoCommonAuthMethod Reason = "no_common_auth_method" ReasonNoCommonCryptoMethod Reason = "no_common_crypto_method" // HandshakeFailed at StageAuthenticate, and AuthAttempt. ReasonAuthFailed Reason = "auth_failed" // the method ran and did not authenticate the peer ReasonNoCredential Reason = "no_credential" // the method completed but the peer presented no credential (SSL without a client certificate) ReasonNoMethodSelected Reason = "no_method_selected" // the client offered no method the server accepts ReasonClientGaveUp Reason = "client_gave_up" // the client ran out of methods while authentication was required ReasonMethodUnsupported Reason = "method_unsupported" // the method is not implemented // HandshakeFailed at StageKeyExchange. ReasonKeyExchange Reason = "key_exchange" // SessionResumeFailed. ReasonSessionNotFound Reason = "session_not_found" // unknown or expired ReasonUnsupportedCrypto Reason = "unsupported_crypto" // keyed with a cipher cedar cannot read ReasonSessionKeyMissing Reason = "session_key_missing" // an authenticated session with no key to prove possession // AuthzDenied. ReasonCommandNotFound Reason = "command_not_found" // no handler for the command ReasonSecurityLevel Reason = "security_level" // the session lacks authentication or encryption the command requires ReasonOutsideLimits Reason = "outside_limits" // the credential's authorization limits exclude the command's levels ReasonLevelNotGranted Reason = "level_not_granted" // the identity is not authorized at any of the command's levels // CommandFailed. ReasonHandler Reason = "handler" // SessionImported. ReasonClaim Reason = "claim" // from a claim id ReasonFileTransfer Reason = "file_transfer" // from a claim id, for file transfer ReasonInherited Reason = "inherited" // handed down by a parent process ReasonMinted Reason = "minted" // minted for a child process ReasonClaimMinted Reason = "claim_minted" // minted with a new claim id (a startd) // SessionEnded. ReasonExpired Reason = "expired" // its duration or lease ran out ReasonInvalidated Reason = "invalidated" // something invalidated it by id ReasonCleared Reason = "cleared" // the whole cache was cleared ReasonReplaced Reason = "replaced" // another session was stored under its id )
Reasons. New ones may be added; existing ones keep their meaning.
type Stage ¶
type Stage string
Stage is how far a handshake got.
const ( // StageCommand: reading the command integer that opens the connection. StageCommand Stage = "command" // StageRequest: reading the client's security ad. StageRequest Stage = "request" // StageResume: resuming a cached session. StageResume Stage = "resume" // StageNegotiate: reconciling the two sides' security policies. StageNegotiate Stage = "negotiate" // StageAuthenticate: running authentication methods. StageAuthenticate Stage = "authenticate" // StageKeyExchange: deriving and enabling the session key. StageKeyExchange Stage = "key_exchange" // StagePostAuth: sending the post-authentication reply. StagePostAuth Stage = "post_auth" )
Handshake stages, in order.
type Type ¶
type Type string
Type is what happened.
const ( // HandshakeFailed: the security handshake failed before a session was // established, for a reason other than the command being refused (that // is AuthzDenied). Stage says how far it got. HandshakeFailed Type = "handshake.failed" // AuthAttempt: one authentication method finished on the server, either // way. A client that tries several methods produces one per method. AuthAttempt Type = "auth.attempt" // SessionCreated: a full handshake established a session and cached it. SessionCreated Type = "session.created" // SessionResumed: a peer resumed a cached session on a new connection. // SessionPeer is the address the session was created with. SessionResumed Type = "session.resumed" // SessionResumeFailed: a peer asked to resume a session the server would // not resume. SessionResumeFailed Type = "session.resume_failed" // SessionImported: a session entered the cache without a handshake, from // a claim id, a parent process, or minted for a child. Reason says which. SessionImported Type = "session.imported" // SessionEnded: a session left the cache. Reason says why. SessionEnded Type = "session.ended" // AuthzDenied: a command was refused, whether by the handshake or at // dispatch. AuthzDenied Type = "authz.denied" // AuthzAllowed: a command was authorized and is being dispatched. AuthzAllowed Type = "authz.allowed" // CommandFailed: a dispatched command's handler returned an error. CommandFailed Type = "command.failed" )
Event types.