credentials

package
v0.1.0-beta.4 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 12 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

View Source
const (
	// LockGrantLifetimeMs is the contract's hard eight-hour device deadline.
	// There is no sliding refresh and no remember-device setting.
	LockGrantLifetimeMs int64 = 8 * 60 * 60 * 1000
)

Variables

View Source
var (

	// ErrLockPinChanged reports a guest identity that differs from the pinned
	// one. It is never resolved automatically: the user re-pairs explicitly.
	ErrLockPinChanged = errors.New("workspace guest identity changed")
	// ErrLockPinUnknown reports that this device has never pinned this guest.
	ErrLockPinUnknown = errors.New("workspace guest identity is not pinned")
	// ErrLockStoreInvalid reports unusable on-disk state. It fails closed.
	ErrLockStoreInvalid = errors.New("workspace lock store is invalid")
)

Functions

func DefaultLockPath added in v0.1.1

func DefaultLockPath(environment map[string]string) (string, error)

DefaultLockPath places the lock store beside the credentials file, so one configuration directory holds everything a logout must clear.

func DefaultPath

func DefaultPath(environment map[string]string) (string, error)

Types

type Backend

type Backend interface {
	Load(baseURL string) (Credential, error)
	Save(credential Credential) error
	Delete(baseURL string) error
	Hosts() ([]string, error)
}

Backend is the credential storage contract. The file store is the only implementation today; a keychain backend would satisfy the same interface. Load and Delete are keyed by the normalized Control Plane base URL so a login to a second host never overwrites the first.

type Credential

type Credential struct {
	BaseURL      string `json:"-"`
	Token        string `json:"token"`
	AccountEmail string `json:"account_email,omitempty"`
	ExpiresAt    string `json:"expires_at,omitempty"`
}

Credential is one Control Plane token bound to the normalized base URL it was issued for. Tokens for different hosts never share an entry.

type LockGrant added in v0.1.1

type LockGrant struct {
	DeviceSessionUUID  string `json:"device_session_uuid"`
	DeviceScalar       []byte `json:"-"`
	EncodedScalar      string `json:"device_scalar"`
	IssuedAtMs         int64  `json:"issued_at"`
	ExpiresAtMs        int64  `json:"expires_at"`
	BootUUID           string `json:"boot_uuid"`
	LockEpoch          int64  `json:"lock_epoch"`
	CredentialRevision int64  `json:"credential_revision"`
	ActorSubjectUUID   string `json:"actor_subject_uuid"`
	MembershipUUID     string `json:"membership_uuid"`
}

LockGrant is a live device session. DeviceScalar is the only private value the CLI writes to disk, and only until the grant's deadline.

type LockPinConfirmation added in v0.1.1

type LockPinConfirmation string

LockPinConfirmation records how the pin was established, so the CLI can be honest about a trust-on-first-use bootstrap rather than calling it verified.

const (
	// LockPinTrustedProvisioning is a first, disclosed bootstrap.
	LockPinTrustedProvisioning LockPinConfirmation = "trusted-provisioning"
	// LockPinManualComparison is a pin the user compared against a trusted
	// device and accepted.
	LockPinManualComparison LockPinConfirmation = "manual-comparison"
)

type LockRecord added in v0.1.1

type LockRecord struct {
	OrganizationUUID     string              `json:"organization_uuid"`
	AssignmentGeneration int64               `json:"assignment_generation"`
	IdentityPin          string              `json:"identity_pin"`
	Confirmation         LockPinConfirmation `json:"confirmation"`
	Grant                *LockGrant          `json:"grant,omitempty"`
}

LockRecord is one workspace assignment's client state.

func (LockRecord) Matches added in v0.1.1

func (r LockRecord) Matches(scope LockScope) bool

Matches reports whether this record was pinned for the same organization and assignment the guest is now presenting.

type LockScope added in v0.1.1

type LockScope struct {
	BaseURL              string
	OrganizationUUID     string
	WorkspaceUUID        string
	AssignmentGeneration int64
}

LockScope names one workspace assignment on one Control Plane. A grant never crosses any of these four boundaries.

type LockStore added in v0.1.1

type LockStore struct {
	Path string
}

LockStore is the owner-only JSON file backend for lock device state.

func (LockStore) Forget added in v0.1.1

func (s LockStore) Forget(baseURL string) error

Forget removes every record for one Control Plane, pins included. Logout calls it: a device grant must not outlive the session that established it.

func (LockStore) Grant added in v0.1.1

func (s LockStore) Grant(scope LockScope, pin string, grant LockGrant, nowMs int64) error

Grant installs a device session under an already pinned identity. It refuses a grant whose deadline exceeds the contract's eight hours.

func (LockStore) Pin added in v0.1.1

func (s LockStore) Pin(scope LockScope, pin string, confirmation LockPinConfirmation) error

Pin records the guest identity for this assignment. An existing pin is never silently replaced: a different one fails closed and requires explicit re-pairing, which also discards any grant held under the old identity.

func (LockStore) Prune added in v0.1.1

func (s LockStore) Prune(nowMs int64) error

Prune removes grants that already expired. It runs on every command that touches the store, so a stale scalar is not left on disk indefinitely.

func (LockStore) Read added in v0.1.1

func (s LockStore) Read(baseURL, workspaceUUID string, nowMs int64) (LockRecord, error)

Read returns this workspace assignment's pinned identity and its live grant, if any. Expired grants, and grants issued in the future because the clock moved backwards, are dropped before the record is returned.

func (LockStore) Repair added in v0.1.1

func (s LockStore) Repair(scope LockScope, pin string, confirmation LockPinConfirmation) error

Repair replaces the pinned identity after the user explicitly accepted a new one. Every grant under the old identity is discarded.

func (LockStore) Revoke added in v0.1.1

func (s LockStore) Revoke(baseURL, workspaceUUID string) error

Revoke drops one workspace's grant, keeping its pin. Locking, stopping or reassigning the workspace all reach this path.

func (LockStore) Scopes added in v0.1.1

func (s LockStore) Scopes() ([]string, error)

Scopes lists the stored keys, sorted. It is used by status output and never exposes a scalar.

func (LockStore) Unpin added in v0.1.1

func (s LockStore) Unpin(baseURL, workspaceUUID string) error

Unpin removes one workspace's record entirely, pin and grant together. It is the explicit "forget this guest" path; a changed identity is never resolved by silently overwriting.

type Store

type Store struct {
	Path string
}

Store is the owner-only JSON file backend.

func (Store) Delete

func (s Store) Delete(baseURL string) error

Delete removes one host's credential. The file is removed once it holds no credentials at all. A missing entry is not an error.

func (Store) Hosts

func (s Store) Hosts() ([]string, error)

Hosts lists the normalized base URLs with a stored credential, sorted.

func (Store) Load

func (s Store) Load(baseURL string) (Credential, error)

Load returns the credential stored for baseURL, or fs.ErrNotExist when the file or that host's entry is absent.

func (Store) Save

func (s Store) Save(credential Credential) error

Save stores the credential under its base URL, keeping every other host's entry. A version 1 file is rewritten as version 2 on the way through.

Jump to

Keyboard shortcuts

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