Documentation
¶
Overview ¶
Package secrets is the safe: the tokens and keys the person hands to the agents of this machine, kept encrypted on the machine and handed to a command's environment or a short-lived file, never to a conversation. A value comes in only from the person's page (Settings → Safe, or the card an agent's `harnessly secret ask` puts on screen) and goes out only through the CLI routes a command runs with; it is never logged, never in a list, never in an answer of the page's routes. See docs/safe.md for the model and what it does not protect against.
Index ¶
- Constants
- func AppName(app, name string) string
- func BrowserValue(value string, now time.Time) (string, error)
- func Clean(value string) string
- func CleanWhy(why string) string
- func DefaultKeyFile(getenv func(string) string, home string) string
- func FileName(s string) string
- func IntegrationCredential(ref string) bool
- func IntegrationName(integration, name string) string
- func IsAppName(name string) bool
- func IsIntegrationName(name string) bool
- func Mask(text string, values []string) string
- func Origin(raw string) string
- func PromptBlock() string
- func ReasonOf(err error) string
- func ValidAppName(name string) bool
- func ValidCode(value string, digits int) bool
- func ValidName(name string) bool
- func ValidRef(s string) bool
- func ValidSharedName(name string) bool
- func ValidSysName(name string) bool
- type AppShared
- type Ask
- type Asks
- func (a *Asks) Decline(id string) bool
- func (a *Asks) Fulfil(name string)
- func (a *Asks) Get(id string) (Ask, bool)
- func (a *Asks) Open(name, why, conv, title string, replace bool) (Ask, string, error)
- func (a *Asks) OpenScoped(request Ask) (Ask, string, error)
- func (a *Asks) PageOpen() bool
- func (a *Asks) Pending() []Ask
- func (a *Asks) Ready(id string)
- func (a *Asks) Wait(ctx context.Context, id string, d time.Duration) string
- type CodeAsk
- type Codes
- func (c *Codes) Cancel(id string) bool
- func (c *Codes) CancelOf(id, conv string) bool
- func (c *Codes) Open(why, conv, title string, digits int, wait time.Duration) (CodeAsk, error)
- func (c *Codes) Pending() []CodeAsk
- func (c *Codes) Put(id, value string) (bool, error)
- func (c *Codes) Wait(ctx context.Context, id, conv string, d time.Duration) (string, string)
- type Files
- type KV
- type Provider
- type Ref
- type RefReader
- type Refusal
- type Remote
- func (r *Remote) DeleteApp(full string) error
- func (r *Remote) Grant(name, project, origin string) error
- func (r *Remote) GrantOrigin(name, project, origin string) error
- func (r *Remote) Has(name string) bool
- func (r *Remote) List() ([]View, error)
- func (r *Remote) Lookup(name, project string) (View, error)
- func (r *Remote) Metadata(name string, origins, projects []string) (View, error)
- func (r *Remote) Put(name, value string) (View, bool, error)
- func (r *Remote) PutAsked(a Ask, value string) (View, bool, error)
- func (r *Remote) ReadApp(full string) (string, error)
- func (r *Remote) ReadRef(path, key string) (string, error)
- func (r *Remote) ReadSys(name string) (string, error)
- func (r *Remote) Remove(name string) error
- func (r *Remote) Reveal(names []string, use Use) (map[string]string, error)
- func (r *Remote) WriteApp(full, value string) error
- func (r *Remote) WriteSys(name, value string) error
- type Safe
- func (s *Safe) Grant(name, project, origin string) error
- func (s *Safe) GrantOrigin(name, project, origin string) error
- func (s *Safe) Has(name string) bool
- func (s *Safe) List() ([]View, error)
- func (s *Safe) Lookup(name, project string) (View, error)
- func (s *Safe) Metadata(name string, origins, projects []string) (View, error)
- func (s *Safe) Put(name, value string) (View, bool, error)
- func (s *Safe) PutAsked(a Ask, value string) (View, bool, error)
- func (s *Safe) Remove(name string) error
- func (s *Safe) Reveal(names []string, use Use) (map[string]string, error)
- type Store
- func (s *Store) Grant(name, project, origin string) error
- func (s *Store) GrantOrigin(name, project, origin string) error
- func (s *Store) Has(name string) bool
- func (s *Store) HasApp(app, name string) bool
- func (s *Store) List() ([]View, error)
- func (s *Store) Lookup(name, project string) (View, error)
- func (s *Store) Metadata(name string, origins, projects []string) (View, error)
- func (s *Store) Put(name, value string) (v View, created bool, err error)
- func (s *Store) PutApp(app, name, value string) error
- func (s *Store) PutAsked(a Ask, value string) (View, bool, error)
- func (s *Store) PutIntegration(integration, name, value string) error
- func (s *Store) Remove(name string) error
- func (s *Store) RemoveApp(app, name string) error
- func (s *Store) RemoveIntegration(integration, name string) error
- func (s *Store) Reveal(names []string, use Use) (map[string]string, error)
- func (s *Store) RevealApp(app string, names []string) (map[string]string, error)
- func (s *Store) RevealIntegration(integration, name string) (string, error)
- func (s *Store) SetShared(sh AppShared)
- func (s *Store) ShareApps() int
- type Use
- type View
Constants ¶
const ( AskWaiting = "waiting" AskReady = "ready" AskDeclined = "declined" )
How an ask ended, or that it still waits.
const ( ReasonRateLimited = "rate-limited" ReasonTooMany = "too-many" )
Reasons an ask is refused with.
const ( CodeWaiting = "waiting" CodeReady = "ready" CodeCancelled = "cancelled" CodeExpired = "expired" CodeGone = "gone" )
How a code ask stands.
const ( ReasonBadCode = "bad-code" ReasonNoChat = "no-chat" )
ReasonBadCode: the code is not as many digits as asked; ReasonNoChat: a code is asked only from a chat.
const ( // DefaultCodeWait and MaxCodeWait: how long an ask waits for the person. DefaultCodeWait = 10 * time.Minute MaxCodeWait = 30 * time.Minute MinCodeDigits = 4 MaxCodeDigits = 8 )
const ( DefaultFileTTL = 15 * time.Minute MaxFileTTL = 2 * time.Hour )
DefaultFileTTL is how long a secret's file lives when the command names no time; MaxFileTTL the longest it may.
const ( LimitsKey = "harnessly-limits" MaxLimits = 16 << 10 )
LimitsKey is the key a secret's limits are kept under at its path, MaxLimits their size.
const ( // ReasonDenied: the server refused this machine's login or this path. ReasonDenied = "denied" ReasonUnavailable = "unavailable" // ReasonReadOnly: a reference is read only; it is changed where it lives. ReasonReadOnly = "read-only" )
More reasons, of a safe whose values live on a server.
const ( WhereLocal = "local" WhereVault = "vault" )
Where a secret lives, as View.Where says it when the safe has more than one place.
const ( ReasonBadName = "bad-name" ReasonEmpty = "empty" ReasonTooLarge = "too-large" ReasonNotFound = "not-found" ReasonKeyLost = "key-lost" ReasonFailed = "failed" )
Reasons a change or a read is refused with; the page and the CLI put them in words.
const MaxValue = 64 << 10
MaxValue is the largest value the safe keeps (a private key with its chain fits).
const ReasonIntegration = "integration"
ReasonIntegration refuses a command the credentials of an integration.
const SysConnections = "sys/connections"
SysConnections is harnessly's record of the person's connections (Settings → Connections) in their shared safe: the list without credentials, so a new machine of the person has them. Like an app's secret it has a slash, so no route that takes a plain name (the page's safe list, `harnessly secret run`) ever sees it.
const ValueKey = "value"
ValueKey is the key a secret's value is kept under at its path.
Variables ¶
This section is empty.
Functions ¶
func AppName ¶ added in v0.16.154
AppName is the name an app's secret has in the safe; "" when the app id or the secret name is not one.
func BrowserValue ¶ added in v0.16.154
BrowserValue resolves a TOTP URI to its current RFC 6238 code. Other values are unchanged. Errors never include the URI or its key.
func Clean ¶
Clean is a value as it is kept: a one-line value (a token) without the spaces and line break a paste brings, a several-line one (a private key) as it was typed.
func DefaultKeyFile ¶
DefaultKeyFile is where the key lies when RUNTIME_SECRETS_KEY_FILE names no other file: the user's state folder ($XDG_STATE_HOME/harnessly, else ~/.local/state/harnessly), not the runtime's data folder (which the agents' CLI reads) nor a workspace.
func FileName ¶ added in v0.16.154
FileName is a file name for the value of s (a valid name or reference): the name itself, or for a vault: reference the last segment of its path and its key, "deploy-token" for vault:shared/ci/deploy#token.
func IntegrationCredential ¶
IntegrationCredential says whether a name or reference points at an integration's credentials: the runtime uses them itself, behind its own confirmations, and gives their values to no command. A vault: reference counts by the last segment of its path, which is how such a record is reached on a server.
func IntegrationName ¶
IntegrationName is the name an integration's secret has in the safe; "" when either part is not one.
func IsAppName ¶ added in v0.16.154
IsAppName says whether name is the safe's name of an app's secret.
func IsIntegrationName ¶
IsIntegrationName says whether name is the safe's name of a built-in integration's secret.
func Mask ¶ added in v0.16.154
Mask replaces known literal values and common wire encodings in one longest-match pass. A replacement is never matched again, and a short prefix cannot expose a longer value's suffix.
func Origin ¶ added in v0.16.154
Origin canonicalizes an HTTPS site, or HTTP on an explicitly local development host. Paths, credentials, queries and fragments are rejected rather than silently discarded.
func PromptBlock ¶
func PromptBlock() string
PromptBlock is what every agent of the machine reads in its system prompt about the safe: secrets are asked for and used by name, a value never goes through the conversation.
func ValidAppName ¶
ValidAppName says whether name is a whole, valid app/<id>/<name>: the only name with slashes a shared safe keeps always two parts below app/, so it cannot leave the owner's folder.
func ValidName ¶
ValidName says whether name may name a secret: letters, digits, '.', '_' and '-', 64 at most, not starting with a sign, so it is safe in a path, a log line and a command line.
func ValidRef ¶ added in v0.16.154
ValidRef says whether s is a secret's name or a reference a command may use.
func ValidSharedName ¶
ValidSharedName is a name a shared safe (the hub's, a server's) keeps: a person's plain name, an app's secret or one of harnessly's own records of the person.
func ValidSysName ¶
ValidSysName says whether name is one of harnessly's own records a shared safe keeps.
Types ¶
type AppShared ¶
type AppShared interface {
}
AppShared is the shared safe an app's secrets are mirrored to, so every machine of the person has them: a VM is only a runner, an app's token put on one is there on the next.
type Ask ¶
type Ask struct {
Origin string `json:"origin,omitempty"`
Project string `json:"project,omitempty"`
// Grant permits the requested project and site.
Grant bool `json:"grant,omitempty"`
// OriginGrant permits only the requested site, without adding project access.
OriginGrant bool `json:"originGrant,omitempty"`
ID string `json:"id"`
Name string `json:"name"`
// Why is the agent's one line of what it needs the secret for.
Why string `json:"why"`
// Conv and Title are the conversation that asked ("" when the asking command ran outside one).
Conv string `json:"conv"`
Title string `json:"title"`
// Replace: the agent asks for a new value of a secret the safe has (it expired, it was revoked).
Replace bool `json:"replace"`
At int64 `json:"at"`
}
Ask requests a value or approval to use an existing safe entry.
func (Ask) NeedsGrant ¶ added in v0.16.154
NeedsGrant reports whether this card approves access without accepting a value.
type Asks ¶
Asks are the open asks of this machine: an agent waits on one, the page lists them and settles them.
func NewAsks ¶
func NewAsks() *Asks
NewAsks is the asks with at most 6 a conversation in 10 minutes.
func (*Asks) Decline ¶
Decline settles a waiting ask as declined; false for an id that waits no more.
func (*Asks) Open ¶
Open is an ask of name: the waiting one of that name when there is one (an agent asking again keeps waiting on it), a declined one of the last two minutes (the person said no), else a new one.
func (*Asks) OpenScoped ¶ added in v0.16.154
OpenScoped deduplicates only requests with the same chat, project and requested origin.
func (*Asks) PageOpen ¶
PageOpen says whether a page looked at the asks lately (the new interface asks every few seconds while open).
func (*Asks) Pending ¶
Pending are the asks waiting for the person, oldest first; the call counts as a page looking.
type CodeAsk ¶
type CodeAsk struct {
ID string `json:"id"`
Why string `json:"why"`
Conv string `json:"conv"`
Title string `json:"title"`
Digits int `json:"digits"`
At int64 `json:"at"`
Until int64 `json:"until"`
}
CodeAsk is what the page shows of a code ask: what it is for, how long it waits, never the code.
type Codes ¶
Codes are the open code asks of this machine.
func NewCodes ¶
func NewCodes() *Codes
NewCodes is the code asks with at most 6 a conversation in 10 minutes.
func (*Codes) Cancel ¶
Cancel ends the ask id without a code: the person said no, or the command gave up; false for one that waits no more.
func (*Codes) Open ¶
Open starts an ask of a code of digits digits for the chat conv, waiting at most wait.
type Files ¶
type Files struct {
Dir string
// contains filtered or unexported fields
}
Files writes a secret into a file only its owner reads, for a tool that takes a key by path, and removes it when its time is up (or when the runtime starts again: the folder is swept then). The folder is in memory when the machine has /dev/shm, so a value does not reach the disk.
type KV ¶ added in v0.16.154
type KV interface {
Read(ctx context.Context, path string) (map[string]string, error)
Write(ctx context.Context, path string, data map[string]string) error
Delete(ctx context.Context, path string) error
List(ctx context.Context, path string) ([]string, error)
}
KV is the key/value engine of a Vault-compatible server, one mount (internal/secrets/vaultkv).
type Provider ¶ added in v0.16.154
type Provider interface {
List() ([]View, error)
Has(name string) bool
Put(name, value string) (View, bool, error)
Remove(name string) error
Reveal(names []string, use Use) (map[string]string, error)
// Lookup, Metadata, Grant, GrantOrigin and PutAsked keep the limits of a secret: the projects whose chats may use
// it and the sites it may be typed into (access.go). They hold no value.
Lookup(name, project string) (View, error)
Metadata(name string, origins, projects []string) (View, error)
Grant(name, project, origin string) error
GrantOrigin(name, project, origin string) error
PutAsked(a Ask, value string) (View, bool, error)
}
Provider is a place the safe keeps secrets in: this machine's sealed file (Store) or a Vault-compatible server (Remote). Every method refuses with a Refusal; none puts a value into an error.
type Ref ¶ added in v0.16.154
type Ref struct {
// Kind is "" for a plain name, WhereLocal or WhereVault.
Kind string
Name string
Path string
Key string
}
Ref is a name a command may use besides a plain secret name:
local:<name> the secret <name> of this machine's file, even when the safe keeps new secrets elsewhere vault:<path>#<key> the key <key> at <path> of the server's mount, read only (no #<key>: the key "value")
type RefReader ¶ added in v0.16.154
RefReader reads a secret an administrator keeps on the server, by its path and key: a reference.
type Remote ¶ added in v0.16.154
type Remote struct {
KV KV
// Prefix is the folder of the person's secrets in the mount, such as harnessly/users/alice.
Prefix string
// RefPrefixes are the folders vault: references may read; "*" any path the login may read; none refuses them.
RefPrefixes []string
Now func() time.Time
// contains filtered or unexported fields
}
Remote keeps the person's secrets on a Vault-compatible server, one path each under Prefix (<prefix>/<name>, the value under the key "value"). Only the value is there; when it was put and who used it stay on this machine, in a ledger without values (<dir>/remote-ledger.json), as the file safe keeps them.
func (*Remote) Grant ¶ added in v0.16.154
Grant adds a project and a site after a person answered a card.
func (*Remote) GrantOrigin ¶ added in v0.16.154
GrantOrigin adds only a site; the project must already be allowed.
func (*Remote) Has ¶ added in v0.16.154
Has says whether the server keeps a secret of that name (by a list at most 10 s old).
func (*Remote) List ¶ added in v0.16.154
List is the secrets under Prefix with what the ledger knows of them.
func (*Remote) Lookup ¶ added in v0.16.154
Lookup is the public view of a secret for a project's chat; a foreign one looks absent. Its limits lie on the server beside the value (limits.go), their copy in the ledger of this machine.
func (*Remote) Metadata ¶ added in v0.16.154
Metadata changes the limits of a secret, never its value.
func (*Remote) PutAsked ¶ added in v0.16.154
PutAsked writes a value a card asked for: a secret of another project is not overwritten, and a new one is limited to the project that asked, as in the file.
func (*Remote) ReadApp ¶
ReadApp reads an app's secret (app/<id>/<name>) the server keeps; not-found when it keeps none.
func (*Remote) ReadRef ¶ added in v0.16.154
ReadRef reads key at path, when path lies under one of RefPrefixes.
func (*Remote) ReadSys ¶
ReadSys reads one of harnessly's own records of the person (sys/<name>); not-found when the server keeps none.
func (*Remote) Reveal ¶ added in v0.16.154
Reveal reads the values from the server and records the use in the ledger. The limits the server keeps decide; for a secret it keeps none of, the ledger's do, and they go to the server then.
type Safe ¶ added in v0.16.154
type Safe struct {
Local *Store
// Primary is where new secrets go; nil keeps everything in Local.
Primary Provider
// Refs reads vault: references; nil refuses them.
Refs RefReader
// Where names Primary for View.Where (WhereVault).
Where string
}
Safe is what the routes use: the machine's file, and, when the safe keeps its secrets on a server, that server (Primary) and its references. A plain name is looked up in Primary first, then in the file, so the secrets put before the switch keep working until they are moved. New secrets go to Primary.
func (*Safe) Grant ¶ added in v0.16.154
Grant lets a project (and a site) use a secret, after a person answered its card.
func (*Safe) GrantOrigin ¶ added in v0.16.154
GrantOrigin lets a secret be typed into one more site.
func (*Safe) Has ¶ added in v0.16.154
Has says whether a name can be used now; a vault: reference is not looked up (it is read when it is used).
func (*Safe) List ¶ added in v0.16.154
List is the secrets of Primary and then those of the file it does not shadow, each with where it lives. With the file alone, the list is the file's, without where.
func (*Safe) Lookup ¶ added in v0.16.154
Lookup is what a project's chat may know of a secret: its public view, or not-found for a foreign one.
func (*Safe) Put ¶ added in v0.16.154
Put keeps a value in Primary. Only plain names are put: a reference is changed where it lives. A secret of the file given a new value moves to Primary: its old copy leaves the file, so no stale value stays behind it.
func (*Safe) PutAsked ¶ added in v0.16.154
PutAsked keeps a value a card asked for. With a server, it goes there, as Put; a copy in the file that belongs to another project is not overwritten, and the limits of one this project may use go with its value.
func (*Safe) Remove ¶ added in v0.16.154
Remove forgets a secret in Primary, or, when Primary has none of that name, in the file (local:<name> says the file outright).
type Store ¶
Store is the safe's file and its key. The file (<dir>/safe.json) holds only sealed values; the key is a separate file, by default outside the runtime's data folder, which every agent of the machine knows (see DefaultKeyFile).
func (*Store) Grant ¶ added in v0.16.154
Grant adds a project and requested site after a person approves an access card.
func (*Store) GrantOrigin ¶ added in v0.16.154
GrantOrigin adds only a site and rechecks project access when the card is answered.
func (*Store) Lookup ¶ added in v0.16.154
Lookup returns only public metadata visible to the project. A foreign entry looks absent.
func (*Store) Metadata ¶ added in v0.16.154
Metadata changes only public access constraints, never the encrypted value.
func (*Store) Put ¶
Put keeps value under name, a new secret or a new value of one (its uses stay); created says which.
func (*Store) PutAsked ¶ added in v0.16.154
PutAsked stores a value from a specific card without overwriting a foreign project entry.
func (*Store) PutIntegration ¶
PutIntegration keeps the value of an integration's secret.
func (*Store) RemoveIntegration ¶
RemoveIntegration forgets an integration's secret.
func (*Store) Reveal ¶
Reveal opens the values of names for one command and records the use; nothing is opened when one of them is missing or cannot be read.
func (*Store) RevealApp ¶ added in v0.16.154
RevealApp opens the values of an app's secrets for the machine to put into the app's MCP server config. The use is recorded under the app's name; names are the secrets' own names (not the safe's). A missing one is a refusal.
func (*Store) RevealIntegration ¶
RevealIntegration opens the value of an integration's secret; a missing one is a refusal (ReasonNotFound).
func (*Store) SetShared ¶
SetShared mirrors the app's secrets of this file to a shared safe; nil keeps them in the file alone.
func (*Store) ShareApps ¶
ShareApps sends up every app's secret this file keeps and has not shared yet: a token put on this machine before the safe was shared reaches the other machines at once, not only on its first use here. One the shared safe already keeps is only marked (its value wins on the next reveal). Errors leave the secret for the next start.
type Use ¶
type Use struct {
// Project is verified by the caller and is never taken from agent request data.
Project string `json:"-"`
Origin string `json:"origin,omitempty"`
Conv string `json:"conv"`
Title string `json:"title"`
At int64 `json:"at"`
}
Use is one command's use of a secret: the conversation it ran from (its title as it was then), when.
type View ¶
type View struct {
Origins []string `json:"origins,omitempty"`
Projects []string `json:"projects,omitempty"`
Name string `json:"name"`
CreatedAt int64 `json:"createdAt"`
UpdatedAt int64 `json:"updatedAt"`
LastUsedAt int64 `json:"lastUsedAt"`
UsedBy []Use `json:"usedBy"`
// Where says which store holds it (WhereLocal, WhereVault) when the safe has more than one; empty otherwise.
Where string `json:"where,omitempty"`
}
View is a secret as anyone may see it: everything but the value.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package execkv keeps the safe in any store a command can reach, without a new build of harnessly: the runtime runs the command once per call, writes one request as JSON to its stdin and reads one answer from its stdout (docs/safe.md, "Any other store").
|
Package execkv keeps the safe in any store a command can reach, without a new build of harnessly: the runtime runs the command once per call, writes one request as JSON to its stdin and reads one answer from its stdout (docs/safe.md, "Any other store"). |
|
Package secretstest has a Vault-compatible store in memory for the tests of the safe's servers.
|
Package secretstest has a Vault-compatible store in memory for the tests of the safe's servers. |
|
Package vaultkv is a small client of the key/value engine of a Vault-compatible server (OpenBao or HashiCorp Vault): read, write, list and delete one path of a mount, KV version 1 or 2, logged in with a token file, AppRole, Kubernetes or JWT.
|
Package vaultkv is a small client of the key/value engine of a Vault-compatible server (OpenBao or HashiCorp Vault): read, write, list and delete one path of a mount, KV version 1 or 2, logged in with a token file, AppRole, Kubernetes or JWT. |