cloud

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 16 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

Overview

Package cloud is the contract for everything terrace asks the cloud: whose credentials a profile holds and until when, what the AWS config says of a profile, and whether the everyday credentials can delete in an account. Its drivers are awscloud, which asks AWS, and democloud, the demo world's local stand-in; cloudbuild picks one at build time.

A driver takes nothing from the environment for a named profile: not its credential, profile, config-file, role, container or endpoint variables. The environment's own credentials are the one case read as the environment has them. A proxy, and the TLS roots AWS_CA_BUNDLE names, passed in through Config, still apply to every call: corporate networks need them, and like any deliberate act of the same user they are outside what the gate stops (spec 1.4.9).

The write-access check is a tripwire for the setups spec 6.4.2–6.4.4 describe, not a proof: it asks AWS's policy simulator whether the everyday principals are allowed a few delete actions on any resource (spec 5.7.3). The principals are the links of the credentials' own chain in the account, and every permission set a live cached Identity Center sign-in reaches there (spec 5.7.4): every file in ~/.aws/sso/cache that holds an accessToken, whichever tool cached it. It answers yes where any is allowed one; no where every one it asked about was denied; and couldn't tell, with its reason, where:

  • a decision turns on context the simulator wasn't given, as an Allow with a condition does, or AWS refused a question or gave an incomplete answer
  • the principal the chain starts from is unknown
  • a principal wasn't found, or is one the simulator can't be asked about, or there is no principal at all
  • a permission set has no role in the account
  • a sign-in, or the folder of them, can't be read, a sign-in renewed into a file terrace can't write, a sign-in names no region, or the sign-in of the credentials' own set reaches none
  • a list of permission sets was cut short

It doesn't see:

  • principals in other accounts that may assume roles into this one, and roles the everyday principals may assume beyond their own chain
  • role trust policies, and resource-based policies generally
  • grants scoped to particular resources, and Deny statements scoped with NotResource or conditions; the simulator treats a condition on a key it isn't given as not matching, so a conditional Deny beside an Allow over-reports yes
  • destructive actions beyond the few it asks about, such as deleting S3 objects or table items, or terminating instances
  • escalation through IAM or service roles (PassRole, Lambda, SSM, CloudFormation, CodeBuild, Step Functions), or through Identity Center administration
  • other profiles' static keys, the AWS CLI's role cache in ~/.aws/cli/cache, aws login sessions, and other tools' tokens beyond ~/.aws/sso/cache
  • the environment's own credentials, where the tier names a profile
  • a change after its answer: Daily keeps an answer up to a day, so a set assigned, or a sign-in that renews itself once its session has ended or someone signs in again to the same file, goes unseen until the next check
  • Daily's own file, which the agent can write without Setup 2

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoCredentialsNamed is a question asked with the zero Credentials,
	// which name neither a profile nor the environment.
	ErrNoCredentialsNamed = errors.New("no profile named, and not the environment's credentials")
	// ErrOutOfReach is the cloud failing or throttling: no answer about the
	// credentials either way.
	ErrOutOfReach = errors.New("the cloud is out of reach")
	// ErrBadProfile is an AWS config terrace can't read: a profile whose
	// source_profile is missing, a file it can't parse, or a CA bundle it
	// can't load. Signing in doesn't fix it.
	ErrBadProfile = errors.New("the AWS config can't be read")
	// ErrUnreadable is a sign-in file terrace may not read. Signing in
	// doesn't fix it.
	ErrUnreadable = errors.New("a sign-in file can't be read")
	// ErrUnwritable is a sign-in terrace renewed but may not cache again.
	// Signing in doesn't fix it.
	ErrUnwritable = errors.New("a sign-in file can't be written")
)
View Source
var (
	// ErrNoProfile is a profile the AWS config doesn't have.
	ErrNoProfile = errors.New("no such profile in the AWS config")
	// ErrNoCredentials is credentials terrace can't use: a profile that
	// holds no static keys, Identity Center sign-in, or role assumed from a
	// profile that holds one; or an environment that holds none, which
	// ErrNoneInEnvironment says too.
	ErrNoCredentials = errors.New("no credentials terrace can use")
	// ErrNoneInEnvironment is an environment in which the AWS SDK's chain
	// finds no credentials at all, as against credentials that don't work.
	ErrNoneInEnvironment = errors.New("no credentials found in the environment")
	// ErrSignedOut is an Identity Center profile with no sign-in, or one
	// the cloud no longer accepts.
	ErrSignedOut = errors.New("not signed in")
	// ErrExpired is an Identity Center sign-in that has ended.
	ErrExpired = errors.New("sign-in expired")
	// ErrRoleRefused is a role the credentials may not take: a permission
	// set the signed-in user no longer has, or a role that refuses the
	// credentials assuming it. Signing in again doesn't fix it.
	ErrRoleRefused = errors.New("role refused to these credentials")
	// ErrRefused is credentials the cloud refused for any other reason,
	// such as static keys it no longer accepts.
	ErrRefused = errors.New("credentials refused")
)

Why credentials don't work, each the Err of a *SignedOutError, wrapped.

View Source
var (
	// ErrNoDeviceSignIn is a profile with no device sign-in to start: one
	// the AWS config doesn't have, or with no Profile.OwnSignIn.
	ErrNoDeviceSignIn = errors.New("no Identity Center sign-in to start for the profile")
	// ErrCodeExpired is a device sign-in whose code expired before anyone
	// used it.
	ErrCodeExpired = errors.New("the sign-in's code expired unused")
	// ErrSignInDenied is a device sign-in the person denied in the browser.
	ErrSignInDenied = errors.New("the sign-in was denied")
)

Why a device sign-in comes to nothing.

View Source
var ErrBadConfig = errors.New("cloud config unusable")

ErrBadConfig is returned, wrapped, for a Config a driver can't use.

Functions

This section is empty.

Types

type ARN

type ARN string

ARN is an Amazon Resource Name: a role's, a user's or a session's.

type AccountMismatchError

type AccountMismatchError struct {
	// Unit is the zero Path where no unit asked, as for the write-access
	// check.
	Unit        unit.Path
	Credentials Credentials
	Expected    account.ID
	Found       account.ID
}

AccountMismatchError is credentials in another account than expected.

func (*AccountMismatchError) Error

func (e *AccountMismatchError) Error() string

func (*AccountMismatchError) Kind

func (e *AccountMismatchError) Kind() errkind.Kind

Kind is errkind.KindAccountMismatch.

type CanDelete

type CanDelete string

CanDelete is the write-access check's answer. It's stored, so each value is its stored form.

const (
	CanDeleteYes     CanDelete = "yes"
	CanDeleteNo      CanDelete = "no"
	CanDeleteUnknown CanDelete = "unknown"
)

The answers: the everyday credentials can delete, they can't, or terrace couldn't tell.

type Cloud

type Cloud interface {
	// Identity is whose credentials c are, and until when their sign-in
	// lasts. Its errors: a *SignedOutError for credentials missing, expired
	// or refused; ErrOutOfReach, wrapped, for the cloud failing or
	// throttling; ErrBadProfile, wrapped, for an AWS config that can't be
	// read; ErrUnreadable or ErrUnwritable, wrapped, for a sign-in file that
	// can't be read or written;
	// ErrNoCredentialsNamed for the zero Credentials; and ctx's own
	// error where it ends. Any other is the cloud refusing the question
	// itself.
	Identity(ctx context.Context, c Credentials) (Identity, error)
	// Profile is what the AWS config says of the named profile, read
	// without signing in, and false where the config has no such profile.
	// Its error is ErrBadProfile, wrapped.
	Profile(ctx context.Context, name config.ProfileName) (Profile, bool, error)
	// WriteAccess is whether the everyday credentials can delete in q's
	// account, asked with read-only calls as the package's doc says. It
	// informs and never blocks a run; Daily keeps its answers. Its errors
	// are Identity's, and an *AccountMismatchError for credentials that
	// reach another account than q's.
	WriteAccess(ctx context.Context, q WriteAccessQuery) (WriteAccess, error)
	// StartSignIn starts a device sign-in for the named profile, through
	// its Profile.OwnSignIn (spec 5.5.1). Its errors: ErrNoDeviceSignIn,
	// wrapped, for a profile the AWS config doesn't have, or that has no
	// such sign-in; ErrBadProfile and ErrOutOfReach, wrapped; and ctx's own
	// error where it ends.
	StartSignIn(ctx context.Context, name config.ProfileName) (DeviceSignIn, error)
}

Cloud is everything terrace asks the cloud.

type Config

type Config struct {
	// Home is the user's home folder, an absolute path, which holds the AWS
	// config and credentials files and the Identity Center sign-ins.
	Home string
	// Now is the time, which decides when a sign-in has ended.
	Now func() time.Time
	// CABundle is the file of TLS roots AWS_CA_BUNDLE names, empty for
	// none. Where it's empty, a profile's own ca_bundle applies.
	CABundle string
}

Config is what a driver needs.

func (Config) Check

func (c Config) Check() error

Check refuses a Config with a Home that isn't absolute, which would read the AWS config from the current folder, or with no clock.

type Credentials

type Credentials struct {
	// contains filtered or unexported fields
}

Credentials are whose credentials a question is asked with: a named profile's, the environment's own, or keys held in memory. The zero value is none of them, and every question refuses it with ErrNoCredentialsNamed.

func CredentialsFor

func CredentialsFor(name config.ProfileName) Credentials

CredentialsFor are the named profile's credentials, or the environment's own where name is empty: a tier that names no profile runs with them (spec 6.1.3).

func EnvironmentCredentials

func EnvironmentCredentials() Credentials

EnvironmentCredentials are the environment's own: the variables, files and roles the AWS SDK finds when no profile is named (spec 6.1.3).

func KeyCredentials

func KeyCredentials(k Keys) Credentials

KeyCredentials are keys held in memory, as the delete sign-in's are (spec 6.1.1). Keys that aren't Complete are the zero Credentials.

func ProfileCredentials

func ProfileCredentials(name config.ProfileName) Credentials

ProfileCredentials are the named profile's. An empty name is the zero Credentials, never the environment's own.

func (Credentials) IsEnvironment

func (c Credentials) IsEnvironment() bool

IsEnvironment reports whether c are the environment's own credentials.

func (Credentials) Keys

func (c Credentials) Keys() (Keys, bool)

Keys are the keys c hold, and false where c are a profile's or the environment's.

func (Credentials) Profile

func (c Credentials) Profile() (config.ProfileName, bool)

Profile is the profile named, and false where c names none.

func (Credentials) String

func (c Credentials) String() string

String names c, and never a key's value.

type Daily

type Daily struct {
	Cloud
	// contains filtered or unexported fields
}

Daily is a Cloud whose write-access check asks the cloud at most once a day for each account and credentials, and keeps its answer, readable by the user alone, in a folder until then. Its other questions pass through.

An answer is kept by the account and the credentials' fingerprint, which costs an Identity call to find: a profile edited, another user signed in to it, a sign-in cached, or one that can't renew itself ending is asked again, never given another's answer, and a renewal isn't. A sign-in that renews itself, once its session has ended or someone signs in again to the same file, goes unseen until the day's answer ages out. Credentials with no fingerprint are asked every time.

func NewDaily

func NewDaily(in DailyInput) (*Daily, error)

NewDaily keeps in.Cloud's write-access answers in in.Dir.

func (*Daily) WriteAccess

func (d *Daily) WriteAccess(ctx context.Context, q WriteAccessQuery) (WriteAccess, error)

WriteAccess is the answer kept for q where it's less than a day old, and otherwise the cloud's, which it keeps. Errors are never kept.

type DailyInput

type DailyInput struct {
	Cloud Cloud
	// Dir is the folder that keeps the answers, made where it's missing.
	Dir string
	Now func() time.Time
}

DailyInput is what NewDaily needs.

type DeviceSignIn

type DeviceSignIn struct {
	// Link is the page that approves it, with its code in it; BaseLink is
	// the page alone, where the code is typed.
	Link, BaseLink string
	Code           string
	ExpiresAt      time.Time
	// Wait waits for the person to approve the sign-in, asking the cloud
	// at the pace it sets, then takes the profile's role credentials and
	// signs the sign-in out, its token dropped, so only the role's keys
	// outlive it. Its errors: ErrCodeExpired, wrapped, for a code that
	// expired unused; ErrSignInDenied, wrapped, for a sign-in the person
	// denied; ErrRoleRefused, wrapped, for a user who can't take the
	// profile's permission set in its account; ErrOutOfReach, wrapped; and
	// ctx's own error where it ends, which stops it asking.
	Wait func(ctx context.Context) (Keys, error)
}

DeviceSignIn is a device sign-in under way: the link and code the person approves it with in a browser, and when the code expires. They're the cloud's answer to the process that started it, which alone shows them (spec 5.5.3, 5.5.8).

type Identity

type Identity struct {
	Credentials Credentials
	Account     account.ID
	// ARN is the principal the credentials act as.
	ARN ARN
	// PermissionSet is the Identity Center permission set whose role the
	// credentials act as, empty where they act as no such role.
	PermissionSet string
	// SignedInUntil is when the Identity Center sign-in behind the
	// credentials ends, zero where that can't be known: for credentials of
	// no sign-in, and for a sign-in that renews its own access token.
	SignedInUntil time.Time
	// Fingerprint is what the credentials resolve to, link by link, the
	// region the check simulates in, and the sign-ins cached beside them,
	// by what survives a renewal. It changes when the profile is edited,
	// another user signs in to its own sign-in, a sign-in is cached, or one
	// that can't renew itself ends, so an answer kept for one is never
	// given for another. A sign-in that renews itself, once its session has
	// ended or someone signs in again to the same file, doesn't change it:
	// that is seen once the day's answer ages out.
	Fingerprint string
}

Identity is whose credentials a question was asked with.

func (Identity) CheckAccount

func (id Identity) CheckAccount(u unit.Path, expected account.ID) error

CheckAccount is nil where the identity is in the account u expects, and an *AccountMismatchError naming u where it isn't.

type IdentityCenter

type IdentityCenter struct {
	// Profile is the profile that holds the setup, the one to sign in with.
	Profile config.ProfileName
	// Session is the sso_session it signs in with, empty in the legacy
	// form, which names its start URL itself.
	Session   string
	StartURL  string
	Region    Region
	AccountID account.ID
	// RoleName is the permission set it takes.
	RoleName string
}

IdentityCenter is an Identity Center setup. A field the profile leaves out is empty.

func (*IdentityCenter) Complete

func (ic *IdentityCenter) Complete() bool

Complete reports whether ic names all a sign-in needs: its start URL, region, account and permission set.

type Keys

type Keys struct {
	// contains filtered or unexported fields
}

Keys are a role's temporary credentials, held in memory alone: the delete sign-in's, as a device sign-in takes them (spec 5.5.2). Every part is a Secret, so Keys never print.

func NewKeys

func NewKeys(id, secret, token string, expires time.Time) Keys

NewKeys are the keys id, secret and session token, which stop working at expires.

func (Keys) Complete

func (k Keys) Complete() bool

Complete reports whether k holds a key, its secret and a session token.

func (Keys) Expires

func (k Keys) Expires() time.Time

Expires is when the keys stop working.

func (Keys) Format

func (Keys) Format(f fmt.State, _ rune)

Format prints k redacted, whatever the verb.

func (Keys) GoString

func (Keys) GoString() string

GoString is k redacted, as %#v prints it.

func (Keys) Live

func (k Keys) Live(now time.Time) bool

Live reports whether k still work at now.

func (Keys) LogValue

func (Keys) LogValue() slog.Value

LogValue is k redacted, as a log prints it.

func (Keys) Reveal

func (k Keys) Reveal() (id, secret, token string)

Reveal is the keys themselves, for the one call that hands them on: the access key's ID, its secret and the session token.

func (Keys) String

func (Keys) String() string

String is k redacted.

type Profile

type Profile struct {
	Name config.ProfileName
	// Region is the profile's region, empty where it names none.
	Region Region
	// RoleARN is the role the profile assumes on top of its credentials,
	// empty where it assumes none.
	RoleARN ARN
	// IdentityCenter is the Identity Center sign-in the profile's
	// credentials come from: its own, or that of the profile at the root of
	// its source_profile chain. It's nil where they come from none, as for
	// a profile whose static keys win over its Identity Center settings.
	IdentityCenter *IdentityCenter
}

Profile is what the AWS config says of a named profile.

func (Profile) LoginCommand

func (p Profile) LoginCommand() string

LoginCommand is the command that signs the profile in, empty where its credentials come from no sign-in terrace knows, or from a setup too incomplete for signing in to help.

func (Profile) OwnSignIn

func (p Profile) OwnSignIn() (*IdentityCenter, bool)

OwnSignIn is the Identity Center sign-in p signs in with itself, whole, with no role assumed on top, and whether it has one: the only kind of profile a delete sign-in can be, since its device sign-in's keys are the permission set's own (5.5.1). A profile that assumes a role, or signs in through another's, has none.

type Region

type Region string

Region is a cloud region, such as eu-west-2.

type Secret

type Secret struct {
	// contains filtered or unexported fields
}

Secret is a value that never prints: a key or a token. The value sits behind a pointer, which fmt prints as an address wherever it can't call Format, as inside an unexported field of a struct printed with %+v.

func NewSecret

func NewSecret(s string) Secret

NewSecret is s, kept secret.

func (Secret) Format

func (Secret) Format(f fmt.State, _ rune)

Format prints s redacted, whatever the verb.

func (Secret) GoString

func (Secret) GoString() string

GoString is s redacted, as %#v prints it.

func (Secret) LogValue

func (Secret) LogValue() slog.Value

LogValue is s redacted, as a log prints it.

func (Secret) Present

func (s Secret) Present() bool

Present reports whether s holds a value.

func (Secret) Reveal

func (s Secret) Reveal() string

Reveal is the value itself, for the one call that sends it on.

func (Secret) String

func (Secret) String() string

String is s redacted.

func (*Secret) UnmarshalJSON

func (s *Secret) UnmarshalJSON(data []byte) error

UnmarshalJSON reads a JSON string into s.

type SignedOutError

type SignedOutError struct {
	Credentials Credentials
	// Login is the command that signs the profile in, given only where
	// signing in helps: a sign-in missing, expired or no longer accepted.
	Login string
	// ExpiredAt is when an expired sign-in ended, zero where that isn't
	// known.
	ExpiredAt time.Time
	Err       error
}

SignedOutError is credentials that don't work.

func (*SignedOutError) Error

func (e *SignedOutError) Error() string

func (*SignedOutError) Kind

func (e *SignedOutError) Kind() errkind.Kind

Kind is errkind.KindSignedOut.

func (*SignedOutError) Unwrap

func (e *SignedOutError) Unwrap() error

type Unchecked

type Unchecked struct {
	Reason UncheckedReason
	Detail string
}

Unchecked is why the write-access check couldn't tell, and what about: the action denied, the context keys missing, the permission set with no role, the principal, or the sign-in.

type UncheckedReason

type UncheckedReason string

UncheckedReason is why the write-access check couldn't tell. It's stored, so each value is its stored form; the empty string is a check that told.

const (
	// UncheckedDenied is a question AWS refused terrace: an action denied,
	// or any other error AWS answered with, its code named.
	UncheckedDenied UncheckedReason = "denied"
	// UncheckedMissingContext is a policy whose answer turns on context the
	// simulator wasn't given.
	UncheckedMissingContext UncheckedReason = "missing_context"
	// UncheckedNoRole is a permission set with no role in the account.
	UncheckedNoRole UncheckedReason = "no_role"
	// UncheckedPrincipal is a principal terrace couldn't find or the
	// simulator can't be asked about, or no principal at all.
	UncheckedPrincipal UncheckedReason = "principal"
	// UncheckedSignIn is a cached Identity Center sign-in terrace can't
	// read, renew into its file or list in full, one that names no region,
	// the folder of them unreadable, or a permission set's role whose
	// sign-in it can't find.
	UncheckedSignIn UncheckedReason = "sign_in"
)

The reasons.

func (UncheckedReason) Known

func (r UncheckedReason) Known() bool

Known reports whether r is one of the reasons, or the empty string.

type WriteAccess

type WriteAccess struct {
	Account     account.ID
	Credentials Credentials
	CanDelete   CanDelete
	// Unchecked is why CanDelete is unknown, zero otherwise.
	Unchecked Unchecked
	// Deleters are what can delete, by name, where CanDelete is yes:
	// permission sets of an Identity Center sign-in, else the principal's
	// role or user.
	Deleters []string
	// CheckedAt is when the cloud was asked.
	CheckedAt time.Time
}

WriteAccess is the write-access check's answer for an account.

type WriteAccessQuery

type WriteAccessQuery struct {
	Account account.ID
	// Credentials are the everyday credentials that reach Account. Every
	// permission set a cached Identity Center sign-in reaches in Account
	// counts too (spec 5.7.4).
	Credentials Credentials
	// Identity is whose Credentials are, where the asker has just asked,
	// so Daily keeps its answer by it rather than ask again (spec 6.3.4);
	// nil, or another credentials', Daily asks.
	Identity *Identity
}

WriteAccessQuery asks whether the everyday credentials can delete in an account.

Directories

Path Synopsis
Package awscloud is the cloud as AWS answers it, the release build's driver of cloud.Cloud.
Package awscloud is the cloud as AWS answers it, the release build's driver of cloud.Cloud.
Package cloudbuild is the cloud this build carries: AWS in the release build, and the demo world's stand-in in the demo build (go build -tags demo), so neither binary holds the other's.
Package cloudbuild is the cloud this build carries: AWS in the release build, and the demo world's stand-in in the demo build (go build -tags demo), so neither binary holds the other's.
Package cloudtest is a cloud.Cloud a test programs, which counts what it's asked.
Package cloudtest is a cloud.Cloud a test programs, which counts what it's asked.
Package democloud is the demo world's cloud, a local stand-in for AWS that never touches the network: the demo build's driver of cloud.Cloud.
Package democloud is the demo world's cloud, a local stand-in for AWS that never touches the network: the demo build's driver of cloud.Cloud.

Jump to

Keyboard shortcuts

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