Documentation
¶
Overview ¶
Package cloudconn holds named cloud account connections (preview). It stores non-secret settings and a credential reference only, and probes health through a read-only provider interface. No provider here creates or changes cloud resources.
Index ¶
- Constants
- Variables
- func CapabilityForAction(action string) (string, bool)
- func CloudFormationTemplate(in TemplateInput) (string, error)
- func NormalizeNamePrefix(s string) string
- func OracleReloginCommand(profile string) string
- func OracleSessionExpiry(token string) (time.Time, error)
- func OracleSessionNeedsRelogin(exp, now time.Time) bool
- func PolicyJSON(names []string, opt PolicyOptions) (string, error)
- func PolicyStatements(compartment, group string) ([]string, error)
- func QuickCreateURL(in TemplateInput, templateURL, stackName, region string) (string, error)
- func SSONeedsRelogin(raw []byte, now time.Time) bool
- func SealOracleSecret(ctx context.Context, s SealedSetter, namespace, key string, sec OracleSecret) (string, error)
- func SetOracleSessionMinSeconds(n int)
- func SetSSOSettings(fn func() SSOSettings)
- func TerraformSnippet(in TemplateInput) (string, error)
- func ValidateOracle(c OracleCredential) error
- func ValidateOracleSession(c OracleCredential, now time.Time) (time.Time, error)
- func ValidateSSOStart(startURL, region string) error
- func WithOracleCredential(base, mountDir string, c OracleCredential, fn func(*OracleCredFiles) error) (err error)
- type AWSIdentity
- type AWSKeys
- type AWSOptions
- type AWSProvider
- func (p *AWSProvider) Check(ctx context.Context, t Target) (string, error)
- func (p *AWSProvider) Identity(ctx context.Context, t Target) (AWSIdentity, string, error)
- func (p *AWSProvider) ListRegions(ctx context.Context, t Target) ([]string, error)
- func (*AWSProvider) Name() string
- func (p *AWSProvider) ProbeCapabilities(ctx context.Context, t Target, names ...string) ([]CapabilityResult, error)
- func (p *AWSProvider) ProbeVault(ctx context.Context, t Target) (string, error)
- func (p *AWSProvider) RevokeVault(ctx context.Context, t Target) error
- func (p *AWSProvider) SSOBroker() *SSOBroker
- func (p *AWSProvider) SSOKeys(ctx context.Context, t Target) (AWSKeys, string, error)
- func (*AWSProvider) ValidateConfig(cfg Config, authMethod string) error
- func (p *AWSProvider) VaultKeys(ctx context.Context, t Target) (vault.AWSCredentials, string, error)
- type CapCondition
- type CapStatement
- type Capability
- type CapabilityResult
- type Config
- type Connection
- type EC2API
- type Fake
- type HealthChecker
- type Input
- type OracleCredFiles
- type OracleCredential
- type OracleHTTPChecker
- type OraclePolicyKit
- type OraclePolicyKitInput
- type OracleProber
- type OracleProvider
- type OracleSecret
- type OracleStored
- type PolicyDocument
- type PolicyOptions
- type PolicySimulator
- type PolicyStatement
- type Provider
- type Registry
- type Rows
- type SSOAccount
- type SSOBroker
- type SSOBundle
- type SSOClient
- func (c *SSOClient) DeviceToken(ctx context.Context, region string, b SSOBundle, deviceCode string, ...) (SSOBundle, error)
- func (c *SSOClient) ListAccounts(ctx context.Context, region, token string, limit int) ([]SSOAccount, error)
- func (c *SSOClient) ListRoles(ctx context.Context, region, token, accountID string) ([]string, error)
- func (c *SSOClient) Refresh(ctx context.Context, region string, b SSOBundle, now time.Time) (SSOBundle, error)
- func (c *SSOClient) Register(ctx context.Context, region, startURL, clientName string) (SSOBundle, error)
- func (c *SSOClient) RoleCredentials(ctx context.Context, region, token, accountID, role string) (AWSKeys, error)
- func (c *SSOClient) StartDevice(ctx context.Context, region, startURL string, b SSOBundle) (SSODevice, error)
- type SSODevice
- type SSOHTTPError
- type SSOSettings
- type STSAPI
- type SealedReader
- type SealedSetter
- type Service
- func (s *Service) Create(ctx context.Context, actor, name string, in Input) (Connection, error)
- func (s *Service) Delete(ctx context.Context, name string) error
- func (s *Service) Get(ctx context.Context, name string) (Connection, error)
- func (s *Service) List(ctx context.Context) ([]Connection, error)
- func (s *Service) Test(ctx context.Context, name string) (TestResult, error)
- func (s *Service) Update(ctx context.Context, name string, in Input) (Connection, error)
- type TagMode
- type Target
- type TemplateInput
- type TestResult
- type VaultKit
- type VaultKitInput
Constants ¶
const ( CapInventory = "inventory" CapDeploy = "deploy" CapCost = "cost" CapS3 = "s3" CapDNS = "dns" CapDestructive = "destructive" )
Capability names a user can grant to a linked AWS account.
const ( ProbeSimulate = "simulate" ProbeDryRun = "dry_run" ProbeNone = "none" )
Probe methods.
const ( OracleConfigFileName = "config" OracleKeyFileName = "oci_api_key.pem" //nolint:gosec // a file name, not a credential )
File names inside a materialized OCI credential directory.
const ( OracleCapCompute = "compute" OracleCapUsage = "usage" OracleCapBudgets = "budgets" // OracleCapNetwork is the virtual-network read that resolves instance addresses. OracleCapNetwork = "network" )
Oracle capability names, one per read the account needs.
const ( ProviderOracle = "oracle" ProviderAWS = "aws" ProviderAzure = "azure" ProviderGCP = "gcp" ProviderHetzner = "hetzner" ProviderDigitalOcean = "digitalocean" AuthOIDCFederation = "oidc_federation" AuthRoleAssumption = "role_assumption" AuthSecretRef = "secret_ref" AuthStatic = "static" AuthVaultAWS = "vault_aws" AuthOAuth = "oauth" AuthAWSSSO = "aws_sso" )
Providers and auth methods accepted on a connection.
const ( ClassOK = "ok" ClassUnsupported = "unsupported" ClassConfigInvalid = "config_invalid" ClassCredentialUnresolved = "credential_unresolved" //nolint:gosec // class name, not a credential ClassAuthFailed = "auth_failed" ClassUnreachable = "unreachable" ClassUnknown = "unknown" )
Health classes. A check reports one of these and nothing from the provider's own output.
const AuthOCISession = "oci_session"
AuthOCISession is the browser login (oci session authenticate) method. It lives here so the shared constant block stays untouched.
const ClassNeedsRelogin = "needs_relogin"
ClassNeedsRelogin is reported when the session token is expired or about to be.
const DefaultNamePrefix = "levelrail"
DefaultNamePrefix is the secret and parameter name prefix when the setting is unset or invalid.
const VaultPolicyName = "levelrail-aws"
VaultPolicyName is the Vault policy that lets Levelrail read creds and revoke its own leases.
Variables ¶
var ( // ErrSSONeedsRelogin means the refresh path is gone; a person must sign in again. ErrSSONeedsRelogin = errors.New("cloudconn: aws sso session ended, sign in again") // ErrSSOPending is the normal device flow answer while the person has not approved yet. ErrSSOPending = errors.New("cloudconn: aws sso authorization pending") // ErrSSOSlowDown asks the caller to poll less often. ErrSSOSlowDown = errors.New("cloudconn: aws sso slow down") // ErrSSODenied covers an expired or refused device code. ErrSSODenied = errors.New("cloudconn: aws sso authorization ended") )
var ( ErrInvalid = errors.New("cloudconn: invalid connection") ErrConflict = errors.New("cloudconn: connection name already in use") ErrNotFound = errors.New("cloudconn: connection not found") )
Errors the API maps to status codes.
var ErrSessionExpired = errors.New("cloudconn: oracle session expired")
ErrSessionExpired marks a session token past its exp or inside the relogin window.
var ErrUnsupported = errors.New("cloudconn: not implemented for this provider")
ErrUnsupported marks a provider operation this build does not implement.
Functions ¶
func CapabilityForAction ¶
CapabilityForAction names the tier whose statements grant an IAM action, so a doctor can tell the owner which tier to add instead of printing a bare action.
func CloudFormationTemplate ¶
func CloudFormationTemplate(in TemplateInput) (string, error)
CloudFormationTemplate returns the YAML that creates the cross-account role: ExternalId trust, the chosen capability tiers, tag and region conditions, and a permission boundary.
func NormalizeNamePrefix ¶
NormalizeNamePrefix trims slashes and falls back to the default for empty or unsafe values.
func OracleReloginCommand ¶
OracleReloginCommand is the exact command that mints a fresh session.
func OracleSessionExpiry ¶
OracleSessionExpiry reads exp from the token's JWT payload without verifying it: the server only needs the clock, OCI does the real verification.
func OracleSessionNeedsRelogin ¶
OracleSessionNeedsRelogin is true when exp has passed or is closer than the window.
func PolicyJSON ¶
func PolicyJSON(names []string, opt PolicyOptions) (string, error)
PolicyJSON renders the plain JSON policy for the named capabilities.
func PolicyStatements ¶
PolicyStatements returns the least privilege OCI IAM policy the user applies themselves. Every statement is scoped to one compartment; Levelrail never creates IAM.
func QuickCreateURL ¶
func QuickCreateURL(in TemplateInput, templateURL, stackName, region string) (string, error)
QuickCreateURL builds the CloudFormation quick-create link. The template must already be hosted as an S3 object, the only source CloudFormation accepts for templateURL.
func SSONeedsRelogin ¶
SSONeedsRelogin reports from the sealed bundle alone whether a person must sign in again.
func SealOracleSecret ¶
func SealOracleSecret(ctx context.Context, s SealedSetter, namespace, key string, sec OracleSecret) (string, error)
SealOracleSecret validates the secret, stores it sealed and returns the NAMESPACE/KEY reference a connection keeps. The key never reaches the connection row.
func SetOracleSessionMinSeconds ¶
func SetOracleSessionMinSeconds(n int)
SetOracleSessionMinSeconds records the relogin window in seconds.
func SetSSOSettings ¶
func SetSSOSettings(fn func() SSOSettings)
SetSSOSettings registers the live source, read again on every call so a change applies at once.
func TerraformSnippet ¶
func TerraformSnippet(in TemplateInput) (string, error)
TerraformSnippet returns the same role, boundary and policy as HCL.
func ValidateOracle ¶
func ValidateOracle(c OracleCredential) error
ValidateOracle checks every field offline: OCID shapes, region, fingerprint and the key.
func ValidateOracleSession ¶
ValidateOracleSession checks a session credential offline: settings, the key and the JWT shape.
func ValidateSSOStart ¶
ValidateSSOStart checks the inputs of a login before any call leaves the host.
func WithOracleCredential ¶
func WithOracleCredential(base, mountDir string, c OracleCredential, fn func(*OracleCredFiles) error) (err error)
WithOracleCredential materializes the credential for fn and always removes it afterwards.
Types ¶
type AWSIdentity ¶
AWSIdentity is what GetCallerIdentity returns for the resolved credential.
type AWSKeys ¶
type AWSKeys struct {
AccessKeyID string
SecretAccessKey string
SessionToken string
Expires time.Time
}
AWSKeys is a short lived key set from the portal.
type AWSOptions ¶
type AWSOptions struct {
// BaseEndpoint redirects every service call, for tests and private endpoints.
BaseEndpoint string
HTTPClient aws.HTTPClient
// PlatformCreds replaces the ambient chain as the identity that assumes customer roles.
PlatformCreds aws.CredentialsProvider
// RegionAllowlist returns the regions a connection may use; empty means all enabled regions.
RegionAllowlist func(Connection) []string
NewSTS func(aws.Config) STSAPI
NewEC2 func(aws.Config) EC2API
NewSimulator func(aws.Config) PolicySimulator
// VaultBroker overrides the shared lease cache used by vault_aws, for tests.
VaultBroker *vault.AWSBroker
// SSO overrides the shared aws_sso credential cache, for tests.
SSO *SSOBroker
}
AWSOptions wires the provider. Every field is optional; the zero value uses the real SDK.
type AWSProvider ¶
type AWSProvider struct {
// contains filtered or unexported fields
}
AWSProvider is the read-only AWS side: identity, regions and capability probes.
func NewAWSProvider ¶
func NewAWSProvider(opts AWSOptions) *AWSProvider
NewAWSProvider builds the provider; pass the zero AWSOptions for production.
func (*AWSProvider) Check ¶
Check calls GetCallerIdentity and, when the connection names an account, confirms it matches.
func (*AWSProvider) Identity ¶
func (p *AWSProvider) Identity(ctx context.Context, t Target) (AWSIdentity, string, error)
Identity runs sts:GetCallerIdentity and returns the account and ARN the credential resolves to.
func (*AWSProvider) ListRegions ¶
ListRegions returns the regions enabled for the account, narrowed by the region allowlist.
func (*AWSProvider) ProbeCapabilities ¶
func (p *AWSProvider) ProbeCapabilities(ctx context.Context, t Target, names ...string) ([]CapabilityResult, error)
ProbeCapabilities checks which capabilities the credential really has. It prefers iam:SimulatePrincipalPolicy and falls back to EC2 DryRun calls; a capability with no probe is reported unverified. Nothing is created or changed in the account.
func (*AWSProvider) ProbeVault ¶
ProbeVault checks Vault is reachable and the role exists; the class never carries Vault's own text.
func (*AWSProvider) RevokeVault ¶
func (p *AWSProvider) RevokeVault(ctx context.Context, t Target) error
RevokeVault ends the account's leases at Vault and clears the cache; call it on delete or disable.
func (*AWSProvider) SSOBroker ¶
func (p *AWSProvider) SSOBroker() *SSOBroker
SSOBroker returns the broker this provider uses.
func (*AWSProvider) SSOKeys ¶
SSOKeys returns role keys for an aws_sso target, for callers that need raw keys.
func (*AWSProvider) ValidateConfig ¶
func (*AWSProvider) ValidateConfig(cfg Config, authMethod string) error
ValidateConfig checks shapes only. oidc_federation means the ambient chain (env, shared config, instance profile); static keys are refused unless the operator opted in.
func (*AWSProvider) VaultKeys ¶
func (p *AWSProvider) VaultKeys(ctx context.Context, t Target) (vault.AWSCredentials, string, error)
VaultKeys returns the leased key set for a vault_aws target, for callers that need raw keys.
type CapCondition ¶
CapCondition is one extra IAM condition operator, key and values.
type CapStatement ¶
type CapStatement struct {
Actions []string
Resources []string
Tag TagMode
Global bool
Conditions []CapCondition
}
CapStatement is one allow statement of a capability. Resources may use the {bucket_prefix} and {self_role} tokens; Global statements skip the region condition (IAM, S3, Route 53, Cost Explorer).
type Capability ¶
type Capability struct {
Name string
Summary string
Mutating bool
Always bool
Hint string
DryRun string
Statements []CapStatement
}
Capability is one grantable tier. DryRun names an EC2 DryRun probe usable when iam:SimulatePrincipalPolicy is not allowed.
func AWSCapabilities ¶
func AWSCapabilities() []Capability
AWSCapabilities returns the registry, always-on entries excluded.
func ResolveCapabilities ¶
func ResolveCapabilities(names []string) ([]Capability, error)
ResolveCapabilities validates names against the registry and returns them in registry order, always-on entries first. An empty list selects every tier.
func (Capability) ActionList ¶
func (c Capability) ActionList() []string
ActionList returns every IAM action of the capability, sorted and unique.
type CapabilityResult ¶
type CapabilityResult struct {
Name string `json:"name"`
OK bool `json:"ok"`
Verified bool `json:"verified"`
Method string `json:"method"`
Missing []string `json:"missing,omitempty"`
Hint string `json:"hint,omitempty"`
}
CapabilityResult is one row of the verify connection report.
type Config ¶
type Config struct {
Region string `json:"region,omitempty"`
AccountID string `json:"account_id,omitempty"` // AWS account, OCI tenancy OCID, GCP project
Compartment string `json:"compartment,omitempty"`
RoleARN string `json:"role_arn,omitempty"`
SubscriptionID string `json:"subscription_id,omitempty"`
ResourceGroup string `json:"resource_group,omitempty"`
OIDCAudience string `json:"oidc_audience,omitempty"`
// Vault fields apply to the vault_aws method. The token comes from VaultTokenRef, a secret:// reference.
VaultAddress string `json:"vault_address,omitempty"`
VaultMount string `json:"vault_mount,omitempty"`
VaultRole string `json:"vault_role,omitempty"`
VaultNamespace string `json:"vault_namespace,omitempty"`
VaultTokenRef string `json:"vault_token_ref,omitempty"`
// SSO fields apply to aws_sso; tokens live only in the sealed bundle.
StartURL string `json:"start_url,omitempty"`
SSORegion string `json:"sso_region,omitempty"`
RoleName string `json:"role_name,omitempty"`
}
Config holds the non-secret settings; which fields apply depends on the provider.
type Connection ¶
type Connection struct {
Name string
Provider string
TeamID string
AuthMethod string
Config Config
CredentialRef string
CreatedBy string
CreatedAt time.Time
UpdatedAt time.Time
LastCheckedAt time.Time
LastCheckClass string
}
Connection is one named cloud account. It never carries a credential value.
type EC2API ¶
type EC2API interface {
DescribeRegions(ctx context.Context, in *ec2.DescribeRegionsInput, optFns ...func(*ec2.Options)) (*ec2.DescribeRegionsOutput, error)
DescribeInstances(ctx context.Context, in *ec2.DescribeInstancesInput, optFns ...func(*ec2.Options)) (*ec2.DescribeInstancesOutput, error)
CreateSecurityGroup(ctx context.Context, in *ec2.CreateSecurityGroupInput, optFns ...func(*ec2.Options)) (*ec2.CreateSecurityGroupOutput, error)
}
EC2API is the slice of the EC2 client this package uses.
type Fake ¶
type Fake struct {
ProviderName string
Class string
Err error
Regions []string
Checked []string
CredLen []int
// contains filtered or unexported fields
}
Fake is an in-memory provider for tests: it validates like the real config rules and returns a scripted class, recording the credential length it was handed.
func (*Fake) ListRegions ¶
ListRegions returns the scripted regions.
type HealthChecker ¶
type HealthChecker interface {
Check(ctx context.Context, c OracleCredential) (string, error)
}
HealthChecker makes one read-only call with an OCI credential and returns a Class constant.
type Input ¶
type Input struct {
Provider string
TeamID string
AuthMethod string
Config Config
CredentialRef string
}
Input creates or updates a connection. On update empty strings keep the stored value and a zero Config keeps the stored settings; Provider and Name never change.
type OracleCredFiles ¶
type OracleCredFiles struct {
// contains filtered or unexported fields
}
OracleCredFiles is a materialized per-step credential. It exposes paths only.
func MaterializeOracle ¶
func MaterializeOracle(base, mountDir string, c OracleCredential) (*OracleCredFiles, error)
MaterializeOracle writes an OCI config profile and key into a fresh 0700 directory under base (a tmpfs). mountDir is where the step sees that directory, so key_file resolves there.
func (*OracleCredFiles) Close ¶
func (h *OracleCredFiles) Close() error
Close removes the directory; safe to call twice.
func (*OracleCredFiles) ConfigPath ¶
func (h *OracleCredFiles) ConfigPath() string
ConfigPath is the host path of the OCI config file.
func (*OracleCredFiles) Dir ¶
func (h *OracleCredFiles) Dir() string
Dir is the host directory holding config and key; mount it read-only into the step.
func (*OracleCredFiles) Redact ¶
func (h *OracleCredFiles) Redact(line string) string
Redact scrubs the key material, whole or line by line, from a log line.
type OracleCredential ¶
type OracleCredential struct {
TenancyOCID string
CompartmentOCID string
Region string
Secret OracleSecret
// SessionToken switches signing to the browser session scheme; Secret then holds only the session key.
SessionToken string
}
OracleCredential is everything one OCI step needs. Tenancy, region and compartment come from the connection settings; IaC documents only name the connection.
func OpenOracleSealed ¶
func OpenOracleSealed(ctx context.Context, r SealedReader, c Connection) (OracleCredential, error)
OpenOracleSealed opens the sealed bundle a static oracle connection references. The returned error never carries the bundle or the reference value.
func OracleCredentialFromStored ¶
func OracleCredentialFromStored(raw string) (OracleCredential, error)
OracleCredentialFromStored decodes the sealed account value into the credential every Oracle call here takes, so an account, a node provider secret and a connection agree.
func OracleFromTarget ¶
func OracleFromTarget(t Target) (OracleCredential, error)
OracleFromTarget joins the stored settings with the resolved sealed bundle.
type OracleHTTPChecker ¶
type OracleHTTPChecker struct {
Client *http.Client
BaseURL func(region string) string
Now func() time.Time
}
OracleHTTPChecker lists at most one instance in the compartment, which the generated compartment policy allows, so a pass proves the key and the scope together.
func NewOracleHTTPChecker ¶
func NewOracleHTTPChecker() OracleHTTPChecker
NewOracleHTTPChecker uses the public regional compute endpoint and an env bounded timeout.
func (OracleHTTPChecker) Check ¶
func (o OracleHTTPChecker) Check(ctx context.Context, c OracleCredential) (string, error)
Check signs and sends one GET. Provider output never leaves this function.
func (OracleHTTPChecker) Regions ¶
func (o OracleHTTPChecker) Regions(ctx context.Context, c OracleCredential) ([]string, error)
Regions on the checker keeps OracleProvider.ListRegions working from one account.
type OraclePolicyKit ¶
type OraclePolicyKit struct {
PolicyName string `json:"policy_name"`
Statements []string `json:"statements"`
PolicyText string `json:"policy_text"`
CLI string `json:"oci_cli"`
Notes []string `json:"notes"`
}
OraclePolicyKit is the least privilege policy text the user applies themselves.
func BuildOraclePolicyKit ¶
func BuildOraclePolicyKit(in OraclePolicyKitInput) (OraclePolicyKit, error)
BuildOraclePolicyKit renders compute in one compartment plus the two tenancy reads (usage and budgets). Levelrail never creates IAM, so this is text only.
type OraclePolicyKitInput ¶
type OraclePolicyKitInput struct {
Group string
PolicyName string
Compartment string
// Manage lets Levelrail start, stop and provision; the default is read only.
Manage bool
}
OraclePolicyKitInput names the policy parts; every name comes from the caller.
type OracleProber ¶
type OracleProber struct {
Client *http.Client
Now func() time.Time
IaaS, UsageAPI, Budgets func(region string) string
Identity func(region string) string
}
OracleProber runs one read-only call per capability with the account key. Bases are per service so tests can point each at a fake.
func NewOracleProber ¶
func NewOracleProber() OracleProber
NewOracleProber uses the public regional endpoints and the env bounded timeout.
func (OracleProber) ProbeCapabilities ¶
func (o OracleProber) ProbeCapabilities(ctx context.Context, c OracleCredential, names ...string) ([]CapabilityResult, error)
ProbeCapabilities reports per capability whether the key can list instances in the compartment, read usage and read budgets. Unknown names are an error.
func (OracleProber) Regions ¶
func (o OracleProber) Regions(ctx context.Context, c OracleCredential) ([]string, error)
Regions lists the tenancy's ready region subscriptions through the identity service.
type OracleProvider ¶
type OracleProvider struct {
Checker HealthChecker
}
OracleProvider is the read-only OCI side. It is not in DefaultRegistry; wiring it is opt-in.
func NewOracleProvider ¶
func NewOracleProvider() OracleProvider
NewOracleProvider returns a provider backed by the real signed HTTP checker.
func (OracleProvider) Check ¶
Check resolves the sealed bundle from the target and runs one read-only call.
func (OracleProvider) ListRegions ¶
ListRegions lists the regions the tenancy subscribes to. It needs the tenancy read the account policy grants, so a compartment only key gets a clear error instead of a guess.
func (OracleProvider) ValidateConfig ¶
func (OracleProvider) ValidateConfig(cfg Config, authMethod string) error
ValidateConfig applies the shared rules, then the OCI shapes.
type OracleSecret ¶
type OracleSecret struct {
UserOCID string
Fingerprint string
// contains filtered or unexported fields
}
OracleSecret is the sealed half of an OCI connection: the user, the key fingerprint and the API signing key. Every formatter masks the key.
func NewOracleSecret ¶
func NewOracleSecret(userOCID, fingerprint string, pemKey []byte) OracleSecret
NewOracleSecret copies the PEM so the caller can wipe its own buffer.
func ParseOracleSecret ¶
func ParseOracleSecret(v secretsource.Value) (OracleSecret, error)
ParseOracleSecret decodes a resolved sealed bundle. Errors never echo the input.
func (OracleSecret) GoString ¶
func (s OracleSecret) GoString() string
GoString masks the key for %#v.
func (OracleSecret) KeyPEM ¶
func (s OracleSecret) KeyPEM() []byte
KeyPEM returns a copy of the key for one upload; the caller wipes it after use.
func (OracleSecret) MarshalJSON ¶
func (s OracleSecret) MarshalJSON() ([]byte, error)
MarshalJSON keeps the key out of any API or log encoding of the struct.
type OracleStored ¶
type OracleStored struct {
TenancyOCID string `json:"tenancy_ocid"`
UserOCID string `json:"user_ocid"`
Fingerprint string `json:"fingerprint"`
PrivateKeyPEM string `json:"private_key_pem"`
Region string `json:"region"`
CompartmentOCID string `json:"compartment_ocid"`
SubnetOCID string `json:"subnet_ocid"`
SessionToken string `json:"session_token,omitempty"`
}
OracleStored is the sealed JSON an Oracle cloud account keeps. Only Go callers see the key.
type PolicyDocument ¶
type PolicyDocument struct {
Version string `json:"Version"`
Statement []PolicyStatement `json:"Statement"`
}
PolicyDocument is an IAM policy document in the shape AWS accepts.
func BoundaryPolicy ¶
func BoundaryPolicy(opt PolicyOptions) PolicyDocument
BoundaryPolicy is the permission ceiling: every capability, plus a deny on identity changes.
func RenderPolicy ¶
func RenderPolicy(names []string, opt PolicyOptions) (PolicyDocument, error)
RenderPolicy builds the permission policy for the named capabilities from the registry.
type PolicyOptions ¶
type PolicyOptions struct {
// Regions becomes an aws:RequestedRegion condition on regional statements; empty means no limit.
Regions []string
TagKey string
TagValue string
BucketPrefix string
RoleName string
// NamePrefix scopes Secrets Manager and SSM parameter names, without slashes.
NamePrefix string
// HostedZoneIDs scopes Route 53 zone statements by ARN; empty falls back to every zone.
HostedZoneIDs []string
}
PolicyOptions shapes a rendered policy. The zero value is filled from DefaultPolicyOptions.
func DefaultPolicyOptions ¶
func DefaultPolicyOptions() PolicyOptions
DefaultPolicyOptions reads the tag key and bucket prefix from env so an operator can rename them.
type PolicySimulator ¶
type PolicySimulator interface {
Simulate(ctx context.Context, req simulateRequest) (map[string]string, error)
}
PolicySimulator answers an action to decision map ("allowed", "implicitDeny", "explicitDeny").
type PolicyStatement ¶
type PolicyStatement struct {
Sid string `json:"Sid"`
Effect string `json:"Effect"`
Action []string `json:"Action"`
Resource []string `json:"Resource"`
Condition map[string]map[string][]string `json:"Condition,omitempty"`
}
PolicyStatement is one IAM statement. Condition maps operator to key to values.
type Provider ¶
type Provider interface {
Name() string
// ValidateConfig checks the non-secret settings for the given auth method.
ValidateConfig(cfg Config, authMethod string) error
// Check makes one read-only call and returns a Class constant; detail stays inside the provider.
Check(ctx context.Context, t Target) (string, error)
// ListRegions returns region identifiers the credential can see, read-only.
ListRegions(ctx context.Context, t Target) ([]string, error)
}
Provider is the read-only side of a cloud. Implementations must not create, change or delete anything in the account.
type Registry ¶
Registry maps a provider name to its implementation.
func DefaultRegistry ¶
func DefaultRegistry() Registry
DefaultRegistry registers every provider as not implemented. The real OCI, AWS and Azure clients need SDK dependencies this repo does not carry yet; adding them is an owner decision.
func FakeRegistry ¶
FakeRegistry maps every provider name to a Fake sharing one script.
type Rows ¶
type Rows interface {
ListCloudConnections(ctx context.Context) ([]store.CloudConnection, error)
GetCloudConnection(ctx context.Context, name string) (store.CloudConnection, error)
CreateCloudConnection(ctx context.Context, c store.CloudConnection) error
UpdateCloudConnection(ctx context.Context, c store.CloudConnection) error
SetCloudConnectionCheck(ctx context.Context, name, class string, at time.Time) error
DeleteCloudConnection(ctx context.Context, name string) error
}
Rows is the connection table.
type SSOAccount ¶
type SSOAccount struct {
AccountID string `json:"account_id"`
AccountName string `json:"account_name"`
Email string `json:"email,omitempty"`
}
SSOAccount and SSORole are the portal listings.
type SSOBroker ¶
type SSOBroker struct {
Client *SSOClient
// contains filtered or unexported fields
}
SSOBroker keeps role credentials per account, refreshes the access token lazily and records a needs_relogin state when the refresh path ends.
func DefaultSSOBroker ¶
func DefaultSSOBroker() *SSOBroker
DefaultSSOBroker is shared so every provider instance reuses one credential cache.
func NewSSOBroker ¶
NewSSOBroker returns a broker over the given client; nil means the production client.
func (*SSOBroker) Credentials ¶
Credentials returns role keys for the account, reading new ones only past the renewal point.
type SSOBundle ¶
type SSOBundle struct {
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"`
ClientExpiresAt int64 `json:"client_expires_at,omitempty"`
AccessToken string `json:"access_token,omitempty"`
AccessExpiresAt int64 `json:"access_expires_at,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
NeedsRelogin bool `json:"needs_relogin,omitempty"`
UpdatedAt int64 `json:"updated_at,omitempty"` // unix milliseconds, newest bundle wins
}
SSOBundle is the sealed secret of an aws_sso account: the OIDC client registration and tokens.
type SSOClient ¶
type SSOClient struct {
HTTP *http.Client
// OIDCBase and PortalBase build the endpoint per region; tests point them at a fake.
OIDCBase func(region string) string
PortalBase func(region string) string
}
SSOClient speaks plain HTTP to the SSO OIDC and portal endpoints; no SigV4 is involved.
func (*SSOClient) DeviceToken ¶
func (c *SSOClient) DeviceToken(ctx context.Context, region string, b SSOBundle, deviceCode string, now time.Time) (SSOBundle, error)
DeviceToken polls the device grant; pending and slow_down come back as sentinel errors.
func (*SSOClient) ListAccounts ¶
func (c *SSOClient) ListAccounts(ctx context.Context, region, token string, limit int) ([]SSOAccount, error)
ListAccounts pages through the accounts the signed in user may use, up to max.
func (*SSOClient) ListRoles ¶
func (c *SSOClient) ListRoles(ctx context.Context, region, token, accountID string) ([]string, error)
ListRoles returns the role names the user holds in one account.
func (*SSOClient) Refresh ¶
func (c *SSOClient) Refresh(ctx context.Context, region string, b SSOBundle, now time.Time) (SSOBundle, error)
Refresh exchanges the refresh token for a new access token.
func (*SSOClient) Register ¶
func (c *SSOClient) Register(ctx context.Context, region, startURL, clientName string) (SSOBundle, error)
Register creates the public OIDC client for one start URL; refresh needs the issuer URL.
type SSODevice ¶
type SSODevice struct {
DeviceCode string `json:"device_code"`
UserCode string `json:"user_code"`
VerificationURI string `json:"verification_uri"`
VerificationURIComplete string `json:"verification_uri_complete"`
ExpiresIn int `json:"expires_in"`
Interval int `json:"interval"`
}
SSODevice is what StartDeviceAuthorization returns for the person to approve.
type SSOHTTPError ¶
SSOHTTPError carries the status and the AWS error code, never the response text.
func (*SSOHTTPError) Error ¶
func (e *SSOHTTPError) Error() string
type SSOSettings ¶
type SSOSettings struct {
RenewPercent int
TokenSkewSeconds int
MaxAccounts int
TimeoutSeconds int
MaxResponseBytes int
}
SSOSettings are the live tunables of the aws_sso path; the API layer feeds them from runtime settings.
func DefaultSSOSettings ¶
func DefaultSSOSettings() SSOSettings
DefaultSSOSettings is what a broker uses until a settings source is registered.
func SSOCurrentSettings ¶
func SSOCurrentSettings() SSOSettings
SSOCurrentSettings returns the live values with out of range ones replaced by the defaults.
type STSAPI ¶
type STSAPI interface {
GetCallerIdentity(ctx context.Context, in *sts.GetCallerIdentityInput, optFns ...func(*sts.Options)) (*sts.GetCallerIdentityOutput, error)
AssumeRole(ctx context.Context, in *sts.AssumeRoleInput, optFns ...func(*sts.Options)) (*sts.AssumeRoleOutput, error)
}
STSAPI is the slice of the STS client this package uses, so tests can fake it.
type SealedReader ¶
SealedReader reads back a value SealOracleSecret stored; secrets.Manager satisfies it.
type SealedSetter ¶
type SealedSetter interface {
SetValue(ctx context.Context, namespace, key, plaintext string) error
}
SealedSetter stores a value sealed at rest; secrets.Manager satisfies it.
type Service ¶
type Service struct {
Rows Rows
Providers Registry
// Sources resolves secret:// references for a probe; nil means references cannot be resolved.
Sources *secretsource.Resolver
Now func() time.Time
}
Service owns the connection set and runs read-only probes.
func (*Service) List ¶
func (s *Service) List(ctx context.Context) ([]Connection, error)
List returns every connection ordered by name.
type TagMode ¶
type TagMode string
TagMode says which tag condition guards a statement.
const ( // TagNone has no tag condition: reads, and actions that cannot be tag scoped. TagNone TagMode = "" // TagResource requires the target resource to carry the managed tag. TagResource TagMode = "resource" // TagRequest requires the create request to set the managed tag. TagRequest TagMode = "request" )
type Target ¶
type Target struct {
Connection Connection
Credential secretsource.Value
}
Target is what a provider needs to probe one connection. Credential is zero for oidc_federation and masks itself when formatted.
type TemplateInput ¶
type TemplateInput struct {
RoleName string
TrustPrincipalARN string
ExternalID string
Capabilities []string
Regions []string
BucketPrefix string
NamePrefix string
HostedZoneIDs []string
}
TemplateInput is everything the generators need about one account link.
type TestResult ¶
TestResult is the outcome of a health probe. Reason comes from a fixed table, never from provider output.
type VaultKit ¶
type VaultKit struct {
RoleARN string `json:"role_arn"`
VaultCommands string `json:"vault_commands"`
VaultPolicy string `json:"vault_policy"`
PolicyJSON string `json:"policy_json"`
TrustPolicyJSON string `json:"trust_policy_json"`
}
VaultKit is everything an operator pastes: Vault commands and policy plus the IAM documents.
func BuildVaultKit ¶
func BuildVaultKit(in VaultKitInput) (VaultKit, error)
BuildVaultKit renders the kit. The IAM permission policy comes from the capability registry.
type VaultKitInput ¶
type VaultKitInput struct {
AccountID string
RoleName string
Region string
Mount string
VaultRole string
Namespace string
PrincipalARN string // IAM principal the Vault aws engine root credentials belong to
Capabilities []string
Regions []string
HostedZones []string
NamePrefix string
}
VaultKitInput shapes the Vault side of an AWS link.