aws

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package aws implements the AWS credential provider for moat.

Unlike other providers that inject credentials via proxy headers, AWS uses a credential endpoint pattern. The provider exposes an HTTP endpoint that returns temporary credentials from STS AssumeRole in ECS container format.

The container is configured with AWS_CONTAINER_CREDENTIALS_FULL_URI pointing to the proxy's credential endpoint, allowing AWS SDKs to automatically fetch credentials when needed.

Grant flow:

  1. User provides IAM role ARN via `moat grant aws`
  2. ARN is validated and tested with STS AssumeRole
  3. Role ARN stored in Credential.Token, region/duration in Metadata

Runtime flow:

  1. Container makes AWS API call
  2. AWS SDK detects AWS_CONTAINER_CREDENTIALS_FULL_URI
  3. SDK fetches credentials from proxy endpoint
  4. Proxy calls STS AssumeRole and returns temporary credentials
  5. SDK uses credentials for the API call

Index

Constants

View Source
const (
	MetaKeyRegion          = "region"
	MetaKeySessionDuration = "session_duration"
	MetaKeyExternalID      = "external_id"
)

Metadata keys for AWS credentials.

View Source
const (
	DefaultRegion          = "us-east-1"
	DefaultSessionDuration = 15 * time.Minute
)

Default values.

View Source
const CredentialHelperScript = `` /* 322-byte string literal not displayed */

CredentialHelperScript is a shell script that fetches AWS credentials from the AgentOps proxy. It implements the AWS credential_process interface.

This requires curl, which is always installed as a base package in containers built with the dependency system (see internal/deps/dockerfile.go). Since --grant aws requires the aws dependency for the AWS CLI, curl is guaranteed to be present in any container using AWS credentials.

Variables

This section is empty.

Functions

func ConfigToJSON

func ConfigToJSON(cfg *Config) (string, error)

ConfigToJSON serializes Config to JSON for storage.

func GetCredentialHelper

func GetCredentialHelper() []byte

GetCredentialHelper returns the credential helper script as bytes.

func WithGrantOptions

func WithGrantOptions(ctx context.Context, role, region, sessionDuration, externalID string) context.Context

WithGrantOptions returns a context with AWS grant options set. These options are used by Grant() instead of prompting interactively.

Types

type Config

type Config struct {
	RoleARN         string
	Region          string
	SessionDuration time.Duration
	ExternalID      string
}

Config holds AWS IAM role configuration.

func ConfigFromCredential

func ConfigFromCredential(cred *provider.Credential) (*Config, error)

ConfigFromCredential extracts Config from a stored credential. Supports both new format (Metadata) and legacy format (Scopes) for backwards compatibility.

func ParseRoleARN

func ParseRoleARN(arn string) (*Config, error)

ParseRoleARN validates an IAM role ARN and returns a Config. ARN format: arn:PARTITION:iam::ACCOUNT_ID:role/ROLE_NAME Supported partitions: aws, aws-cn, aws-us-gov

type Credentials

type Credentials struct {
	AccessKeyID     string
	SecretAccessKey string
	SessionToken    string
	Expiration      time.Time
}

Credentials holds temporary AWS credentials.

type EndpointHandler

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

EndpointHandler serves AWS credentials via HTTP in ECS container format.

func NewEndpointHandler

func NewEndpointHandler(cred *provider.Credential) *EndpointHandler

NewEndpointHandler creates a new AWS credential endpoint handler.

func (*EndpointHandler) Region

func (h *EndpointHandler) Region() string

Region returns the configured AWS region.

func (*EndpointHandler) RoleARN

func (h *EndpointHandler) RoleARN() string

RoleARN returns the configured IAM role ARN.

func (*EndpointHandler) ServeHTTP

func (h *EndpointHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler, returning credentials in credential_process format.

func (*EndpointHandler) SetAuthToken

func (h *EndpointHandler) SetAuthToken(token string)

SetAuthToken sets the required auth token for the credential endpoint.

func (*EndpointHandler) SetSTSClient

func (h *EndpointHandler) SetSTSClient(client STSAssumeRoler)

SetSTSClient sets a custom STS client (for testing).

type Provider

type Provider struct{}

Provider implements provider.CredentialProvider and provider.EndpointProvider for AWS credentials via STS AssumeRole.

func New

func New() *Provider

New creates a new AWS provider.

func (*Provider) Cleanup

func (p *Provider) Cleanup(cleanupPath string)

Cleanup is a no-op for AWS.

func (*Provider) ConfigureProxy

func (p *Provider) ConfigureProxy(pc provider.ProxyConfigurer, cred *provider.Credential)

ConfigureProxy is a no-op for AWS since it uses the endpoint pattern. AWS credentials are served via RegisterEndpoints, not header injection.

func (*Provider) ContainerEnv

func (p *Provider) ContainerEnv(cred *provider.Credential) []string

ContainerEnv returns nil; the run manager sets AWS_CONTAINER_CREDENTIALS_FULL_URI.

func (*Provider) ContainerMounts

func (p *Provider) ContainerMounts(cred *provider.Credential, containerHome string) ([]provider.MountConfig, string, error)

ContainerMounts returns nil; AWS doesn't require any mounts.

func (*Provider) Grant

func (p *Provider) Grant(ctx context.Context) (*provider.Credential, error)

Grant acquires AWS credentials by prompting for an IAM role ARN.

func (*Provider) ImpliedDependencies

func (p *Provider) ImpliedDependencies() []string

ImpliedDependencies returns dependencies implied by AWS grant.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the provider identifier.

func (*Provider) RegisterEndpoints

func (p *Provider) RegisterEndpoints(mux *http.ServeMux, cred *provider.Credential)

RegisterEndpoints registers the AWS credential endpoint handler. The handler serves temporary credentials from STS AssumeRole.

type STSAssumeRoler

type STSAssumeRoler interface {
	AssumeRole(ctx context.Context, params *sts.AssumeRoleInput, optFns ...func(*sts.Options)) (*sts.AssumeRoleOutput, error)
}

STSAssumeRoler interface for STS AssumeRole operation (enables testing).

Jump to

Keyboard shortcuts

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