-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: application of sigv4a #1186
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5464aa1
Fix sigv4a application
lauzadis c04e2d5
Simplify
lauzadis 88a29b2
ktlint
lauzadis 4b19660
changelog
lauzadis 7acd860
Add a check for if SigV4ATrait is already applied
lauzadis fd3e47b
Merge branch 'main' of github.com:awslabs/aws-sdk-kotlin into fix-sigv4a
lauzadis 17a5bbc
Add a special-case for CloudFront KVS
lauzadis 4966aed
ktlint
lauzadis 088f490
Merge branch 'main' of github.com:awslabs/aws-sdk-kotlin into fix-sigv4a
lauzadis 10804da
Relocate file and preserve existing auth trait values
lauzadis 9138074
Check first element
lauzadis dc4e09d
Add explanation of SigV4A being added to the end
lauzadis d60f45e
Remove "cloudfront keyvaluestore" from SigV4AsymmetricTraitCustomization
lauzadis 5184124
Remove lonely comment
lauzadis 17ab7d9
Add a check when applying the SigV4A trait
lauzadis 7761766
ktlint
lauzadis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"id": "517318e5-0ba6-472c-a51f-bb4e758215e2", | ||
"type": "bugfix", | ||
"description": "Fix application of sigv4a authentication scheme for S3, Eventbridge, and CloudFront KeyValueStore" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...s/sdk/kotlin/codegen/customization/cloudfrontkeyvaluestore/BackfillSigV4ACustomization.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package aws.sdk.kotlin.codegen.customization.cloudfrontkeyvaluestore | ||
|
||
import software.amazon.smithy.aws.traits.ServiceTrait | ||
import software.amazon.smithy.aws.traits.auth.SigV4ATrait | ||
import software.amazon.smithy.aws.traits.auth.SigV4Trait | ||
import software.amazon.smithy.kotlin.codegen.KotlinSettings | ||
import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration | ||
import software.amazon.smithy.kotlin.codegen.model.getTrait | ||
import software.amazon.smithy.model.Model | ||
import software.amazon.smithy.model.shapes.ServiceShape | ||
import software.amazon.smithy.model.traits.AuthTrait | ||
import software.amazon.smithy.model.transform.ModelTransformer | ||
|
||
/** | ||
* Modify the [AuthTrait] of the CloudFront KeyValueStore service, placing SigV4A before SigV4 in the | ||
* prioritized list. | ||
*/ | ||
class BackfillSigV4ACustomization : KotlinIntegration { | ||
override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = settings.sdkId.lowercase() == "cloudfront keyvaluestore" | ||
|
||
override fun preprocessModel(model: Model, settings: KotlinSettings): Model = | ||
ModelTransformer.create().mapShapes(model) { shape -> | ||
when (shape.isServiceShape) { | ||
true -> { | ||
val builder = (shape as ServiceShape).toBuilder() | ||
|
||
builder.addTrait( | ||
SigV4ATrait.builder() | ||
.name(shape.getTrait<SigV4Trait>()?.name ?: shape.getTrait<ServiceTrait>()?.arnNamespace) | ||
.build(), | ||
) | ||
|
||
val authTraitValueSet = shape.getTrait<AuthTrait>()?.valueSet ?: mutableSetOf() | ||
|
||
if (authTraitValueSet.firstOrNull() != SigV4ATrait.ID) { | ||
// remove existing auth trait | ||
builder.removeTrait(AuthTrait.ID) | ||
|
||
// add a new auth trait with SigV4A in front of the existing values | ||
builder.addTrait(AuthTrait(mutableSetOf(SigV4ATrait.ID) + authTraitValueSet)) | ||
} | ||
|
||
builder.build() | ||
} | ||
false -> shape | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Probably want a remark in here about why this is ordered this way.
(It's because existing services (cloudfront KVS excluded) that use sigv4a do so through endpoint rules and it's not on the model. We don't know which operations it should apply for in those cases and so the safest thing to do is add it at the end and let endpoint rules change the priority as needed. Adding it this way registers support for the trait to let the rest of codegen Just Work (TM)).