service

package
v1.0.0-alpha1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 14 Imported by: 1 module, 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 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

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

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

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

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

func (a *KeyAccess) Find(ctx context.Context, id string) (*model.SSHCredential, error)

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

func (a *KeyAccess) RequireOwned(ctx context.Context, id string) (*model.SSHCredential, error)

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.

func (*KeyAccess) WithTx

func (a *KeyAccess) WithTx(tx *gorm.DB) *KeyAccess

WithTx returns a checker bound to tx, for checks made from inside a transaction.

type KeyReferrer

type KeyReferrer interface {
	CountByKeyID(ctx context.Context, keyID string) (int64, error)
}

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

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

Get returns one key.

func (*SSHCredentialService) List

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

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.

Jump to

Keyboard shortcuts

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