generated from falcosecurity/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 52
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
new(pkg,cmd): refactored builder script logic. #324
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ec18417
new(pkg,cmd): refactored builder script logic.
FedeDP d32b74f
fix(pkg/driverbuilder): fixed debian_kernel template.
FedeDP bddc7a8
fix(pkg/driverbuilder): fixed archlinux kernel urls discovering.
FedeDP 98d1211
chore(cmd,pkg): support automatic kernel headers download/extraction …
FedeDP bd11d56
fix(pkg/driverbuilder): fixed kubernetes command.
FedeDP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,42 +7,33 @@ import ( | |
"github.com/spf13/viper" | ||
"log/slog" | ||
"os" | ||
"os/user" | ||
"runtime" | ||
) | ||
|
||
type localCmdOptions struct { | ||
useDKMS bool | ||
srcDir string | ||
envMap map[string]string | ||
useDKMS bool | ||
downloadHeaders bool | ||
srcDir string | ||
envMap map[string]string | ||
} | ||
|
||
// NewLocalCmd creates the `driverkit local` command. | ||
func NewLocalCmd(rootCommand *RootCmd, rootOpts *RootOptions, rootFlags *pflag.FlagSet) *cobra.Command { | ||
func NewLocalCmd(rootOpts *RootOptions, rootFlags *pflag.FlagSet) *cobra.Command { | ||
opts := localCmdOptions{} | ||
localCmd := &cobra.Command{ | ||
Use: "local", | ||
Short: "Build Falco kernel modules and eBPF probes in local env with local kernel sources and gcc/clang.", | ||
PersistentPreRunE: persistentPreRunFunc(rootCommand, rootOpts), | ||
Use: "local", | ||
Short: "Build Falco kernel modules and eBPF probes in local env with local kernel sources and gcc/clang.", | ||
Run: func(c *cobra.Command, args []string) { | ||
slog.With("processor", c.Name()).Info("driver building, it will take a few seconds") | ||
if !configOptions.DryRun { | ||
b := rootOpts.ToBuild() | ||
if !b.HasOutputs() { | ||
return | ||
} | ||
if opts.useDKMS { | ||
currentUser, err := user.Current() | ||
if err != nil { | ||
slog.With("err", err.Error()).Error("Failed to retrieve user. Exiting.") | ||
os.Exit(1) | ||
} | ||
if currentUser.Username != "root" { | ||
slog.Error("Must be run as root for DKMS build.") | ||
os.Exit(1) | ||
} | ||
} | ||
if err := driverbuilder.NewLocalBuildProcessor(viper.GetInt("timeout"), opts.useDKMS, opts.srcDir, opts.envMap).Start(b); err != nil { | ||
if err := driverbuilder.NewLocalBuildProcessor(viper.GetInt("timeout"), | ||
opts.useDKMS, | ||
opts.downloadHeaders, | ||
opts.srcDir, | ||
opts.envMap).Start(b); err != nil { | ||
slog.With("err", err.Error()).Error("exiting") | ||
os.Exit(1) | ||
} | ||
|
@@ -52,7 +43,6 @@ func NewLocalCmd(rootCommand *RootCmd, rootOpts *RootOptions, rootFlags *pflag.F | |
// Add root flags, but not the ones unneeded | ||
unusedFlagsSet := map[string]struct{}{ | ||
"architecture": {}, | ||
"target": {}, | ||
"kernelurls": {}, | ||
"builderrepo": {}, | ||
"builderimage": {}, | ||
|
@@ -71,18 +61,9 @@ func NewLocalCmd(rootCommand *RootCmd, rootOpts *RootOptions, rootFlags *pflag.F | |
} | ||
}) | ||
flagSet.BoolVar(&opts.useDKMS, "dkms", false, "Enforce usage of DKMS to build the kernel module.") | ||
flagSet.BoolVar(&opts.downloadHeaders, "download-headers", false, "Try to automatically download kernel headers.") | ||
flagSet.StringVar(&opts.srcDir, "src-dir", "", "Enforce usage of local source dir to build drivers.") | ||
flagSet.StringToStringVar(&opts.envMap, "env", nil, "Env variables to be enforced during the driver build.") | ||
flagSet.StringToStringVar(&opts.envMap, "env", make(map[string]string), "Env variables to be enforced during the driver build.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default to an empty map instead of nil. Not a big deal anyway. |
||
localCmd.PersistentFlags().AddFlagSet(flagSet) | ||
return localCmd | ||
} | ||
|
||
// Partially overrides rootCmd.persistentPreRunFunc setting some defaults before config init/validation stage. | ||
func persistentPreRunFunc(rootCommand *RootCmd, rootOpts *RootOptions) func(c *cobra.Command, args []string) error { | ||
return func(c *cobra.Command, args []string) error { | ||
// Default values | ||
rootOpts.Target = "local" | ||
rootOpts.Architecture = runtime.GOARCH | ||
return rootCommand.c.PersistentPreRunE(c, args) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,9 @@ import ( | |
"github.com/falcosecurity/driverkit/pkg/kernelrelease" | ||
) | ||
|
||
//go:embed templates/alinux_kernel.sh | ||
var alinuxKernelTemplate string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Each builder does now expose a kernel download/extract template too. |
||
|
||
//go:embed templates/alinux.sh | ||
var alinuxTemplate string | ||
|
||
|
@@ -32,7 +35,6 @@ func init() { | |
} | ||
|
||
type alinuxTemplateData struct { | ||
commonTemplateData | ||
KernelDownloadURL string | ||
} | ||
|
||
|
@@ -43,6 +45,10 @@ func (c *alinux) Name() string { | |
return TargetTypeAlinux.String() | ||
} | ||
|
||
func (c *alinux) TemplateKernelUrlsScript() string { | ||
return alinuxKernelTemplate | ||
} | ||
|
||
func (c *alinux) TemplateScript() string { | ||
return alinuxTemplate | ||
} | ||
|
@@ -51,10 +57,9 @@ func (c *alinux) URLs(kr kernelrelease.KernelRelease) ([]string, error) { | |
return fetchAlinuxKernelURLS(kr), nil | ||
} | ||
|
||
func (c *alinux) TemplateData(cfg Config, kr kernelrelease.KernelRelease, urls []string) interface{} { | ||
func (c *alinux) KernelTemplateData(_ kernelrelease.KernelRelease, urls []string) interface{} { | ||
return alinuxTemplateData{ | ||
commonTemplateData: cfg.toTemplateData(c, kr), | ||
KernelDownloadURL: urls[0], | ||
KernelDownloadURL: urls[0], | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Local cmd now supports automatically downloading kernel headers for the build.
Note that it is not a fatal error if kernel headers are not found; it will just continue trying with locally installed ones, if any.