Skip to content

Commit cf022e8

Browse files
authored
feat: sra identity&auth refactor (#2364)
1 parent 1433025 commit cf022e8

File tree

16,447 files changed

+375940
-1989582
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

16,447 files changed

+375940
-1989582
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "3d28deab-28ab-4b13-89b3-eb1441d90b89",
3+
"type": "feature",
4+
"description": "**BREAKING CHANGE**: V2 endpoint resolution middleware has changed steps from Serialize to Finalize. Middleware that indexes off of this field will need to be updated accordingly.",
5+
"modules": [
6+
"."
7+
]
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "4b09f5bc-a287-465e-90e5-98267752b46b",
3+
"type": "feature",
4+
"description": "Add client config helpers for overriding SigV4 signing name and region.",
5+
"modules": [
6+
"."
7+
]
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "5b1f5186-7cf6-4283-bb29-9ade04d2d3d6",
3+
"type": "feature",
4+
"description": "Support smithy-modeled identity and auth resolution. Service clients can now be configured to override or use additional authentication schemes.",
5+
"modules": [
6+
"."
7+
]
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "cb8e0d47-3b92-4443-96bc-d34db0cefe86",
3+
"type": "feature",
4+
"description": "**BREAKING CHANGE**: Request body checksum middlewares (flex checksums, SHA256, etc.) have changed steps from Build to Finalize. Middleware that indexes off of this field will need to be updated accordingly.",
5+
"modules": [
6+
"."
7+
]
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "f074fcf7-bb8c-43ac-be57-5b407d7efdae",
3+
"type": "feature",
4+
"description": "Refactored endpoint resolution middleware into a single implementation per-service, reducing generated code footprint.",
5+
"modules": [
6+
"."
7+
]
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"id": "fc9d5a0f-6ff6-4fc8-a19e-b9711740be6e",
3+
"type": "feature",
4+
"description": "**BREAKING CHANGE**: DisableHTTPS middleware has changed steps from Serialize to Finalize. Middleware that indexes off of this field will need to be updated accordingly.",
5+
"modules": [
6+
"."
7+
]
8+
}

aws/middleware/metadata.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ func GetServiceID(ctx context.Context) (v string) {
6565
//
6666
// Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues
6767
// to clear all stack values.
68+
//
69+
// Deprecated: This value is unstable. The resolved signing name is available
70+
// in the signer properties object passed to the signer.
6871
func GetSigningName(ctx context.Context) (v string) {
6972
v, _ = middleware.GetStackValue(ctx, signingNameKey{}).(string)
7073
return v
@@ -74,6 +77,9 @@ func GetSigningName(ctx context.Context) (v string) {
7477
//
7578
// Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues
7679
// to clear all stack values.
80+
//
81+
// Deprecated: This value is unstable. The resolved signing region is available
82+
// in the signer properties object passed to the signer.
7783
func GetSigningRegion(ctx context.Context) (v string) {
7884
v, _ = middleware.GetStackValue(ctx, signingRegionKey{}).(string)
7985
return v
@@ -125,10 +131,13 @@ func SetRequiresLegacyEndpoints(ctx context.Context, value bool) context.Context
125131
return middleware.WithStackValue(ctx, requiresLegacyEndpointsKey{}, value)
126132
}
127133

128-
// SetSigningName set or modifies the signing name on the context.
134+
// SetSigningName set or modifies the sigv4 or sigv4a signing name on the context.
129135
//
130136
// Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues
131137
// to clear all stack values.
138+
//
139+
// Deprecated: This value is unstable. Use WithSigV4SigningName client option
140+
// funcs instead.
132141
func SetSigningName(ctx context.Context, value string) context.Context {
133142
return middleware.WithStackValue(ctx, signingNameKey{}, value)
134143
}
@@ -137,6 +146,9 @@ func SetSigningName(ctx context.Context, value string) context.Context {
137146
//
138147
// Scoped to stack values. Use github.com/aws/smithy-go/middleware#ClearStackValues
139148
// to clear all stack values.
149+
//
150+
// Deprecated: This value is unstable. Use WithSigV4SigningRegion client option
151+
// funcs instead.
140152
func SetSigningRegion(ctx context.Context, value string) context.Context {
141153
return middleware.WithStackValue(ctx, signingRegionKey{}, value)
142154
}

aws/signer/v4/middleware.go

Lines changed: 41 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (e *SigningError) Unwrap() error {
5858
// S3 PutObject API allows unsigned payload signing auth usage when TLS is enabled, and uses this middleware to
5959
// dynamically switch between unsigned and signed payload based on TLS state for request.
6060
func UseDynamicPayloadSigningMiddleware(stack *middleware.Stack) error {
61-
_, err := stack.Build.Swap(computePayloadHashMiddlewareID, &dynamicPayloadSigningMiddleware{})
61+
_, err := stack.Finalize.Swap(computePayloadHashMiddlewareID, &dynamicPayloadSigningMiddleware{})
6262
return err
6363
}
6464

@@ -71,24 +71,22 @@ func (m *dynamicPayloadSigningMiddleware) ID() string {
7171
return computePayloadHashMiddlewareID
7272
}
7373

74-
// HandleBuild sets a resolver that directs to the payload sha256 compute handler.
75-
func (m *dynamicPayloadSigningMiddleware) HandleBuild(
76-
ctx context.Context, in middleware.BuildInput, next middleware.BuildHandler,
74+
// HandleFinalize delegates SHA256 computation according to whether the request
75+
// is TLS-enabled.
76+
func (m *dynamicPayloadSigningMiddleware) HandleFinalize(
77+
ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler,
7778
) (
78-
out middleware.BuildOutput, metadata middleware.Metadata, err error,
79+
out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
7980
) {
8081
req, ok := in.Request.(*smithyhttp.Request)
8182
if !ok {
8283
return out, metadata, fmt.Errorf("unknown transport type %T", in.Request)
8384
}
8485

85-
// if TLS is enabled, use unsigned payload when supported
8686
if req.IsHTTPS() {
87-
return (&unsignedPayload{}).HandleBuild(ctx, in, next)
87+
return (&unsignedPayload{}).HandleFinalize(ctx, in, next)
8888
}
89-
90-
// else fall back to signed payload
91-
return (&computePayloadSHA256{}).HandleBuild(ctx, in, next)
89+
return (&computePayloadSHA256{}).HandleFinalize(ctx, in, next)
9290
}
9391

9492
// unsignedPayload sets the SigV4 request payload hash to unsigned.
@@ -104,31 +102,24 @@ type unsignedPayload struct{}
104102
// AddUnsignedPayloadMiddleware adds unsignedPayload to the operation
105103
// middleware stack
106104
func AddUnsignedPayloadMiddleware(stack *middleware.Stack) error {
107-
return stack.Build.Add(&unsignedPayload{}, middleware.After)
105+
return stack.Finalize.Insert(&unsignedPayload{}, "ResolveEndpointV2", middleware.After)
108106
}
109107

110108
// ID returns the unsignedPayload identifier
111109
func (m *unsignedPayload) ID() string {
112110
return computePayloadHashMiddlewareID
113111
}
114112

115-
// HandleBuild sets the payload hash to be an unsigned payload
116-
func (m *unsignedPayload) HandleBuild(
117-
ctx context.Context, in middleware.BuildInput, next middleware.BuildHandler,
113+
// HandleFinalize sets the payload hash magic value to the unsigned sentinel.
114+
func (m *unsignedPayload) HandleFinalize(
115+
ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler,
118116
) (
119-
out middleware.BuildOutput, metadata middleware.Metadata, err error,
117+
out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
120118
) {
121-
// This should not compute the content SHA256 if the value is already
122-
// known. (e.g. application pre-computed SHA256 before making API call).
123-
// Does not have any tight coupling to the X-Amz-Content-Sha256 header, if
124-
// that header is provided a middleware must translate it into the context.
125-
contentSHA := GetPayloadHash(ctx)
126-
if len(contentSHA) == 0 {
127-
contentSHA = v4Internal.UnsignedPayload
119+
if GetPayloadHash(ctx) == "" {
120+
ctx = SetPayloadHash(ctx, v4Internal.UnsignedPayload)
128121
}
129-
130-
ctx = SetPayloadHash(ctx, contentSHA)
131-
return next.HandleBuild(ctx, in)
122+
return next.HandleFinalize(ctx, in)
132123
}
133124

134125
// computePayloadSHA256 computes SHA256 payload hash to sign.
@@ -144,13 +135,13 @@ type computePayloadSHA256 struct{}
144135
// AddComputePayloadSHA256Middleware adds computePayloadSHA256 to the
145136
// operation middleware stack
146137
func AddComputePayloadSHA256Middleware(stack *middleware.Stack) error {
147-
return stack.Build.Add(&computePayloadSHA256{}, middleware.After)
138+
return stack.Finalize.Insert(&computePayloadSHA256{}, "ResolveEndpointV2", middleware.After)
148139
}
149140

150141
// RemoveComputePayloadSHA256Middleware removes computePayloadSHA256 from the
151142
// operation middleware stack
152143
func RemoveComputePayloadSHA256Middleware(stack *middleware.Stack) error {
153-
_, err := stack.Build.Remove(computePayloadHashMiddlewareID)
144+
_, err := stack.Finalize.Remove(computePayloadHashMiddlewareID)
154145
return err
155146
}
156147

@@ -159,27 +150,24 @@ func (m *computePayloadSHA256) ID() string {
159150
return computePayloadHashMiddlewareID
160151
}
161152

162-
// HandleBuild compute the payload hash for the request payload
163-
func (m *computePayloadSHA256) HandleBuild(
164-
ctx context.Context, in middleware.BuildInput, next middleware.BuildHandler,
153+
// HandleFinalize computes the payload hash for the request, storing it to the
154+
// context. This is a no-op if a caller has previously set that value.
155+
func (m *computePayloadSHA256) HandleFinalize(
156+
ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler,
165157
) (
166-
out middleware.BuildOutput, metadata middleware.Metadata, err error,
158+
out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
167159
) {
160+
if GetPayloadHash(ctx) != "" {
161+
return next.HandleFinalize(ctx, in)
162+
}
163+
168164
req, ok := in.Request.(*smithyhttp.Request)
169165
if !ok {
170166
return out, metadata, &HashComputationError{
171167
Err: fmt.Errorf("unexpected request middleware type %T", in.Request),
172168
}
173169
}
174170

175-
// This should not compute the content SHA256 if the value is already
176-
// known. (e.g. application pre-computed SHA256 before making API call)
177-
// Does not have any tight coupling to the X-Amz-Content-Sha256 header, if
178-
// that header is provided a middleware must translate it into the context.
179-
if contentSHA := GetPayloadHash(ctx); len(contentSHA) != 0 {
180-
return next.HandleBuild(ctx, in)
181-
}
182-
183171
hash := sha256.New()
184172
if stream := req.GetStream(); stream != nil {
185173
_, err = io.Copy(hash, stream)
@@ -198,7 +186,7 @@ func (m *computePayloadSHA256) HandleBuild(
198186

199187
ctx = SetPayloadHash(ctx, hex.EncodeToString(hash.Sum(nil)))
200188

201-
return next.HandleBuild(ctx, in)
189+
return next.HandleFinalize(ctx, in)
202190
}
203191

204192
// SwapComputePayloadSHA256ForUnsignedPayloadMiddleware replaces the
@@ -207,7 +195,7 @@ func (m *computePayloadSHA256) HandleBuild(
207195
// Use this to disable computing the Payload SHA256 checksum and instead use
208196
// UNSIGNED-PAYLOAD for the SHA256 value.
209197
func SwapComputePayloadSHA256ForUnsignedPayloadMiddleware(stack *middleware.Stack) error {
210-
_, err := stack.Build.Swap(computePayloadHashMiddlewareID, &unsignedPayload{})
198+
_, err := stack.Finalize.Swap(computePayloadHashMiddlewareID, &unsignedPayload{})
211199
return err
212200
}
213201

@@ -218,13 +206,13 @@ type contentSHA256Header struct{}
218206
// AddContentSHA256HeaderMiddleware adds ContentSHA256Header to the
219207
// operation middleware stack
220208
func AddContentSHA256HeaderMiddleware(stack *middleware.Stack) error {
221-
return stack.Build.Insert(&contentSHA256Header{}, computePayloadHashMiddlewareID, middleware.After)
209+
return stack.Finalize.Insert(&contentSHA256Header{}, computePayloadHashMiddlewareID, middleware.After)
222210
}
223211

224212
// RemoveContentSHA256HeaderMiddleware removes contentSHA256Header middleware
225213
// from the operation middleware stack
226214
func RemoveContentSHA256HeaderMiddleware(stack *middleware.Stack) error {
227-
_, err := stack.Build.Remove((*contentSHA256Header)(nil).ID())
215+
_, err := stack.Finalize.Remove((*contentSHA256Header)(nil).ID())
228216
return err
229217
}
230218

@@ -233,21 +221,20 @@ func (m *contentSHA256Header) ID() string {
233221
return "SigV4ContentSHA256Header"
234222
}
235223

236-
// HandleBuild sets the X-Amz-Content-Sha256 header value to the Payload hash
224+
// HandleFinalize sets the X-Amz-Content-Sha256 header value to the Payload hash
237225
// stored in the context.
238-
func (m *contentSHA256Header) HandleBuild(
239-
ctx context.Context, in middleware.BuildInput, next middleware.BuildHandler,
226+
func (m *contentSHA256Header) HandleFinalize(
227+
ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler,
240228
) (
241-
out middleware.BuildOutput, metadata middleware.Metadata, err error,
229+
out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
242230
) {
243231
req, ok := in.Request.(*smithyhttp.Request)
244232
if !ok {
245233
return out, metadata, &HashComputationError{Err: fmt.Errorf("unexpected request middleware type %T", in.Request)}
246234
}
247235

248236
req.Header.Set(v4Internal.ContentSHAKey, GetPayloadHash(ctx))
249-
250-
return next.HandleBuild(ctx, in)
237+
return next.HandleFinalize(ctx, in)
251238
}
252239

253240
// SignHTTPRequestMiddlewareOptions is the configuration options for the SignHTTPRequestMiddleware middleware.
@@ -332,17 +319,17 @@ type streamingEventsPayload struct{}
332319

333320
// AddStreamingEventsPayload adds the streamingEventsPayload middleware to the stack.
334321
func AddStreamingEventsPayload(stack *middleware.Stack) error {
335-
return stack.Build.Add(&streamingEventsPayload{}, middleware.After)
322+
return stack.Finalize.Add(&streamingEventsPayload{}, middleware.Before)
336323
}
337324

338325
func (s *streamingEventsPayload) ID() string {
339326
return computePayloadHashMiddlewareID
340327
}
341328

342-
func (s *streamingEventsPayload) HandleBuild(
343-
ctx context.Context, in middleware.BuildInput, next middleware.BuildHandler,
329+
func (s *streamingEventsPayload) HandleFinalize(
330+
ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler,
344331
) (
345-
out middleware.BuildOutput, metadata middleware.Metadata, err error,
332+
out middleware.FinalizeOutput, metadata middleware.Metadata, err error,
346333
) {
347334
contentSHA := GetPayloadHash(ctx)
348335
if len(contentSHA) == 0 {
@@ -351,7 +338,7 @@ func (s *streamingEventsPayload) HandleBuild(
351338

352339
ctx = SetPayloadHash(ctx, contentSHA)
353340

354-
return next.HandleBuild(ctx, in)
341+
return next.HandleFinalize(ctx, in)
355342
}
356343

357344
// GetSignedRequestSignature attempts to extract the signature of the request.

0 commit comments

Comments
 (0)