Documentation
¶
Overview ¶
Package credentials provides credential retrieval and management
The Credentials is the primary method of getting access to and managing credentials Values. Using dependency injection retrieval of the credential values is handled by a object which satisfies the Provider interface.
By default the Credentials.Get() will cache the successful result of a Provider's Retrieve() until Provider.IsExpired() returns true. At which point Credentials will call Provider's Retrieve() to get new credential Value.
The Provider is responsible for determining when credentials Value have expired. It is also important to note that Credentials will always call Retrieve the first time Credentials.Get() is called.
Example of using the environment variable credentials.
creds := credentials.NewEnvCredentials()
// Retrieve the credentials value
credValue, err := creds.Get()
if err != nil {
// handle error
}
Example of forcing credentials to expire and be refreshed on the next Get(). This may be helpful to proactively expire credentials and refresh them sooner than they would naturally expire on their own.
creds := credentials.NewCredentials(&ec2rolecreds.EC2RoleProvider{})
creds.Expire()
credsValue, err := creds.Get()
// New credentials will be retrieved instead of from cache.
Custom Provider ¶
Each Provider built into this package also provides a helper method to generate a Credentials pointer setup with the provider. To use a custom Provider just create a type which satisfies the Provider interface and pass it to the NewCredentials method.
type MyProvider struct{}
func (m *MyProvider) Retrieve() (Value, error) {...}
func (m *MyProvider) IsExpired() bool {...}
creds := credentials.NewCredentials(&MyProvider{})
credValue, err := creds.Get()
Index ¶
- Constants
- Variables
- func GetEnvWithFallback(names ...string) string
- func StsAssumeRole(p *StsAssumeRoleProvider) (*Credentials, *StsAssumeRoleTime, error)
- func StsAssumeRoleWithOptions(accessKey, securityKey, roleName, accountId string, ...) (*Credentials, *StsAssumeRoleTime, error)
- type AssumeRoleWithOIDCResponse
- type AssumeRoleWithSAMLResponse
- type AssumedRoleUser
- type ChainProvider
- type Credentials
- func NewChainCredentials(providers []Provider) *Credentials
- func NewCredentials(provider Provider) *Credentials
- func NewDefaultCredentialProviderFromProviders(providers []Provider, reuseEnabled, verboseErrors bool) *Credentials
- func NewEcsRoleCredentials(roleName string) *Credentials
- func NewEnvCredentials() *Credentials
- func NewExpireAbleCredentials(provider Provider) *Credentials
- func NewSharedCredentials(filename, profile string) *Credentials
- func NewStaticCredentials(id, secret, token string) *Credentials
- func NewStaticCredentialsFromCreds(creds Value) *Credentials
- func NewStsCredentials(value StsValue) *Credentials
- func NewStsCredentialsWithOptions(accessKey, securityKey, roleName, accountId string, ...) *Credentials
- func (c *Credentials) Expire()
- func (c *Credentials) ExpiresAt() (time.Time, error)
- func (c *Credentials) Get() (Value, error)
- func (c *Credentials) GetBase(region string, service string) (base.Credentials, error)
- func (c *Credentials) GetProvider() Provider
- func (c *Credentials) IsExpired() bool
- func (c *Credentials) WithSTSConfig(cfg STSConfig) *Credentials
- type DefaultCredentialProvider
- type DefaultCredentialProviderOptions
- type EcsRoleProvider
- type EcsRoleProviderOptions
- type EnvProvider
- type ErrorProvider
- type Expirer
- type Expiry
- type HttpOptions
- type OIDCCredentials
- type OIDCCredentialsProvider
- type OIDCProviderOptions
- type OIDCTokenInfo
- type Provider
- type ProxyConfig
- type Result
- type SAMLCredentialsProvider
- type SAMLProviderOptions
- type SAMLResult
- type STSConfig
- type SharedCredentialsProvider
- type StaticProvider
- type StsAssumeRoleOptions
- type StsAssumeRoleProvider
- type StsAssumeRoleTime
- type StsProvider
- type StsValue
- type Value
Constants ¶
const ( // DefaultRetryerMaxNumRetries is the shared fallback retry count used by // credential providers when they opt into the default retry policy. DefaultRetryerMaxNumRetries = 3 // DefaultRetryerRetryDelay is the shared fallback retry interval used by // credential providers when retry interval is unset or invalid. DefaultRetryerRetryDelay = 1 * time.Second )
const DefaultEndpoint = "sts.ap-southeast-1.byteplusapi.com"
const DefaultProviderName = "DefaultCredentialProvider"
DefaultProviderName is the name used by DefaultCredentialProvider.
const EcsRoleProviderName = "EcsRoleProvider"
EcsRoleProviderName provides a name of EcsRole provider.
const EnvProviderName = "EnvProvider"
EnvProviderName provides a name of Env provider
SharedCredsProviderName provides a name of SharedCreds provider
const StaticProviderName = "StaticProvider"
StaticProviderName provides a name of Static provider
Variables ¶
var ( // ErrAccessKeyIDNotFound is returned when the byteplus Access Key ID can't be // found in the process's environment. ErrAccessKeyIDNotFound = bytepluserr.New("EnvAccessKeyNotFound", "BYTEPLUS_ACCESS_KEY not found in environment", nil) // ErrSecretAccessKeyNotFound is returned when the byteplus Secret Access Key // can't be found in the process's environment. ErrSecretAccessKeyNotFound = bytepluserr.New("EnvSecretNotFound", "BYTEPLUS_SECRET_KEY not found in environment", nil) )
var AnonymousCredentials = NewStaticCredentials("", "", "")
AnonymousCredentials is an empty Credential object that can be used as dummy placeholder credentials for requests that do not need signed.
var ( // ErrNoValidProvidersFoundInChain Is returned when there are no valid // providers in the ChainProvider. // // This has been deprecated. For verbose error messaging set // byteplus.Config.CredentialsChainVerboseErrors to true. ErrNoValidProvidersFoundInChain = bytepluserr.New("NoCredentialProviders", `no valid providers in chain. Deprecated. For verbose messaging see byteplus.Config.CredentialsChainVerboseErrors`, nil) )
var ( ErrSharedCredentialsHomeNotFound = bytepluserr.New("UserHomeNotFound", "user home directory not found.", nil) )
var ( // ErrStaticCredentialsEmpty is emitted when static credentials are empty. ErrStaticCredentialsEmpty = bytepluserr.New("EmptyStaticCreds", "static credentials are empty", nil) )
Functions ¶
func GetEnvWithFallback ¶ added in v1.0.62
GetEnvWithFallback returns the first non-empty environment variable value from the given list of names.
func StsAssumeRole ¶
func StsAssumeRole(p *StsAssumeRoleProvider) (*Credentials, *StsAssumeRoleTime, error)
func StsAssumeRoleWithOptions ¶ added in v1.0.62
func StsAssumeRoleWithOptions(accessKey, securityKey, roleName, accountId string, optFns ...func(*StsAssumeRoleOptions)) (*Credentials, *StsAssumeRoleTime, error)
StsAssumeRoleWithOptions creates a one-shot AssumeRole call with required parameters and optional functional options.
Types ¶
type AssumeRoleWithOIDCResponse ¶ added in v1.0.62
type AssumeRoleWithOIDCResponse struct {
ResponseMetadata response.ResponseMetadata `json:"ResponseMetadata,omitempty"`
Result Result `json:"Result,omitempty"`
}
type AssumeRoleWithSAMLResponse ¶ added in v1.0.62
type AssumeRoleWithSAMLResponse struct {
ResponseMetadata response.ResponseMetadata `json:"ResponseMetadata,omitempty"`
Result SAMLResult `json:"Result,omitempty"`
}
AssumeRoleWithSAMLResponse is the full STS response for AssumeRoleWithSAML.
type AssumedRoleUser ¶ added in v1.0.62
type ChainProvider ¶
type ChainProvider struct {
Providers []Provider
VerboseErrors bool
// contains filtered or unexported fields
}
A ChainProvider will search for a provider which returns credentials and cache that provider until Retrieve is called again.
The ChainProvider provides a way of chaining multiple providers together which will pick the first available using priority order of the Providers in the list.
If none of the Providers retrieve valid credentials Value, ChainProvider's Retrieve() will return the error ErrNoValidProvidersFoundInChain.
If a Provider is found which returns valid credentials Value ChainProvider will cache that Provider for all calls to IsExpired(), until Retrieve is called again.
Example of ChainProvider to be used with an EnvProvider and EC2RoleProvider. In this example EnvProvider will first check if any credentials are available via the environment variables. If there are none ChainProvider will check the next Provider in the list, EC2RoleProvider in this case. If EC2RoleProvider does not return any credentials ChainProvider will return the error
func (*ChainProvider) IsExpired ¶
func (c *ChainProvider) IsExpired() bool
IsExpired will returned the expired state of the currently cached provider if there is one. If there is no current provider, true will be returned.
func (*ChainProvider) Retrieve ¶
func (c *ChainProvider) Retrieve() (Value, error)
Retrieve returns the credentials value or error if no provider returned without error.
If a provider is found it will be cached and any calls to IsExpired() will return the expired state of the cached provider.
type Credentials ¶
type Credentials struct {
// contains filtered or unexported fields
}
A Credentials provides concurrency safe retrieval of byteplus credentials Value. Credentials will cache the credentials value until they expire. Once the value expires the next Get will attempt to retrieve valid credentials.
Credentials is safe to use across multiple goroutines and will manage the synchronous state so the Providers do not need to implement their own synchronization.
The first Credentials.Get() will always call Provider.Retrieve() to get the first instance of the credentials Value. All calls to Get() after that will return the cached credentials Value until IsExpired() returns true.
func NewChainCredentials ¶
func NewChainCredentials(providers []Provider) *Credentials
NewChainCredentials returns a pointer to a new Credentials object wrapping a chain of providers.
func NewCredentials ¶
func NewCredentials(provider Provider) *Credentials
NewCredentials returns a pointer to a new Credentials with the provider set.
func NewDefaultCredentialProviderFromProviders ¶ added in v1.0.62
func NewDefaultCredentialProviderFromProviders(providers []Provider, reuseEnabled, verboseErrors bool) *Credentials
NewDefaultCredentialProviderFromProviders creates a DefaultCredentialProvider from an explicit list of providers. This is intended to be called from the defaults package which assembles the full default chain.
verboseErrors mirrors byteplus.Config.CredentialsChainVerboseErrors: when true the failure error includes per-provider details, otherwise the stable ErrNoValidProvidersFoundInChain is returned (compatible with the legacy ChainProvider behavior).
func NewEcsRoleCredentials ¶ added in v1.0.62
func NewEcsRoleCredentials(roleName string) *Credentials
NewEcsRoleCredentials returns a pointer to a new Credentials object wrapping the EcsRoleProvider.
func NewEnvCredentials ¶
func NewEnvCredentials() *Credentials
NewEnvCredentials returns a pointer to a new Credentials object wrapping the environment variable provider.
func NewExpireAbleCredentials ¶
func NewExpireAbleCredentials(provider Provider) *Credentials
NewExpireAbleCredentials returns a pointer to a new Credentials with the provider set and disable forceRefresh.
func NewSharedCredentials ¶
func NewSharedCredentials(filename, profile string) *Credentials
NewSharedCredentials returns a pointer to a new Credentials object wrapping the Profile file provider.
func NewStaticCredentials ¶
func NewStaticCredentials(id, secret, token string) *Credentials
NewStaticCredentials returns a pointer to a new Credentials object wrapping a static credentials value provider.
func NewStaticCredentialsFromCreds ¶
func NewStaticCredentialsFromCreds(creds Value) *Credentials
NewStaticCredentialsFromCreds returns a pointer to a new Credentials object wrapping the static credentials value provide. Same as NewStaticCredentials but takes the creds Value instead of individual fields
func NewStsCredentials ¶
func NewStsCredentials(value StsValue) *Credentials
func NewStsCredentialsWithOptions ¶ added in v1.0.62
func NewStsCredentialsWithOptions(accessKey, securityKey, roleName, accountId string, optFns ...func(*StsAssumeRoleOptions)) *Credentials
NewStsCredentialsWithOptions constructs an StsProvider-backed Credentials with required parameters and optional functional options.
func (*Credentials) Expire ¶
func (c *Credentials) Expire()
Expire expires the credentials and forces them to be retrieved on the next call to Get().
This will override the Provider's expired state, and force Credentials to call the Provider's Retrieve().
func (*Credentials) ExpiresAt ¶
func (c *Credentials) ExpiresAt() (time.Time, error)
ExpiresAt provides access to the functionality of the Expirer interface of the underlying Provider, if it supports that interface. Otherwise, it returns an error.
func (*Credentials) Get ¶
func (c *Credentials) Get() (Value, error)
Get returns the credentials value, or error if the credentials Value failed to be retrieved.
Will return the cached credentials Value if it has not expired. If the credentials Value has expired the Provider's Retrieve() will be called to refresh the credentials.
If Credentials.Expire() was called the credentials Value will be force expired, and the next call to Get() will cause them to be refreshed.
func (*Credentials) GetBase ¶
func (c *Credentials) GetBase(region string, service string) (base.Credentials, error)
func (*Credentials) GetProvider ¶
func (c *Credentials) GetProvider() Provider
GetProvider returns provider instance of the credentials
func (*Credentials) IsExpired ¶
func (c *Credentials) IsExpired() bool
IsExpired returns if the credentials are no longer valid, and need to be retrieved.
If the Credentials were forced to be expired with Expire() this will reflect that override.
func (*Credentials) WithSTSConfig ¶
func (c *Credentials) WithSTSConfig(cfg STSConfig) *Credentials
WithSTSConfig binds built-in STS credentials to independent client state. It does not change the source provider or copy a live credential mutex/cache. Custom providers retain their existing sharing and retrieval contract.
type DefaultCredentialProvider ¶ added in v1.0.62
type DefaultCredentialProvider struct {
Providers []Provider
// contains filtered or unexported fields
}
DefaultCredentialProvider implements Provider and walks through a chain of credential providers. When reuseLastProviderEnabled is true (default), after the first successful resolution the chain remembers the provider and reuses it for subsequent calls, falling back to full traversal if that provider later fails.
func (*DefaultCredentialProvider) IsExpired ¶ added in v1.0.62
func (d *DefaultCredentialProvider) IsExpired() bool
IsExpired checks if the last successful provider's credentials are expired. If no provider has been cached yet, returns true to force a Retrieve.
func (*DefaultCredentialProvider) Retrieve ¶ added in v1.0.62
func (d *DefaultCredentialProvider) Retrieve() (Value, error)
Retrieve walks the chain and returns the first successful credentials.
type DefaultCredentialProviderOptions ¶ added in v1.0.62
type DefaultCredentialProviderOptions struct {
// RoleName is the ECS IMDS role name. If empty, it will be resolved
// from env var BYTEPLUS_ECS_METADATA.
RoleName string
// ReuseLastProviderEnabled controls whether the chain caches and
// reuses the last successful provider on subsequent calls.
// Default is true.
ReuseLastProviderEnabled *bool
}
DefaultCredentialProviderOptions holds configuration for the default credential chain.
func (*DefaultCredentialProviderOptions) IsReuseEnabled ¶ added in v1.0.62
func (o *DefaultCredentialProviderOptions) IsReuseEnabled() bool
IsReuseEnabled returns whether the reuse-last-provider optimization is enabled. Defaults to true if not explicitly set.
type EcsRoleProvider ¶ added in v1.0.62
type EcsRoleProvider struct {
Expiry
// RoleName is the IAM role name. If empty, resolved from env or auto-detected.
RoleName string
// ExpiryWindow will allow the credentials to trigger refreshing prior to
// the credentials actually expiring.
ExpiryWindow time.Duration
// MaxRetries is the number of retry attempts after the initial IMDS request.
// Nil falls back to DefaultRetryerMaxNumRetries (3); 0 disables retries.
MaxRetries *int
// RetryInterval is the sleep interval between IMDS retry attempts.
// If zero or negative, it falls back to DefaultRetryerRetryDelay (1s).
RetryInterval time.Duration
// contains filtered or unexported fields
}
EcsRoleProvider retrieves credentials from the ECS Instance Metadata Service (IMDSv2).
Flow:
- PUT to get IMDSv2 token (fresh every time)
- Resolve roleName: param > env > auto-detect from IMDS
- GET STS credentials with token header
func NewEcsRoleProvider ¶ added in v1.0.62
func NewEcsRoleProvider(roleName string) *EcsRoleProvider
NewEcsRoleProvider returns a new EcsRoleProvider.
func NewEcsRoleProviderWithOptions ¶ added in v1.0.62
func NewEcsRoleProviderWithOptions(roleName string, optFns ...func(*EcsRoleProviderOptions)) *EcsRoleProvider
NewEcsRoleProviderWithOptions constructs an EcsRoleProvider with the role name as a required parameter and optional functional options.
func (*EcsRoleProvider) IsExpired ¶ added in v1.0.62
func (p *EcsRoleProvider) IsExpired() bool
IsExpired returns whether the cached credentials have expired.
func (*EcsRoleProvider) Retrieve ¶ added in v1.0.62
func (p *EcsRoleProvider) Retrieve() (Value, error)
Retrieve retrieves ECS role credentials from IMDS via IMDSv2.
type EcsRoleProviderOptions ¶ added in v1.0.62
type EcsRoleProviderOptions struct {
ExpiryWindow time.Duration
MaxRetries *int
RetryInterval time.Duration
HttpTimeout time.Duration
}
EcsRoleProviderOptions contains optional configuration for EcsRoleProvider.
type EnvProvider ¶
type EnvProvider struct {
// contains filtered or unexported fields
}
A EnvProvider retrieves credentials from the environment variables of the running process. Environment credentials never expire.
Environment variables used:
* Access Key ID: BYTEPLUS_ACCESS_KEY > BYTEPLUS_ACCESS_KEY_ID
* Secret Access Key: BYTEPLUS_SECRET_KEY > BYTEPLUS_SECRET_ACCESS_KEY
func (*EnvProvider) IsExpired ¶
func (e *EnvProvider) IsExpired() bool
IsExpired returns if the credentials have been retrieved.
func (*EnvProvider) Retrieve ¶
func (e *EnvProvider) Retrieve() (Value, error)
Retrieve retrieves the keys from the environment.
type ErrorProvider ¶
type ErrorProvider struct {
// The error to be returned from Retrieve
Err error
// The provider name to set on the Retrieved returned Value
ProviderName string
}
An ErrorProvider is a stub credentials provider that always returns an error this is used by the SDK when construction a known provider is not possible due to an error.
func (ErrorProvider) IsExpired ¶
func (p ErrorProvider) IsExpired() bool
IsExpired will always return not expired.
func (ErrorProvider) Retrieve ¶
func (p ErrorProvider) Retrieve() (Value, error)
Retrieve will always return the error that the ErrorProvider was created with.
type Expirer ¶
type Expirer interface {
// The time at which the credentials are no longer valid
ExpiresAt() time.Time
}
An Expirer is an interface that Providers can implement to expose the expiration time, if known. If the Provider cannot accurately provide this info, it should not implement this interface.
type Expiry ¶
type Expiry struct {
// If set will be used by IsExpired to determine the current time.
// Defaults to time.Now if CurrentTime is not set. Available for testing
// to be able to mock out the current time.
CurrentTime func() time.Time
// contains filtered or unexported fields
}
A Expiry provides shared expiration logic to be used by credentials providers to implement expiry functionality.
The best method to use this struct is as an anonymous field within the provider's struct.
Example:
type EC2RoleProvider struct {
Expiry
...
}
func (*Expiry) SetExpiration ¶
SetExpiration sets the expiration IsExpired will check when called.
If window is greater than 0 the expiration time will be reduced by the window value.
Using a window is helpful to trigger credentials to expire sooner than the expiration time given to ensure no requests are made with expired tokens.
type HttpOptions ¶ added in v1.0.62
type OIDCCredentials ¶ added in v1.0.62
type OIDCCredentialsProvider ¶ added in v1.0.62
type OIDCCredentialsProvider struct {
OIDCTokenFilePath string
RoleTrn string
RoleSessionName string
DurationSeconds int
Policy string
// for sts endpoint
Schema string
Endpoint string
MaxRetries *int // Retry attempts. Nil falls back to DefaultRetryerMaxNumRetries (3); 0 disables retries.
RetryInterval time.Duration // Sleep interval between retries. If zero or negative, falls back to DefaultRetryerRetryDelay (1s).
// ProxyURL 指定访问 STS 端点时使用的正向代理地址,格式
// scheme://[user:password@]host:port。留空时先使用绑定客户端中与 STS
// 协议对应的 HTTPProxy/HTTPSProxy,再保留原传输层代理行为。
ProxyURL string
// CAFile 指定用于校验 STS 服务端证书的自定义 CA 证书文件路径(PEM 格式)。
// 留空时保留原传输层的根证书配置,标准默认值使用系统根证书。
CAFile string
// InsecureSkipVerify 控制是否跳过 STS 服务端 TLS 证书校验。
// 仅限联调(如自签证书 / 代理拦截),生产环境禁用,会导致中间人攻击风险。
InsecureSkipVerify bool
// contains filtered or unexported fields
}
func NewOIDCCredentialsProviderFromEnv ¶ added in v1.0.62
func NewOIDCCredentialsProviderFromEnv() *OIDCCredentialsProvider
func NewOIDCCredentialsProviderWithOptions ¶ added in v1.0.62
func NewOIDCCredentialsProviderWithOptions(tokenFilePath, roleTrn string, optFns ...func(*OIDCProviderOptions)) *OIDCCredentialsProvider
NewOIDCCredentialsProviderWithOptions constructs an OIDCCredentialsProvider with required parameters and optional functional options.
func (*OIDCCredentialsProvider) IsExpired ¶ added in v1.0.62
func (p *OIDCCredentialsProvider) IsExpired() bool
func (*OIDCCredentialsProvider) Retrieve ¶ added in v1.0.62
func (p *OIDCCredentialsProvider) Retrieve() (Value, error)
type OIDCProviderOptions ¶ added in v1.0.62
type OIDCProviderOptions struct {
RoleSessionName string
DurationSeconds int
Policy string
Schema string
Endpoint string
MaxRetries *int
RetryInterval time.Duration
HttpOptions *HttpOptions
// ProxyURL 正向代理地址,格式 scheme://[user:password@]host:port。
ProxyURL string
// CAFile 自定义 CA 证书文件路径(PEM 格式)。
CAFile string
// InsecureSkipVerify 跳过 TLS 证书校验,仅限联调,生产禁用。
InsecureSkipVerify bool
}
OIDCProviderOptions contains optional configuration for OIDCCredentialsProvider.
type OIDCTokenInfo ¶ added in v1.0.62
type Provider ¶
type Provider interface {
// Retrieve returns nil if it successfully retrieved the value.
// Error is returned if the value were not obtainable, or empty.
Retrieve() (Value, error)
// IsExpired returns if the credentials are no longer valid, and need
// to be retrieved.
IsExpired() bool
}
A Provider is the interface for any component which will provide credentials Value. A provider is required to manage its own Expired state, and what to be expired means.
The Provider should not need to implement its own mutexes, because that will be managed by Credentials.
type ProxyConfig ¶
type ProxyConfig struct {
// ProxyURL 正向代理地址,格式 scheme://[user:password@]host:port。
// 为空时保留原 Transport 的代理行为;标准默认 Transport 会处理
// HTTP_PROXY / HTTPS_PROXY / NO_PROXY。
ProxyURL string
// CAFile 自定义 CA 证书文件路径(PEM 格式),用于校验 STS 服务端证书。
// 为空时保留原 Transport 的 TLS 根配置;未自定义时使用系统根证书。
CAFile string
// InsecureSkipVerify 为 true 时跳过 TLS 证书链与主机名校验。
// 仅限联调,生产环境禁用。
InsecureSkipVerify bool
// contains filtered or unexported fields
}
ProxyConfig 汇总访问 STS 端点时的代理与 TLS 相关配置。
该结构用于把 ProxyURL、CAFile、InsecureSkipVerify 三个对外参数统一 传递给 buildProxyTransport / buildProxyHTTPClient,便于各 Provider 复用同一套构建逻辑。
func (ProxyConfig) IsZero ¶
func (cfg ProxyConfig) IsZero() bool
IsZero 判断显式代理/TLS 参数和客户端代理兜底是否都为空。
为 true 时表示调用方未显式配置任何代理/TLS 选项,此时应保持底层 http.Client 原样(例如 base.Client 复用的连接池及其 环境变量代理),避免无意义地覆盖 Transport。
type Result ¶ added in v1.0.62
type Result struct {
Credentials OIDCCredentials `json:"Credentials,omitempty"`
OIDCTokenInfo OIDCTokenInfo `json:"OIDCTokenInfo,omitempty"`
AssumedRoleUser AssumedRoleUser `json:"AssumedRoleUser,omitempty"`
}
type SAMLCredentialsProvider ¶ added in v1.0.62
type SAMLCredentialsProvider struct {
RoleTrn string
SAMLProviderTrn string
SAMLAssertion string
DurationSeconds int
Policy string
// for sts endpoint
Schema string
Endpoint string
MaxRetries *int // Retry attempts. Nil falls back to DefaultRetryerMaxNumRetries (3); 0 disables retries.
RetryInterval time.Duration // Sleep interval between retries. If zero or negative, falls back to DefaultRetryerRetryDelay (1s).
// ProxyURL 指定访问 STS 端点时使用的正向代理地址,格式
// scheme://[user:password@]host:port。留空时先使用绑定客户端中与 STS
// 协议对应的 HTTPProxy/HTTPSProxy,再保留原传输层代理行为。
ProxyURL string
// CAFile 指定用于校验 STS 服务端证书的自定义 CA 证书文件路径(PEM 格式)。
// 留空时保留原传输层的根证书配置,标准默认值使用系统根证书。
CAFile string
// InsecureSkipVerify 控制是否跳过 STS 服务端 TLS 证书校验。
// 仅限联调(如自签证书 / 代理拦截),生产环境禁用,会导致中间人攻击风险。
InsecureSkipVerify bool
// contains filtered or unexported fields
}
SAMLCredentialsProvider obtains temporary credentials from STS via AssumeRoleWithSAML. It refreshes credentials automatically before expiration.
func NewSAMLCredentialsProvider ¶ added in v1.0.62
func NewSAMLCredentialsProvider(roleTrn, samlProviderTrn, samlAssertion string) *SAMLCredentialsProvider
NewSAMLCredentialsProvider constructs a SAMLCredentialsProvider with the required role/saml-provider TRNs and the base64-encoded SAML assertion returned by your IdP.
func NewSAMLCredentialsProviderWithOptions ¶ added in v1.0.62
func NewSAMLCredentialsProviderWithOptions(roleTrn, samlProviderTrn, samlAssertion string, optFns ...func(*SAMLProviderOptions)) *SAMLCredentialsProvider
NewSAMLCredentialsProviderWithOptions constructs a SAMLCredentialsProvider with required parameters and optional functional options.
func (*SAMLCredentialsProvider) IsExpired ¶ added in v1.0.62
func (p *SAMLCredentialsProvider) IsExpired() bool
func (*SAMLCredentialsProvider) Retrieve ¶ added in v1.0.62
func (p *SAMLCredentialsProvider) Retrieve() (Value, error)
type SAMLProviderOptions ¶ added in v1.0.62
type SAMLProviderOptions struct {
DurationSeconds int
Policy string
Schema string
Endpoint string
MaxRetries *int
RetryInterval time.Duration
HttpOptions *HttpOptions
// ProxyURL 正向代理地址,格式 scheme://[user:password@]host:port。
ProxyURL string
// CAFile 自定义 CA 证书文件路径(PEM 格式)。
CAFile string
// InsecureSkipVerify 跳过 TLS 证书校验,仅限联调,生产禁用。
InsecureSkipVerify bool
}
SAMLProviderOptions contains optional configuration for SAMLCredentialsProvider.
type SAMLResult ¶ added in v1.0.62
type SAMLResult struct {
Credentials OIDCCredentials `json:"Credentials,omitempty"`
AssumedRoleUser AssumedRoleUser `json:"AssumedRoleUser,omitempty"`
}
SAMLResult is the result body returned by AssumeRoleWithSAML.
type STSConfig ¶
type STSConfig struct {
Region string
// Host is an independent AssumeRole endpoint, not a business API endpoint.
Host string
HTTPProxy string
HTTPSProxy string
}
STSConfig holds client defaults for built-in STS providers. Values are snapshotted when a session or service client is created. Explicit provider settings take precedence; environment proxy values must not be stored here.
type SharedCredentialsProvider ¶
type SharedCredentialsProvider struct {
//
// If empty will look for "BYTEPLUS_SHARED_CREDENTIALS_FILE" env variable. If the
// env value is empty will default to current user's home directory.
// Linux/OSX: "$HOME/.byteplus/credentials"
// Windows: "%USERPROFILE%\.byteplus\credentials"
Filename string
// will default to environment variable "BYTEPLUS_PROFILE" or "default" if
// environment variable is also not set.
Profile string
// contains filtered or unexported fields
}
A SharedCredentialsProvider retrieves credentials from the current user's home directory, and keeps track if those credentials are expired.
Profile ini file example: $HOME/.byteplus/credentials
func (*SharedCredentialsProvider) IsExpired ¶
func (p *SharedCredentialsProvider) IsExpired() bool
IsExpired returns if the shared credentials have expired.
func (*SharedCredentialsProvider) Retrieve ¶
func (p *SharedCredentialsProvider) Retrieve() (Value, error)
Retrieve reads and extracts the shared credentials from the current users home directory.
type StaticProvider ¶
type StaticProvider struct {
Value
}
A StaticProvider is a set of credentials which are set programmatically, and will never expire.
func (*StaticProvider) IsExpired ¶
func (s *StaticProvider) IsExpired() bool
IsExpired returns if the credentials are expired.
For StaticProvider, the credentials never expired.
func (*StaticProvider) Retrieve ¶
func (s *StaticProvider) Retrieve() (Value, error)
Retrieve returns the credentials or error if the credentials are invalid.
type StsAssumeRoleOptions ¶ added in v1.0.62
type StsAssumeRoleOptions struct {
SessionToken string
Host string
Region string
Schema string
Timeout time.Duration
DurationSeconds int
Policy string
// MaxRetries controls AssumeRole retry attempts.
// Zero or negative values fall back to DefaultRetryerMaxNumRetries.
MaxRetries int
RetryInterval time.Duration
// ProxyURL 指定访问 STS 端点时使用的正向代理地址,格式
// scheme://[user:password@]host:port。留空时先使用绑定客户端中与 STS
// 协议对应的 HTTPProxy/HTTPSProxy,再保留原传输层代理行为。
// 直接调用 StsAssumeRoleWithOptions 不包含客户端配置兜底层。
ProxyURL string
// CAFile 指定用于校验 STS 服务端证书的自定义 CA 证书文件路径(PEM 格式)。
CAFile string
// InsecureSkipVerify 控制是否跳过 STS 服务端 TLS 证书校验,仅限联调,生产禁用。
InsecureSkipVerify bool
}
StsAssumeRoleOptions contains optional configuration for STS AssumeRole.
type StsAssumeRoleProvider ¶
type StsAssumeRoleProvider struct {
AccessKey string
SecurityKey string
SessionToken string
RoleName string
AccountId string
Host string
Region string
Schema string
Timeout time.Duration
DurationSeconds int
Policy string
// MaxRetries controls AssumeRole retry attempts.
// Zero or negative values fall back to DefaultRetryerMaxNumRetries.
MaxRetries int
RetryInterval time.Duration
// ProxyURL 指定访问 STS 端点时使用的正向代理地址,适用于客户端位于企业内网、
// 需经统一出口代理访问公网的场景。
//
// 格式为 scheme://[user:password@]host:port,例如:
// - 无认证: "http://10.0.0.1:8080"
// - 需账号密码: "http://user:pass@10.0.0.1:8080"
//
// 代理认证信息(用户名/密码)以 Basic 方式随请求发送。若含特殊字符,
// 请按 RFC 3986 进行百分号编码。
//
// 留空时先使用绑定客户端中与 STS 协议对应的 HTTPProxy/HTTPSProxy,
// 再保留原传输层代理行为(标准默认传输层处理 HTTP_PROXY/HTTPS_PROXY/NO_PROXY)。
// 直接调用 StsAssumeRole 不包含客户端配置兜底层。
ProxyURL string
// CAFile 指定用于校验 STS 服务端证书的自定义 CA 证书文件路径(PEM 格式)。
//
// 适用于企业代理对 HTTPS 流量做 TLS 拦截(中间人)、使用私有 CA 重新签发证书,
// 且该 CA 未安装到操作系统信任库的场景。设置后,SDK 将以此 CA 校验证书链。
//
// 留空时保留原传输层的根证书配置,标准默认值使用系统根证书。
CAFile string
// InsecureSkipVerify 控制是否跳过 STS 服务端 TLS 证书校验。
//
// 置为 true 时将不校验证书链与主机名,可用于自签证书或代理拦截等联调场景。
//
// 警告:此选项会使连接易受中间人攻击,切勿在生产环境启用。
// 生产环境请改用 CAFile 显式信任所需的 CA 证书。
InsecureSkipVerify bool
}
type StsAssumeRoleTime ¶
type StsProvider ¶
func (*StsProvider) IsExpired ¶
func (s *StsProvider) IsExpired() bool
func (*StsProvider) Retrieve ¶
func (s *StsProvider) Retrieve() (Value, error)
type StsValue ¶
type StsValue StsAssumeRoleProvider
type Value ¶
type Value struct {
// byteplus Access key ID
AccessKeyID string
// byteplus Secret Access Key
SecretAccessKey string
// byteplus Session Token
SessionToken string
// Provider used to get credentials
ProviderName string
}
A Value is the byteplus credentials value for individual credential fields.