sshkey

package
v0.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func NewFromConfig(
	rawCfg *yaml.Node,
	options ...Option,
) (core.Authenticator, error)

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

func NewKeyStore(keys map[string][]KeyEntry) *KeyStore

NewKeyStore creates a KeyStore from an in-memory map.

func NewKeyStoreFromFile

func NewKeyStoreFromFile(path string) (*KeyStore, error)

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

func (*KeyStore) GetKeys

func (m *KeyStore) GetKeys(username string) []ssh.PublicKey

GetKeys returns all non-disabled SSH public keys for the given username.

type Option

type Option func(*authenticatorOptions)

Option configures the Authenticator.

func WithLog

func WithLog(log *zap.Logger) Option

WithLog sets the logger.

func WithTimeWindow

func WithTimeWindow(d time.Duration) Option

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

func (m *Token) CanonicalSignedData() []byte

CanonicalSignedData builds the canonical string that must be signed.

Format:

version={version}\nusername={username}\ntimestamp={timestamp}\n
nonce={nonce}\nmethod={method}

func (*Token) CheckTimestamp

func (m *Token) CheckTimestamp(now time.Time, window time.Duration) error

CheckTimestamp verifies that the token timestamp is within the allowed window relative to the current time.

func (*Token) Validate

func (m *Token) Validate() error

Validate checks token fields for correctness.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL