feat(misconf): Add compliance check support (#3130)

Signed-off-by: Simar <simar@linux.com>
Co-authored-by: knqyf263 <knqyf263@gmail.com>
This commit is contained in:
simar7
2022-12-07 12:42:59 -08:00
committed by GitHub
parent 7a6cf5a27c
commit a3eece4fef
20 changed files with 605 additions and 73 deletions

View File

@@ -100,6 +100,7 @@ func Test_Run(t *testing.T) {
{
"Type": "AWS",
"ID": "AVD-AWS-0086",
"AVDID": "AVD-AWS-0086",
"Title": "S3 Access block should block public ACL",
"Description": "S3 buckets should block public ACLs on buckets and any objects they contain. By blocking, PUTs with fail if the object has any public ACL a.",
"Message": "No public access block so not blocking public acls",
@@ -123,6 +124,7 @@ func Test_Run(t *testing.T) {
{
"Type": "AWS",
"ID": "AVD-AWS-0087",
"AVDID": "AVD-AWS-0087",
"Title": "S3 Access block should block public policy",
"Description": "S3 bucket policy should have block public policy to prevent users from putting a policy that enable public access.",
"Message": "No public access block so not blocking public policies",
@@ -146,6 +148,7 @@ func Test_Run(t *testing.T) {
{
"Type": "AWS",
"ID": "AVD-AWS-0088",
"AVDID": "AVD-AWS-0088",
"Title": "Unencrypted S3 bucket.",
"Description": "S3 Buckets should be encrypted to protect the data that is stored within them if access is compromised.",
"Message": "Bucket does not have encryption enabled",
@@ -169,6 +172,7 @@ func Test_Run(t *testing.T) {
{
"Type": "AWS",
"ID": "AVD-AWS-0089",
"AVDID": "AVD-AWS-0089",
"Title": "S3 Bucket does not have logging enabled.",
"Description": "Buckets should have logging enabled so that access can be audited.",
"Message": "Bucket does not have logging enabled",
@@ -192,6 +196,7 @@ func Test_Run(t *testing.T) {
{
"Type": "AWS",
"ID": "AVD-AWS-0090",
"AVDID": "AVD-AWS-0090",
"Title": "S3 Data should be versioned",
"Description": "Versioning in Amazon S3 is a means of keeping multiple variants of an object in the same bucket. \nYou can use the S3 Versioning feature to preserve, retrieve, and restore every version of every object stored in your buckets. \nWith versioning you can recover more easily from both unintended user actions and application failures.",
"Message": "Bucket does not have versioning enabled",
@@ -215,6 +220,7 @@ func Test_Run(t *testing.T) {
{
"Type": "AWS",
"ID": "AVD-AWS-0132",
"AVDID": "AVD-AWS-0132",
"Title": "S3 encryption should use Customer Managed Keys",
"Description": "Encryption using AWS keys provides protection for your S3 buckets. To increase control of the encryption and manage factors like rotation use customer managed keys.",
"Message": "Bucket does not encrypt data with a customer managed key.",
@@ -238,6 +244,7 @@ func Test_Run(t *testing.T) {
{
"Type": "AWS",
"ID": "AVD-AWS-0091",
"AVDID": "AVD-AWS-0091",
"Title": "S3 Access Block should Ignore Public Acl",
"Description": "S3 buckets should ignore public ACLs on buckets and any objects they contain. By ignoring rather than blocking, PUT calls with public ACLs will still be applied but the ACL will be ignored.",
"Message": "No public access block so not ignoring public acls",
@@ -261,6 +268,7 @@ func Test_Run(t *testing.T) {
{
"Type": "AWS",
"ID": "AVD-AWS-0093",
"AVDID": "AVD-AWS-0093",
"Title": "S3 Access block should restrict public bucket to limit access",
"Description": "S3 buckets should restrict public policies for the bucket. By enabling, the restrict_public_buckets, only the bucket owner and AWS Services can access if it has a public policy.",
"Message": "No public access block so not restricting public buckets",
@@ -284,6 +292,7 @@ func Test_Run(t *testing.T) {
{
"Type": "AWS",
"ID": "AVD-AWS-0094",
"AVDID": "AVD-AWS-0094",
"Title": "S3 buckets should each define an aws_s3_bucket_public_access_block",
"Description": "The \"block public access\" settings in S3 override individual policies that apply to a given bucket, meaning that all public access can be controlled in one central types for that bucket. It is therefore good practice to define these settings for each bucket in order to clearly define the public access that can be allowed for it.",
"Message": "Bucket does not have a corresponding public access block.",
@@ -381,6 +390,7 @@ deny[res] {
{
"Type": "AWS",
"ID": "AVD-AWS-0086",
"AVDID": "AVD-AWS-0086",
"Title": "S3 Access block should block public ACL",
"Description": "S3 buckets should block public ACLs on buckets and any objects they contain. By blocking, PUTs with fail if the object has any public ACL a.",
"Message": "No public access block so not blocking public acls",
@@ -404,6 +414,7 @@ deny[res] {
{
"Type": "AWS",
"ID": "AVD-AWS-0087",
"AVDID": "AVD-AWS-0087",
"Title": "S3 Access block should block public policy",
"Description": "S3 bucket policy should have block public policy to prevent users from putting a policy that enable public access.",
"Message": "No public access block so not blocking public policies",
@@ -427,6 +438,7 @@ deny[res] {
{
"Type": "AWS",
"ID": "AVD-AWS-0088",
"AVDID": "AVD-AWS-0088",
"Title": "Unencrypted S3 bucket.",
"Description": "S3 Buckets should be encrypted to protect the data that is stored within them if access is compromised.",
"Message": "Bucket does not have encryption enabled",
@@ -450,6 +462,7 @@ deny[res] {
{
"Type": "AWS",
"ID": "AVD-AWS-0089",
"AVDID": "AVD-AWS-0089",
"Title": "S3 Bucket does not have logging enabled.",
"Description": "Buckets should have logging enabled so that access can be audited.",
"Message": "Bucket does not have logging enabled",
@@ -473,6 +486,7 @@ deny[res] {
{
"Type": "AWS",
"ID": "AVD-AWS-0090",
"AVDID": "AVD-AWS-0090",
"Title": "S3 Data should be versioned",
"Description": "Versioning in Amazon S3 is a means of keeping multiple variants of an object in the same bucket. \nYou can use the S3 Versioning feature to preserve, retrieve, and restore every version of every object stored in your buckets. \nWith versioning you can recover more easily from both unintended user actions and application failures.",
"Message": "Bucket does not have versioning enabled",
@@ -496,6 +510,7 @@ deny[res] {
{
"Type": "AWS",
"ID": "AVD-AWS-0132",
"AVDID": "AVD-AWS-0132",
"Title": "S3 encryption should use Customer Managed Keys",
"Description": "Encryption using AWS keys provides protection for your S3 buckets. To increase control of the encryption and manage factors like rotation use customer managed keys.",
"Message": "Bucket does not encrypt data with a customer managed key.",
@@ -519,6 +534,7 @@ deny[res] {
{
"Type": "AWS",
"ID": "AVD-AWS-0091",
"AVDID": "AVD-AWS-0091",
"Title": "S3 Access Block should Ignore Public Acl",
"Description": "S3 buckets should ignore public ACLs on buckets and any objects they contain. By ignoring rather than blocking, PUT calls with public ACLs will still be applied but the ACL will be ignored.",
"Message": "No public access block so not ignoring public acls",
@@ -542,6 +558,7 @@ deny[res] {
{
"Type": "AWS",
"ID": "AVD-AWS-0093",
"AVDID": "AVD-AWS-0093",
"Title": "S3 Access block should restrict public bucket to limit access",
"Description": "S3 buckets should restrict public policies for the bucket. By enabling, the restrict_public_buckets, only the bucket owner and AWS Services can access if it has a public policy.",
"Message": "No public access block so not restricting public buckets",
@@ -565,6 +582,7 @@ deny[res] {
{
"Type": "AWS",
"ID": "AVD-AWS-0094",
"AVDID": "AVD-AWS-0094",
"Title": "S3 buckets should each define an aws_s3_bucket_public_access_block",
"Description": "The \"block public access\" settings in S3 override individual policies that apply to a given bucket, meaning that all public access can be controlled in one central types for that bucket. It is therefore good practice to define these settings for each bucket in order to clearly define the public access that can be allowed for it.",
"Message": "Bucket does not have a corresponding public access block.",
@@ -613,6 +631,47 @@ deny[res] {
}
`,
},
{
name: "compliance report summary",
options: flag.Options{
AWSOptions: flag.AWSOptions{
Region: "us-east-1",
Services: []string{"s3"},
Account: "12345678",
},
CloudOptions: flag.CloudOptions{
MaxCacheAge: time.Hour * 24 * 365 * 100,
},
ReportOptions: flag.ReportOptions{Compliance: "@./testdata/example-spec.yaml", Format: "table", ReportFormat: "summary"},
},
cacheContent: exampleS3Cache,
want: `
Summary Report for compliance: my-custom-spec
┌─────┬──────────┬───────────────────────┬────────┬────────┐
│ ID │ Severity │ Control Name │ Status │ Issues │
├─────┼──────────┼───────────────────────┼────────┼────────┤
│ 1.1 │ HIGH │ Unencrypted S3 bucket │ FAIL │ 1 │
└─────┴──────────┴───────────────────────┴────────┴────────┘
`,
},
{
name: "error loading compliance report",
expectErr: true,
options: flag.Options{
AWSOptions: flag.AWSOptions{
Region: "us-east-1",
Services: []string{"s3"},
Account: "12345678",
},
CloudOptions: flag.CloudOptions{
MaxCacheAge: time.Hour * 24 * 365 * 100,
},
ReportOptions: flag.ReportOptions{Compliance: "@./testdata/nosuchspec.yaml", Format: "table", ReportFormat: "summary"},
},
cacheContent: exampleS3Cache,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
@@ -620,7 +679,9 @@ deny[res] {
test.options.Output = buffer
test.options.Debug = true
test.options.GlobalOptions.Timeout = time.Minute
test.options.Format = "json"
if test.options.Format == "" {
test.options.Format = "json"
}
test.options.Severities = []dbTypes.Severity{
dbTypes.SeverityUnknown,
dbTypes.SeverityLow,