sshcert

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: 18 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 "sshcert " prefix.
	ErrInvalidTokenPrefix = errors.New(`token does not have "sshcert " prefix`)
	// ErrUnsupportedVersion is returned when the token version is not
	// supported.
	ErrUnsupportedVersion = errors.New("unsupported token version")
	// ErrEmptyCertificate is returned when the token has an empty certificate
	// field.
	ErrEmptyCertificate = errors.New("empty certificate")
	// 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 the signature could not
	// be verified.
	ErrSignatureVerificationFailed = errors.New("signature verification failed")
	// ErrInvalidCertificate is returned when the certificate cannot be parsed.
	ErrInvalidCertificate = errors.New("invalid certificate")
	// ErrUnsupportedKeyType is returned when the certificate key type is not
	// supported.
	ErrUnsupportedKeyType = errors.New("unsupported key type")
	// ErrNotUserCert is returned when the certificate is not a user
	// certificate.
	ErrNotUserCert = errors.New("not a user certificate")
	// ErrCertExpired is returned when the certificate validity period has
	// passed.
	ErrCertExpired = errors.New("certificate expired")
	// ErrCertNotYetValid is returned when the certificate is not yet valid.
	ErrCertNotYetValid = errors.New("certificate not yet valid")
	// ErrEmptyPrincipals is returned when the certificate has no valid
	// principals.
	ErrEmptyPrincipals = errors.New("certificate has no principals")
	// ErrUntrustedCA is returned when the certificate is not signed by a
	// trusted CA.
	ErrUntrustedCA = errors.New("certificate not signed by trusted CA")
	// ErrCertRevoked is returned when the certificate has been revoked via
	// KRL.
	ErrCertRevoked = errors.New("certificate revoked")
)

Functions

func NewFromConfig

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

NewFromConfig creates an SSH certificate Authenticator from a raw YAML.

Types

type Authenticator

type Authenticator struct {
	// contains filtered or unexported fields
}

Authenticator implements SSH certificate authentication.

It verifies tokens signed with SSH private keys whose corresponding certificates are signed by a trusted CA.

Only ecdsa-sha2-nistp256 certificates are supported.

func NewAuthenticator

func NewAuthenticator(
	caVerifier CAVerifier,
	revocationChecker RevocationChecker,
	opts ...Option,
) *Authenticator

NewAuthenticator creates a new SSH certificate Authenticator.

func (*Authenticator) Authenticate

func (m *Authenticator) Authenticate(
	ctx context.Context,
	credential core.Credential,
	reqInfo *core.RequestInfo,
) (*core.AuthInfo, error)

Authenticate validates the SSH certificate token and returns authentication info.

Validation covers request binding and freshness, certificate constraints, CA trust, revocation, and the token signature. The first certificate principal becomes the local account lookup name.

func (*Authenticator) Close

func (m *Authenticator) Close()

Close stops the periodic refresh goroutine.

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 "sshcert " prefix.

type CAEntry

type CAEntry struct {
	// PublicKey is the parsed CA public key.
	PublicKey ssh.PublicKey
}

CAEntry represents a single trusted certificate authority.

type CAStore

type CAStore struct {
	// contains filtered or unexported fields
}

CAStore stores trusted certificate authority public keys.

func NewCAStore

func NewCAStore(entries []CAEntry) *CAStore

NewCAStore creates a CAStore from an in-memory slice.

func NewCAStoreFromLoader

func NewCAStoreFromLoader(source loader.Loader) (*CAStore, error)

NewCAStoreFromLoader creates a CAStore by loading CA data from the given loader.

func (*CAStore) Reload

func (m *CAStore) Reload() error

Reload reloads CA data from the loader.

On error the old data is preserved.

func (*CAStore) VerifyCA

func (m *CAStore) VerifyCA(cert *ssh.Certificate) error

VerifyCA cryptographically verifies that the certificate was signed by a trusted CA.

type CAVerifier

type CAVerifier interface {
	// VerifyCA checks the certificate against trusted CAs.
	VerifyCA(cert *ssh.Certificate) error
	// Reload refreshes CA data from the source.
	//
	// On error the old data is preserved.
	Reload() error
}

CAVerifier verifies that a certificate was signed by a trusted CA and supports periodic reload of CA data.

type CompositeCAStore

type CompositeCAStore struct {
	// contains filtered or unexported fields
}

CompositeCAStore wraps multiple independent CAStore instances.

VerifyCA succeeds if any underlying store trusts the certificate.

func NewCompositeCAStore

func NewCompositeCAStore(stores []*CAStore) *CompositeCAStore

NewCompositeCAStore creates a CompositeCAStore from the given CA stores.

func (*CompositeCAStore) Reload

func (m *CompositeCAStore) Reload() error

Reload refreshes each underlying store.

func (*CompositeCAStore) VerifyCA

func (m *CompositeCAStore) VerifyCA(cert *ssh.Certificate) error

VerifyCA succeeds if at least one underlying store trusts the certificate's CA.

type Config

type Config struct {
	// CASources is a list of paths or URLs to CA public keys files.
	//
	// Sources starting with "http://" or "https://" use HTTP, otherwise the
	// source is treated as a file path.
	//
	// Keys are merged.
	CASources []string `yaml:"ca_sources"`
	// KRLSource is the path or URL to the OpenSSH KRL file (optional).
	//
	// Sources starting with "http://" or "https://" use HTTP, otherwise the
	// source is treated as a file path.
	KRLSource string `yaml:"krl_source"`
	// TimeWindow is the timestamp tolerance window for replay protection.
	//
	// Default: 5s.
	TimeWindow time.Duration `yaml:"time_window"`
	// RefreshInterval is the polling interval for reloading CA and KRL data
	// from their sources.
	//
	// Default: 5m.
	RefreshInterval time.Duration `yaml:"refresh_interval"`
}

Config configures SSH Certificate Authentication.

type KRLRevocationChecker

type KRLRevocationChecker struct {
	// contains filtered or unexported fields
}

KRLRevocationChecker checks certificates against an OpenSSH KRL.

func NewKRLRevocationChecker

func NewKRLRevocationChecker(k *krl.KRL) *KRLRevocationChecker

NewKRLRevocationChecker creates a RevocationChecker from a parsed KRL.

func NewKRLRevocationCheckerFromLoader

func NewKRLRevocationCheckerFromLoader(
	source loader.Loader,
) (*KRLRevocationChecker, error)

NewKRLRevocationCheckerFromLoader creates a RevocationChecker by loading KRL data from the given loader.

func (*KRLRevocationChecker) IsRevoked

func (m *KRLRevocationChecker) IsRevoked(cert *ssh.Certificate) error

IsRevoked checks if the given certificate has been revoked.

func (*KRLRevocationChecker) Reload

func (m *KRLRevocationChecker) Reload() error

Reload reloads KRL data from the loader.

On error the old data is preserved.

type Option

type Option func(*authenticatorOptions)

Option configures the Authenticator.

func WithLog

func WithLog(log *zap.Logger) Option

WithLog sets the logger.

func WithRefreshInterval

func WithRefreshInterval(d time.Duration) Option

WithRefreshInterval sets the periodic refresh interval.

func WithTimeWindow

func WithTimeWindow(d time.Duration) Option

WithTimeWindow sets the timestamp tolerance window.

type RevocationChecker

type RevocationChecker interface {
	// IsRevoked returns ErrCertRevoked if the certificate is
	// revoked, nil otherwise.
	IsRevoked(cert *ssh.Certificate) error
	// Reload refreshes the revocation data from the source.
	// On error the old data is preserved.
	Reload() error
}

RevocationChecker checks whether a certificate has been revoked.

func NewNopRevocationChecker

func NewNopRevocationChecker() RevocationChecker

NewNopRevocationChecker returns a RevocationChecker that never considers any certificate revoked.

type Token

type Token struct {
	// Version is the token format version (must be 1).
	Version int `json:"version"`
	// Certificate is the base64-encoded SSH certificate.
	Certificate string `json:"certificate"`
	// 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 certificate authentication token.

func (*Token) CanonicalSignedData

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

CanonicalSignedData builds the canonical string that must be signed.

Format:

version={version}\ncertificate={certificate}\n
timestamp={timestamp}\nnonce={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