Enforce origin traffic via CloudFront.
Project description
npm i -D @alma-cdk/origin-verify
Enforce API Gateway REST API, AppSync GraphQL API, or Application Load Balancer traffic via CloudFront by generating a Secrets Manager secret value which is used as a CloudFront Origin Custom header and a WAFv2 WebACL header match rule.
Essentially this is an implementation of AWS Solution “Enhance Amazon CloudFront Origin Security with AWS WAF and AWS Secrets Manager” without the secret rotation.
🚧 Project Stability
This construct is still versioned with v0
major version and breaking changes might be introduced if necessary (without a major version bump), though we aim to keep the API as stable as possible (even within v0
development). We aim to publish v1.0.0
soon and after that breaking changes will be introduced via major version bumps.
Getting Started
import { OriginVerify } from '@alma-cdk/origin-verify';
import { Distribution } from 'aws-cdk-lib/aws-cloudfront';
const api: RestApi; // TODO: implement the RestApi
const apiDomain: string; // TODO: implement the domain
const verification = new OriginVerify(this, 'OriginVerify', {
origin: api.deploymentStage,
});
new Distribution(this, 'CDN', {
defaultBehavior: {
origin: new HttpOrigin(apiDomain, {
customHeaders: {
[verification.headerName]: verification.headerValue,
},
protocolPolicy: OriginProtocolPolicy.HTTPS_ONLY,
})
},
})
For more detailed example usage see /examples
directory.
Custom Secret Value
Additionally, you may pass in custom secretValue
if you don't want to use a generated secret (which you should use in most cases):
const myCustomValue = SecretValue.unsafePlainText('foobar');
const verification = new OriginVerify(this, 'OriginVerify', {
origin: api.deploymentStage,
secretValue: myCustomValue,
});
Notes
Use OriginProtocolPolicy.HTTPS_ONLY
!
In your CloudFront distribution Origin configuration use OriginProtocolPolicy.HTTPS_ONLY
to avoid exposing the verification.headerValue
secret to the world.
Why secretValue.unsafeUnwrap()
?
Internally this construct creates the headerValue
by using AWS Secrets Manager but the secret value is exposed directly by using secretValue.unsafeUnwrap()
method: This is:
- required, because we must be able to set it into the WAFv2 WebACL rule
- required, because you must be able to set it into the CloudFront Origin Custom Header
- okay, because it's meant to protect the API externally and it's not considered as a secret that should be kept – well – secret within your AWS account
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file alma-cdk.origin-verify-0.0.34.tar.gz
.
File metadata
- Download URL: alma-cdk.origin-verify-0.0.34.tar.gz
- Upload date:
- Size: 129.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91307ee12818c47c7440cd28d9beab79b5f0875252177471e634963b294d9d2c |
|
MD5 | 240095dac80a0ec1a957e48538a0051b |
|
BLAKE2b-256 | e86a5cf15505b8f4ebbe8cf905a7019f0f7946d4b3886f32166f65dc31ba68a1 |
File details
Details for the file alma_cdk.origin_verify-0.0.34-py3-none-any.whl
.
File metadata
- Download URL: alma_cdk.origin_verify-0.0.34-py3-none-any.whl
- Upload date:
- Size: 127.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab4283f7d315cf04898584997a9cea9b0d2dad5d972de14b8a391ef85aa44523 |
|
MD5 | cb4d18108593eeef91f83a0ae1236781 |
|
BLAKE2b-256 | 6fac9b50bd3b784aa76044b1e3d575521404565d61ab290098bd1c66827dc100 |