Documentation
¶
Overview ¶
Package service holds the credential vertical's business rules: the write-only handling that keeps a stored private key from ever being read back, and the ownership that keeps a key to the person who registered it.
Index ¶
- type InteractiveAuthService
- func (s *InteractiveAuthService) Answer(pending *ssh.SSHInteractiveAuth, answer *dto.InteractiveAuthAnswer) error
- func (s *InteractiveAuthService) Get(ctx context.Context, authID string) (*ssh.SSHInteractiveAuth, error)
- func (s *InteractiveAuthService) List(ctx context.Context) ([]dto.InteractiveAuthResponse, error)
- func (s *InteractiveAuthService) Next(ctx context.Context) (*ssh.SSHInteractiveAuth, <-chan struct{}, error)
- type KeyAccess
- type KeyReferrer
- type SSHCredentialService
- func (s *SSHCredentialService) Create(ctx context.Context, req *dto.SSHCredentialRequest) (*dto.SSHCredentialResponse, error)
- func (s *SSHCredentialService) Delete(ctx context.Context, id string) error
- func (s *SSHCredentialService) Get(ctx context.Context, id string) (*dto.SSHCredentialResponse, error)
- func (s *SSHCredentialService) List(ctx context.Context) ([]dto.SSHCredentialResponse, error)
- func (s *SSHCredentialService) Update(ctx context.Context, id string, req *dto.SSHCredentialRequest) (*dto.SSHCredentialResponse, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type InteractiveAuthService ¶
type InteractiveAuthService struct {
// contains filtered or unexported fields
}
InteractiveAuthService exposes the keyboard-interactive challenges waiting on the calling user.
An interactive auth belongs to the user whose request opened the connection, and only that user sees it — admins included, for the same reason a credential is private: the answer is a password or a one-time code.
func NewInteractiveAuthService ¶
func NewInteractiveAuthService(sshContext *ssh.GlobalSSHContext) *InteractiveAuthService
func (*InteractiveAuthService) Answer ¶
func (s *InteractiveAuthService) Answer(pending *ssh.SSHInteractiveAuth, answer *dto.InteractiveAuthAnswer) error
Answer hands the caller's responses to the handshake waiting on pending.
The responses are never logged or kept beyond the interactive auth: they are passwords and one-time codes.
func (*InteractiveAuthService) Get ¶
func (s *InteractiveAuthService) Get(ctx context.Context, authID string) (*ssh.SSHInteractiveAuth, error)
Get returns one of the caller's pending interactive auths. Another user's is a 404, not a 403: the store is keyed by owner, so it is simply not there to find.
func (*InteractiveAuthService) List ¶
func (s *InteractiveAuthService) List(ctx context.Context) ([]dto.InteractiveAuthResponse, error)
List returns the caller's pending interactive auths, oldest first.
func (*InteractiveAuthService) Next ¶
func (s *InteractiveAuthService) Next(ctx context.Context) (*ssh.SSHInteractiveAuth, <-chan struct{}, error)
Next returns the caller's oldest unanswered interactive auth (nil if none) without blocking, and a channel closed the next time the caller's auths change.
type KeyAccess ¶
type KeyAccess struct {
// contains filtered or unexported fields
}
KeyAccess answers "may this caller present this key?" for services outside the credentials package.
A cluster config and a data storage both name a key, and both ask this before pointing at one. Exposing the question rather than the table is what keeps a single definition of who may present a key — its owner, nobody else.
func NewKeyAccess ¶
func NewKeyAccess(keys *repository.SSHCredentialRepository) *KeyAccess
NewKeyAccess returns a checker over the key table.
func (*KeyAccess) Find ¶
Find loads a key without asking who owns it. It is for a record re-presenting the key it already holds: keeping a key is not assigning one, so someone editing a config shared with them does not need to own the key already on it.
func (*KeyAccess) RequireOwned ¶
RequireOwned loads a key the caller may assign: 404 when there is no such key, 403 when it belongs to somebody else. Assigning a key is presenting its private material under a name of your choosing, which is the owner's to allow — and they allow it by sharing what holds the key, never the key.
type KeyReferrer ¶
KeyReferrer counts the records outside this package that still present a key.
A key is registered here but used elsewhere — a cluster config logs in with one, a data storage stages under one — and this package must not import those verticals to find out. They satisfy this interface instead, and are handed to the service in internal/app, which is the one place that knows the whole graph.
type SSHCredentialService ¶
type SSHCredentialService struct {
// contains filtered or unexported fields
}
SSHCredentialService manages registered SSH credentials.
Registering one is self-service — any authenticated caller may register one, and it belongs to them — but nothing about it is reachable by anyone else. Reads, updates and deletes are the owner's alone, and there is no share to open one up: a credential is the secret material itself, so lending it out is what sharing a cluster config is for.
Platform admins are deliberately not treated as owners here, unlike everywhere else in this API. An admin has no business reading or repointing someone's key material.
func NewSSHCredentialService ¶
func NewSSHCredentialService(keys *repository.SSHCredentialRepository, users *iamrepo.UserRepository, usedBy ...KeyReferrer) *SSHCredentialService
NewSSHCredentialService returns an SSH credential service. usedBy is every kind of record that can hold a credential; one that none of them names is free to delete.
func (*SSHCredentialService) Create ¶
func (s *SSHCredentialService) Create(ctx context.Context, req *dto.SSHCredentialRequest) (*dto.SSHCredentialResponse, error)
Create registers a key owned by the calling user.
The owner is taken from the token, so there is no way to register a key on someone else's behalf. The private key is required here even though the payload makes it optional: the same payload is reused for updates, where omitting it means "keep what is stored".
func (*SSHCredentialService) Delete ¶
func (s *SSHCredentialService) Delete(ctx context.Context, id string) error
Delete removes a key, refusing while anything still presents it.
Every foreign key pointing at a key is RESTRICT, so the database would refuse this anyway; asking first turns an opaque constraint violation into a 409 that says how many records still hold the key. The count runs before the delete rather than in a transaction with it — as the data storage service checks its products — and the constraint remains the backstop for anything registered in between.
func (*SSHCredentialService) Get ¶
func (s *SSHCredentialService) Get(ctx context.Context, id string) (*dto.SSHCredentialResponse, error)
Get returns one key.
func (*SSHCredentialService) List ¶
func (s *SSHCredentialService) List(ctx context.Context) ([]dto.SSHCredentialResponse, error)
List returns the caller's own credentials. There is no listing across owners: a credential is private to whoever registered it, and that holds for admins too.
func (*SSHCredentialService) Update ¶
func (s *SSHCredentialService) Update(ctx context.Context, id string, req *dto.SSHCredentialRequest) (*dto.SSHCredentialResponse, error)
Update changes a key.
A blank or absent private key or passphrase means "leave the stored secret alone", not "erase it". Without that rule, a client round-tripping a response — which never contains the secrets — would silently wipe them.