Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidTokenPrefix is returned when the token does not start // with the expected "sshkey " prefix. ErrInvalidTokenPrefix = errors.New("token does not have \"sshkey \" prefix") // ErrUnsupportedVersion is returned when the token version is not // supported. ErrUnsupportedVersion = errors.New("unsupported token version") // ErrEmptyUsername is returned when the token has an empty username. ErrEmptyUsername = errors.New("empty username") // ErrMissingTimestamp is returned when the token has a zero // timestamp. ErrMissingTimestamp = errors.New("missing timestamp") // ErrEmptyNonce is returned when the token has an empty nonce. ErrEmptyNonce = errors.New("empty nonce") // ErrEmptyMethod is returned when the token has an empty method. ErrEmptyMethod = errors.New("empty method") // ErrEmptySignature is returned when the token has an empty // signature. ErrEmptySignature = errors.New("empty signature") // ErrTimestampOutsideWindow is returned when the token timestamp // is outside the allowed time window. ErrTimestampOutsideWindow = errors.New("token timestamp outside allowed window") // ErrSignatureVerificationFailed is returned when no public key // successfully verified the signature. ErrSignatureVerificationFailed = errors.New("signature verification failed") )
Functions ¶
func NewFromConfig ¶
NewFromConfig creates an SSH key Authenticator from a raw YAML config node.
Types ¶
type Authenticator ¶
type Authenticator struct {
// contains filtered or unexported fields
}
Authenticator implements SSH key authentication.
It verifies tokens signed with SSH private keys against known public keys, with method binding and timestamp-based replay protection.
func NewAuthenticator ¶
func NewAuthenticator(keyStore *KeyStore, opts ...Option) *Authenticator
NewAuthenticator creates a new SSH key Authenticator.
func (*Authenticator) Authenticate ¶
func (m *Authenticator) Authenticate( ctx context.Context, credential core.Credential, reqInfo *core.RequestInfo, ) (*core.AuthInfo, error)
Authenticate validates the SSH key token and returns authentication info.
Validation covers request binding and freshness before checking the token signature against the locally registered keys. The claimed username becomes the local account lookup name.
func (*Authenticator) KeyStore ¶
func (m *Authenticator) KeyStore() *KeyStore
KeyStore returns the underlying key store for external configuration (e.g. manager wiring).
func (*Authenticator) Name ¶
func (m *Authenticator) Name() string
Name returns the authenticator name for logging.
func (*Authenticator) Supports ¶ added in v0.1.0
func (m *Authenticator) Supports(credential core.Credential) bool
Supports checks if the credential carries a token with the "sshkey " prefix.
type Config ¶
type Config struct {
// KeysPath is the path to the ssh_keys.yaml file.
KeysPath string `yaml:"keys_path"`
// TimeWindow is the timestamp tolerance window for replay protection.
// Tokens with timestamps outside this window are rejected.
//
// Default: 5s.
TimeWindow time.Duration `yaml:"time_window"`
}
Config configures SSH Key Authentication.
type KeyEntry ¶
type KeyEntry struct {
// PublicKey is the parsed SSH public key.
PublicKey ssh.PublicKey
// Comment is an optional human-readable description.
Comment string
// Disabled indicates whether this key is disabled.
Disabled bool
}
KeyEntry represents a single SSH public key entry.
type KeyStore ¶
type KeyStore struct {
// contains filtered or unexported fields
}
KeyStore stores SSH public keys indexed by username.
One user can have multiple keys. Disabled keys are filtered out at lookup time.
func NewKeyStore ¶
NewKeyStore creates a KeyStore from an in-memory map.
func NewKeyStoreFromFile ¶
NewKeyStoreFromFile creates a KeyStore by loading keys from a YAML file.
The file format:
keys:
- username: alice
public_key: "ssh-ed25519 AAAAC3..."
comment: "Alice's workstation key"
disabled: false
type Option ¶
type Option func(*authenticatorOptions)
Option configures the Authenticator.
func WithTimeWindow ¶
WithTimeWindow sets the timestamp tolerance window.
type Token ¶
type Token struct {
// Version is the token format version (must be 1).
Version int `json:"version"`
// Username is the authenticating user.
Username string `json:"username"`
// Timestamp is the token creation time in Unix nanoseconds.
Timestamp int64 `json:"timestamp"`
// Nonce is a random value for uniqueness within the timestamp window.
Nonce string `json:"nonce"`
// Method is the gRPC method this token is bound to.
Method string `json:"method"`
// Signature is the base64-encoded SSH signature over the canonical
// signed data.
Signature string `json:"signature"`
}
Token represents a parsed SSH key authentication token.
func (*Token) CanonicalSignedData ¶
CanonicalSignedData builds the canonical string that must be signed.
Format:
version={version}\nusername={username}\ntimestamp={timestamp}\n
nonce={nonce}\nmethod={method}
func (*Token) CheckTimestamp ¶
CheckTimestamp verifies that the token timestamp is within the allowed window relative to the current time.