Skip to content

Commit

Permalink
Rollout as a code (#161)
Browse files Browse the repository at this point in the history
* feat: implement single CloudFormation template

* fix: remove old templates

* fix: remove whitespaces

* feat: attach domain name and its certificate to CloudFront distribution

* feat: add condition to attach aliases

* fix: add NoValue for default properties

* chore: minor change

* chore: fix description

* feat: ability to specify multiple domain names

* fix: replace secret's JSON creation to basic join func

* fix: don't ask for secret region, use us-east-1 by default

* fix: domainName to domainNames

* feat: add cfn-guard rules for the template

* feat: add GitHub action for cfn validation

* fix: fix call

* fix: fix paths

---------

Co-authored-by: Sergey Shelomentsev <sergey.shelomentsev@fingerprint.com>
  • Loading branch information
Sergey Shelomentsev and Sergey Shelomentsev committed Dec 14, 2023
1 parent 6296abd commit 665f8bb
Show file tree
Hide file tree
Showing 5 changed files with 346 additions and 355 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/check-cloudformation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Rules to check CloudFormation template

on:
pull_request:
paths:
- cloudformation/*

jobs:
validate:
name: Validate template
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install cfn-guard
run: curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/aws-cloudformation/cloudformation-guard/main/install-guard.sh | sh

- name: Validate
run: ~/.guard/bin/cfn-guard validate --rules cloudformation/rules.guard --data cloudformation/template.yml


97 changes: 0 additions & 97 deletions cloudformation/minimal-template.yml

This file was deleted.

100 changes: 100 additions & 0 deletions cloudformation/rules.guard
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
let SecretName = "FingerprintIntegrationSettings"
let DistributionId = "ABCDEF123456"
let FpjsBehaviorPath = "fpjs"
let FpjsGetResultPath = "result"
let FpjsAgentDownloadPath = "agent"
let FpjsPreSharedSecret = "secret-string-123"

rule check_conditions {
Conditions.CreateCloudFrontDistribution exists
Conditions.CreateCloudFrontDistribution is_struct

Conditions.AttachDomainToCloudFront exists
Conditions.AttachDomainToCloudFront is_struct
}

rule check_secret {
Resources.FingerprintIntegrationSettingsSecret {
Type == "AWS::SecretsManager::Secret"
Properties {
SecretString !empty
}
}
}

rule check_lambda {
Resources.FingerprintProCloudfrontLambda {
Type == "AWS::Serverless::Function"
Properties {
Handler == "fingerprintjs-pro-cloudfront-lambda-function.handler"
Runtime == "nodejs16.x"
CodeUri == "s3://fingerprint-pro-cloudfront-integration-lambda-function/release/lambda_latest.zip"
}
}
}

rule check_lambda_role {
Resources.FpIntLambdaFunctionExecutionRole {
Properties {
AssumeRolePolicyDocument {
some Statement[*].Principal.Service == "lambda.amazonaws.com"
some Statement[*].Principal.Service == "edgelambda.amazonaws.com"
}
}
}
}

rule check_lambda_version {
Resources.FingerprintProCloudfrontLambdaVersion {
Type == "AWS::Lambda::Version"
}
}

rule check_mgmt_lambda {
Resources.FingerprintProMgmtLambda {
Type == "AWS::Serverless::Function"
Properties {
Handler == "fingerprintjs-pro-cloudfront-mgmt-lambda-function.handler"
Runtime == "nodejs18.x"
CodeUri == "s3://fingerprint-pro-cloudfront-integration-lambda-function/release/mgmt_lambda_latest.zip"
Timeout == 120
}
}
}

rule check_mgmt_lambda_role {
Resources.FpMgmtLambdaFunctionExecutionRole {
Properties {
AssumeRolePolicyDocument {
some Statement[*].Principal.Service == "lambda.amazonaws.com"
}
}
}
}

rule check_cache_policy {
Resources.FingerprintProCDNCachePolicy {
Type == "AWS::CloudFront::CachePolicy"
Properties {
CachePolicyConfig.MinTTL == 0
CachePolicyConfig.MaxTTL == 180
CachePolicyConfig.DefaultTTL == 180
}
}
}

rule check_cloudfront_distribution {
Resources.CloudFrontDistribution {
Type == "AWS::CloudFront::Distribution"
Condition exists
}
}

rule check_output {
Outputs {
LambdaFunctionName exists
CachePolicyName exists
CloudFrontDistributionId exists
IsCloudFrontDistributionCreatedByDeployment exists
}
}
Loading

0 comments on commit 665f8bb

Please sign in to comment.