Skip to content

Commit

Permalink
Merge branch 'master' into appsec-user-agent-header
Browse files Browse the repository at this point in the history
  • Loading branch information
blotus authored Mar 7, 2024
2 parents a871e2f + 98560d0 commit a01b669
Show file tree
Hide file tree
Showing 47 changed files with 460 additions and 230 deletions.
50 changes: 50 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,56 @@ linters-settings:
deny:
- pkg: "github.com/pkg/errors"
desc: "errors.Wrap() is deprecated in favor of fmt.Errorf()"
yaml:
files:
- "!**/cmd/crowdsec-cli/alerts.go"
- "!**/cmd/crowdsec-cli/capi.go"
- "!**/cmd/crowdsec-cli/config_show.go"
- "!**/cmd/crowdsec-cli/hubtest.go"
- "!**/cmd/crowdsec-cli/lapi.go"
- "!**/cmd/crowdsec-cli/simulation.go"
- "!**/cmd/crowdsec/crowdsec.go"
- "!**/cmd/notification-dummy/main.go"
- "!**/cmd/notification-email/main.go"
- "!**/cmd/notification-http/main.go"
- "!**/cmd/notification-slack/main.go"
- "!**/cmd/notification-splunk/main.go"
- "!**/pkg/acquisition/acquisition.go"
- "!**/pkg/acquisition/acquisition_test.go"
- "!**/pkg/acquisition/modules/appsec/appsec.go"
- "!**/pkg/acquisition/modules/cloudwatch/cloudwatch.go"
- "!**/pkg/acquisition/modules/docker/docker.go"
- "!**/pkg/acquisition/modules/file/file.go"
- "!**/pkg/acquisition/modules/journalctl/journalctl.go"
- "!**/pkg/acquisition/modules/kafka/kafka.go"
- "!**/pkg/acquisition/modules/kinesis/kinesis.go"
- "!**/pkg/acquisition/modules/kubernetesaudit/k8s_audit.go"
- "!**/pkg/acquisition/modules/loki/loki.go"
- "!**/pkg/acquisition/modules/loki/timestamp_test.go"
- "!**/pkg/acquisition/modules/s3/s3.go"
- "!**/pkg/acquisition/modules/syslog/syslog.go"
- "!**/pkg/acquisition/modules/wineventlog/wineventlog_windows.go"
- "!**/pkg/appsec/appsec.go"
- "!**/pkg/appsec/loader.go"
- "!**/pkg/csplugin/broker.go"
- "!**/pkg/csplugin/broker_test.go"
- "!**/pkg/dumps/bucker_dump.go"
- "!**/pkg/dumps/bucket_dump.go"
- "!**/pkg/dumps/parser_dump.go"
- "!**/pkg/hubtest/coverage.go"
- "!**/pkg/hubtest/hubtest_item.go"
- "!**/pkg/hubtest/parser_assert.go"
- "!**/pkg/hubtest/scenario_assert.go"
- "!**/pkg/leakybucket/buckets_test.go"
- "!**/pkg/leakybucket/manager_load.go"
- "!**/pkg/metabase/metabase.go"
- "!**/pkg/parser/node.go"
- "!**/pkg/parser/node_test.go"
- "!**/pkg/parser/parsing_test.go"
- "!**/pkg/parser/stage.go"
deny:
- pkg: "gopkg.in/yaml.v2"
desc: "yaml.v2 is deprecated for new code in favor of yaml.v3"

wsl:
# Allow blocks to end with comments
Expand Down
10 changes: 4 additions & 6 deletions cmd/crowdsec-cli/bouncers_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"time"

"github.com/aquasecurity/table"
"github.com/enescakir/emoji"

"github.com/crowdsecurity/crowdsec/pkg/database/ent"
"github.com/crowdsecurity/crowdsec/pkg/emoji"
)

func getBouncersTable(out io.Writer, bouncers []*ent.Bouncer) {
Expand All @@ -17,11 +17,9 @@ func getBouncersTable(out io.Writer, bouncers []*ent.Bouncer) {
t.SetAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft)

for _, b := range bouncers {
var revoked string
if !b.Revoked {
revoked = emoji.CheckMark.String()
} else {
revoked = emoji.Prohibited.String()
revoked := emoji.CheckMark
if b.Revoked {
revoked = emoji.Prohibited
}

t.AddRow(b.Name, b.IPAddress, revoked, b.LastPull.Format(time.RFC3339), b.Type, b.Version, b.AuthType)
Expand Down
14 changes: 7 additions & 7 deletions cmd/crowdsec-cli/console_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"io"

"github.com/aquasecurity/table"
"github.com/enescakir/emoji"

"github.com/crowdsecurity/crowdsec/pkg/csconfig"
"github.com/crowdsecurity/crowdsec/pkg/emoji"
)

func cmdConsoleStatusTable(out io.Writer, consoleCfg csconfig.ConsoleConfig) {
Expand All @@ -17,28 +17,28 @@ func cmdConsoleStatusTable(out io.Writer, consoleCfg csconfig.ConsoleConfig) {
t.SetHeaderAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft)

for _, option := range csconfig.CONSOLE_CONFIGS {
activated := string(emoji.CrossMark)
activated := emoji.CrossMark

switch option {
case csconfig.SEND_CUSTOM_SCENARIOS:
if *consoleCfg.ShareCustomScenarios {
activated = string(emoji.CheckMarkButton)
activated = emoji.CheckMarkButton
}
case csconfig.SEND_MANUAL_SCENARIOS:
if *consoleCfg.ShareManualDecisions {
activated = string(emoji.CheckMarkButton)
activated = emoji.CheckMarkButton
}
case csconfig.SEND_TAINTED_SCENARIOS:
if *consoleCfg.ShareTaintedScenarios {
activated = string(emoji.CheckMarkButton)
activated = emoji.CheckMarkButton
}
case csconfig.SEND_CONTEXT:
if *consoleCfg.ShareContext {
activated = string(emoji.CheckMarkButton)
activated = emoji.CheckMarkButton
}
case csconfig.CONSOLE_MANAGEMENT:
if *consoleCfg.ConsoleManagement {
activated = string(emoji.CheckMarkButton)
activated = emoji.CheckMarkButton
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec-cli/hubtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
"text/template"

"github.com/AlecAivazis/survey/v2"
"github.com/enescakir/emoji"
"github.com/fatih/color"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"

"github.com/crowdsecurity/crowdsec/pkg/dumps"
"github.com/crowdsecurity/crowdsec/pkg/emoji"
"github.com/crowdsecurity/crowdsec/pkg/hubtest"
)

Expand Down
21 changes: 12 additions & 9 deletions cmd/crowdsec-cli/hubtest_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"io"

"github.com/aquasecurity/table"
"github.com/enescakir/emoji"

"github.com/crowdsecurity/crowdsec/pkg/emoji"
"github.com/crowdsecurity/crowdsec/pkg/hubtest"
)

Expand All @@ -17,9 +17,9 @@ func hubTestResultTable(out io.Writer, testResult map[string]bool) {
t.SetAlignment(table.AlignLeft)

for testName, success := range testResult {
status := emoji.CheckMarkButton.String()
status := emoji.CheckMarkButton
if !success {
status = emoji.CrossMark.String()
status = emoji.CrossMark
}

t.AddRow(testName, status)
Expand Down Expand Up @@ -50,11 +50,12 @@ func hubTestParserCoverageTable(out io.Writer, coverage []hubtest.Coverage) {
parserTested := 0

for _, test := range coverage {
status := emoji.RedCircle.String()
status := emoji.RedCircle
if test.TestsCount > 0 {
status = emoji.GreenCircle.String()
status = emoji.GreenCircle
parserTested++
}

t.AddRow(test.Name, status, fmt.Sprintf("%d times (across %d tests)", test.TestsCount, len(test.PresentIn)))
}

Expand All @@ -70,11 +71,12 @@ func hubTestAppsecRuleCoverageTable(out io.Writer, coverage []hubtest.Coverage)
parserTested := 0

for _, test := range coverage {
status := emoji.RedCircle.String()
status := emoji.RedCircle
if test.TestsCount > 0 {
status = emoji.GreenCircle.String()
status = emoji.GreenCircle
parserTested++
}

t.AddRow(test.Name, status, fmt.Sprintf("%d times (across %d tests)", test.TestsCount, len(test.PresentIn)))
}

Expand All @@ -90,11 +92,12 @@ func hubTestScenarioCoverageTable(out io.Writer, coverage []hubtest.Coverage) {
parserTested := 0

for _, test := range coverage {
status := emoji.RedCircle.String()
status := emoji.RedCircle
if test.TestsCount > 0 {
status = emoji.GreenCircle.String()
status = emoji.GreenCircle
parserTested++
}

t.AddRow(test.Name, status, fmt.Sprintf("%d times (across %d tests)", test.TestsCount, len(test.PresentIn)))
}

Expand Down
11 changes: 5 additions & 6 deletions cmd/crowdsec-cli/machines_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"time"

"github.com/aquasecurity/table"
"github.com/enescakir/emoji"

"github.com/crowdsecurity/crowdsec/pkg/database/ent"
"github.com/crowdsecurity/crowdsec/pkg/emoji"
)

func getAgentsTable(out io.Writer, machines []*ent.Machine) {
Expand All @@ -17,17 +17,16 @@ func getAgentsTable(out io.Writer, machines []*ent.Machine) {
t.SetAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft)

for _, m := range machines {
var validated string
validated := emoji.Prohibited
if m.IsValidated {
validated = emoji.CheckMark.String()
} else {
validated = emoji.Prohibited.String()
validated = emoji.CheckMark
}

hb, active := getLastHeartbeat(m)
if !active {
hb = emoji.Warning.String() + " " + hb
hb = emoji.Warning + " " + hb
}

t.AddRow(m.MachineId, m.IpAddress, m.UpdatedAt.Format(time.RFC3339), validated, m.Version, m.AuthType, hb)
}

Expand Down
14 changes: 11 additions & 3 deletions cmd/crowdsec-cli/notifications_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,40 @@ import (
"strings"

"github.com/aquasecurity/table"
"github.com/enescakir/emoji"

"github.com/crowdsecurity/crowdsec/pkg/emoji"
)

func notificationListTable(out io.Writer, ncfgs map[string]NotificationsCfg) {
t := newLightTable(out)
t.SetHeaders("Active", "Name", "Type", "Profile name")
t.SetHeaderAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft)
t.SetAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft)

keys := make([]string, 0, len(ncfgs))
for k := range ncfgs {
keys = append(keys, k)
}

sort.Slice(keys, func(i, j int) bool {
return len(ncfgs[keys[i]].Profiles) > len(ncfgs[keys[j]].Profiles)
})

for _, k := range keys {
b := ncfgs[k]
profilesList := []string{}

for _, p := range b.Profiles {
profilesList = append(profilesList, p.Name)
}
active := emoji.CheckMark.String()

active := emoji.CheckMark
if len(profilesList) == 0 {
active = emoji.Prohibited.String()
active = emoji.Prohibited
}

t.AddRow(active, b.Config.Name, b.Config.Type, strings.Join(profilesList, ", "))
}

t.Render()
}
5 changes: 4 additions & 1 deletion cmd/crowdsec-cli/utils_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"strconv"

"github.com/aquasecurity/table"
"github.com/enescakir/emoji"

"github.com/crowdsecurity/crowdsec/pkg/cwhub"
"github.com/crowdsecurity/crowdsec/pkg/emoji"
)

func listHubItemTable(out io.Writer, title string, items []*cwhub.Item) {
Expand All @@ -21,6 +21,7 @@ func listHubItemTable(out io.Writer, title string, items []*cwhub.Item) {
status := fmt.Sprintf("%v %s", item.State.Emoji(), item.State.Text())
t.AddRow(item.Name, status, item.State.LocalVersion, item.State.LocalPath)
}

renderTableTitle(out, title)
t.Render()
}
Expand All @@ -42,6 +43,7 @@ func scenarioMetricsTable(out io.Writer, itemName string, metrics map[string]int
if metrics["instantiation"] == 0 {
return
}

t := newTable(out)
t.SetHeaders("Current Count", "Overflows", "Instantiated", "Poured", "Expired")

Expand Down Expand Up @@ -72,6 +74,7 @@ func parserMetricsTable(out io.Writer, itemName string, metrics map[string]map[s
strconv.Itoa(stats["parsed"]),
strconv.Itoa(stats["unparsed"]),
)

showTable = true
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec/api.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package main

import (
"errors"
"fmt"
"runtime"
"time"

"github.com/pkg/errors"
log "github.com/sirupsen/logrus"

"github.com/crowdsecurity/go-cs-lib/trace"
Expand Down
Loading

0 comments on commit a01b669

Please sign in to comment.