From eb20d7be7a99dd5ed6d14e4670d0e494943e82f5 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Mon, 22 Mar 2021 13:02:05 +0100 Subject: [PATCH 1/3] add OpenBSD support for generating the machine id if /etc/machine-id is unavailable use the hw.uuid sysctl on openbsd to get the hardware UUID in case /etc/machine-id is not available because /proc is linux-only --- cmd/crowdsec-cli/machines.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cmd/crowdsec-cli/machines.go b/cmd/crowdsec-cli/machines.go index bbdf11c05e2..8ade47f215b 100644 --- a/cmd/crowdsec-cli/machines.go +++ b/cmd/crowdsec-cli/machines.go @@ -9,6 +9,8 @@ import ( "os" "strings" "time" + "runtime" + "syscall" "github.com/AlecAivazis/survey/v2" "github.com/crowdsecurity/crowdsec/pkg/csconfig" @@ -65,11 +67,18 @@ func generateID() (string, error) { log.Debugf("failed to get machine-id with usual files : %s", err) } if id == "" || err != nil { - bID, err := ioutil.ReadFile(uuid) + var err error + var bID []byte + switch runtime.GOOS { + case "openbsd": + id, err = syscall.Sysctl("hw.uuid") + default: + bID, err = ioutil.ReadFile(uuid) + id = string(bID) + } if err != nil { return "", errors.Wrap(err, "generating machine id") } - id = string(bID) } id = strings.ReplaceAll(id, "-", "")[:32] id = fmt.Sprintf("%s%s", id, generatePassword(16)) From 111268597d1353b5dd71b47a7721a6abdc94ea0c Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Mon, 22 Mar 2021 13:05:42 +0100 Subject: [PATCH 2/3] allow overriding the MAKE variable from the environment outside of linux GNU make is usually called gmake so let's allow overriding the MAKE variable from the environment --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b2e92df9c1f..fe815f807aa 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ CSCLI_FOLDER = "./cmd/crowdsec-cli/" CROWDSEC_BIN = "crowdsec" CSCLI_BIN = "cscli" BUILD_CMD = "build" -MAKE = "make" +MAKE ?= "make" GOARCH=amd64 GOOS=linux From b8ec10f08321eccff88f14f0d5a460b37e26ea87 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Mon, 22 Mar 2021 13:35:15 +0100 Subject: [PATCH 3/3] use golang.org/x/sys/unix instead of syscall.Sysctl --- cmd/crowdsec-cli/machines.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/crowdsec-cli/machines.go b/cmd/crowdsec-cli/machines.go index 8ade47f215b..d0457645609 100644 --- a/cmd/crowdsec-cli/machines.go +++ b/cmd/crowdsec-cli/machines.go @@ -10,7 +10,6 @@ import ( "strings" "time" "runtime" - "syscall" "github.com/AlecAivazis/survey/v2" "github.com/crowdsecurity/crowdsec/pkg/csconfig" @@ -23,6 +22,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "gopkg.in/yaml.v2" + "golang.org/x/sys/unix" ) var machineID string @@ -71,7 +71,7 @@ func generateID() (string, error) { var bID []byte switch runtime.GOOS { case "openbsd": - id, err = syscall.Sysctl("hw.uuid") + id, err = unix.Sysctl("hw.uuid") default: bID, err = ioutil.ReadFile(uuid) id = string(bID)