Skip to content

Commit

Permalink
chore(pkg,cmd): updated urlArchFmt to point to github pages urls.
Browse files Browse the repository at this point in the history
Moreover, updated driverkit to v0.15.2 and dropped LastRunDistro support.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
  • Loading branch information
FedeDP authored and poiana committed Oct 19, 2023
1 parent 790d97b commit 41fe0b3
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ GO ?= go
GORELEASER ?= goreleaser
output ?= dbg-go
TEST_FLAGS ?= -v -race -tags=test_all
DRIVERKIT_VERSION=v0.15.1
DRIVERKIT_VERSION=v0.15.2
LDFLAGS := -X github.com/falcosecurity/driverkit/pkg/driverbuilder/builder.defaultImageTag=${DRIVERKIT_VERSION}

.PHONY: build
Expand Down
1 change: 0 additions & 1 deletion cmd/generate/generate_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func NewGenerateConfigsCmd() *cobra.Command {
Short: "Generate new dbg configs",
Long: `In auto mode, configs will be generated starting from kernel-crawler output.
In this scenario, --target-{distro,kernelrelease,kernelversion} are available to filter to-be-generated configs. Regexes are allowed.
Moreover, you can pass special value "load" as target-distro to make the tool automatically fetch latest distro kernel-crawler ran against.
Instead, when auto mode is disabled, the tool is able to generate a single config (for each driver version).
In this scenario, --target-{distro,kernelrelease,kernelversion} CANNOT be regexes but must be exact values.
Also, in non-automatic mode, kernelurls will be retrieved using driverkit libraries.
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/aws/aws-sdk-go-v2/config v1.18.37
github.com/aws/aws-sdk-go-v2/credentials v1.13.35
github.com/aws/aws-sdk-go-v2/service/s3 v1.38.5
github.com/falcosecurity/driverkit v0.15.1
github.com/falcosecurity/driverkit v0.15.2
github.com/johannesboyne/gofakes3 v0.0.0-20230506070712-04da935ef877
github.com/json-iterator/go v1.1.12
github.com/olekukonko/tablewriter v0.0.5
Expand Down Expand Up @@ -115,12 +115,12 @@ require (
github.com/subosito/gotenv v1.6.0 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.starlark.net v0.0.0-20230831151029-c9e9adf3fde2 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.11.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 // indirect
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ github.com/falcosecurity/driverkit v0.15.0 h1:pi4GT+qQU+6kx6w1/yZ3DsPqzXiHFkCs4N
github.com/falcosecurity/driverkit v0.15.0/go.mod h1:RPI15yAVBOELYZ2iJUl3+cOwVBi4o8kWd0AYoBF4xrk=
github.com/falcosecurity/driverkit v0.15.1 h1:wTSrY3QKzOv4oEaJZERWVsNd5tN7hJ8Y+9neGpfKeg4=
github.com/falcosecurity/driverkit v0.15.1/go.mod h1:RPI15yAVBOELYZ2iJUl3+cOwVBi4o8kWd0AYoBF4xrk=
github.com/falcosecurity/driverkit v0.15.2 h1:QDC3PEzpIILTwZA8/bqGZYBXxWRD2ZVVEAtZcDtLLno=
github.com/falcosecurity/driverkit v0.15.2/go.mod h1:RXG4bbofv903PwXKZne3RgnFcVKlyOTioKeWnDt9qBw=
github.com/falcosecurity/falcoctl v0.6.0 h1:+VW6/HJ9mWU2p8apiTQuKRHFsBngfG1s35ao4X2BEfc=
github.com/falcosecurity/falcoctl v0.6.0/go.mod h1:4Hx4h3KtcaQzPKxvYn5S9x4IHxwd6QRK9Gu04HHNbhE=
github.com/fatih/camelcase v1.0.0 h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8=
Expand Down Expand Up @@ -429,6 +431,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -505,6 +509,8 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -576,6 +582,8 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand All @@ -584,6 +592,8 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU=
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
3 changes: 1 addition & 2 deletions pkg/generate/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ limitations under the License.
package generate

const (
urlArchFmt = "https://raw.githubusercontent.com/falcosecurity/kernel-crawler/kernels/%s/list.json"
urlLastDistro = "https://raw.githubusercontent.com/falcosecurity/kernel-crawler/kernels/last_run_distro.txt"
urlArchFmt = "https://falcosecurity.github.io/kernel-crawler/%s/list.json"
)
44 changes: 3 additions & 41 deletions pkg/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,23 @@ package generate
import (
"errors"
"fmt"
"log/slog"
"os"
"path/filepath"
"strings"

"github.com/falcosecurity/dbg-go/pkg/root"
"github.com/falcosecurity/dbg-go/pkg/validate"
"github.com/falcosecurity/driverkit/pkg/driverbuilder/builder"
"github.com/falcosecurity/driverkit/pkg/kernelrelease"
json "github.com/json-iterator/go"
"golang.org/x/sync/errgroup"
"gopkg.in/yaml.v3"
"log/slog"
"os"
"path/filepath"
)

var (
testJsonData []byte
testCacheData bool
)

func loadLastRunDistro() (string, error) {
lastDistroBytes, err := getURL(urlLastDistro)
if err != nil {
return "", err
}
lastDistro := strings.TrimSuffix(string(lastDistroBytes), "\n")
if lastDistro == "*" {
// Fix up regex (empty regex -> always true)
lastDistro = ""
}
return lastDistro, nil
}

func Run(opts Options) error {
slog.Info("generating config files")
if opts.Auto {
Expand Down Expand Up @@ -85,29 +70,6 @@ func autogenerateConfigs(opts Options) error {
testJsonData = jsonData
}

// either download latest distro from kernel-crawler
// or translate the driverkit distro provided by the user to its kernel-crawler naming
if opts.Distro == "load" {
// Fetch last distro kernel-crawler ran against
lastDistro, err := loadLastRunDistro()
if err != nil {
return err
}
slog.Info("loaded last-distro", "distro", lastDistro)

// If lastDistro is empty it means we need to run on all supported distros; this is done automatically.
if lastDistro != "" {
// Map back the kernel crawler distro to our internal driverkit distro
opts.Distro = root.ToDriverkitDistro(root.KernelCrawlerDistro(lastDistro))
if opts.Distro == "" {
return fmt.Errorf("kernel-crawler last run distro '%s' unsupported.\n", lastDistro)
}
} else {
// This will match all supported distros
opts.Distro = ""
}
}

fullJson := map[string][]validate.DriverkitYaml{}

// Unmarshal the big json
Expand Down
25 changes: 2 additions & 23 deletions pkg/generate/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,6 @@ func TestGenerate(t *testing.T) {
expectError bool
expectedMinConfigs int
}{
"run in auto mode with loaded from kernel-crawler distro on multiple driver versions": {
opts: Options{
Options: root.Options{
RepoRoot: "./test/",
Architecture: "amd64",
DriverVersion: []string{"1.0.0+driver", "2.0.0+driver"},
Target: root.Target{
Distro: "load", // Should load it from lastDistro kernel crawler file
},
DriverName: "falco",
},
Auto: true,
},
expectError: false,
expectedMinConfigs: 1,
},
"run in auto mode with any target distro filter on single driver version": {
opts: Options{
Options: root.Options{
Expand Down Expand Up @@ -289,17 +273,12 @@ func TestGenerate(t *testing.T) {
statsOpts.KernelRelease = ""
statsOpts.Distro = ""

stats, err := statter.GetDriverStats(statsOpts)
driverStats, err := statter.GetDriverStats(statsOpts)
assert.NoError(t, err)
assert.GreaterOrEqual(t, len(stats), test.expectedMinConfigs)
assert.GreaterOrEqual(t, len(driverStats), test.expectedMinConfigs)

// Validate all generated files
validateOpts := validate.Options{Options: test.opts.Options}
if validateOpts.Distro == "load" {
// When we load from last kernel-crawler distro,
// force validate all
validateOpts.Distro = ""
}
err = validate.Run(validateOpts)
assert.NoError(t, err)
}
Expand Down

0 comments on commit 41fe0b3

Please sign in to comment.