vendor: github.com/aws/aws-sdk-go-v2/config v1.26.6

vendor github.com/aws/aws-sdk-go-v2/config v1.26.6 and related dependencies.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2024-02-05 18:08:03 +01:00
parent 089982153f
commit 43ed470208
190 changed files with 12340 additions and 13837 deletions

View File

@ -1,3 +1,108 @@
# v1.14.11 (2024-01-04)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.14.10 (2023-12-07)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.14.9 (2023-12-01)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.14.8 (2023-11-30)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.14.7 (2023-11-29)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.14.6 (2023-11-28.2)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.14.5 (2023-11-20)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.14.4 (2023-11-15)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.14.3 (2023-11-09)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.14.2 (2023-11-02)
* No change notes available for this release.
# v1.14.1 (2023-11-01)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.14.0 (2023-10-31)
* **Feature**: **BREAKING CHANGE**: Bump minimum go version to 1.19 per the revised [go version support policy](https://aws.amazon.com/blogs/developer/aws-sdk-for-go-aligns-with-go-release-policy-on-supported-runtimes/).
* **Dependency Update**: Updated to the latest SDK module versions
# v1.13.13 (2023-10-12)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.13.12 (2023-10-06)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.13.11 (2023-08-21)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.13.10 (2023-08-18)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.13.9 (2023-08-17)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.13.8 (2023-08-07)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.13.7 (2023-07-31)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.13.6 (2023-07-28)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.13.5 (2023-07-13)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.13.4 (2023-06-13)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.13.3 (2023-04-24)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.13.2 (2023-04-07)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.13.1 (2023-03-21)
* **Dependency Update**: Updated to the latest SDK module versions
# v1.13.0 (2023-03-14)
* **Feature**: Add flag to disable IMDSv1 fallback
# v1.12.24 (2023-03-10)
* **Dependency Update**: Updated to the latest SDK module versions

View File

@ -119,6 +119,7 @@ func NewFromConfig(cfg aws.Config, optFns ...func(*Options)) *Client {
resolveClientEnableState(cfg, &opts)
resolveEndpointConfig(cfg, &opts)
resolveEndpointModeConfig(cfg, &opts)
resolveEnableFallback(cfg, &opts)
return New(opts, optFns...)
}
@ -174,6 +175,16 @@ type Options struct {
// The logger writer interface to write logging messages to.
Logger logging.Logger
// Configure IMDSv1 fallback behavior. By default, the client will attempt
// to fall back to IMDSv1 as needed for backwards compatibility. When set to [aws.FalseTernary]
// the client will return any errors encountered from attempting to fetch a token
// instead of silently using the insecure data flow of IMDSv1.
//
// See [configuring IMDS] for more information.
//
// [configuring IMDS]: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html
EnableFallback aws.Ternary
// provides the caching of API tokens used for operation calls. If unset,
// the API token will not be retrieved for the operation.
tokenProvider *tokenProvider
@ -318,3 +329,20 @@ func resolveEndpointConfig(cfg aws.Config, options *Options) error {
options.Endpoint = value
return nil
}
func resolveEnableFallback(cfg aws.Config, options *Options) {
if options.EnableFallback != aws.UnknownTernary {
return
}
disabled, ok := internalconfig.ResolveV1FallbackDisabled(cfg.ConfigSources)
if !ok {
return
}
if disabled {
options.EnableFallback = aws.FalseTernary
} else {
options.EnableFallback = aws.TrueTernary
}
}

View File

@ -56,6 +56,7 @@ type GetDynamicDataOutput struct {
func addGetDynamicDataMiddleware(stack *middleware.Stack, options Options) error {
return addAPIRequestMiddleware(stack,
options,
"GetDynamicData",
buildGetDynamicDataPath,
buildGetDynamicDataOutput)
}

View File

@ -53,6 +53,7 @@ type GetIAMInfoOutput struct {
func addGetIAMInfoMiddleware(stack *middleware.Stack, options Options) error {
return addAPIRequestMiddleware(stack,
options,
"GetIAMInfo",
buildGetIAMInfoPath,
buildGetIAMInfoOutput,
)

View File

@ -54,6 +54,7 @@ type GetInstanceIdentityDocumentOutput struct {
func addGetInstanceIdentityDocumentMiddleware(stack *middleware.Stack, options Options) error {
return addAPIRequestMiddleware(stack,
options,
"GetInstanceIdentityDocument",
buildGetInstanceIdentityDocumentPath,
buildGetInstanceIdentityDocumentOutput,
)

View File

@ -56,6 +56,7 @@ type GetMetadataOutput struct {
func addGetMetadataMiddleware(stack *middleware.Stack, options Options) error {
return addAPIRequestMiddleware(stack,
options,
"GetMetadata",
buildGetMetadataPath,
buildGetMetadataOutput)
}

View File

@ -45,6 +45,7 @@ type GetRegionOutput struct {
func addGetRegionMiddleware(stack *middleware.Stack, options Options) error {
return addAPIRequestMiddleware(stack,
options,
"GetRegion",
buildGetInstanceIdentityDocumentPath,
buildGetRegionOutput,
)

View File

@ -49,6 +49,7 @@ func addGetTokenMiddleware(stack *middleware.Stack, options Options) error {
err := addRequestMiddleware(stack,
options,
"PUT",
"GetToken",
buildGetTokenPath,
buildGetTokenOutput)
if err != nil {

View File

@ -45,6 +45,7 @@ type GetUserDataOutput struct {
func addGetUserDataMiddleware(stack *middleware.Stack, options Options) error {
return addAPIRequestMiddleware(stack,
options,
"GetUserData",
buildGetUserDataPath,
buildGetUserDataOutput)
}

View File

@ -0,0 +1,48 @@
package imds
import (
"context"
"github.com/aws/smithy-go/middleware"
)
type getIdentityMiddleware struct {
options Options
}
func (*getIdentityMiddleware) ID() string {
return "GetIdentity"
}
func (m *getIdentityMiddleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (
out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
) {
return next.HandleFinalize(ctx, in)
}
type signRequestMiddleware struct {
}
func (*signRequestMiddleware) ID() string {
return "Signing"
}
func (m *signRequestMiddleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (
out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
) {
return next.HandleFinalize(ctx, in)
}
type resolveAuthSchemeMiddleware struct {
operation string
options Options
}
func (*resolveAuthSchemeMiddleware) ID() string {
return "ResolveAuthScheme"
}
func (m *resolveAuthSchemeMiddleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (
out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
) {
return next.HandleFinalize(ctx, in)
}

View File

@ -0,0 +1,20 @@
package imds
import (
"context"
"github.com/aws/smithy-go/middleware"
)
type resolveEndpointV2Middleware struct {
options Options
}
func (*resolveEndpointV2Middleware) ID() string {
return "ResolveEndpointV2"
}
func (m *resolveEndpointV2Middleware) HandleFinalize(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (
out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
) {
return next.HandleFinalize(ctx, in)
}

View File

@ -3,4 +3,4 @@
package imds
// goModuleVersion is the tagged release for this module
const goModuleVersion = "1.12.24"
const goModuleVersion = "1.14.11"

View File

@ -58,6 +58,10 @@ type EndpointResolver interface {
GetEC2IMDSEndpoint() (string, bool, error)
}
type v1FallbackDisabledResolver interface {
GetEC2IMDSV1FallbackDisabled() (bool, bool)
}
// ResolveClientEnableState resolves the ClientEnableState from a list of configuration sources.
func ResolveClientEnableState(sources []interface{}) (value ClientEnableState, found bool, err error) {
for _, source := range sources {
@ -96,3 +100,15 @@ func ResolveEndpointConfig(sources []interface{}) (value string, found bool, err
}
return value, found, err
}
// ResolveV1FallbackDisabled ...
func ResolveV1FallbackDisabled(sources []interface{}) (bool, bool) {
for _, source := range sources {
if resolver, ok := source.(v1FallbackDisabledResolver); ok {
if v, found := resolver.GetEC2IMDSV1FallbackDisabled(); found {
return v, true
}
}
}
return false, false
}

View File

@ -17,10 +17,11 @@ import (
func addAPIRequestMiddleware(stack *middleware.Stack,
options Options,
operation string,
getPath func(interface{}) (string, error),
getOutput func(*smithyhttp.Response) (interface{}, error),
) (err error) {
err = addRequestMiddleware(stack, options, "GET", getPath, getOutput)
err = addRequestMiddleware(stack, options, "GET", operation, getPath, getOutput)
if err != nil {
return err
}
@ -44,6 +45,7 @@ func addAPIRequestMiddleware(stack *middleware.Stack,
func addRequestMiddleware(stack *middleware.Stack,
options Options,
method string,
operation string,
getPath func(interface{}) (string, error),
getOutput func(*smithyhttp.Response) (interface{}, error),
) (err error) {
@ -101,6 +103,10 @@ func addRequestMiddleware(stack *middleware.Stack,
return err
}
if err := addProtocolFinalizerMiddlewares(stack, options, operation); err != nil {
return fmt.Errorf("add protocol finalizers: %w", err)
}
// Retry support
return retry.AddRetryMiddlewares(stack, retry.AddRetryMiddlewaresOptions{
Retryer: options.Retryer,
@ -283,3 +289,19 @@ func appendURIPath(base, add string) string {
}
return reqPath
}
func addProtocolFinalizerMiddlewares(stack *middleware.Stack, options Options, operation string) error {
if err := stack.Finalize.Add(&resolveAuthSchemeMiddleware{operation: operation, options: options}, middleware.Before); err != nil {
return fmt.Errorf("add ResolveAuthScheme: %w", err)
}
if err := stack.Finalize.Insert(&getIdentityMiddleware{options: options}, "ResolveAuthScheme", middleware.After); err != nil {
return fmt.Errorf("add GetIdentity: %w", err)
}
if err := stack.Finalize.Insert(&resolveEndpointV2Middleware{options: options}, "GetIdentity", middleware.After); err != nil {
return fmt.Errorf("add ResolveEndpointV2: %w", err)
}
if err := stack.Finalize.Insert(&signRequestMiddleware{}, "ResolveEndpointV2", middleware.After); err != nil {
return fmt.Errorf("add Signing: %w", err)
}
return nil
}

View File

@ -4,12 +4,14 @@ import (
"context"
"errors"
"fmt"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/smithy-go"
"github.com/aws/smithy-go/logging"
"net/http"
"sync"
"sync/atomic"
"time"
smithy "github.com/aws/smithy-go"
"github.com/aws/smithy-go/middleware"
smithyhttp "github.com/aws/smithy-go/transport/http"
)
@ -68,7 +70,7 @@ func (t *tokenProvider) HandleFinalize(
) (
out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
) {
if !t.enabled() {
if t.fallbackEnabled() && !t.enabled() {
// short-circuits to insecure data flow if token provider is disabled.
return next.HandleFinalize(ctx, input)
}
@ -115,23 +117,15 @@ func (t *tokenProvider) HandleDeserialize(
}
if resp.StatusCode == http.StatusUnauthorized { // unauthorized
err = &retryableError{Err: err}
t.enable()
err = &retryableError{Err: err, isRetryable: true}
}
return out, metadata, err
}
type retryableError struct {
Err error
}
func (*retryableError) RetryableError() bool { return true }
func (e *retryableError) Error() string { return e.Err.Error() }
func (t *tokenProvider) getToken(ctx context.Context) (tok *apiToken, err error) {
if !t.enabled() {
if t.fallbackEnabled() && !t.enabled() {
return nil, &bypassTokenRetrievalError{
Err: fmt.Errorf("cannot get API token, provider disabled"),
}
@ -147,7 +141,7 @@ func (t *tokenProvider) getToken(ctx context.Context) (tok *apiToken, err error)
tok, err = t.updateToken(ctx)
if err != nil {
return nil, fmt.Errorf("cannot get API token, %w", err)
return nil, err
}
return tok, nil
@ -167,17 +161,19 @@ func (t *tokenProvider) updateToken(ctx context.Context) (*apiToken, error) {
TokenTTL: t.tokenTTL,
})
if err != nil {
// change the disabled flag on token provider to true, when error is request timeout error.
var statusErr interface{ HTTPStatusCode() int }
if errors.As(err, &statusErr) {
switch statusErr.HTTPStatusCode() {
// Disable get token if failed because of 403, 404, or 405
// Disable future get token if failed because of 403, 404, or 405
case http.StatusForbidden,
http.StatusNotFound,
http.StatusMethodNotAllowed:
t.disable()
if t.fallbackEnabled() {
logger := middleware.GetLogger(ctx)
logger.Logf(logging.Warn, "falling back to IMDSv1: %v", err)
t.disable()
}
// 400 errors are terminal, and need to be upstreamed
case http.StatusBadRequest:
@ -192,8 +188,17 @@ func (t *tokenProvider) updateToken(ctx context.Context) (*apiToken, error) {
atomic.StoreUint32(&t.disabled, 1)
}
// Token couldn't be retrieved, but bypass this, and allow the
// request to continue.
if !t.fallbackEnabled() {
// NOTE: getToken() is an implementation detail of some outer operation
// (e.g. GetMetadata). It has its own retries that have already been exhausted.
// Mark the underlying error as a terminal error.
err = &retryableError{Err: err, isRetryable: false}
return nil, err
}
// Token couldn't be retrieved, fallback to IMDSv1 insecure flow for this request
// and allow the request to proceed. Future requests _may_ re-attempt fetching a
// token if not disabled.
return nil, &bypassTokenRetrievalError{Err: err}
}
@ -206,21 +211,21 @@ func (t *tokenProvider) updateToken(ctx context.Context) (*apiToken, error) {
return tok, nil
}
type bypassTokenRetrievalError struct {
Err error
}
func (e *bypassTokenRetrievalError) Error() string {
return fmt.Sprintf("bypass token retrieval, %v", e.Err)
}
func (e *bypassTokenRetrievalError) Unwrap() error { return e.Err }
// enabled returns if the token provider is current enabled or not.
func (t *tokenProvider) enabled() bool {
return atomic.LoadUint32(&t.disabled) == 0
}
// fallbackEnabled returns false if EnableFallback is [aws.FalseTernary], true otherwise
func (t *tokenProvider) fallbackEnabled() bool {
switch t.client.options.EnableFallback {
case aws.FalseTernary:
return false
default:
return true
}
}
// disable disables the token provider and it will no longer attempt to inject
// the token, nor request updates.
func (t *tokenProvider) disable() {
@ -235,3 +240,22 @@ func (t *tokenProvider) enable() {
t.tokenMux.Unlock()
atomic.StoreUint32(&t.disabled, 0)
}
type bypassTokenRetrievalError struct {
Err error
}
func (e *bypassTokenRetrievalError) Error() string {
return fmt.Sprintf("bypass token retrieval, %v", e.Err)
}
func (e *bypassTokenRetrievalError) Unwrap() error { return e.Err }
type retryableError struct {
Err error
isRetryable bool
}
func (e *retryableError) RetryableError() bool { return e.isRetryable }
func (e *retryableError) Error() string { return e.Err.Error() }