Documentation
¶
Overview ¶
Package awsrole assumes AWS roles for writ serve's runs and hands the credentials to providers. Each run gets temporary credentials from STS, with a role session name and a source identity that name who asked, so CloudTrail shows them. Providers fetch the credentials from a loopback endpoint that speaks the AWS SDKs' container credentials protocol, with a token for each run, so the endpoint can assume the role again before the credentials expire and refuse the token once the run ends.
Index ¶
- Constants
- func AccountOf(role string) string
- func CheckRoleARN(s string) error
- func SessionName(name, run string) string
- func SourceIdentity(s string) string
- type AssumedSession
- type Assumer
- type Broker
- type BrokerOptions
- type Credentials
- type DeniedError
- type Keeper
- type Run
- type STS
- type STSOptions
- type Session
Constants ¶
const ( MinDuration = 15 * time.Minute MaxDuration = 12 * time.Hour )
Bounds AWS sets on a session.
const CredentialsPath = "/v1/credentials"
CredentialsPath is the endpoint's path.
const ( // DefaultRefreshBefore is how long before credentials expire the // broker assumes the role again. The AWS SDKs fetch again within a few // minutes of expiry. DefaultRefreshBefore = 15 * time.Minute )
Defaults of BrokerOptions.
Variables ¶
This section is empty.
Functions ¶
func CheckRoleARN ¶
CheckRoleARN reports whether s is an IAM role's ARN.
func SessionName ¶
SessionName is writ-NAME-RUN, with characters STS refuses replaced by "-". STS allows 64 characters, so a long NAME is cut to fit and RUN is kept whole.
func SourceIdentity ¶
SourceIdentity is s with characters STS refuses replaced by "-", cut to 64 characters.
Types ¶
type AssumedSession ¶
AssumedSession is a role session the control plane assumed. From is when its first credentials were issued, and Until when its last ones expire.
type Assumer ¶
type Assumer interface {
Assume(ctx context.Context, s Session) (Credentials, error)
}
Assumer assumes roles. *STS is one.
type Broker ¶
type Broker struct {
// contains filtered or unexported fields
}
Broker serves each run's credentials on a loopback HTTP endpoint, as the AWS SDKs' container credentials provider reads them: a GET with the run's token in the Authorization header.
func NewBroker ¶
func NewBroker(o BrokerOptions) (*Broker, error)
NewBroker listens on a free loopback port and serves until Close.
func (*Broker) Handler ¶ added in v0.1.6
Handler serves the endpoint as its listener does, with the same tokens, for a run that reaches it on a listener of its own, as one in its own network namespace does.
type BrokerOptions ¶
type BrokerOptions struct {
Assumer Assumer
RefreshBefore time.Duration
Now func() time.Time
Log *slog.Logger
// Assumed is told of each session the broker assumes, before its
// credentials are served. When it fails at a run's start the run does
// not start; when it fails at a refresh the credentials are served
// anyway.
Assumed func(ctx context.Context, s AssumedSession) error
}
BrokerOptions configures NewBroker.
type Credentials ¶
type Credentials struct {
AccessKeyID string
SecretAccessKey string
SessionToken string
Expires time.Time
}
Credentials are temporary credentials from STS.
type DeniedError ¶
DeniedError is STS refusing to assume a role.
func (*DeniedError) Error ¶
func (e *DeniedError) Error() string
func (*DeniedError) Unwrap ¶
func (e *DeniedError) Unwrap() error
type Keeper ¶
type Keeper struct {
// contains filtered or unexported fields
}
Keeper holds the credentials of one session, such as the one the change watcher reads its queue with or one run's. It assumes the role again when the credentials have less than RefreshBefore left. When a refresh fails it keeps serving the old credentials while they have a minute left.
type Run ¶
type Run struct {
// contains filtered or unexported fields
}
Run is one run's credentials and its token.
func (*Run) Env ¶
Env is what a provider needs to fetch the run's credentials. The AWS SDKs read these two variables.
func (*Run) Secrets ¶ added in v0.1.4
Secrets are the secret access key and session token of every credentials the broker assumed for the run, so far: a provider can echo them in its output, and ending the run's token does not revoke them. The access key id is left out, as it names the session and is no secret.
type STS ¶
type STS struct {
// contains filtered or unexported fields
}
STS assumes roles through the AWS SDK as the control plane's own identity: the SDK's default chain of environment, shared files, and the instance's role.
type STSOptions ¶
type STSOptions struct {
Region string
// Endpoint replaces the regional STS endpoint, for an interface VPC
// endpoint or a test. "" uses the SDK's.
Endpoint string
}
STSOptions configures NewSTS.
type Session ¶
type Session struct {
Role string // the role's ARN
// Name is the role session name, which CloudTrail shows with each
// call the session makes.
Name string
// SourceIdentity names the principal behind the session. AWS keeps it
// on every session chained from this one.
SourceIdentity string
Duration time.Duration
}
Session is one AssumeRole request.