The Wayback Machine - https://web.archive.org/web/20221016233952/https://repost.aws/
By using AWS re:Post, you agree to the Terms of Use

Learn AWS faster by following popular topics

see all
1/18

Recent questions

see all
1/18

CloudFront not sending custom headers to origin for additional behavior

# Situation I am currently in the process of migrating on of my pet projects from another provider to AWS. As a first step, I have created a CloudFront distribution sending all requests as-is to the loadbalancer my application is currently running on (external provider). The CDK stack I started with looks like follows: ```java package mypackagename; import software.amazon.awscdk.Stack; import software.amazon.awscdk.StackProps; import software.amazon.awscdk.services.certificatemanager.Certificate; import software.amazon.awscdk.services.cloudfront.*; import software.amazon.awscdk.services.cloudfront.origins.HttpOrigin; import software.constructs.Construct; import java.util.List; import java.util.Map; public class MyServiceNameCloudfrontCdkStack extends Stack { public MyServiceNameCloudfrontCdkStack(final Construct scope, final String id, final StackProps props, final Config config) { super(scope, id, props); Distribution.Builder.create(this, "cloudfront") .priceClass(PriceClass.PRICE_CLASS_ALL) .httpVersion(HttpVersion.HTTP2) .enableIpv6(true) .domainNames(List.of(config.domain())) .certificate(Certificate.fromCertificateArn(this, "sslcert", config.sslCertArn())) .minimumProtocolVersion(SecurityPolicyProtocol.TLS_V1_2_2021) .defaultBehavior( BehaviorOptions.builder() .origin( HttpOrigin.Builder.create("<hostname of the LB at external provider>") .protocolPolicy(OriginProtocolPolicy.HTTP_ONLY) .httpPort(8080) .customHeaders(Map.of( "Forwarded", String.format("host=%s;proto=https", config.domain()), "X-Forwarded-Host", config.domain(), "X-Forwarded-Proto", "https", "X-Forwarded-Port", "443" )) .build() ) .compress(true) .viewerProtocolPolicy(ViewerProtocolPolicy.REDIRECT_TO_HTTPS) .allowedMethods(AllowedMethods.ALLOW_ALL) .cachePolicy(CachePolicy.CACHING_DISABLED) .originRequestPolicy(OriginRequestPolicy.ALL_VIEWER) .build() ) .enableLogging(false) .enabled(true) .build(); } public record Config(String domain, String sslCertArn) {} } ``` With this stack, everything works as expected. As a second step, I updated the CDK stack to have separate behaviors for each of the components I'm planning to split my logic to in the future. They all still use the same origin but with some minor changes to the behavior. The updated CDK stack looks like follows: ```java package mypackagename; import software.amazon.awscdk.Stack; import software.amazon.awscdk.StackProps; import software.amazon.awscdk.services.certificatemanager.Certificate; import software.amazon.awscdk.services.cloudfront.*; import software.amazon.awscdk.services.cloudfront.origins.HttpOrigin; import software.constructs.Construct; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; public class MyServiceNameCloudfrontCdkStack extends Stack { public MyServiceNameCloudfrontCdkStack(final Construct scope, final String id, final StackProps props, final Config config) { super(scope, id, props); // region custom response headers for the fallthrough behaviour (ui stuff) final ResponseHeadersPolicy uiResponseHeadersPolicy = ResponseHeadersPolicy.Builder.create(this, "ui-response-headers-policy") .securityHeadersBehavior( ResponseSecurityHeadersBehavior.builder() .frameOptions( ResponseHeadersFrameOptions.builder() .frameOption(HeadersFrameOption.DENY) .override(true) .build() ) .contentSecurityPolicy( ResponseHeadersContentSecurityPolicy.builder() .contentSecurityPolicy(String.join("; ", "default-src 'self'", "connect-src 'self' https://api.guildwars2.com", "script-src 'self' 'unsafe-inline'", "style-src 'self' 'unsafe-inline'", "img-src 'self' https://icons-gw2.darthmaim-cdn.com/ data:", "frame-src https://www.youtube.com/embed/" )) .override(true) .build() ) .build() ) .build(); // endregion // region the external loadbalancer origin config final IOrigin externalLBOrigin = HttpOrigin.Builder.create("<hostname of the LB at external provider>") .protocolPolicy(OriginProtocolPolicy.HTTP_ONLY) .httpPort(8080) .customHeaders(Map.of( "Forwarded", String.format("host=%s;proto=https", config.domain()), "X-Forwarded-Host", config.domain(), "X-Forwarded-Proto", "https", "X-Forwarded-Port", "443" )) .build(); // endregion // region additional behaviours (everything except ui) final Map <String , BehaviorOptions> additionalBehaviors = new LinkedHashMap<>(); additionalBehaviors.put( "/api*", BehaviorOptions.builder() .origin(externalLBOrigin) .compress(true) .viewerProtocolPolicy(ViewerProtocolPolicy.REDIRECT_TO_HTTPS) .allowedMethods(AllowedMethods.ALLOW_ALL) .cachePolicy(CachePolicy.CACHING_DISABLED) .originRequestPolicy(OriginRequestPolicy.ALL_VIEWER) .build() ); additionalBehaviors.put( "/oauth2*", BehaviorOptions.builder() .origin(externalLBOrigin) .compress(true) .viewerProtocolPolicy(ViewerProtocolPolicy.REDIRECT_TO_HTTPS) .allowedMethods(AllowedMethods.ALLOW_ALL) .cachePolicy(CachePolicy.CACHING_DISABLED) .originRequestPolicy(OriginRequestPolicy.ALL_VIEWER) .build() ); additionalBehaviors.put( "/.well-known/oauth-authorization-server", BehaviorOptions.builder() .origin(externalLBOrigin) .compress(true) .viewerProtocolPolicy(ViewerProtocolPolicy.REDIRECT_TO_HTTPS) .allowedMethods(AllowedMethods.ALLOW_GET_HEAD) .cachePolicy(CachePolicy.CACHING_DISABLED) .build() ); // endregion Distribution.Builder.create(this, "cloudfront") .priceClass(PriceClass.PRICE_CLASS_ALL) .httpVersion(HttpVersion.HTTP2) .enableIpv6(true) .domainNames(List.of(config.domain())) .certificate(Certificate.fromCertificateArn(this, "sslcert", config.sslCertArn())) .minimumProtocolVersion(SecurityPolicyProtocol.TLS_V1_2_2021) .defaultBehavior( BehaviorOptions.builder() .origin(externalLBOrigin) .compress(true) .viewerProtocolPolicy(ViewerProtocolPolicy.REDIRECT_TO_HTTPS) .allowedMethods(AllowedMethods.ALLOW_GET_HEAD) .cachePolicy(CachePolicy.CACHING_OPTIMIZED) .originRequestPolicy(OriginRequestPolicy.ALL_VIEWER) .responseHeadersPolicy(uiResponseHeadersPolicy) .build() ) .additionalBehaviors(additionalBehaviors) .enableLogging(false) .enabled(true) .build(); } public record Config(String domain, String sslCertArn) {} } ``` # Issue Most of the changes work as expected (for example, I see that caching now takes place for the default behavior). BUT: For `/oauth2*` requests, CloudFront does not send all or at least *some* of the defined `customHeaders` to the origin server. I don't know if it also affects the other behaviors, but I know for sure it does affect the `/oauth2*` behavior. This is especially weird because (as expected) the resulting CloudFront Distribution shows only one Origin, which correctly lists the Custom Headers I have set in CDK code. When rolling back to the previous version of my CDK stack everything works as expected again. # Versions Maven Versions: ``` <cdk.version>2.46.0</cdk.version> <constructs.version>[10.0.0,11.0.0)</constructs.version> ``` `cdk.out`: ``` {"version":"21.0.0"} ```
0
answers
0
votes
4
views
asked an hour ago

AWS ECR allow roles from secondary account

I have an ECR in a prod account that I want to grant push access to from the dev role. This is my current policy ```json { "Version": "2008-10-17", "Statement": [ { "Sid": "AllowPushPull", "Effect": "Allow", "Principal": { "AWS": [ "arn:aws:iam::account:role/rolename", "arn:aws:sts::account:assumed-role/rolename/instance", "arn:aws:sts::account:assumed-role/rolename/AWSCLI-Session" ] }, "Action": [ "ecr:BatchCheckLayerAvailability", "ecr:BatchGetImage", "ecr:CompleteLayerUpload", "ecr:DescribeImages", "ecr:DescribeRepositories", "ecr:GetDownloadUrlForLayer", "ecr:GetLifecyclePolicy", "ecr:GetLifecyclePolicyPreview", "ecr:GetRepositoryPolicy", "ecr:InitiateLayerUpload", "ecr:ListImages", "ecr:PutImage", "ecr:PutLifecyclePolicy", "ecr:SetRepositoryPolicy", "ecr:StartLifecyclePolicyPreview", "ecr:UploadLayerPart" ] } ] } ``` Running aws sts get-caller-identity I can see I have the role checked out "arn:aws:sts::account:assumed-role/rolename/AWSCLI-Session" but I do not have access to push. I receive the following until timeout. > The push refers to repository > [account.dkr.ecr.us-west-2.amazonaws.com/repo] 87e2ce75493a: Retrying > in 4 seconds My non-prod account does exist in us-east-1. but my login command specifies west. task: [docker:ecr-login] aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin accpunt.dkr.ecr.us-west-2.amazonaws.com Any ideas what may be my problem on this repo? (this works with my production account so the registry is valid) Also this works when I use my dev account and allow the user IAM
0
answers
0
votes
8
views
asked 10 hours ago

Emailed being rejected from an Amazon SES IP address

Dear Amazon. Please either sort out this IP address (76.223.180.3) or remove it from your pool for ap-south-1. Refer to see bounce notification below: ``` {"notificationType":"Bounce","bounce":{"feedbackId":"01090183ba5cfe35-d0fed3b5-ca5e-4c55-9b88-e88081ca576d-000000","bounceType":"Transient","bounceSubType":"General","bouncedRecipients":[{"emailAddress":"REDACTED@hotmail.fr ","action":"failed","status":"5.7.1","diagnosticCode":"smtp; 550 5.7.1 Unfortunately, messages from [76.223.180.3] weren't sent. Please contact your Internet service provider since part of their network is on our block list (S3140). You can also refer your provider to http://mail.live.com/mail/troubleshooting.aspx#errors . [AM6EUR05FT060.eop-eur05.prod.protection.outlook.com ]"}],"timestamp":"2022-10-09T01:30:00.000Z","remoteMtaIp":"104.47.18.97","reportingMTA":"dns; c180-3.smtp-out.ap-south-1.amazonses.com "},"mail":{"timestamp":"2022-10-09T01:29:58.460Z","source":"info@REDACTED ","sourceArn":"arn:aws:ses:ap-south-1:REDACTED:identity/REDACTED","sourceIp":"REDACTED","callerIdentity":"ses-smtp-user.20201217-221145","sendingAccountId":"REDACTED","messageId":"01090183ba5cf7bc-444ec2e6-b96f-4f6f-b8a7-46bcec8a2dac-000000","destination":["REDACTED@hotmail.fr "],"headersTruncated":false,"headers":[{"name":"Received","value":"from REDACTED ([REDACTED]) by email-smtp.amazonaws.com with SMTP (SimpleEmailService-d-0NU5RY97J) id YEblTafH6wWTtpnr5wO0 for REDACTED@hotmail.fr ; Sun, 09 Oct 2022 01:29:58 +0000 (UTC)"},{"name":"MIME-Version","value":"1.0"},{"name":"From","value":"\"REDACTED\" <info@REDACTED >"},{"name":"To","value":"REDACTED@hotmail.fr "},{"name":"Date","value":"9 Oct 2022 04:29:58 +0300"},{"name":"Subject","value":"=?utf-8?B?TmV3IEZlYXR1cmUg8J+OiSBJbWFnZSBSZW9yZGVyaW5nIPCf?=\r\n =?utf-8?B?lIA=?="},{"name":"Content-Type","value":"text/html; charset=us-ascii"},{"name":"Content-Transfer-Encoding","value":"quoted-printable"}],"commonHeaders":{"from":["REDACTED <info@REDACTED >"],"date":"9 Oct 2022 04:29:58 +0300","to":["REDACTED@hotmail.fr "],"subject":"REDACTED"}}} ``` We've got loads of these from Outlook and Hotmail recipients. By the way, if anyone reading this can recommend another SES region which is more reliable than ap-south-1 for sending email then please let me know.
0
answers
0
votes
3
views
asked a day ago

Recent articles

see all
1/18