Documentation
¶
Overview ¶
Package profile reads and writes kcli's profiles, so a program uses the deployment and credentials kcli is set up with: Client(name) is the one-line form.
Settings live in ~/.config/kcli/config.toml (XDG_CONFIG_HOME and KCLI_CONFIG respected):
version = 1 active_profile = "default" [defaults] output = "table" timeout = 30 [profiles.default] url = "https://kasm.example.com" auth = "api_key" api_key = "..." verify_tls = true
The file is a public interface shared by kcli and the SDKs: a change to its shape needs a version bump, and a reader refuses a newer version.
Secrets (API key secret, password, session token, OIDC refresh token) never live in this file; they are in the SecretStore. Precedence when resolving a value: override > environment > profile > defaults.
Index ¶
Constants ¶
const ( EnvConfig = "KCLI_CONFIG" // path to config.toml EnvProfile = "KCLI_PROFILE" // profile name EnvOutput = "KCLI_OUTPUT" // table | wide | json | yaml EnvURL = "KASM_URL" // deployment URL EnvAPIKey = "KASM_API_KEY" // API key id EnvAPIKeySecret = "KASM_API_KEY_SECRET" // API key secret EnvSecretStore = "KCLI_SECRET_STORE" // keyring | file EnvAuth = "KCLI_AUTH" // api_key | password, overriding the profile EnvUsername = "KASM_USERNAME" // username for password auth EnvPassword = "KASM_PASSWORD" // password for password auth )
Environment variables. Secrets are accepted from the environment (for CI) but never from command-line arguments.
const ( AuthAPIKey = "api_key" AuthPassword = "password" AuthOIDC = "oidc" )
Auth modes. api_key is a developer API key (HTTP Basic). password signs in as a user and sends that session's token (Bearer), which is what the self-service ("the caller") operations need, since an API key has no user. oidc is reserved for the platform's planned OIDC client authentication.
const ( SecretAPIKeySecret = "api_key_secret" SecretPassword = "password" // SecretSessionToken caches a password login's session token as // "<username>\n<token>", reused until the token expires. SecretSessionToken = "session_token" SecretOIDCRefresh = "oidc_refresh_token" )
Secret names, stored per profile.
const CurrentVersion = 1
CurrentVersion is the config.toml schema version this build reads and writes.
Variables ¶
var ErrNoSecret = errors.New("secret not found")
ErrNoSecret is returned when no value is stored.
Functions ¶
func Client ¶
Client returns a client for the named profile, as kcli would use it: the environment, then the profile, then the defaults. An empty name is the active profile (KCLI_PROFILE, then active_profile). opts apply after the profile's timeout and TLS setting. A password profile signs in, or reuses kcli's cached session token, and never prompts.
Types ¶
type Config ¶
type Config struct {
Version int `toml:"version"`
ActiveProfile string `toml:"active_profile"`
Defaults Defaults `toml:"defaults"`
Profiles map[string]Profile `toml:"profiles"`
}
Config is the on-disk document.
func New ¶
func New() *Config
New returns an empty configuration with defaults and one empty profile.
func (*Config) ProfileNames ¶
ProfileNames returns profile names sorted.
func (*Config) Resolve ¶
Resolve applies precedence (flags > env > profile > defaults) and returns the effective settings. It does not require the profile to be fully configured; callers that need a client check Resolved.URL and credentials.
type OIDC ¶
type OIDC struct {
Issuer string `toml:"issuer"`
ClientID string `toml:"client_id"`
Scopes []string `toml:"scopes,omitempty"`
}
OIDC holds the non-secret half of an OIDC client configuration. Tokens go in the secret store. Not yet used by any command.
type Profile ¶
type Profile struct {
URL string `toml:"url"`
Auth string `toml:"auth"`
APIKey string `toml:"api_key,omitempty"`
Username string `toml:"username,omitempty"`
VerifyTLS *bool `toml:"verify_tls,omitempty"`
OIDC *OIDC `toml:"oidc,omitempty"`
}
Profile describes one deployment and how to authenticate to it.
type Resolved ¶
type Resolved struct {
ProfileName string
Profile Profile
URL string
Auth string
APIKey string
// APIKeySecret is set only when it came from the environment. Otherwise the
// caller fetches it from the secret store.
APIKeySecret string
Username string
// Password is set only when it came from the environment (KASM_PASSWORD).
Password string
VerifyTLS bool
Timeout int
Output string
}
Resolved is the effective configuration for one invocation.
func (*Resolved) Authenticator ¶
func (r *Resolved) Authenticator(store SecretStore, prompt func(username string) (string, error), opts ...sdk.Option) (sdk.Authenticator, error)
Authenticator returns the credentials for r, with secrets from the environment or store:
- api_key: the key ID and its secret, as HTTP Basic.
- password: a session token as Bearer. The token cached in store is reused until two minutes before it expires; otherwise it signs in with the password from KASM_PASSWORD, the store, or prompt (nil means none), and caches the new token. A token the server rejects is replaced once.
opts configure the sign-in request (HTTP client, user agent, trace).
type SecretStore ¶
type SecretStore interface {
Get(profile, key string) (string, error)
Set(profile, key, value string) error
Delete(profile, key string) error
// Name identifies the backend for `kcli config show`.
Name() string
}
SecretStore is a per-profile secret store.
func OpenSecrets ¶
func OpenSecrets(configDir string, warn io.Writer) (SecretStore, error)
OpenSecrets returns the secret store for the profiles in configDir. The system keyring (macOS Keychain, Secret Service, Windows Credential Manager) is preferred. When it is unavailable, typically on headless Linux without D-Bus, secrets fall back to an owner-only credentials.toml in configDir. KCLI_SECRET_STORE=keyring|file forces one or the other. warn receives a one-line notice the first time a fallback happens; nil discards it.
type SetupError ¶
type SetupError struct {
// contains filtered or unexported fields
}
SetupError is a profile that cannot authenticate as configured: no URL, API key, secret, username or password. Its message says how to fix it.
func (*SetupError) Error ¶
func (e *SetupError) Error() string