Setting Values for CloudFormation Template (CFT) Parameters and Pseudo Parameters
When DevOps engineers write IaC templates, they'll often use parameters and pseudo parameters to enable using the same infrastructure for different purposes and environments. InsightCloudSec can run IaC scans on these templates without manually providing any values for them because the default value from the template is used (if one is specified) or a new value is generated as necessary (if there isn't a default specified).
However, InsightCloudSec can more accurately simulate IaC resources if it has the same parameter and pseudo parameter values that AWS does when CloudFormation creates a stack. To support these more accurate simulations, the mimics
client accepts containing values for parameters using the --parameters-path
flag and values for pseudo parameters using the --overrides-path
flag.
CFT Parameters
Here's an example of a CFT defining an application that's deployed with different instance sizes in development and production environments:
yaml
1AWSTemplateFormatVersion: "2010-09-09"2Description: Example template with parameterized instance sizes3Parameters:4ParameterizedInstanceType:5Type: String6Default: t2.micro7AllowedValues:8- t2.micro9- m1.large10Description: Use large instances in production, small instances in development11Resources:12AppInstance:13Type: AWS::EC2::Instance14Properties:15InstanceType:16Ref: ParameterizedInstanceType17ImageId: example-ami
This template defines a parameter named ParameterizedInstanceType
in its Parameters
block, which is later used in the Resources
block. As a result, DevOps users can specify it as a variable when the stack is created rather than in the template itself. In many automated workflows, they do so by specifying a parameter file to aws create-stack
:
sh
1aws cloudformation create-stack \2--stack-name ExampleStack \3--template-body file://template.yaml4--parameters file://example-parameters.json
The file can have any name, so CloudFormation users simply pass that name to the create-stack
subcommand. In this case, example-parameters.json
contains a JSON array of parameter objects in an AWS-specific format:
json
1[2{3"ParameterKey": "ParameterizedInstanceType",4"ParameterValue": "m1.large"5}6]
This is a simple example, but CFTs often have dozens of user-defined parameters. If no file is provided or if the parameter name isn't in the parameters file, CloudFormation will use the Default
value with which the parameter was defined in the template.
Setting Parameter Values in InsightCloudSec CFT Scans
Because the create-stack
command expects the format listed in the example above, DevOps teams using CFT probably already have files in this format. For convenience, the mimics
--parameters-path
flag accepts the same format; you can use these files without modification. InsightCloudSec uses the "ParameterKey"
and "ParameterValue"
keys in the objects and ignores all other keys.
For example, if a DevOps team sets parameter values in a file named example-parameters.json
, you could provide it to mimics
with a command like this:
sh
1$ mimics scan \2./example-cft.json \3--base-url=ics-url.net \4--ics-config='Example Configuration Name' \5--report-formats=html \6--parameters-path=./example-parameters.json
As with CloudFormation, if no file is provided to InsightCloudSec or if the parameter name isn't in the parameters file, InsightCloudSec will use the Default
value with which the parameter was defined in the template.
CFT Pseudo Parameters
CFT resources can also use values for AWS-specific parameters called pseudo parameters, which can specify the current account ID, region name, and other deployment-time values that can't be changed in templates. For example, it's common to dynamically generate ARNs for resources using the AWS::AccountId
and AWS::Region
pseudo parameters:
yaml
1Resources:2DynamicAccessPolicy:3Type: AWS::IAM::Policy4Properties:5PolicyName: ExampleDynamicPolicy6Roles:7- Ref: ExampleRole8PolicyDocument:9Version: "2012-10-17"10Statement:11- Sid: ReceieveFromAny12Effect: Allow13Action:14- sqs:ReceiveMessage15Resource:16- Fn::Join:17- ""18- - "arn:aws:sqs:"19- Ref: AWS::Region20- ":"21- Ref: AWS::AccountNumber22- ":*"
Note that CFT authors can't specify custom values for these parameters. Instead, AWS will substitute these values in the cloud when the stack is created. In this case, the ARN constructed in Fn::Join
will be a valid ARN pattern for all SQS queues in the region and account in which the stack is created.
For accurate and complete analysis, it can be helpful to set these values for InsightCloudSec scans. For example, in the template above, providing the correct account number can help us accurately analyze for policies granting permissions to principals in unknown accounts.
Setting Pseudo Parameter Values in InsightCloudSec CFT Scans
To specify values for pseudo parameters, create a file to provide to the mimics
--overrides
flag. This file can have any name and should contain a single JSON object mapping pseudo parameter names to the values you want to substitute:
json
1{2"AWS::AccountId": "123456789012",3"AWS::Region": "us-west-2"4}
Use this file with the --overrides
flag to set these values in scans:
sh
1$ mimics scan \2./example-cft.json \3--base-url=ics-url.net \4--ics-config='Example Configuration Name' \5--report-formats=html \6--overrides-path=./example-pseudo-params.json
You can also specify the names of user-specified parameters as keys; if you do, they will take precedent over values set in the file passed via --parameters-path
. This allows you to override values in the parameters files your DevOps team uses without changing those configuration files:
json
1{2"AWS::AccountId": "123456789012",3"AWS::Region": "us-west-2",4"ParameterizedInstanceType": "fake.ics.scan.instance.type"5}
The values for pseudo parameters will likely be different depending on the pipeline in which the template is used; a single CFT could be used by many pipelines to define deployments in different environments. Work with CFT authors and pipeline teams to determine how to choose values for pseudo parameters in this file for each pipeline in which the template is used.