Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add listenaddress option #187

Merged
merged 1 commit into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ vars_ override values from _file_.
See **config_example.yaml** :

```yaml
#listenaddress: "" # ip address to bind falcosidekick to (default: "" meaning all addresses)
#listenport: 2801 # port to listen for daemon (default: 2801)
debug: false # if true all outputs will print in stdout the payload they send (default: false)
customfields: # custom fields are added to falco events
Expand Down Expand Up @@ -320,6 +321,7 @@ override these from _yaml file_.
The _env vars_ "match" field names in \*yaml file with this structure (**take
care of lower/uppercases**) : `yaml: a.b --> envvar: A_B` :

- **LISTENADDRESS** : ip address to bind falcosidekick to (default: "" meaning all addresses)
- **LISTENPORT** : port to listen for daemon (default: `2801`)
- **DEBUG** : if _true_ all outputs will print in stdout the payload they send
(default: false)
Expand Down
6 changes: 6 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"log"
"net"
"os"
"path"
"path/filepath"
Expand All @@ -26,6 +27,7 @@ func getConfig() *types.Configuration {
kingpin.Parse()

v := viper.New()
v.SetDefault("ListenAddress", "")
v.SetDefault("ListenPort", 2801)
v.SetDefault("Debug", false)
v.SetDefault("CheckCert", true)
Expand Down Expand Up @@ -198,6 +200,10 @@ func getConfig() *types.Configuration {
log.Fatalf("[ERROR] : Bad port number\n")
}

if ip := net.ParseIP(c.ListenAddress); c.ListenAddress != "" && ip == nil {
log.Fatalf("[ERROR] : Failed to parse ListenAddress")
}

c.Slack.MinimumPriority = checkPriority(c.Slack.MinimumPriority)
c.Rocketchat.MinimumPriority = checkPriority(c.Rocketchat.MinimumPriority)
c.Mattermost.MinimumPriority = checkPriority(c.Mattermost.MinimumPriority)
Expand Down
1 change: 1 addition & 0 deletions config_example.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#listenaddress: "" # ip address to bind falcosidekick to (default: "" meaning all addresses)
#listenport: 2801 # port to listen for daemon (default: 2801)
debug: false # if true all outputs will print in stdout the payload they send (default: false)
customfields: # custom fields are added to falco events
Expand Down
10 changes: 5 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
"fmt"
"log"
"net/http"
"strconv"
"strings"

"github.com/DataDog/datadog-go/statsd"
Expand Down Expand Up @@ -371,12 +371,12 @@ func main() {
http.HandleFunc("/test", testHandler)
http.Handle("/metrics", promhttp.Handler())

log.Printf("[INFO] : Falco Sidekick is up and listening on port %v\n", config.ListenPort)
log.Printf("[INFO] : Falco Sidekick is up and listening on %s:%d", config.ListenAddress, config.ListenPort)
if config.Debug {
log.Printf("[INFO] : Debug mode : %v\n", config.Debug)
log.Printf("[INFO] : Debug mode : %v", config.Debug)
}

if err := http.ListenAndServe(":"+strconv.Itoa(config.ListenPort), nil); err != nil {
log.Fatalf("[ERROR] : %v\n", err.Error())
if err := http.ListenAndServe(fmt.Sprintf("%s:%d", config.ListenAddress, config.ListenPort), nil); err != nil {
log.Fatalf("[ERROR] : %v", err.Error())
}
}
5 changes: 3 additions & 2 deletions outputs/webui.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package outputs
import (
"encoding/json"
"expvar"
"fmt"
"log"

"github.com/falcosecurity/falcosidekick/types"
Expand All @@ -19,7 +18,9 @@ type WebUIPayload struct {
func newWebUIPayload(falcopayload types.FalcoPayload, config *types.Configuration) WebUIPayload {
s := new(map[string]int64)

json.Unmarshal([]byte(fmt.Sprintf("%v", expvar.Get("falco.priority"))), &s)
if err := json.Unmarshal([]byte(expvar.Get("falco.priority").String()), &s); err != nil {
log.Printf("[ERROR] : WebUI - failed to unmarshal expvar : %s", err)
}

return WebUIPayload{
UUID: config.UUID,
Expand Down
1 change: 1 addition & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Configuration struct {
UUID string
CheckCert bool
Debug bool
ListenAddress string
ListenPort int
Customfields map[string]string
Slack SlackOutputConfig
Expand Down