Skip to main content


Alma CDK Origin Verify

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.



diagram


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

experimental

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

Release files for alma-cdk.origin-verify 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for alma-cdk.origin-verify 1.1.0
File Size Uploaded
alma_cdk_origin_verify-1.1.0.tar.gz 134.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for alma-cdk.origin-verify 1.1.0
File Interpreter ABI Platform
alma_cdk_origin_verify-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 266.4 kB

Release files / alma_cdk_origin_verify-1.1.0.tar.gz

Download URL alma_cdk_origin_verify-1.1.0.tar.gz
Size 134.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f46897dbc53d63cdb413bc569f200cf6b9f429c85050dec8d1606a9fe51dba29
BLAKE2b-256 checksum
How to use checksums
9253aae9a16cf4b5d35d44a9bf93ff277b05ffbcc4ca24fb7b0676c850511133
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.14.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log

Release files / alma_cdk_origin_verify-1.1.0-py3-none-any.whl

Download URL alma_cdk_origin_verify-1.1.0-py3-none-any.whl
Size 132.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
afa763b816545321f2f0db3320fa55a3d62b6bbaff10fc0acb2b4bc4e42e2516
BLAKE2b-256 checksum
How to use checksums
7279d96ec2de88a38f2f084d8bff2c4766a96e4bf568d0f215780668b3a04b43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.14.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page