critter - AWS Config Rule Integration TesTER
critter enables AWS Config rule integration testing. Use it to validate that AWS Config rules evaluate resources as expected.
Customers use AWS Config rules to evaluate their AWS resources against their own unique compliance and governance requirements. critter is a command line tool that enables a continuous integration workflow to validate that Config rules evaluate resources as expected. This is essential to guaranteeing compliance within AWS accounts, especially when you consider the potential impact of unexpected behavior from Config rule auto-remediations.
This project is in MVP phase - it is functional but the api may change significantly before release 1.0.
Overview
Usage of critter within the Config rule development workflow looks like this:
- Developer writes Config custom rule evaluation Lambda function code that evaluates AWS resources.
- Example Config custom rules Python code
crittercan also test Config managed rules
- Developer deploys their Config rule and Lambda function.
- CloudFormation, the RDK (Rule Development Kit), or Terraform can be used to deploy Config rules.
- Example Config rules CloudFormation templates
- Developer creates a CloudFormation template that defines test resources to be evaluated by the Config rule
- Example
crittertest CloudFormation templates - The template declares a few outputs that will be used by
critterResources: CompliantResource1: # ... CompliantResource2: # ... NonCompliantResource1: # ... NonCompliantResource2: # ... Outputs: ConfigRuleName: Value: my-custom-config-rule CompliantResourceIds: Value: !Sub "${CompliantResource1.Id},${CompliantResource2.Id}" NonCompliantResourceIds: Value: !Sub "${NonCompliantResource1.Id},${NonCompliantResource2.Id}"
- Example
- Developer triggers
critterfrom the command line (or from within a CI/CD system).critterthen ...- Deploys the
crittertest CloudFormation stack - Waits for the resources to be evaluated by the Config rule
- Validates that resources declared in output
CompliantResourceIdswere evaluated asCOMPLIANTand resources declared in outputNonCompliantResourceIdswere evaluated asNON_COMPLIANT - Deletes the
crittertest CloudFormation stack
- Deploys the
- Developer is confident their Config rule will evaluate resources as expected!
Install
Install with Python pip from the GitHub project using git + ssh:
pip install git+ssh://git@github.com:awslabs/critter.git
After critter is installed, you can verify the installation by showing the help: critter -h.
Usage
- Deploy an AWS Config rule. The rule can be a managed rule or a custom rule that utilizes an AWS Lambda function for resource valuation.
- Create a
crittertest CloudFormation template (i.e.my-test-template.yml) that deploys at least one resource you expect the rule to evaluate asCOMPLIANTand at least one resource you expect the rule to evaluate asNON_COMPLIANT. - Declare the following
Outputsin thecrittertest CloudFormation template (documentation below):ConfigRuleName: The name of the Config rule to testCompliantResourceIds: A comma separated list of one or more AWS Config resource IDs expected to be evaluated asCOMPLIANT.NonCompliantResourceIds: A comma separated list of one or more AWS Config resource IDs expected to be evaluated asNON_COMPLIANT.
critter TEMPLATE(i.e.critter ./my-test-template.yml) deploys thecrittertest CloudFormation stack and validates the resource evaluations.critterAWS integration is configured with standardboto3configuration (environment variables and the~/.aws/configfile).- The
crittertest CloudFormation stack will be deleted after testingOnSuccessby default (i.e. if all tests pass). This behavior can be controlled with--delete-stack.
Continuous Integration
To understand how critter can be utilized in a Continuous Integration (CI) workflow to automatically test changes to AWS Config rules, see the AWS CodeBuild CI example in examples/ci-pipelines/aws-codebuild/.
AWS Config Resource IDs
Most AWS resources have an id attribute (or similar) that is used as the AWS Config resource ID. For EC2 instances, resource IDs are the EC2 instance IDs (i.e. i-111111111aaaaaaaa,i-222222222bbbbbbbb). For VPC security groups, the resource ID is the security group ID (i.e. sg-333333333cccccccc). For IAM roles, the resource ID is the role ID (i.e. AROAJI4AVVEXAMPLE, which can be retrieved in a CloudFormation template using Fn::Sub '${MyIamRole.RoleId}').
Generally, resource IDs can be obtained using the CloudFormation intrinsic Ref function with the resource's logical name. To confirm which attribute is used as a resource's Config resource ID, there are a few options:
- Browse resources in the AWS Config console
- Browse resources using the AWS CLI:
aws configservice list-discovered-resources --resource-type AWS::EC2::Instance - See the
resourceIdfield on example configuration items here.
critter Test CloudFormation Stack Outputs
See example critter test CloudFormation templates in the ./examples/test-stacks/. Below is an explanation of each of the supported test stack outputs. Note that CloudFormation stack outputs are always strings.
ConfigRuleName- AWS Config rule name to be tested. Be sure the rule is already deployed within the account and Region the
crittertest CloudFormation stack will be deployed to. - Example values:
"my-custom-config-rule"
- AWS Config rule name to be tested. Be sure the rule is already deployed within the account and Region the
CompliantResourceIds- A comma separated list of one or more AWS Config resource IDs expected to be evaluated as
COMPLIANT. At least one ofCompliantResourceIdsandNonCompliantResourceIdsmust be output. - Typically generated with
!Sub "${CompliantResource1.Id},${CompliantResource2.Id}" - Example values:
"i-11111111111111111""sg-22222222222222222,sg-33333333333333333"
- A comma separated list of one or more AWS Config resource IDs expected to be evaluated as
NonCompliantResourceIds- A comma separated list of one or more AWS Config resource IDs expected to be evaluated as
NON_COMPLIANT. At least one ofCompliantResourceIdsandNonCompliantResourceIdsmust be output. - Typically generated with
!Sub "${NonCompliantResource1.Id},${NonCompliantResource2.Id}" - Example values:
"sg-11111111111111111""i-22222222222222222,i-33333333333333333"
- A comma separated list of one or more AWS Config resource IDs expected to be evaluated as
DelayAfterDeploy- Seconds to delay after
crittertest CloudFormation stack create or update. If the test stack is already deployed and no update occurs, the delay will be skipped. - Example values:
"60"
- Seconds to delay after
SkipWaitForResourceRecording- Skip waiting for resources to be recorded in Config. Useful if Config rule is testing resources not natively supported by Config.
- Allowed values:
"True""False"(default behavior)
CLI Options
Warning - This documentation may become out of date until the api stabilizes. Show the up to date help with critter -h.
$ critter -h
usage: critter [-h] [--trigger-rule-evaluation] [--stack-name STACK-NAME] [--stack-tags '[{"Key": "TagKey", "Value": "TagValue"}, ...]']
[--capabilities CAPABILITY [CAPABILITY ...]] [--delete-stack {Always,OnSuccess,Never}]
TEMPLATE
critter - AWS Config Rule Integration TesTER
positional arguments:
TEMPLATE CloudFormation template(s) to test already deployed Config rule
optional arguments:
-h, --help show this help message and exit
--trigger-rule-evaluation
Trigger Config rule evaluation after CloudFormation stack deployment. Useful for periodic evaluation rules. Also ensures the rule
evaluation occured after stack deployment.
--stack-name STACK-NAME
CloudFormation stack name (default is generated from TEMPLATE file name)
--stack-tags '[{"Key": "TagKey", "Value": "TagValue"}, ...]'
Tags to associate with the CloudFormation stack formatted as a JSON string
--capabilities CAPABILITY [CAPABILITY ...]
CloudFormation capabilities needed to deploy the stack (i.e. CAPABILITY_IAM, CAPABILITY_NAMED_IAM)
--delete-stack {Always,OnSuccess,Never}
Test outcome that should trigger CloudFormation stack delete (default: OnSuccess)
Contributing and Security
See CONTRIBUTING for more information.
License
This project is licensed under the Apache-2.0 License.
Metadata
Release files for critter 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| critter-0.1.3.tar.gz | 17.4 kB | Without provenance | Details for critter-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| critter-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for critter-0.1.3-py3-none-any.whl |
Total release size: 32.5 kB
Release files / critter-0.1.3.tar.gz
| Download URL | critter-0.1.3.tar.gz |
|---|---|
| Size | 17.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f1cfa6c17595bb60bcf578bc4cbd767c2f0dba100cbf3c9541ce0263bf4be1a1
|
|
BLAKE2b-256 checksum How to use checksums |
f9778ff7eff9cbbc2cf226fa78a3c01609c14997593718da1ab3042e6ce256ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Release files / critter-0.1.3-py3-none-any.whl
| Download URL | critter-0.1.3-py3-none-any.whl |
|---|---|
| Size | 15.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2a7ce7f2e442c74a9cb7bcd63c8bfc60f591e9f857ec42f41ac8c96985dc99a7
|
|
BLAKE2b-256 checksum How to use checksums |
dbf4acfe42610fb56c4701bef38a2c134a791f2773120be8aafed16cc8ad0e50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
|
Security for critter 0.1.3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.