Skip to content

Commit

Permalink
SigV4A auth selection update
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyRyabinin committed Dec 16, 2024
1 parent 0efa522 commit 7d0fcd6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import lombok.Data;

import java.util.List;
import java.util.Map;

@Data
Expand Down Expand Up @@ -43,4 +44,7 @@ public class Metadata {
private boolean hasPreSignedUrl;

private boolean awsQueryCompatible;

// Priority-ordered list of auth types present on the service model
private List<String> auth;
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,37 @@ protected void addRequestIdToResults(final ServiceModel serviceModel) {
});
}

private static Set<String> servicesMissingMultiAuthMRAPTrait = new HashSet<>();
static {
servicesMissingMultiAuthMRAPTrait.add("S3");
servicesMissingMultiAuthMRAPTrait.add("S3-CRT");
servicesMissingMultiAuthMRAPTrait.add("CloudFront KeyValueStore");
servicesMissingMultiAuthMRAPTrait.add("SESv2");
servicesMissingMultiAuthMRAPTrait.add("EventBridge");
}

private void CheckAndEnableSigV4A(final ServiceModel serviceModel, VelocityContext context) {
List<String> c2jAuthList = serviceModel.getMetadata().getAuth();
String serviceId = serviceModel.getMetadata().getServiceId();
if (c2jAuthList != null && c2jAuthList.contains("aws.auth#sigv4a") ||
servicesMissingMultiAuthMRAPTrait.contains(serviceId)) {
context.put("multiRegionAccessPointSupported", true);
}
// todo: remove these checks later
if (serviceModel.getEndpointRules().contains("\"sigv4a\"") &&
!context.containsKey("multiRegionAccessPointSupported")) {
throw new RuntimeException("Endpoint rules reference sigv4a auth scheme but c2j model " + serviceId +
" does not list aws.auth#sigv4a as a supported auth!");
}
if (c2jAuthList != null) {
boolean hasSigV4AndBearer = c2jAuthList.contains("smithy.api#httpBearerAuth") &&
(c2jAuthList.contains("aws.auth#sigv4a") || c2jAuthList.contains("aws.auth#sigv4"));
if (!serviceModel.isUseSmithyClient() && hasSigV4AndBearer) {
throw new RuntimeException("SDK Clients cannot mix AWS and Bearer Credentials without enabling Smithy Identity!");
}
}
}

protected final VelocityContext createContext(final ServiceModel serviceModel) {
VelocityContext context = new VelocityContext();
context.put("nl", System.lineSeparator());
Expand All @@ -216,9 +247,8 @@ protected final VelocityContext createContext(final ServiceModel serviceModel) {
context.put("output.encoding", StandardCharsets.UTF_8.name());
context.put("nullChar", '\0');

if (serviceModel.getEndpointRules().contains("\"sigv4a\"")) {
context.put("multiRegionAccessPointSupported", true);
}
CheckAndEnableSigV4A(serviceModel, context);

return context;
}

Expand Down

0 comments on commit 7d0fcd6

Please sign in to comment.