Skip to content

Commit 3d2d5e9

Browse files
committed
feat: use falllback user for Slack
1 parent 4b4101d commit 3d2d5e9

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@ Nags users on Slack about outstanding application vulnerabilities found by Crowd
1010

1111
```yaml
1212
slack:
13+
# slack bot token
1314
token: "XXX"
15+
# Slack user that receives messages if the user is not found
16+
fallback_user: "[email protected]"
1417

1518
falcon:
1619
clientid: "XXX"
1720
secret: "XXX"
1821
cloud_region: "eu-1"
1922

20-
email_domain: "mycompany"
23+
email:
24+
# email domain
25+
domain: "mycompany"
2126

27+
# what is sent to the user in Go templating
2228
message: |
2329
*:warning: We found security vulnerabilities on your device(s)*
2430
Hi {{ .Slack.Profile.FirstName }} {{ .Slack.Profile.LastName }}! One or more of your devices seem to be vulnerable.

cmd/main.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ func getUniqueDeviceID(hostInfo models.DomainAPIVulnerabilityHostInfoV2) (string
6161

6262
func findEmailTag(tags []string, emailHost string) (email string, err error) {
6363
for _, tag := range tags {
64-
tag = strings.TrimLeft(tag, tagFalconPrefix)
64+
tag = strings.ToLower(tag)
65+
tag = strings.TrimLeft(tag, strings.ToLower(tagFalconPrefix))
66+
67+
logrus.WithField("tag", tag).Debug("looking at falcon tag")
6568

6669
if !strings.HasPrefix(tag, tagEmailPrefix) {
6770
continue
@@ -95,9 +98,16 @@ func findEmailTag(tags []string, emailHost string) (email string, err error) {
9598
func main() {
9699
ctx := context.Background()
97100

98-
configPath := flag.String("config", "", "Path to your config file")
101+
configPath := flag.String("config", "", "Path to your config file.")
102+
logLevelStr:= flag.String("log", "info", "Log level.")
99103
flag.Parse()
100104

105+
logLevel, err := logrus.ParseLevel(*logLevelStr)
106+
if err != nil {
107+
logrus.WithError(err).Fatal("could not parse log level")
108+
}
109+
logrus.SetLevel(logLevel)
110+
101111
config, err := config2.LoadConfig(*configPath)
102112
if err != nil {
103113
log.Fatalf("could not load configuration: %s", err)
@@ -227,14 +237,16 @@ func main() {
227237
users := map[string]DeviceUser{}
228238

229239
for _, device := range devices {
230-
userEmail, err := findEmailTag(device.Tags, config.EmailDomain)
240+
userEmail, err := findEmailTag(device.Tags, config.Email.Domain)
231241
if err != nil {
232242
logrus.
233243
WithError(err).
234244
WithField("tags", device.Tags).
235245
WithField("prefix", tagEmailPrefix).
236-
Warn("could not find user email for " + device.MachineName)
237-
continue
246+
WithField("device", device.MachineName).
247+
Warn("could not find user email, using fallback user")
248+
249+
userEmail = config.Slack.FallbackUser
238250
}
239251

240252
user, ok := users[userEmail]

config/config.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const (
1515
type Config struct {
1616
Slack struct {
1717
Token string `yaml:"token" env:"SLACK_TOKEN"`
18+
FallbackUser string `yaml:"fallback_user" emv:"SLACK_FALLBACK_USER"`
1819
} `yaml:"slack"`
1920

2021
Falcon struct {
@@ -23,7 +24,9 @@ type Config struct {
2324
CloudRegion string `yaml:"cloud_region" env:"FALCON_CLOUD_REGION"`
2425
} `yaml:"falcon"`
2526

26-
EmailDomain string `yaml:"email_domain" env:"EMAIL_DOMAIN"`
27+
Email struct {
28+
Domain string `yaml:"domain" env:"DOMAIN"`
29+
} `yaml:"email"`
2730

2831
Message string `yaml:"message" env:"MESSAGE"`
2932
}
@@ -68,7 +71,7 @@ func (c *Config) Validate() error {
6871
return errors.New("missing falcon cloud region")
6972
}
7073

71-
if c.EmailDomain == "" {
74+
if c.Email.Domain == "" {
7275
return errors.New("missing email domain")
7376
}
7477

0 commit comments

Comments
 (0)