Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"fileType": "masterSnapshot",
"snapshots": [
{
"source": "gitConnectorCloudformation",
"testUser": "Shahin",
"nodes": [
{
"masterSnapshotId": "ref_",
"type": "cloudformation",
"collection": "cloudFormation",
"paths":[
"/leaked_secret/"
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"fileType": "snapshot",
"snapshots": [
{
"source": "gitConnectorCloudformation",
"testUser": "Shahin",
"nodes": [
{
"masterSnapshotId": "ref_",
"type": "cloudformation",
"collection": "cloudFormation",
"paths": [
"/leaked_secret/secret.yaml"
],
"snapshotId": "ref_1",
"status": "active",
"validate": true
}
]
}
]
}
40 changes: 40 additions & 0 deletions validation/scenario-cloudformation-secret-fail/master-test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"fileType":"mastertest",
"masterSnapshot":"master-snapshot",
"testSet": [
{
"masterTestName": "AWS_TEST",
"version": "0.1",
"cases": [
{
"masterTestId": "TEST_Ref_1",
"masterSnapshotId": [
"ref_"
],
"type":"rego",
"rule": "file(secrets.rego)",
"evals": [
{
"id": "PR-AWS-0028-RGX",
"eval": "data.rule.gl_aws_secrets"
}
]
},
{
"masterTestId": "TEST_Ref_2",
"masterSnapshotId": [
"ref_"
],
"type":"rego",
"rule": "file(secrets.rego)",
"evals": [
{
"id": "PR-AWS-0029-RGX",
"eval": "data.rule.gl_aws_account"
}
]
}
]
}
]
}
78 changes: 78 additions & 0 deletions validation/scenario-cloudformation-secret-fail/secrets.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package rule

# PR-AWS-0028-RGX
#

default gl_aws_secrets = null

aws_issue["gl_aws_secrets"] {
[path, value] := walk(input)
regexp := "^[A-Za-z0-9/\\+=]{40}$"
regex.match(regexp, format_int(value, 10))
regex.match("^(?i)aws_?(secret)?_?(access)?_?key$", path[_])
}

aws_issue["gl_aws_secrets"] {
[path, value] := walk(input)
regexp := "^[A-Za-z0-9/\\+=]{40}$"
regex.match(regexp, value)
regex.match("^(?i)aws_?(secret)?_?(access)?_?key$", path[_])
}

gl_aws_secrets = false {
aws_issue["gl_aws_secrets"]
}

gl_aws_secrets_err = "There is a possibility that AWS secret has leaked" {
aws_issue["gl_aws_secrets"]
}

gl_aws_secrets_metadata := {
"Policy Code": "PR-AWS-0028-RGX",
"Type": "IaC",
"Product": "AWS",
"Language": "AWS Cloud formation",
"Policy Title": "Secrets should be removed from the source code",
"Policy Description": "We should not have any secret in the source code. Make sure to put the secrets in a vault",
"Resource Type": "",
"Policy Help URL": "",
"Resource Help URL": ""
}

#
# PR-AWS-0029-RGX
#

default gl_aws_account = null

aws_issue["gl_aws_account"] {
[path, value] := walk(input)
regexp := "^[0-9]{12}$"
regex.match(regexp, format_int(value, 10))
}

aws_issue["gl_aws_account"] {
[path, value] := walk(input)
regexp := "^[0-9]{12}$"
regex.match(regexp, value)
}

gl_aws_account = false {
aws_issue["gl_aws_account"]
}

gl_aws_account_err = "There is a possibility that AWS account ID has leaked" {
aws_issue["gl_aws_account"]
}

gl_aws_account_metadata := {
"Policy Code": "PR-AWS-0029-RGX",
"Type": "IaC",
"Product": "AWS",
"Language": "AWS Cloud formation",
"Policy Title": "Secrets should be removed from the source code",
"Policy Description": "We should not have any secret in the source code. Make sure to put the secrets in a vault",
"Resource Type": "",
"Policy Help URL": "",
"Resource Help URL": ""
}
80 changes: 80 additions & 0 deletions validation/scenario-cloudformation-secret-fail/snapshots/ref_1
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"structure": "filesystem",
"error": null,
"reference": "master",
"contentType": "yaml",
"source": "gitConnectorCloudformation",
"paths": [
"/leaked_secret/secret.yaml"
],
"timestamp": 1631619532149,
"queryuser": null,
"checksum": "99914b932bd37a50b983c5e7c90ae93b",
"node": {
"masterSnapshotId": "ref_",
"type": "cloudformation",
"collection": "cloudFormation",
"paths": [
"/leaked_secret/secret.yaml"
],
"snapshotId": "ref_1",
"status": "active",
"validate": true
},
"snapshotId": "ref_1",
"collection": "cloudformation",
"json": {
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": [
{
"Type": "AWS::Lambda::Function",
"Properties": {
"Environment": {
"Variables": {
"AWS_SECRET_ACCESS_KEY": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"AWS_ACCESS_KEY_ID": "ASIAIOSFODNN7EXAMPLE",
"AWS_ACCOUNT_ID": "123456789012"
}
},
"Runtime": "nodejs12.x",
"Role": {
"Fn::GetAtt": [
"FunctionExecutionRole",
"Arn"
]
},
"Handler": "index.handler",
"Code": {
"ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n"
}
},
"Name": "MyProxyFunction"
},
{
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": [
"lambda.amazonaws.com"
]
},
"Action": [
"sts:AssumeRole"
]
}
]
},
"ManagedPolicyArns": [
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
]
},
"Name": "FunctionExecutionRole"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"fileType": "masterSnapshot",
"snapshots": [
{
"source": "gitConnectorCloudformation",
"testUser": "Shahin",
"nodes": [
{
"masterSnapshotId": "ref_",
"type": "cloudformation",
"collection": "cloudFormation",
"paths":[
"/lambda/"
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"fileType": "snapshot",
"snapshots": [
{
"source": "gitConnectorCloudformation",
"testUser": "Shahin",
"nodes": [
{
"masterSnapshotId": "ref_",
"type": "cloudformation",
"collection": "cloudFormation",
"paths": [
"/lambda/lambda-sample.yaml"
],
"snapshotId": "ref_1",
"status": "active",
"validate": true
}
]
}
]
}
40 changes: 40 additions & 0 deletions validation/scenario-cloudformation-secret-pass/master-test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"fileType":"mastertest",
"masterSnapshot":"master-snapshot",
"testSet": [
{
"masterTestName": "AWS_TEST",
"version": "0.1",
"cases": [
{
"masterTestId": "TEST_Ref_1",
"masterSnapshotId": [
"ref_"
],
"type":"rego",
"rule": "file(secrets.rego)",
"evals": [
{
"id": "PR-AWS-0028-RGX",
"eval": "data.rule.gl_aws_secrets"
}
]
},
{
"masterTestId": "TEST_Ref_2",
"masterSnapshotId": [
"ref_"
],
"type":"rego",
"rule": "file(secrets.rego)",
"evals": [
{
"id": "PR-AWS-0029-RGX",
"eval": "data.rule.gl_aws_account"
}
]
}
]
}
]
}
Loading