Skip to content

Commit 0875037

Browse files
cpu1idanshoham
cpu1
authored and
idanshoham
committed
Fix generating presigned URL for K8s authentication
With `[email protected]`, API server requests containing URLs presigned by `sts.PresignClient` fail with an `Unauthorized` error. `[email protected]` adds an extra header `amz-sdk-request` to the generated request, but this header is not allow-listed by `aws-iam-authenticator` server running on the control plane. This is likely due to [this change](aws/aws-sdk-go-v2#2438) which reorders the middleware operations to execute `RetryMetricsHeader` before `Signing`. This changelist removes the `RetryMetricsHeader` middleware from the stack when constructing `sts.PresignClient`.
1 parent bbda829 commit 0875037

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

pkg/eks/auth/generator.go

+13-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import (
66
"fmt"
77
"time"
88

9+
"github.com/aws/aws-sdk-go-v2/aws/retry"
910
"github.com/aws/aws-sdk-go-v2/service/sts"
11+
12+
"github.com/aws/smithy-go/middleware"
1013
smithyhttp "github.com/aws/smithy-go/transport/http"
1114

1215
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5"
@@ -64,9 +67,15 @@ func (g Generator) GetWithSTS(ctx context.Context, clusterID string) (Token, err
6467

6568
func (g Generator) appendPresignHeaderValuesFunc(clusterID string) func(stsOptions *sts.Options) {
6669
return func(stsOptions *sts.Options) {
67-
// Add clusterId Header
68-
stsOptions.APIOptions = append(stsOptions.APIOptions, smithyhttp.SetHeaderValue(clusterIDHeader, clusterID))
69-
// Add X-Amz-Expires query param
70-
stsOptions.APIOptions = append(stsOptions.APIOptions, smithyhttp.SetHeaderValue("X-Amz-Expires", "60"))
70+
stsOptions.APIOptions = append(stsOptions.APIOptions,
71+
// Add clusterId Header.
72+
smithyhttp.SetHeaderValue(clusterIDHeader, clusterID),
73+
// Add X-Amz-Expires query param.
74+
smithyhttp.SetHeaderValue("X-Amz-Expires", "60"),
75+
// Remove any extraneous headers: https://github.com/eksctl-io/eksctl/issues/7486.
76+
func(stack *middleware.Stack) error {
77+
_, err := stack.Finalize.Remove((&retry.MetricsHeader{}).ID())
78+
return err
79+
})
7180
}
7281
}

0 commit comments

Comments
 (0)