Skip to content

Commit

Permalink
Merge branch 'main' of github.com:krumIO/raid-rds into strike-messages
Browse files Browse the repository at this point in the history
  • Loading branch information
eddie-knight committed Oct 31, 2023
2 parents ea9dce3 + cab7eb4 commit 4f74582
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ var (
Strikes.SQLFeatures,
Strikes.AutomatedBackups,
Strikes.MultiRegion,
Strikes.Encryption,
},
"CCC-Taxonomy": {
Strikes.SQLFeatures,
Strikes.AutomatedBackups,
Strikes.MultiRegion,
Strikes.Encryption,
Strikes.RBAC,
// Strikes.VerticalScaling,
// Strikes.Replication,
// Strikes.BackupRecovery,
// Strikes.Encryption,
// Strikes.RBAC,
// Strikes.Logging,
// Strikes.Monitoring,
// Strikes.Alerting,
Expand Down
75 changes: 75 additions & 0 deletions strikes/Encryption.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package strikes

import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/privateerproj/privateer-sdk/raidengine"
"github.com/privateerproj/privateer-sdk/utils"
)

// Todo/Roadmap: Features to evaluate implementing
// Encryption.go - AWS CLI

// This creates a database table
func (a *Strikes) Encryption() (strikeName string, result raidengine.StrikeResult) {
strikeName = "Encryption"
result = raidengine.StrikeResult{
Passed: false,
Description: "Check if storage is encrypted on the specified RDS instance",
DocsURL: "https://www.github.com/krumIO/raid-rds",
ControlID: "CCC-Taxonomy-1",
Movements: make(map[string]raidengine.MovementResult),
}

// Get Configuration
cfg, err := getAWSConfig()
if err != nil {
result.Message = err.Error()
return
}

rdsInstanceMovement := checkRDSInstanceMovement(cfg)
result.Movements["CheckForDBInstance"] = rdsInstanceMovement
if !rdsInstanceMovement.Passed {
result.Message = rdsInstanceMovement.Message
return
}

storageEncryptedMovement := checkIfStorageIsEncryptedMovement(cfg)
result.Movements["CheckForStorageEncryption"] = storageEncryptedMovement
if !storageEncryptedMovement.Passed {
result.Message = storageEncryptedMovement.Message
return
}

result.Passed = true
result.Message = "Completed Successfully"
return
}

func checkIfStorageIsEncryptedMovement(cfg aws.Config) (result raidengine.MovementResult) {

result = raidengine.MovementResult{
Description: "Check if the instance has storage encryption enabled",
Function: utils.CallerPath(0),
}

instanceIdentifier, _ := getHostDBInstanceIdentifier()

instance, err := getRDSInstanceFromIdentifier(cfg, instanceIdentifier)
if err != nil {
// Handle error
result.Message = err.Error()
result.Passed = false
return
}

if !instance.DBInstances[0].StorageEncrypted {
result.Message = "Storage encryption is not enabled"
result.Passed = false
return
}

// Loop through the instances and print information
result.Passed = true
return
}
32 changes: 32 additions & 0 deletions strikes/Encryption_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package strikes

import (
"encoding/json"
"fmt"
"testing"

"github.com/spf13/viper"
)

func TestEncryption(t *testing.T) {
viper.AddConfigPath("../")
viper.SetConfigName("config")
viper.SetConfigType("yaml")
err := viper.ReadInConfig()

if err != nil {
fmt.Println("Config file not found...")
return
}

strikes := Strikes{}
strikeName, result := strikes.Encryption()

fmt.Println(strikeName)
b, err := json.MarshalIndent(result, "", " ")
if err != nil {
fmt.Println(err)
}
fmt.Print(string(b))
fmt.Println()
}
75 changes: 75 additions & 0 deletions strikes/RBAC.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package strikes

import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/privateerproj/privateer-sdk/raidengine"
"github.com/privateerproj/privateer-sdk/utils"
)

// Todo/Roadmap: Features to evaluate implementing
// RBAC.go - AWS CLI

// This creates a database table
func (a *Strikes) RBAC() (strikeName string, result raidengine.StrikeResult) {
strikeName = "RBAC"
result = raidengine.StrikeResult{
Passed: false,
Description: "Check if database IAM authentication is enabled on the specified RDS instance",
DocsURL: "https://www.github.com/krumIO/raid-rds",
ControlID: "CCC-Taxonomy-1",
Movements: make(map[string]raidengine.MovementResult),
}

// Get Configuration
cfg, err := getAWSConfig()
if err != nil {
result.Message = err.Error()
return
}

rdsInstanceMovement := checkRDSInstanceMovement(cfg)
result.Movements["CheckForDBInstance"] = rdsInstanceMovement
if !rdsInstanceMovement.Passed {
result.Message = rdsInstanceMovement.Message
return
}

iamDatabaseAuthMovement := checkForIAMDatabaseAuthMovement(cfg)
result.Movements["CheckForIAMDatabaseAuth"] = iamDatabaseAuthMovement
if !iamDatabaseAuthMovement.Passed {
result.Message = iamDatabaseAuthMovement.Message
return
}

result.Passed = true
result.Message = "Completed Successfully"
return
}

func checkForIAMDatabaseAuthMovement(cfg aws.Config) (result raidengine.MovementResult) {

result = raidengine.MovementResult{
Description: "Check if the instance has IAM Database Authentication enabled",
Function: utils.CallerPath(0),
}

instanceIdentifier, _ := getHostDBInstanceIdentifier()

instance, err := getRDSInstanceFromIdentifier(cfg, instanceIdentifier)
if err != nil {
// Handle error
result.Message = err.Error()
result.Passed = false
return
}

if !instance.DBInstances[0].IAMDatabaseAuthenticationEnabled {
result.Message = "IAM Database Authentication is not enabled"
result.Passed = false
return
}

// Loop through the instances and print information
result.Passed = true
return
}
32 changes: 32 additions & 0 deletions strikes/RBAC_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package strikes

import (
"encoding/json"
"fmt"
"testing"

"github.com/spf13/viper"
)

func TestRBAC(t *testing.T) {
viper.AddConfigPath("../")
viper.SetConfigName("config")
viper.SetConfigType("yaml")
err := viper.ReadInConfig()

if err != nil {
fmt.Println("Config file not found...")
return
}

strikes := Strikes{}
strikeName, result := strikes.RBAC()

fmt.Println(strikeName)
b, err := json.MarshalIndent(result, "", " ")
if err != nil {
fmt.Println(err)
}
fmt.Print(string(b))
fmt.Println()
}

0 comments on commit 4f74582

Please sign in to comment.