From 3b0a740f2daddb9f97ccaf38889a66ca2716797a Mon Sep 17 00:00:00 2001 From: Sam Seelbach Date: Fri, 6 Dec 2024 14:29:30 -0500 Subject: [PATCH] Add support for vpc-lattice auth according to https://docs.aws.amazon.com/vpc-lattice/latest/ug/sigv4-authenticated-requests.html --- src/Private/ServiceName.cs | 1 + src/Private/Signer.cs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Private/ServiceName.cs b/src/Private/ServiceName.cs index 1974da04..9d104163 100644 --- a/src/Private/ServiceName.cs +++ b/src/Private/ServiceName.cs @@ -4,5 +4,6 @@ internal static class ServiceName { internal const string OpenSearchServerless = "aoss"; internal const string S3 = "s3"; + internal const string VpcLatticeService = "vpc-lattice-svcs"; } } diff --git a/src/Private/Signer.cs b/src/Private/Signer.cs index 405d0e50..9c78cc9f 100644 --- a/src/Private/Signer.cs +++ b/src/Private/Signer.cs @@ -23,7 +23,9 @@ public static async Task SignAsync( UpdateRequestUri(request, baseAddress); - var contentHash = await ContentHash.CalculateAsync(request.Content).ConfigureAwait(false); + var contentHash = serviceName == ServiceName.VpcLatticeService ? + "UNSIGNED-PAYLOAD" : + await ContentHash.CalculateAsync(request.Content).ConfigureAwait(false); AddHeaders(request, now, serviceName, credentials, contentHash); @@ -136,6 +138,7 @@ private static void AddHeaders( request.AddHeaderIf(credentials.UseToken, HeaderKeys.XAmzSecurityTokenHeader, credentials.Token); request.AddHeaderIf(!request.Headers.Contains(HeaderKeys.HostHeader), HeaderKeys.HostHeader, request.RequestUri!.Host); request.AddHeaderIf(serviceName == ServiceName.OpenSearchServerless, HeaderKeys.XAmzContentSha256Header, contentHash); + request.AddHeaderIf(serviceName == ServiceName.VpcLatticeService, HeaderKeys.XAmzContentSha256Header, contentHash); request.AddHeaderIf(serviceName == ServiceName.S3, HeaderKeys.XAmzContentSha256Header, contentHash); }