
Security News
Socket Integrates With Bun 1.3’s Security Scanner API
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
@studyportals/cdk-cloudfront-auth
Advanced tools
CDK Constructs for adding authentication for a CloudFront Distribution
Easily add Cognito-based authorization to your CloudFront distribution, to place static files behind authorization.
This is based on https://github.com/henrist/cdk-cloudfront-auth.
New features:
userPoolAssumedRole
) that can be assumed in that accountuserPoolDomain
Support for Cognito user pool custom domain (if provided)mode
is now sent as an inputallowedCriterias
can now be used to pass exceptions from the authorization layer
allowedAuthorization?: string[]
is an array of allowed authroization header values that will be matched against the current authorization
headerallowedUserAgents?: string[]
is an array of regexes that will be used to match the current user-agent
allowedURIs?: string[]
is an array of regexes that will be used to match the current uri
allowedIPs?: string[]
is an array of IPs (/32) that will be used to match the current clientIp
concurrencySafe?
is a boolean controlling the creation of a DynamoDB holdings locks for updating the Lambda@Edge functionshttpHeaders
oauthScopes
npm install @studyportals/cdk-cloudfront-auth
Deploy the Lambda@Edge functions to us-east-1:
// In a stack deployed to us-east-1.
const authLambdas = new AuthLambdas(this, "AuthLambdas", {
regions: ["eu-west-1"], // Regions to make Lambda version params available.
})
Deploy the Cognito and CloudFront setup in whatever region of your choice:
const auth = new CloudFrontAuth(this, "Auth", {
cognitoAuthDomain: `${domain.domainName}.auth.${region}.amazoncognito.com`,
authLambdas, // AuthLambdas from above
userPool, // Cognito User Pool (OPTIONAL - if userPoolDomain is defined)
userPoolAssumedRole, // IAM Role to access the Cognito User Pool (OPTIONAL)
userPoolDomain, // Custom User Pool Domain (OPTIONAL - if userPool is defined)
})
const distribution = new cloudfront.Distribution(this, "Distribution", {
defaultBehavior: auth.createProtectedBehavior(origin),
additionalBehaviors: auth.createAuthPagesBehaviors(origin),
})
auth.updateClient("ClientUpdate", {
signOutUrl: `https://${distribution.distributionDomainName}${auth.signOutRedirectTo}`,
callbackUrl: `https://${distribution.distributionDomainName}${auth.callbackPath}`,
})
If using CloudFrontWebDistribution
instead of Distribution
:
const distribution = new cloudfront.CloudFrontWebDistribution(
this,
"Distribution",
{
originConfigs: [
{
behaviors: [
...auth.authPages,
{
isDefaultBehavior: true,
lambdaFunctionAssociations: auth.authFilters,
},
],
},
],
},
)
Sometimes multiple stacks may want to perfom updates to the Lambda@Edge functions. This can cause issues if the updates are not performed sequentially. To prevent this, the concurrencySafe
property can be set to true
. This will create a DynamoDB table that will be used to hold a lock for updating the Lambda@Edge functions. The table DynamoDB table will be created in the same region as the Lambda@Edge function and @studyportals/cdk-lambda-config knows how to handle this.
When updating the Lambda@Edge functions, the old versions will not be deleted. This is because the Lambda@Edge functions are used by CloudFront and CloudFront will not allow you to delete a version that is in use. To work around this, calling the enableAutoCleanup
on the authLambdas
. This will create a Lambda function that will delete the old versions of the Lambda@Edge functions. This function will be triggered by a CloudWatch event that is triggered daily and tries to delete all versions that are not attached to anything. The Lambda function will be created in the same region as the Lambda@Edge function.
// In a stack deployed to us-east-1.
const authLambdas = new AuthLambdas(this, "AuthLambdas", {
regions: ["eu-west-1"], // Regions to make Lambda version params available.
})
authLambdas.enableAutoCleanup()
The CloudFrontAuth
construct accepts a requireGroupAnyOf
property
that causes access to be restricted to only users in specific groups.
FAQs
CDK Constructs for adding authentication for a CloudFront Distribution
The npm package @studyportals/cdk-cloudfront-auth receives a total of 64 weekly downloads. As such, @studyportals/cdk-cloudfront-auth popularity was classified as not popular.
We found that @studyportals/cdk-cloudfront-auth demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 23 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Security News
Python 3.14 adds template strings, deferred annotations, and subinterpreters, plus free-threaded mode, an experimental JIT, and Sigstore verification.
Security News
Former RubyGems maintainers have launched The Gem Cooperative, a new community-run project aimed at rebuilding open governance in the Ruby ecosystem.