identity

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 11 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

Overview

Package identity provides the user identity: the user's SSH private key and certificate, and how a new certificate is obtained from the CA and added to the SSH agent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ObtainOption

type ObtainOption int

ObtainOption changes how User.Obtain obtains a certificate

const (
	// WithoutAgent does not add the new certificate to the SSH agent
	WithoutAgent ObtainOption = iota + 1

	// WithoutInteractiveLogin only uses cached tokens or a refresh token, so
	// the request fails with [auth.ErrInteractiveLoginRequired] rather than
	// start an interactive login
	WithoutInteractiveLogin
)

type Option

type Option func(*options)

Option configures a User

func WithAuthHandler

func WithAuthHandler(h auth.Handler) Option

WithAuthHandler uses h to authenticate certificate requests instead of an OIDC login using conf

func WithLifetime

func WithLifetime(d time.Duration) Option

WithLifetime sets the lifetime requested for new certificates. The default is cert.DefaultUserCertificateLifetime.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger sets the logger used for the OIDC login and for reporting stale certificates removed from the SSH agent

func WithStore

func WithStore(s cert.Storage) Option

WithStore uses s for the private key and certificate instead of the system keyring

type User

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

User is the user identity. By default the private key and certificate are kept in the system keyring and certificates are obtained after an OIDC login, with the refresh token also kept in the system keyring.

func NewUser

func NewUser(conf *config.ClientConfig, opts ...Option) (*User, error)

NewUser creates the User for conf. Neither the CA nor the identity provider is contacted until a certificate is obtained.

func (*User) AddToAgent

func (u *User) AddToAgent() error

AddToAgent adds the current private key and certificate to the SSH agent, then removes any stale certificates from the agent. Failures adding to the agent are returned as cert.ErrAddingToAgent.

func (*User) Certificate

func (u *User) Certificate() (*ssh.Certificate, error)

Certificate returns the current certificate, or an error wrapping cert.ErrCertificateNotFound if there is none

func (*User) GeneratePrivateKey

func (u *User) GeneratePrivateKey() error

GeneratePrivateKey generates a new private key, replacing any existing key and its certificate

func (*User) HasPrivateKey

func (u *User) HasPrivateKey() bool

HasPrivateKey reports whether there is a private key

func (*User) Obtain

func (u *User) Obtain(ctx context.Context, opts ...ObtainOption) error

Obtain requests a new certificate from the CA, saves it and adds it to the SSH agent, then removes any stale certificates from the agent. This blocks until any interactive login completes, times out or ctx is cancelled. If the certificate is saved but cannot be added to the agent the returned error wraps cert.ErrAddingToAgent.

Jump to

Keyboard shortcuts

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