diff --git a/internal/cli/cli.go b/internal/cli/cli.go index e20f8b5..621074e 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -124,7 +124,7 @@ func initPluginWorker(plChan chan models.MeshCheckResults, completedChan chan bo } //StartCLICommand invoke cli lxd command mesh-kridik cli -func StartCLICommand(fm utils.FolderMgr, plChan chan models.MeshCheckResults, completedChan chan bool, ad ArgsData, cmdArgs []string, commands map[string]cli.CommandFactory, log *logger.LdxProbeLogger) { +func StartCLICommand(fm utils.FolderMgr, plChan chan models.MeshCheckResults, completedChan chan bool, ad ArgsData, cmdArgs []string, commands map[string]cli.CommandFactory, log *logger.MeshKridikLogger) { // init plugin folders initPluginFolders(fm) // init plugin worker diff --git a/internal/cli/commands/command-helper.go b/internal/cli/commands/command-helper.go index 9730398..ad24661 100644 --- a/internal/cli/commands/command-helper.go +++ b/internal/cli/commands/command-helper.go @@ -16,7 +16,7 @@ import ( "time" ) -func printTestResults(at []*models.AuditBench, table *tablewriter.Table, category string) models.AuditTestTotals { +func printTestResults(at []*models.AuditBench, table *tablewriter.Table, category string) models.CheckTotals { var ( warnCounter int passCounter int @@ -46,10 +46,10 @@ func printTestResults(at []*models.AuditBench, table *tablewriter.Table, categor failCounter++ } } - return models.AuditTestTotals{Fail: failCounter, Pass: passCounter, Warn: warnCounter} + return models.CheckTotals{Fail: failCounter, Pass: passCounter, Warn: warnCounter} } -func printClassicTestResults(at []*models.AuditBench, log *logger.LdxProbeLogger) models.AuditTestTotals { +func printClassicTestResults(at []*models.AuditBench, log *logger.MeshKridikLogger) models.CheckTotals { var ( warnCounter int passCounter int @@ -72,7 +72,7 @@ func printClassicTestResults(at []*models.AuditBench, log *logger.LdxProbeLogger failCounter++ } } - return models.AuditTestTotals{Fail: failCounter, Pass: passCounter, Warn: warnCounter} + return models.CheckTotals{Fail: failCounter, Pass: passCounter, Warn: warnCounter} } //AddFailedMessages add failed audit test to report data @@ -112,7 +112,7 @@ func NewFileLoader() TestLoader { //LoadAuditTests load audit test from benchmark folder func (tl AuditTestLoader) LoadAuditTests(auditFiles []utils.FilesInfo) []*models.SubCategory { auditTests := make([]*models.SubCategory, 0) - audit := models.Audit{} + audit := models.Check{} for _, auditFile := range auditFiles { err := yaml.Unmarshal([]byte(auditFile.Data), &audit) if err != nil { @@ -203,9 +203,9 @@ func filteredAuditBenchTests(auditTests []*models.SubCategory, pc []filters.Pred return ft } -func executeTests(ft []*models.SubCategory, execTestFunc func(ad *models.AuditBench) []*models.AuditBench, log *logger.LdxProbeLogger) []*models.SubCategory { +func executeTests(ft []*models.SubCategory, execTestFunc func(ad *models.AuditBench) []*models.AuditBench, log *logger.MeshKridikLogger) []*models.SubCategory { completedTest := make([]*models.SubCategory, 0) - log.Console(ui.LxdAuditTest) + log.Console(ui.MeshCheck) bar := pb.StartNew(len(ft)).Prefix("Executing LXD specs:") for _, f := range ft { tr := ui.ExecuteSpecs(f, execTestFunc) diff --git a/internal/cli/commands/command-helper_test.go b/internal/cli/commands/command-helper_test.go index e35cbe0..2cf0de0 100644 --- a/internal/cli/commands/command-helper_test.go +++ b/internal/cli/commands/command-helper_test.go @@ -204,7 +204,7 @@ func TestPrintTestResults(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - var tr models.AuditTestTotals + var tr models.CheckTotals if tt.testType == "regular" { tr = printTestResults(tt.tests, tablewriter.NewWriter(os.Stdout), tt.testCategory) } else { diff --git a/internal/cli/commands/mesh-check.go b/internal/cli/commands/mesh-check.go index 5fcec58..242cfb0 100644 --- a/internal/cli/commands/mesh-check.go +++ b/internal/cli/commands/mesh-check.go @@ -27,17 +27,17 @@ type MeshCheck struct { CompletedChan chan bool FilesInfo []utils.FilesInfo Evaluator eval.CmdEvaluator - log *logger.LdxProbeLogger + log *logger.MeshKridikLogger } // ResultProcessor process audit results type ResultProcessor func(at *models.AuditBench, isSucceeded bool) []*models.AuditBench // ConsoleOutputGenerator print audit tests to stdout -var ConsoleOutputGenerator ui.OutputGenerator = func(at []*models.SubCategory, log *logger.LdxProbeLogger) { - grandTotal := make([]models.AuditTestTotals, 0) +var ConsoleOutputGenerator ui.OutputGenerator = func(at []*models.SubCategory, log *logger.MeshKridikLogger) { + grandTotal := make([]models.CheckTotals, 0) table := tablewriter.NewWriter(os.Stdout) - table.SetHeader([]string{"Category", "Status", "Type", "Audit Test Description"}) + table.SetHeader([]string{"Category", "Status", "Type", "Check Test Description"}) table.SetAutoWrapText(false) table.SetBorder(true) // Set for _, a := range at { @@ -51,8 +51,8 @@ var ConsoleOutputGenerator ui.OutputGenerator = func(at []*models.SubCategory, l } // ClassicOutputGenerator print audit tests to stdout in classic view -var ClassicOutputGenerator ui.OutputGenerator = func(at []*models.SubCategory, log *logger.LdxProbeLogger) { - grandTotal := make([]models.AuditTestTotals, 0) +var ClassicOutputGenerator ui.OutputGenerator = func(at []*models.SubCategory, log *logger.MeshKridikLogger) { + grandTotal := make([]models.CheckTotals, 0) for _, a := range at { log.Console(fmt.Sprintf("%s %s\n", "[Category]", a.Name)) categoryTotal := printClassicTestResults(a.AuditTests, log) @@ -61,7 +61,7 @@ var ClassicOutputGenerator ui.OutputGenerator = func(at []*models.SubCategory, l log.Console(printFinalResults(grandTotal)) } -func printFinalResults(grandTotal []models.AuditTestTotals) string { +func printFinalResults(grandTotal []models.CheckTotals) string { finalTotal := calculateFinalTotal(grandTotal) passTest := colorstring.Color("[green]Pass:") failTest := colorstring.Color("[red]Fail:") @@ -70,7 +70,7 @@ func printFinalResults(grandTotal []models.AuditTestTotals) string { return fmt.Sprintf("%s %s %d , %s %d , %s %d ", title, passTest, finalTotal.Pass, warnTest, finalTotal.Warn, failTest, finalTotal.Fail) } -func calculateFinalTotal(granTotal []models.AuditTestTotals) models.AuditTestTotals { +func calculateFinalTotal(granTotal []models.CheckTotals) models.CheckTotals { var ( warn int fail int @@ -81,11 +81,11 @@ func calculateFinalTotal(granTotal []models.AuditTestTotals) models.AuditTestTot fail = fail + total.Fail pass = pass + total.Pass } - return models.AuditTestTotals{Pass: pass, Fail: fail, Warn: warn} + return models.CheckTotals{Pass: pass, Fail: fail, Warn: warn} } // ReportOutputGenerator print failed audit test to human report -var ReportOutputGenerator ui.OutputGenerator = func(at []*models.SubCategory, log *logger.LdxProbeLogger) { +var ReportOutputGenerator ui.OutputGenerator = func(at []*models.SubCategory, log *logger.MeshKridikLogger) { for _, a := range at { log.Table(reports.GenerateAuditReport(a.AuditTests)) } diff --git a/internal/cli/commands/mesh-check_test.go b/internal/cli/commands/mesh-check_test.go index a92b30c..9815b80 100644 --- a/internal/cli/commands/mesh-check_test.go +++ b/internal/cli/commands/mesh-check_test.go @@ -35,7 +35,7 @@ func TestRunAuditTests(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - ab := models.Audit{} + ab := models.Check{} err := yaml.Unmarshal(readTestData(tt.testFile, t), &ab) if err != nil { t.Errorf("failed to Unmarshal test file %s error : %s", tt.testFile, err.Error()) @@ -144,15 +144,15 @@ func Test_sendResultToPlugin(t *testing.T) { } func Test_calculateFinalTotal(t *testing.T) { - att := make([]models.AuditTestTotals, 0) - atOne := models.AuditTestTotals{Fail: 2, Pass: 3, Warn: 1} - atTwo := models.AuditTestTotals{Fail: 1, Pass: 5, Warn: 7} + att := make([]models.CheckTotals, 0) + atOne := models.CheckTotals{Fail: 2, Pass: 3, Warn: 1} + atTwo := models.CheckTotals{Fail: 1, Pass: 5, Warn: 7} att = append(att, atOne) att = append(att, atTwo) res := calculateFinalTotal(att) assert.Equal(t, res.Warn, 8) assert.Equal(t, res.Pass, 8) assert.Equal(t, res.Fail, 3) - str := printFinalResults([]models.AuditTestTotals{res}) + str := printFinalResults([]models.CheckTotals{res}) assert.Equal(t, str, "Test Result Total: \x1b[32mPass:\x1b[0m 8 , \x1b[33mWarn:\x1b[0m 8 , \x1b[31mFail:\x1b[0m 3 ") } diff --git a/internal/logger/ldxlogger.go b/internal/logger/ldxlogger.go deleted file mode 100644 index eabd00e..0000000 --- a/internal/logger/ldxlogger.go +++ /dev/null @@ -1,26 +0,0 @@ -package logger - -import ( - "log" -) - -//LdxProbeLogger Object -type LdxProbeLogger struct { -} - -//GetLog return native logger -func GetLog() *LdxProbeLogger { - return &LdxProbeLogger{} -} - -//Console print to console -func (BLogger *LdxProbeLogger) Console(str string) { - log.SetFlags(0) - log.Print(str) -} - -//Table print to console -func (BLogger *LdxProbeLogger) Table(v interface{}) { - log.SetFlags(0) - log.Print(v) -} diff --git a/internal/logger/meshlogger.go b/internal/logger/meshlogger.go new file mode 100644 index 0000000..f143e6d --- /dev/null +++ b/internal/logger/meshlogger.go @@ -0,0 +1,26 @@ +package logger + +import ( + "log" +) + +//MeshKridikLogger Object +type MeshKridikLogger struct { +} + +//GetLog return native logger +func GetLog() *MeshKridikLogger { + return &MeshKridikLogger{} +} + +//Console print to console +func (BLogger *MeshKridikLogger) Console(str string) { + log.SetFlags(0) + log.Print(str) +} + +//Table print to console +func (BLogger *MeshKridikLogger) Table(v interface{}) { + log.SetFlags(0) + log.Print(v) +} diff --git a/internal/models/audit.go b/internal/models/check.go similarity index 95% rename from internal/models/audit.go rename to internal/models/check.go index 050b87f..1961192 100644 --- a/internal/models/audit.go +++ b/internal/models/check.go @@ -5,14 +5,14 @@ import ( "github.com/mitchellh/mapstructure" ) -//Audit data model -type Audit struct { +//Check data model +type Check struct { BenchmarkType string `yaml:"benchmark_type"` Categories []Category `yaml:"categories"` } -//AuditTestTotals model -type AuditTestTotals struct { +//CheckTotals model +type CheckTotals struct { Warn int Pass int Fail int diff --git a/internal/models/audit_test.go b/internal/models/check_test.go similarity index 98% rename from internal/models/audit_test.go rename to internal/models/check_test.go index fbac4e8..7319f56 100644 --- a/internal/models/audit_test.go +++ b/internal/models/check_test.go @@ -20,7 +20,7 @@ func TestAuditBench_UnmarshalYAML(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - ab := Audit{} + ab := Check{} err := yaml.Unmarshal(readTestData(tt.fileName, t), &ab) if err != nil { t.Errorf("TestAuditBench_UnmarshalYAML failed to unmarshal json %v", err) diff --git a/internal/reports/processor.go b/internal/reports/processor.go index ea7bea2..a94febb 100644 --- a/internal/reports/processor.go +++ b/internal/reports/processor.go @@ -19,7 +19,7 @@ func GenerateAuditReport(adtsReport []*models.AuditBench) *uitable.Table { table.AddRow("Status:", status) table.AddRow("Name:", failedAudit.Name) table.AddRow("Description:", failedAudit.Description) - table.AddRow("Audit:", failedAudit.AuditCommand) + table.AddRow("Check:", failedAudit.AuditCommand) table.AddRow("Remediation:", failedAudit.Remediation) table.AddRow("References:", failedAudit.References) table.AddRow("") // blank diff --git a/internal/startup/templates_test.go b/internal/startup/templates_test.go index 0b5c9c9..02de52e 100644 --- a/internal/startup/templates_test.go +++ b/internal/startup/templates_test.go @@ -16,67 +16,15 @@ func Test_CreateLxdBenchmarkFilesIfNotExist(t *testing.T) { } // generate test with packr assert.Equal(t, bFiles[0].Name, common.FilesystemConfiguration) - assert.Equal(t, bFiles[1].Name, common.ConfigureSoftwareUpdates) - assert.Equal(t, bFiles[2].Name, common.ConfigureSudo) - assert.Equal(t, bFiles[3].Name, common.FilesystemIntegrityChecking) - assert.Equal(t, bFiles[4].Name, common.AdditionalProcessHardening) - assert.Equal(t, bFiles[5].Name, common.MandatoryAccessControl) - assert.Equal(t, bFiles[6].Name, common.WarningBanners) - assert.Equal(t, bFiles[7].Name, common.EnsureUpdates) - assert.Equal(t, bFiles[8].Name, common.InetdServices) - assert.Equal(t, bFiles[9].Name, common.SpecialPurposeServices) - assert.Equal(t, bFiles[10].Name, common.ServiceClients) - assert.Equal(t, bFiles[11].Name, common.NonessentialServices) - assert.Equal(t, bFiles[12].Name, common.NetworkParameters) - assert.Equal(t, bFiles[13].Name, common.NetworkParametersHost) - assert.Equal(t, bFiles[14].Name, common.TCPWrappers) - assert.Equal(t, bFiles[15].Name, common.FirewallConfiguration) - assert.Equal(t, bFiles[16].Name, common.ConfigureLogging) - assert.Equal(t, bFiles[17].Name, common.EnsureLogrotateConfigured) - assert.Equal(t, bFiles[18].Name, common.EnsureLogrotateAssignsAppropriatePermissions) - assert.Equal(t, bFiles[19].Name, common.ConfigureCron) - assert.Equal(t, bFiles[20].Name, common.SSHServerConfiguration) - assert.Equal(t, bFiles[21].Name, common.ConfigurePam) - assert.Equal(t, bFiles[22].Name, common.UserAccountsAndEnvironment) - assert.Equal(t, bFiles[23].Name, common.RootLoginRestrictedSystemConsole) - assert.Equal(t, bFiles[24].Name, common.EnsureAccessSuCommandRestricted) - assert.Equal(t, bFiles[25].Name, common.SystemFilePermissions) - assert.Equal(t, bFiles[26].Name, common.UserAndGroupSettings) fm := utils.NewKFolder() - err = utils.CreateBenchmarkFolderIfNotExist("lxd", "v1.0.0", fm) + err = utils.CreateBenchmarkFolderIfNotExist("mesh", "v1.0.0", fm) assert.NoError(t, err) // save benchmark files to folder - err = SaveBenchmarkFilesIfNotExist("lxd", "v1.0.0", bFiles) + err = SaveBenchmarkFilesIfNotExist("mesh", "v1.0.0", bFiles) assert.NoError(t, err) // fetch files from benchmark folder - bFiles, err = utils.GetLxdBenchAuditFiles("lxd", "v1.0.0", fm) + bFiles, err = utils.GetLxdBenchAuditFiles("mesh", "v1.0.0", fm) assert.Equal(t, bFiles[0].Name, common.FilesystemConfiguration) - assert.Equal(t, bFiles[1].Name, common.ConfigureSoftwareUpdates) - assert.Equal(t, bFiles[2].Name, common.ConfigureSudo) - assert.Equal(t, bFiles[3].Name, common.FilesystemIntegrityChecking) - assert.Equal(t, bFiles[4].Name, common.AdditionalProcessHardening) - assert.Equal(t, bFiles[5].Name, common.MandatoryAccessControl) - assert.Equal(t, bFiles[6].Name, common.WarningBanners) - assert.Equal(t, bFiles[7].Name, common.EnsureUpdates) - assert.Equal(t, bFiles[8].Name, common.InetdServices) - assert.Equal(t, bFiles[9].Name, common.SpecialPurposeServices) - assert.Equal(t, bFiles[10].Name, common.ServiceClients) - assert.Equal(t, bFiles[11].Name, common.NonessentialServices) - assert.Equal(t, bFiles[12].Name, common.NetworkParameters) - assert.Equal(t, bFiles[13].Name, common.NetworkParametersHost) - assert.Equal(t, bFiles[14].Name, common.TCPWrappers) - assert.Equal(t, bFiles[15].Name, common.FirewallConfiguration) - assert.Equal(t, bFiles[16].Name, common.ConfigureLogging) - assert.Equal(t, bFiles[17].Name, common.EnsureLogrotateConfigured) - assert.Equal(t, bFiles[18].Name, common.EnsureLogrotateAssignsAppropriatePermissions) - assert.Equal(t, bFiles[19].Name, common.ConfigureCron) - assert.Equal(t, bFiles[20].Name, common.SSHServerConfiguration) - assert.Equal(t, bFiles[21].Name, common.ConfigurePam) - assert.Equal(t, bFiles[22].Name, common.UserAccountsAndEnvironment) - assert.Equal(t, bFiles[23].Name, common.RootLoginRestrictedSystemConsole) - assert.Equal(t, bFiles[24].Name, common.EnsureAccessSuCommandRestricted) - assert.Equal(t, bFiles[25].Name, common.SystemFilePermissions) - assert.Equal(t, bFiles[26].Name, common.UserAndGroupSettings) assert.NoError(t, err) err = os.RemoveAll(utils.GetHomeFolder()) assert.NoError(t, err) diff --git a/jobs/lxd-probe.yaml b/jobs/mesh-kridik.yaml similarity index 100% rename from jobs/lxd-probe.yaml rename to jobs/mesh-kridik.yaml diff --git a/pkg/img/lxc-probe-social.gif b/pkg/img/lxc-probe-social.gif deleted file mode 100644 index 04f5445..0000000 Binary files a/pkg/img/lxc-probe-social.gif and /dev/null differ diff --git a/pkg/img/lxd-gopher.png b/pkg/img/lxd-gopher.png deleted file mode 100644 index a34e975..0000000 Binary files a/pkg/img/lxd-gopher.png and /dev/null differ diff --git a/pkg/img/lxd-probe-social.gif b/pkg/img/lxd-probe-social.gif deleted file mode 100644 index 6ffbd56..0000000 Binary files a/pkg/img/lxd-probe-social.gif and /dev/null differ diff --git a/pkg/img/lxd-probe.gif b/pkg/img/lxd-probe.gif deleted file mode 100644 index cd81e7b..0000000 Binary files a/pkg/img/lxd-probe.gif and /dev/null differ diff --git a/pkg/models/audit_results.go b/pkg/models/check_results.go similarity index 100% rename from pkg/models/audit_results.go rename to pkg/models/check_results.go diff --git a/ui/banners.go b/ui/banners.go index d11a602..4c5aaa5 100644 --- a/ui/banners.go +++ b/ui/banners.go @@ -1,16 +1,17 @@ package ui -//LxdAuditTest banner -const LxdAuditTest = ` +//MeshCheck banner +const MeshCheck = ` - _ _ _____ _ _ ___ __ _ ___ -| | (_) / __ \ | | (_) / / | / / | | | \ \ -| | _ _ __ _ ___ __ | / \/ ___ _ __ | |_ __ _ _ _ __ ___ _ __ ___ | || | __ _____ / / | | __ ____| || | -| | | | '_ \| | | \ \/ / | | / _ \| '_ \| __/ _'' | | '_ \ / _ \ '__/ __ | || | \ \/ / __| / / | | \ \/ / _' || | -| |___| | | | | |_| |> < | \__/\ (_) | | | | || (_| | | | | | __/ | \__ \ | || |____> < (__ / / | |____> < (_| || | -\_____/_|_| |_|\__,_/_/\_\ \____/\___/|_| |_|\__\__,_|_|_| |_|\___|_| |___/ | |\_____/_/\_\___| /_/ \_____/_/\_\__,_|| | - \_\ /_/ - + + __ __ _ _ __ _ _ _ _ + | \/ | | | | |/ / (_) | (_) | + | \ / | ___ ___| |__ | ' / _ __ _ __| |_| | __ + | |\/| |/ _ \/ __| '_ \ | < | '__| |/ _' | | |/ / + | | | | __/\__ \ | | | | . \| | | | (_| | | < + |_| |_|\___||___/_| |_| |_|\_\_| |_|\__,_|_|_|\_\ + + ` diff --git a/ui/console.go b/ui/console.go index 57184ce..7c7d3ff 100644 --- a/ui/console.go +++ b/ui/console.go @@ -6,10 +6,10 @@ import ( ) // OutputGenerator for audit results -type OutputGenerator func(at []*models.SubCategory, log *logger.LdxProbeLogger) +type OutputGenerator func(at []*models.SubCategory, log *logger.MeshKridikLogger) //PrintOutput print audit test result to console -func PrintOutput(auditTests []*models.SubCategory, outputGenerator OutputGenerator, log *logger.LdxProbeLogger) { +func PrintOutput(auditTests []*models.SubCategory, outputGenerator OutputGenerator, log *logger.MeshKridikLogger) { log.Console(auditResult) outputGenerator(auditTests, log) }