Documentation
¶
Overview ¶
Package cloud holds komando's own clients for cloud and secret-manager APIs, so no vendor CLI (aws, gcloud, vault) has to be installed (docs/design/code-layout.md). Logins stay with the person: komando reads the credentials they already have and never stores them.
Index ¶
- Variables
- func AWSConfig(ctx context.Context, profile, region string) (aws.Config, error)
- func AWSCredentials(ctx context.Context, profile string) (aws.Credentials, error)
- func AWSProfileAccess(ctx context.Context, profile, configFile, credsFile string) (aws.Credentials, string, string, error)
- func AWSProfileMissing(err error) bool
- func AWSSSOLogin(ctx context.Context, profile string, show func(url, code string)) (string, error)
- func AWSSecret(ctx context.Context, id string) (string, error)
- func AzureLoginHint(resource string) string
- func AzureSecret(ctx context.Context, path string) (string, error)
- func AzureTenant(token string) string
- func AzureToken(ctx context.Context, resource string) (string, error)
- func Bitwarden(ctx context.Context, ref string) (string, error)
- func BitwardenDecrypt(s string, key []byte) ([]byte, error)
- func BitwardenEncrypt(plain, key []byte) (string, error)
- func BitwardenMasterKey(password, email string, kdf, iterations, memoryMiB, parallelism int) ([]byte, error)
- func BitwardenPasswordHash(master []byte, password string) string
- func BitwardenStretch(master []byte) []byte
- func ECRToken(ctx context.Context, profile, region string) (string, error)
- func EKSToken(ctx context.Context, profile, region, cluster, roleARN string) (string, error)
- func GCPAccessToken(ctx context.Context) (string, error)
- func GCPSecret(ctx context.Context, name, project string) (string, error)
- func KeePass(ref string) (string, error)
- func KeyVaultResource(path string) string
- func OnePassword(ctx context.Context, ref string) (string, error)
- func SSMDial(ctx context.Context, profile, region, target, port string) (net.Conn, error)
- func VaultKV(ctx context.Context, path, field string) (string, error)
- type AWSLogin
- type AWSSSO
- type EC2Instance
Constants ¶
This section is empty.
Variables ¶
var CheckLocalFile = func(what, path string) error { return nil }
CheckLocalFile is asked before a file of this computer that the environment or a cloud config file names is read to be sent as a login (what names the setting). The cli sets it: for an AI agent it refuses a file the agent may not send (a private key, komando's own data, a credential store).
var ErrAWSLogin = errors.New("AWS login required")
ErrAWSLogin is wrapped by errors that a person fixes by logging in again (an expired or missing SSO session).
var ErrAWSNotSSO = errors.New("the profile does not use SSO")
ErrAWSNotSSO says a profile has no IAM Identity Center (SSO) login: its keys come from ~/.aws/credentials or the environment, so there is nothing to log in to.
var ErrAzureLogin = errors.New("no Azure login")
ErrAzureLogin is wrapped by errors that an Azure login fixes.
var ErrGCPLogin = errors.New("google cloud credentials required")
ErrGCPLogin is wrapped by errors that credentials fix.
var ErrGCPNoCredentials = errors.New("none found")
ErrGCPNoCredentials is wrapped, with ErrGCPLogin, when no Google credentials were found at all (not one that failed).
var ErrNoConnect = errors.New("1Password Connect is not set up (OP_CONNECT_HOST and OP_CONNECT_TOKEN)")
ErrNoConnect: op:// needs a 1Password Connect server (OP_CONNECT_HOST).
var UnlockEnv = os.Getenv
UnlockEnv reads a variable that unlocks a secret store (KOMANDO_BW_PASSWORD, KOMANDO_KDBX_PASSWORD, OP_CONNECT_TOKEN, VAULT_TOKEN...). komando's vault sets it to also find the values it took out of the environment when it started (vault.TakeUnlockEnv), so the programs komando starts never inherit them.
Functions ¶
func AWSConfig ¶
AWSConfig is the SDK configuration for a profile: "" or "default" is the usual chain (environment, ~/.aws/config and credentials, SSO, roles, instance metadata). region overrides the profile's region when set.
func AWSCredentials ¶
AWSCredentials are the profile's current keys.
func AWSProfileAccess ¶ added in v0.3.0
func AWSProfileAccess(ctx context.Context, profile, configFile, credsFile string) (aws.Credentials, string, string, error)
AWSProfileAccess is what a profile in the given config and credentials files gives: its current keys, region and custom endpoint ("" for AWS).
func AWSProfileMissing ¶
AWSProfileMissing reports whether err says the profile is not in ~/.aws/config or ~/.aws/credentials.
func AWSSSOLogin ¶
AWSSSOLogin logs a person in to the IAM Identity Center (SSO) of a profile, the way `aws sso login` does: the device-code flow. A profile that assumes a role from an SSO profile logs in to that one. show gets the page and the code to confirm there. The token is written to the same cache file the aws CLI uses (~/.aws/sso/cache), so the SDK, the aws CLI and komando share the login.
func AzureLoginHint ¶ added in v0.9.0
AzureLoginHint says how to give komando an Azure login for resource. The Azure CLI saves a resource manager token at `az login` and renews it with each az command; a token for another resource only when asked.
func AzureSecret ¶ added in v0.9.0
AzureSecret reads a Key Vault secret. path is VAULT/NAME or VAULT/NAME/VERSION; without a version it is the current one.
func AzureTenant ¶ added in v0.9.0
AzureTenant is the tenant an Azure AD access token was given in (its tid claim), or "". The token is not checked: the service it goes to does.
func AzureToken ¶ added in v0.9.0
AzureToken is an access token for resource (an Azure AD resource such as https://vault.azure.net), from the first login that is there:
- a service principal: AZURE_TENANT_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET;
- a workload identity (AKS): AZURE_TENANT_ID, AZURE_CLIENT_ID and AZURE_FEDERATED_TOKEN_FILE;
- a token for resource that the Azure CLI saved and that is still good (az refreshes it; komando cannot without the CLI's own app id);
- the managed identity of this Azure machine (AZURE_CLIENT_ID picks a user-assigned one).
func Bitwarden ¶
Bitwarden reads bw://ITEM/FIELD. FIELD is password, username, notes, uri, totp, or the name of a custom field. ITEM is the item's name or id.
func BitwardenDecrypt ¶
BitwardenDecrypt opens a type 2 cipher string "2.IV|DATA|MAC" (AES-256-CBC with HMAC-SHA256, encrypt-then-MAC). key is 64 bytes.
func BitwardenEncrypt ¶
BitwardenEncrypt makes a type 2 cipher string (used by tests and the e2e seeding; komando itself only reads).
func BitwardenMasterKey ¶
func BitwardenMasterKey(password, email string, kdf, iterations, memoryMiB, parallelism int) ([]byte, error)
BitwardenMasterKey derives the 32-byte master key: kdf 0 is PBKDF2-SHA256 (salt: the e-mail in lower case), kdf 1 Argon2id (salt: its SHA-256; memory in MiB).
func BitwardenPasswordHash ¶
BitwardenPasswordHash is what the server checks at login: one more PBKDF2 round of the master key with the password as salt.
func BitwardenStretch ¶
BitwardenStretch expands the master key into an encryption and a MAC key (64 bytes: enc then mac), with HKDF-Expand.
func EKSToken ¶
EKSToken is a bearer token for an Amazon EKS cluster, made the way `aws eks get-token` and aws-iam-authenticator make it: a presigned STS GetCallerIdentity URL naming the cluster, valid for 15 minutes. roleARN, when set, is assumed first.
func GCPAccessToken ¶
GCPAccessToken is an OAuth access token from the application-default credentials, as gke-gcloud-auth-plugin gives GKE and `gcloud auth print-access-token` a registry login.
func GCPSecret ¶
GCPSecret reads the latest version of a Secret Manager secret. name is a secret id (project from project, the credentials or the gcloud config), or a full projects/P/secrets/S[/versions/V] name.
func KeePass ¶
KeePass reads one field of an entry in a KeePass or KeePassXC file (KDBX 3.1 and 4). ref is FILE#GROUP/.../ENTRY[#FIELD]; the field is the password unless named (UserName, URL, Notes, or a custom one). The file is opened with KOMANDO_KDBX_PASSWORD and/or the key file KOMANDO_KDBX_KEYFILE.
func KeyVaultResource ¶ added in v0.9.0
KeyVaultResource is the Azure AD resource for the vault of an azure-kv: path (VAULT/NAME), which is the one an Azure CLI token must be for: https://vault.azure.cn for shop.vault.azure.cn. It is the public cloud's for a vault name without a host, or one that is not valid.
func OnePassword ¶
OnePassword reads op://VAULT/ITEM[/SECTION]/FIELD from a 1Password Connect server, through its documented REST API: OP_CONNECT_HOST is the server, OP_CONNECT_TOKEN its access token. Vaults and items are matched by name or id, fields by label or id (and section when given).
func VaultKV ¶
VaultKV reads one field of a KV secret from HashiCorp Vault or OpenBao, the way `vault kv get -field=FIELD PATH` does: PATH starts with the mount ("secret/shop/db"), KV version 1 or 2 is found out from the mount. The address and token come from the same places the CLI uses: VAULT_ADDR, VAULT_TOKEN or ~/.vault-token, VAULT_NAMESPACE, VAULT_CACERT.
Types ¶
type AWSLogin ¶ added in v0.14.0
type AWSLogin struct {
Profiles []string `json:"profiles"` // the ~/.aws/config profiles that use it
StartURL string `json:"sso_start_url"` // the sign-in page
Region string `json:"sso_region"` // where IAM Identity Center runs
Session string `json:"sso_session,omitempty"` // the [sso-session NAME] it belongs to
LoggedInAt time.Time `json:"logged_in_at,omitzero"` // when the token was saved
ExpiresAt time.Time `json:"expires_at"` // when the token runs out
// Renews: it has a refresh token, so the SDKs and komando get a new
// token after expires_at, for as long as the AWS session lasts
Renews bool `json:"renews,omitempty"`
File string `json:"-"`
}
AWSLogin is an IAM Identity Center (SSO) login saved in the aws CLI's cache (~/.aws/sso/cache): by komando login aws, aws sso login or an SDK. It never holds the token itself.
func AWSSSOLogins ¶ added in v0.14.0
AWSSSOLogins are the SSO logins that still work among the given profiles, one per cache file with every profile that uses it. It reads only files on this computer.
func AWSSSOLogout ¶ added in v0.14.0
AWSSSOLogout ends the SSO login a profile uses, as `aws sso logout` does: IAM Identity Center is told to end the token (revoked; best effort, it needs the network), then its cache file is deleted. ok is false when the profile has no login that still works.
type AWSSSO ¶ added in v0.13.0
type AWSSSO struct {
Profile, StartURL, Region string
// Role is the profile's role_arn, also when there is no SSO behind it
Role string
// contains filtered or unexported fields
}
AWSSSO is the SSO login a profile uses: its own, or that of the profile its role is assumed from (role_arn with source_profile). key names the token's cache file.
func AWSProfileSSO ¶ added in v0.13.0
AWSProfileSSO is the SSO login behind a profile, or an error wrapping ErrAWSNotSSO when it has none. files, when given, are the config and credentials file to read (import).
type EC2Instance ¶ added in v0.14.0
type EC2Instance struct {
ID, Name, Region, Zone string
PublicIP, PublicDNS string
PrivateIP, PrivateDNS string
Platform, KeyName, VPCID string
}
EC2Instance is a running EC2 server, as import aws-ec2 adds it.
func EC2Instances ¶ added in v0.14.0
func EC2Instances(ctx context.Context, creds aws.Credentials, region, endpoint string, max int) ([]EC2Instance, error)
EC2Instances lists the running instances of one region with the keys creds, by the EC2 Query API (DescribeInstances, read only), signed as the SDKs sign it. endpoint, when set, replaces ec2.REGION.amazonaws.com (a test server, LocalStack). It reads at most max instances.