-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(configservice): test if aws config is enabled
- Loading branch information
Showing
8 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package configservice | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/padok-team/yatas/plugins/commons" | ||
) | ||
|
||
func RunChecks(wa *sync.WaitGroup, s aws.Config, c *commons.Config, queue chan []commons.Check) { | ||
|
||
var checkConfig commons.CheckConfig | ||
checkConfig.Init(c) | ||
var checks []commons.Check | ||
configurationRecorderStatus := GetConfigurationRecorderStatus(s) | ||
|
||
go commons.CheckTest(checkConfig.Wg, c, "AWS_CFG_001", CheckIfConfigServiceIsEnabled)(checkConfig, "AWS_CFG_001", configurationRecorderStatus) | ||
|
||
go func() { | ||
for t := range checkConfig.Queue { | ||
t.EndCheck() | ||
checks = append(checks, t) | ||
|
||
checkConfig.Wg.Done() | ||
|
||
} | ||
}() | ||
|
||
checkConfig.Wg.Wait() | ||
|
||
queue <- checks | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package configservice | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/configservice/types" | ||
"github.com/padok-team/yatas/plugins/commons" | ||
) | ||
|
||
func CheckIfConfigServiceIsEnabled(checkConfig commons.CheckConfig, testName string, configurationRecorderStatus []types.ConfigurationRecorderStatus) { | ||
var check commons.Check | ||
check.InitCheck("AWS Config is enabled in the account", "Check if AWS Config is enabled", testName, []string{"Security", "Good Practice"}) | ||
|
||
Message := "AWS Config is not enabled" | ||
result := commons.Result{Status: "FAIL", Message: Message} | ||
|
||
for _, recorderStatus := range configurationRecorderStatus { | ||
if aws.ToBool(&recorderStatus.Recording) { | ||
Message = "AWS Config is enabled" | ||
result = commons.Result{Status: "OK", Message: Message} | ||
break | ||
} | ||
} | ||
|
||
check.AddResult(result) | ||
|
||
checkConfig.Queue <- check | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package configservice | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go-v2/service/configservice/types" | ||
"github.com/padok-team/yatas/plugins/commons" | ||
) | ||
|
||
func TestCheckIfConfigServiceIsEnabled(t *testing.T) { | ||
t.Run("AWS Config is not enabled (empty recorder status)", func(t *testing.T) { | ||
queue := make(chan commons.Check, 1) | ||
checkConfig := commons.CheckConfig{Queue: queue} | ||
configurationRecorderStatus := []types.ConfigurationRecorderStatus{} | ||
|
||
CheckIfConfigServiceIsEnabled(checkConfig, "TestAWSConfigDisabled", configurationRecorderStatus) | ||
|
||
check := <-queue | ||
if len(check.Results) != 1 { | ||
t.Fatalf("Expected 1 result, got %d", len(check.Results)) | ||
} | ||
result := check.Results[0] | ||
if result.Status != "FAIL" { | ||
t.Errorf("Expected status FAIL, got %s", result.Status) | ||
} | ||
if result.Message != "AWS Config is not enabled" { | ||
t.Errorf("Expected message 'AWS Config is not enabled', got '%s'", result.Message) | ||
} | ||
}) | ||
|
||
t.Run("AWS Config is enabled (Recording is true)", func(t *testing.T) { | ||
queue := make(chan commons.Check, 1) | ||
checkConfig := commons.CheckConfig{Queue: queue} | ||
configurationRecorderStatus := []types.ConfigurationRecorderStatus{ | ||
{Recording: true}, | ||
} | ||
|
||
CheckIfConfigServiceIsEnabled(checkConfig, "TestAWSConfigEnabled", configurationRecorderStatus) | ||
|
||
check := <-queue | ||
if len(check.Results) != 1 { | ||
t.Fatalf("Expected 1 result, got %d", len(check.Results)) | ||
} | ||
result := check.Results[0] | ||
if result.Status != "OK" { | ||
t.Errorf("Expected status OK, got %s", result.Status) | ||
} | ||
if result.Message != "AWS Config is enabled" { | ||
t.Errorf("Expected message 'AWS Config is enabled', got '%s'", result.Message) | ||
} | ||
}) | ||
|
||
t.Run("AWS Config is not enabled (Recording is false)", func(t *testing.T) { | ||
queue := make(chan commons.Check, 1) | ||
checkConfig := commons.CheckConfig{Queue: queue} | ||
configurationRecorderStatus := []types.ConfigurationRecorderStatus{ | ||
{Recording: false}, | ||
} | ||
|
||
CheckIfConfigServiceIsEnabled(checkConfig, "TestAWSConfigDisabledFalse", configurationRecorderStatus) | ||
|
||
check := <-queue | ||
if len(check.Results) != 1 { | ||
t.Fatalf("Expected 1 result, got %d", len(check.Results)) | ||
} | ||
result := check.Results[0] | ||
if result.Status != "FAIL" { | ||
t.Errorf("Expected status FAIL, got %s", result.Status) | ||
} | ||
if result.Message != "AWS Config is not enabled" { | ||
t.Errorf("Expected message 'AWS Config is not enabled', got '%s'", result.Message) | ||
} | ||
}) | ||
|
||
t.Run("AWS Config is enabled with at least one Recording as true", func(t *testing.T) { | ||
queue := make(chan commons.Check, 1) | ||
checkConfig := commons.CheckConfig{Queue: queue} | ||
configurationRecorderStatus := []types.ConfigurationRecorderStatus{ | ||
{Recording: true}, | ||
{Recording: false}, | ||
} | ||
|
||
CheckIfConfigServiceIsEnabled(checkConfig, "TestAWSConfigEnabled", configurationRecorderStatus) | ||
|
||
check := <-queue | ||
if len(check.Results) != 1 { | ||
t.Fatalf("Expected 1 result, got %d", len(check.Results)) | ||
} | ||
result := check.Results[0] | ||
if result.Status != "OK" { | ||
t.Errorf("Expected status OK, got %s", result.Status) | ||
} | ||
if result.Message != "AWS Config is enabled" { | ||
t.Errorf("Expected message 'AWS Config is enabled', got '%s'", result.Message) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package configservice | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/configservice" | ||
"github.com/aws/aws-sdk-go-v2/service/configservice/types" | ||
"github.com/padok-team/yatas-aws/logger" | ||
) | ||
|
||
func GetConfigurationRecorderStatus(s aws.Config) []types.ConfigurationRecorderStatus { | ||
svc := configservice.NewFromConfig(s) | ||
result, err := svc.DescribeConfigurationRecorderStatus(context.TODO(), &configservice.DescribeConfigurationRecorderStatusInput{}) | ||
if err != nil { | ||
logger.Logger.Error(err.Error()) | ||
return []types.ConfigurationRecorderStatus{} | ||
} | ||
|
||
return result.ConfigurationRecordersStatus | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters