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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file alma_cdk_origin_verify-1.0.1.tar.gz.
File metadata
- Download URL: alma_cdk_origin_verify-1.0.1.tar.gz
- Upload date:
- Size: 133.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56061f00542f7948f9ebe697830fedffd21c595f19c50d10da65202fa7d9a4af
|
|
| MD5 |
ebf47551cfea9e0ac6cdd90f93eb803a
|
|
| BLAKE2b-256 |
fa97c5122cdd9fa97cdc18bb15104f405aea5e3251b814aac6870629a1603c8e
|
Provenance
The following attestation bundles were made for alma_cdk_origin_verify-1.0.1.tar.gz:
Publisher:
release.yml on alma-cdk/origin-verify
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
alma_cdk_origin_verify-1.0.1.tar.gz -
Subject digest:
56061f00542f7948f9ebe697830fedffd21c595f19c50d10da65202fa7d9a4af - Sigstore transparency entry: 1246151890
- Sigstore integration time:
-
Permalink:
alma-cdk/origin-verify@eb2ef67afa20ecdbf39ecbdc8b5a4b37e022cf90 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/alma-cdk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@eb2ef67afa20ecdbf39ecbdc8b5a4b37e022cf90 -
Trigger Event:
push
-
Statement type:
File details
Details for the file alma_cdk_origin_verify-1.0.1-py3-none-any.whl.
File metadata
- Download URL: alma_cdk_origin_verify-1.0.1-py3-none-any.whl
- Upload date:
- Size: 132.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6b89b760207339d1dc10c26dacf68ea4286a4d55dbc81e055304af810ead252
|
|
| MD5 |
1e2c14f4465ed50e785019d30707e11e
|
|
| BLAKE2b-256 |
20286b9c76c6f7d098354e17722763e3f7e639ef62c41b4c2a0218bbde389f9a
|
Provenance
The following attestation bundles were made for alma_cdk_origin_verify-1.0.1-py3-none-any.whl:
Publisher:
release.yml on alma-cdk/origin-verify
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
alma_cdk_origin_verify-1.0.1-py3-none-any.whl -
Subject digest:
c6b89b760207339d1dc10c26dacf68ea4286a4d55dbc81e055304af810ead252 - Sigstore transparency entry: 1246151886
- Sigstore integration time:
-
Permalink:
alma-cdk/origin-verify@eb2ef67afa20ecdbf39ecbdc8b5a4b37e022cf90 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/alma-cdk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@eb2ef67afa20ecdbf39ecbdc8b5a4b37e022cf90 -
Trigger Event:
push
-
Statement type: