Repository: falcosecurity/driverkit
Pull request #215 (2022-09-23 10:21:06)

fix(pkg,cmd,validate): fixed flatcar builder
**What type of PR is this?**

/kind bug

<!--
Please remove the leading whitespace before the `/kind <>` you uncommented.
-->

**Any specific area of the project related to this PR?**

/area pkg


**What this PR does / why we need it**:

Fix a crash in the flatcar builder; moreover, make it actually work.
Basically it is now the same as vanilla/minikube builders, with some small differences. It will now require `kernelconfigdata` option. That is much more smart than fetching the kernelconfigdata URL only to download it in the template script, considering that we already had a `kernelconfigdata` option in driverkit.

Moreover, moved all builder structs receivers to pointers, so that we can actually update any struct members in receiver methods.

Finally, actually require `kernelconfigdata` param for minikube and flatcar too.

This goes together with https://github.com/falcosecurity/kernel-crawler/pull/50.

**Which issue(s) this PR fixes**:

Flatcar crash + make it working.

Fixes #

**Special notes for your reviewer**:

**Does this PR introduce a user-facing change?**:

<!--
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below.
If the PR requires additional action from users switching to the new release, prepend the string "action required:".
For example, `action required: change the API interface of the rule engine`.
-->

```release-note
fix(pkg): fixed flatcar builder crash and implementation
```


poiana: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/falcosecurity/driverkit/pull/215#" title="Author self-approved">FedeDP</a>*

The full list of commands accepted by this bot can be found [here](https://prow.falco.org/command-help?repo=falcosecurity%2Fdriverkit).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/falcosecurity/driverkit/blob/master/OWNERS)~~ [FedeDP]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/Example_configs.md b/Example_configs.md
index df163ab..54ed990 100644
--- a/Example_configs.md
+++ b/Example_configs.md
@@ -128,7 +128,8 @@ driverversion: master
 ## flatcar
 
 Example configuration file to build both the Kernel module and eBPF probe for Flatcar.
-The Flatcar release version needs to be provided in the `kernelrelease` field instead of the kernel version.
+The Flatcar release version needs to be provided in the `kernelrelease` field instead of the kernel version;
+moreover, kernelconfigdata must be provided.
 
 ```yaml
 kernelrelease: 3185.0.0
@@ -137,6 +138,7 @@ output:
   module: /tmp/falco-flatcar-3185.0.0.ko
   probe: /tmp/falco-flatcar-3185.0.0.o
 driverversion: master
+kernelconfigdata: Q09ORklHX0ZBTk9USUZZPXkKQ09ORklHX0t...
 ```
 
 ## minikube
diff --git a/cmd/root.go b/cmd/root.go
index f83327b..11fddda 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -148,6 +148,9 @@ func NewRootCmd() *RootCmd {
 
 	flags.StringSliceVar(&rootOpts.KernelUrls, "kernelurls", nil, "list of kernel header urls (e.g. --kernelurls <URL1> --kernelurls <URL2> --kernelurls \"<URL3>,<URL4>\")")
 
+	flags.StringVar(&rootOpts.Repo.Org, "repo-org", rootOpts.Repo.Org, "repository github organization")
+	flags.StringVar(&rootOpts.Repo.Name, "repo-name", rootOpts.Repo.Name, "repository github name")
+
 	viper.BindPFlags(flags)
 
 	// Flag annotations and custom completions
diff --git a/cmd/root_options.go b/cmd/root_options.go
index dc8dcad..714f4e5 100644
--- a/cmd/root_options.go
+++ b/cmd/root_options.go
@@ -15,6 +15,11 @@ type OutputOptions struct {
 	Probe  string `validate:"required_without=Module,filepath,omitempty,endswith=.o" name:"output probe path"`
 }
 
+type RepoOptions struct {
+	Org  string `default:"falcosecurity" name:"organization name"`
+	Name string `default:"libs" name:"repo name"`
+}
+
 // RootOptions ...
 type RootOptions struct {
 	Architecture     string   `validate:"required,architecture" name:"architecture"`
@@ -28,6 +33,7 @@ type RootOptions struct {
 	BuilderImage     string   `validate:"imagename" name:"builder image"`
 	GCCVersion       float64  `name:"gcc version"`
 	KernelUrls       []string `name:"kernel header urls"`
+	Repo             RepoOptions
 	Output           OutputOptions
 }
 
@@ -86,6 +92,8 @@ func (ro *RootOptions) Log() {
 	if len(ro.KernelUrls) > 0 {
 		fields["kernelurls"] = ro.KernelUrls
 	}
+	fields["repo-org"] = ro.Repo.Org
+	fields["repo-name"] = ro.Repo.Name
 
 	logger.WithFields(fields).Debug("running with options")
 }
@@ -110,6 +118,8 @@ func (ro *RootOptions) toBuild() *builder.Build {
 		GCCVersion:         ro.GCCVersion,
 		CustomBuilderImage: ro.BuilderImage,
 		KernelUrls:         ro.KernelUrls,
+		RepoOrg:            ro.Repo.Org,
+		RepoName:           ro.Repo.Name,
 	}
 }
 
@@ -119,8 +129,12 @@ func (ro *RootOptions) toBuild() *builder.Build {
 func RootOptionsLevelValidation(level validator.StructLevel) {
 	opts := level.Current().Interface().(RootOptions)
 
-	if len(opts.KernelConfigData) == 0 && opts.Target == builder.TargetTypeVanilla.String() {
-		level.ReportError(opts.KernelConfigData, "kernelConfigData", "KernelConfigData", "required_kernelconfigdata_with_target_vanilla", "")
+	if opts.Target == builder.TargetTypeVanilla.String() ||
+		opts.Target == builder.TargetTypeMinikube.String() ||
+		opts.Target == builder.TargetTypeFlatcar.String() {
+		if len(opts.KernelConfigData) == 0 {
+			level.ReportError(opts.KernelConfigData, "kernelConfigData", "KernelConfigData", "required_kernelconfigdata_with_target_vanilla", "")
+		}
 	}
 
 	if opts.KernelVersion == "" && (opts.Target == builder.TargetTypeUbuntu.String()) {
diff --git a/pkg/driverbuilder/builder/amazonlinux.go b/pkg/driverbuilder/builder/amazonlinux.go
index b7f0117..174d858 100644
--- a/pkg/driverbuilder/builder/amazonlinux.go
+++ b/pkg/driverbuilder/builder/amazonlinux.go
@@ -62,26 +62,26 @@ type amazonlinuxTemplateData struct {
 	KernelDownloadURLs []string
 }
 
-func (a amazonlinux) Name() string {
+func (a *amazonlinux) Name() string {
 	return TargetTypeAmazonLinux.String()
 }
 
-func (a amazonlinux) TemplateScript() string {
+func (a *amazonlinux) TemplateScript() string {
 	return amazonlinuxTemplate
 }
 
-func (a amazonlinux) URLs(_ Config, kr kernelrelease.KernelRelease) ([]string, error) {
+func (a *amazonlinux) URLs(_ Config, kr kernelrelease.KernelRelease) ([]string, error) {
 	return fetchAmazonLinuxPackagesURLs(a, kr)
 }
 
-func (a amazonlinux) TemplateData(c Config, kr kernelrelease.KernelRelease, urls []string) interface{} {
+func (a *amazonlinux) TemplateData(c Config, kr kernelrelease.KernelRelease, urls []string) interface{} {
 	return amazonlinuxTemplateData{
-		commonTemplateData: c.toTemplateData(),
+		commonTemplateData: c.toTemplateData(a, kr),
 		KernelDownloadURLs: urls,
 	}
 }
 
-func (a amazonlinux) repos() []string {
+func (a *amazonlinux) repos() []string {
 	return []string{
 		"latest/updates",
 		"latest/main",
@@ -94,46 +94,46 @@ func (a amazonlinux) repos() []string {
 	}
 }
 
-func (a amazonlinux) baseUrl() string {
+func (a *amazonlinux) baseUrl() string {
 	return "http://repo.us-east-1.amazonaws.com"
 }
 
-func (a amazonlinux) ext() string {
+func (a *amazonlinux) ext() string {
 	return "bz2"
 }
 
-func (a amazonlinux2022) Name() string {
+func (a *amazonlinux2022) Name() string {
 	return TargetTypeAmazonLinux2022.String()
 }
 
-func (a amazonlinux2022) URLs(_ Config, kr kernelrelease.KernelRelease) ([]string, error) {
+func (a *amazonlinux2022) URLs(_ Config, kr kernelrelease.KernelRelease) ([]string, error) {
 	return fetchAmazonLinuxPackagesURLs(a, kr)
 }
 
-func (a amazonlinux2022) repos() []string {
+func (a *amazonlinux2022) repos() []string {
 	return []string{
 		"2022.0.20220202",
 		"2022.0.20220315",
 	}
 }
 
-func (a amazonlinux2022) baseUrl() string {
+func (a *amazonlinux2022) baseUrl() string {
 	return "https://al2022-repos-us-east-1-9761ab97.s3.dualstack.us-east-1.amazonaws.com/core/mirrors"
 }
 
-func (a amazonlinux2022) ext() string {
+func (a *amazonlinux2022) ext() string {
 	return "gz"
 }
 
-func (a amazonlinux2) Name() string {
+func (a *amazonlinux2) Name() string {
 	return TargetTypeAmazonLinux2.String()
 }
 
-func (a amazonlinux2) URLs(_ Config, kr kernelrelease.KernelRelease) ([]string, error) {
+func (a *amazonlinux2) URLs(_ Config, kr kernelrelease.KernelRelease) ([]string, error) {
 	return fetchAmazonLinuxPackagesURLs(a, kr)
 }
 
-func (a amazonlinux2) repos() []string {
+func (a *amazonlinux2) repos() []string {
 	return []string{
 		"core/2.0",
 		"core/latest",
@@ -142,22 +142,22 @@ func (a amazonlinux2) repos() []string {
 	}
 }
 
-func (a amazonlinux2) baseUrl() string {
+func (a *amazonlinux2) baseUrl() string {
 	return "http://amazonlinux.us-east-1.amazonaws.com/2"
 }
 
-func (a amazonlinux2) ext() string {
+func (a *amazonlinux2) ext() string {
 	return "gz"
 }
 
 func buildMirror(a amazonBuilder, r string, kv kernelrelease.KernelRelease) (string, error) {
 	var baseURL string
 	switch a.(type) {
-	case amazonlinux:
+	case *amazonlinux:
 		baseURL = fmt.Sprintf("%s/%s", a.baseUrl(), r)
-	case amazonlinux2:
+	case *amazonlinux2:
 		baseURL = fmt.Sprintf("%s/%s/%s", a.baseUrl(), r, kv.Architecture.ToNonDeb())
-	case amazonlinux2022:
+	case *amazonlinux2022:
 		baseURL = fmt.Sprintf("%s/%s/%s", a.baseUrl(), r, kv.Architecture.ToNonDeb())
 	default:
 		return "", fmt.Errorf("unsupported target")
diff --git a/pkg/driverbuilder/builder/archlinux.go b/pkg/driverbuilder/builder/archlinux.go
index 314b344..20e9814 100644
--- a/pkg/driverbuilder/builder/archlinux.go
+++ b/pkg/driverbuilder/builder/archlinux.go
@@ -27,15 +27,15 @@ type archlinuxTemplateData struct {
 	KernelDownloadURL string
 }
 
-func (c archlinux) Name() string {
+func (c *archlinux) Name() string {
 	return TargetTypeArchlinux.String()
 }
 
-func (c archlinux) TemplateScript() string {
+func (c *archlinux) TemplateScript() string {
 	return archlinuxTemplate
 }
 
-func (c archlinux) URLs(cfg Config, kr kernelrelease.KernelRelease) ([]string, error) {
+func (c *archlinux) URLs(cfg Config, kr kernelrelease.KernelRelease) ([]string, error) {
 	urls := []string{}
 
 	if kr.Architecture == kernelrelease.ArchitectureAmd64 {
@@ -92,9 +92,9 @@ func (c archlinux) URLs(cfg Config, kr kernelrelease.KernelRelease) ([]string, e
 	return urls, nil
 }
 
-func (c archlinux) TemplateData(cfg Config, _ kernelrelease.KernelRelease, urls []string) interface{} {
+func (c *archlinux) TemplateData(cfg Config, kr kernelrelease.KernelRelease, urls []string) interface{} {
 	return archlinuxTemplateData{
-		commonTemplateData: cfg.toTemplateData(),
+		commonTemplateData: cfg.toTemplateData(c, kr),
 		KernelDownloadURL:  urls[0],
 	}
 }
diff --git a/pkg/driverbuilder/builder/build.go b/pkg/driverbuilder/builder/build.go
index 73bf35a..80ab5d4 100644
--- a/pkg/driverbuilder/builder/build.go
+++ b/pkg/driverbuilder/builder/build.go
@@ -1,6 +1,9 @@
 package builder
 
-import "github.com/falcosecurity/driverkit/pkg/kernelrelease"
+import (
+	"fmt"
+	"github.com/falcosecurity/driverkit/pkg/kernelrelease"
+)
 
 // Build contains the info about the on-going build.
 type Build struct {
@@ -17,6 +20,8 @@ type Build struct {
 	CustomBuilderImage string
 	KernelUrls         []string
 	GCCVersion         float64
+	RepoOrg            string
+	RepoName           string
 }
 
 func (b *Build) KernelReleaseFromBuildConfig() kernelrelease.KernelRelease {
@@ -24,3 +29,16 @@ func (b *Build) KernelReleaseFromBuildConfig() kernelrelease.KernelRelease {
 	kv.Architecture = kernelrelease.Architecture(b.Architecture)
 	return kv
 }
+
+func (b *Build) toGithubRepoArchive() string {
+	return fmt.Sprintf("https://github.com/%s/%s/archive", b.RepoOrg, b.RepoName)
+}
+
+func (b *Build) ToConfig() Config {
+	return Config{
+		DriverName:      b.ModuleDriverName,
+		DeviceName:      b.ModuleDeviceName,
+		DownloadBaseURL: b.toGithubRepoArchive(),
+		Build:           b,
+	}
+}
diff --git a/pkg/driverbuilder/builder/builders.go b/pkg/driverbuilder/builder/builders.go
index fc89aba..04435a3 100644
--- a/pkg/driverbuilder/builder/builders.go
+++ b/pkg/driverbuilder/builder/builders.go
@@ -58,7 +58,7 @@ type Builder interface {
 	Name() string
 	TemplateScript() string
 	URLs(c Config, kr kernelrelease.KernelRelease) ([]string, error)
-	TemplateData(c Config, kr kernelrelease.KernelRelease, urls []string) interface{}
+	TemplateData(c Config, kr kernelrelease.KernelRelease, urls []string) interface{} // error return type is managed
 }
 
 // MinimumURLsBuilder is an optional interface
@@ -68,8 +68,6 @@ type MinimumURLsBuilder interface {
 }
 
 func Script(b Builder, c Config, kr kernelrelease.KernelRelease) (string, error) {
-	c.SetGCCVersion(b, kr)
-
 	t := template.New(b.Name())
 	parsed, err := t.Parse(b.TemplateScript())
 	if err != nil {
@@ -105,6 +103,10 @@ func Script(b Builder, c Config, kr kernelrelease.KernelRelease) (string, error)
 	}
 
 	td := b.TemplateData(c, kr, urls)
+	if tdErr, ok := td.(error); ok {
+		return "", tdErr
+	}
+
 	buf := bytes.NewBuffer(nil)
 	err = parsed.Execute(buf, td)
 	if err != nil {
@@ -163,7 +165,7 @@ func defaultGCC(kr kernelrelease.KernelRelease) float64 {
 	}
 }
 
-func (b *Build) SetGCCVersion(builder Builder, kr kernelrelease.KernelRelease) {
+func (b *Build) setGCCVersion(builder Builder, kr kernelrelease.KernelRelease) {
 	if b.GCCVersion != 0 {
 		// If set from user, go on
 		return
@@ -260,7 +262,8 @@ func Factory(target Type) (Builder, error) {
 	return b, nil
 }
 
-func (c Config) toTemplateData() commonTemplateData {
+func (c Config) toTemplateData(b Builder, kr kernelrelease.KernelRelease) commonTemplateData {
+	c.setGCCVersion(b, kr)
 	return commonTemplateData{
 		DriverBuildDir:    DriverDirectory,
 		ModuleDownloadURL: fmt.Sprintf("%s/%s.tar.gz", c.DownloadBaseURL, c.DriverVersion),
diff --git a/pkg/driverbuilder/builder/centos.go b/pkg/driverbuilder/builder/centos.go
index e19a3de..a98f9b1 100644
--- a/pkg/driverbuilder/builder/centos.go
+++ b/pkg/driverbuilder/builder/centos.go
@@ -25,15 +25,15 @@ type centosTemplateData struct {
 	KernelDownloadURL string
 }
 
-func (c centos) Name() string {
+func (c *centos) Name() string {
 	return TargetTypeCentos.String()
 }
 
-func (c centos) TemplateScript() string {
+func (c *centos) TemplateScript() string {
 	return centosTemplate
 }
 
-func (c centos) URLs(_ Config, kr kernelrelease.KernelRelease) ([]string, error) {
+func (c *centos) URLs(_ Config, kr kernelrelease.KernelRelease) ([]string, error) {
 	vaultReleases := []string{
 		"6.0/os",
 		"6.0/updates",
@@ -160,9 +160,9 @@ func (c centos) URLs(_ Config, kr kernelrelease.KernelRelease) ([]string, error)
 	return urls, nil
 }
 
-func (c centos) TemplateData(cfg Config, _ kernelrelease.KernelRelease, urls []string) interface{} {
+func (c *centos) TemplateData(cfg Config, kr kernelrelease.KernelRelease, urls []string) interface{} {
 	return centosTemplateData{
-		commonTemplateData: cfg.toTemplateData(),
+		commonTemplateData: cfg.toTemplateData(c, kr),
 		KernelDownloadURL:  urls[0],
 	}
 }
diff --git a/pkg/driverbuilder/builder/debian.go b/pkg/driverbuilder/builder/debian.go
index bf3eeb8..c85eede 100644
--- a/pkg/driverbuilder/builder/debian.go
+++ b/pkg/driverbuilder/builder/debian.go
@@ -37,28 +37,28 @@ type debianTemplateData struct {
 type debian struct {
 }
 
-func (v debian) Name() string {
+func (v *debian) Name() string {
 	return TargetTypeDebian.String()
 }
 
-func (v debian) TemplateScript() string {
+func (v *debian) TemplateScript() string {
 	return debianTemplate
 }
 
-func (v debian) URLs(_ Config, kr kernelrelease.KernelRelease) ([]string, error) {
+func (v *debian) URLs(_ Config, kr kernelrelease.KernelRelease) ([]string, error) {
 	return fetchDebianKernelURLs(kr)
 }
 
-func (v debian) TemplateData(c Config, kr kernelrelease.KernelRelease, urls []string) interface{} {
+func (v *debian) TemplateData(c Config, kr kernelrelease.KernelRelease, urls []string) interface{} {
 	return debianTemplateData{
-		commonTemplateData: c.toTemplateData(),
+		commonTemplateData: c.toTemplateData(v, kr),
 		KernelDownloadURLS: urls,
 		KernelLocalVersion: kr.FullExtraversion,
 		KernelArch:         kr.Architecture.String(),
 	}
 }
 
-func (v debian) MinimumURLs() int {
+func (v *debian) MinimumURLs() int {
 	return debianRequiredURLs
 }
 
diff --git a/pkg/driverbuilder/builder/flatcar.go b/pkg/driverbuilder/builder/flatcar.go
index 10bb96f..b8a22c9 100644
--- a/pkg/driverbuilder/builder/flatcar.go
+++ b/pkg/driverbuilder/builder/flatcar.go
@@ -6,7 +6,6 @@ import (
 	"github.com/falcosecurity/driverkit/pkg/kernelrelease"
 	"io/ioutil"
 	"net/http"
-	"strconv"
 	"strings"
 )
 
@@ -23,66 +22,68 @@ func init() {
 type flatcarTemplateData struct {
 	commonTemplateData
 	KernelDownloadURL string
-	FlatcarVersion    string
-	FlatcarChannel    string
-	KernelConfigURL   string
 }
 
 // flatcar is a driverkit target.
 type flatcar struct {
-	version   string
-	info      *flatcarReleaseInfo
-	kconfUrls []string
+	info *flatcarReleaseInfo
 }
 
-func (f flatcar) Name() string {
+func (f *flatcar) Name() string {
 	return TargetTypeFlatcar.String()
 }
 
-func (f flatcar) TemplateScript() string {
+func (f *flatcar) TemplateScript() string {
 	return flatcarTemplate
 }
 
-func (f flatcar) URLs(_ Config, kr kernelrelease.KernelRelease) ([]string, error) {
-	if kr.Extraversion != "" {
-		return nil, fmt.Errorf("unexpected extraversion: %s", kr.Extraversion)
-	}
-
-	// convert string to int
-	if kr.Version < 1500 {
-		return nil, fmt.Errorf("not a valid flatcar release version: %d", kr.Version)
-	}
-	f.version = kr.Fullversion
-
-	var err error
-	f.info, err = fetchFlatcarMetadata(kr)
-	if err != nil {
-		return nil, err
-	}
-
-	f.kconfUrls, err = getResolvingURLs(fetchFlatcarKernelConfigURL(kr.Architecture, f.info.Channel, kr.Fullversion))
-	if err != nil {
+func (f *flatcar) URLs(_ Config, kr kernelrelease.KernelRelease) ([]string, error) {
+	if err := f.fillFlatcarInfos(kr); err != nil {
 		return nil, err
 	}
 	return fetchFlatcarKernelURLS(f.info.KernelVersion), nil
 }
 
-func (f flatcar) TemplateData(c Config, _ kernelrelease.KernelRelease, urls []string) interface{} {
+func (f *flatcar) TemplateData(c Config, kr kernelrelease.KernelRelease, urls []string) interface{} {
+	// This happens when `kernelurls` option is passed,
+	// therefore URLs() method is not called.
+	if f.info == nil {
+		if err := f.fillFlatcarInfos(kr); err != nil {
+			return err
+		}
+	}
+
 	return flatcarTemplateData{
-		commonTemplateData: c.toTemplateData(),
+		commonTemplateData: c.toTemplateData(f, kr),
 		KernelDownloadURL:  urls[0],
-		FlatcarVersion:     f.version,
-		FlatcarChannel:     f.info.Channel,
-		KernelConfigURL:    f.kconfUrls[0],
 	}
 }
 
-func (f flatcar) GCCVersion(_ kernelrelease.KernelRelease) float64 {
-	v, err := strconv.ParseFloat(f.info.GCCVersion, 64)
-	if err != nil {
-		return 8
+func (f *flatcar) GCCVersion(_ kernelrelease.KernelRelease) float64 {
+	// Parse maj,min,patch
+	gccV := kernelrelease.FromString(f.info.GCCVersion)
+	targetV := float64(gccV.Version) + float64(gccV.PatchLevel)/10
+	return targetV
+}
+
+func (f *flatcar) fillFlatcarInfos(kr kernelrelease.KernelRelease) error {
+	if kr.Extraversion != "" {
+		return fmt.Errorf("unexpected extraversion: %s", kr.Extraversion)
+	}
+
+	// convert string to int
+	if kr.Version < 1500 {
+		return fmt.Errorf("not a valid flatcar release version: %d", kr.Version)
 	}
-	return v
+
+	var err error
+	f.info, err = fetchFlatcarMetadata(kr)
+	return err
+}
+
+func fetchFlatcarKernelURLS(kernelVersion string) []string {
+	kv := kernelrelease.FromString(kernelVersion)
+	return []string{fetchVanillaKernelURLFromKernelVersion(kv)}
 }
 
 func fetchFlatcarMetadata(kr kernelrelease.KernelRelease) (*flatcarReleaseInfo, error) {
@@ -143,15 +144,6 @@ func fetchFlatcarPackageListURL(architecture kernelrelease.Architecture, flatcar
 	return urls
 }
 
-func fetchFlatcarKernelConfigURL(architecture kernelrelease.Architecture, flatcarChannel, flatcarVersion string) []string {
-	return []string{fmt.Sprintf("https://%s.release.flatcar-linux.net/%s-usr/%s/flatcar_production_image_kernel_config.txt", flatcarChannel, architecture.String(), flatcarVersion)}
-}
-
-func fetchFlatcarKernelURLS(kernelVersion string) []string {
-	kv := kernelrelease.FromString(kernelVersion)
-	return []string{fmt.Sprintf("https://cdn.kernel.org/pub/linux/kernel/v%d.x/linux-%s.tar.xz", kv.Version, kv.Fullversion)}
-}
-
 type flatcarReleaseInfo struct {
 	Channel       string
 	GCCVersion    string
diff --git a/pkg/driverbuilder/builder/photon.go b/pkg/driverbuilder/builder/photon.go
index 57fdf37..c2c7c67 100644
--- a/pkg/driverbuilder/builder/photon.go
+++ b/pkg/driverbuilder/builder/photon.go
@@ -25,21 +25,21 @@ type photonTemplateData struct {
 	KernelDownloadURL string
 }
 
-func (p photon) Name() string {
+func (p *photon) Name() string {
 	return TargetTypePhoton.String()
 }
 
-func (p photon) TemplateScript() string {
+func (p *photon) TemplateScript() string {
 	return photonTemplate
 }
 
-func (p photon) URLs(_ Config, kr kernelrelease.KernelRelease) ([]string, error) {
+func (p *photon) URLs(_ Config, kr kernelrelease.KernelRelease) ([]string, error) {
 	return fetchPhotonKernelURLS(kr), nil
 }
 
-func (p photon) TemplateData(cfg Config, kr kernelrelease.KernelRelease, urls []string) interface{} {
+func (p *photon) TemplateData(cfg Config, kr kernelrelease.KernelRelease, urls []string) interface{} {
 	return photonTemplateData{
-		commonTemplateData: cfg.toTemplateData(),
+		commonTemplateData: cfg.toTemplateData(p, kr),
 		KernelDownloadURL:  urls[0],
 	}
 }
diff --git a/pkg/driverbuilder/builder/redhat.go b/pkg/driverbuilder/builder/redhat.go
index 3e67005..aa2c0e8 100644
--- a/pkg/driverbuilder/builder/redhat.go
+++ b/pkg/driverbuilder/builder/redhat.go
@@ -24,26 +24,26 @@ type redhatTemplateData struct {
 	KernelPackage string
 }
 
-func (v redhat) Name() string {
+func (v *redhat) Name() string {
 	return TargetTypeRedhat.String()
 }
 
-func (v redhat) TemplateScript() string {
+func (v *redhat) TemplateScript() string {
 	return redhatTemplate
 }
 
-func (v redhat) URLs(_ Config, _ kernelrelease.KernelRelease) ([]string, error) {
+func (v *redhat) URLs(_ Config, _ kernelrelease.KernelRelease) ([]string, error) {
 	return nil, nil
 }
 
-func (v redhat) MinimumURLs() int {
+func (v *redhat) MinimumURLs() int {
 	// We don't need any url
 	return 0
 }
 
-func (v redhat) TemplateData(c Config, kr kernelrelease.KernelRelease, _ []string) interface{} {
+func (v *redhat) TemplateData(c Config, kr kernelrelease.KernelRelease, _ []string) interface{} {
 	return redhatTemplateData{
-		commonTemplateData: c.toTemplateData(),
+		commonTemplateData: c.toTemplateData(v, kr),
 		KernelPackage:      kr.Fullversion + kr.FullExtraversion,
 	}
 }
diff --git a/pkg/driverbuilder/builder/rocky.go b/pkg/driverbuilder/builder/rocky.go
index 65c9738..14884d0 100644
--- a/pkg/driverbuilder/builder/rocky.go
+++ b/pkg/driverbuilder/builder/rocky.go
@@ -25,21 +25,21 @@ type rockyTemplateData struct {
 type rocky struct {
 }
 
-func (c rocky) Name() string {
+func (c *rocky) Name() string {
 	return TargetTypeRocky.String()
 }
 
-func (c rocky) TemplateScript() string {
+func (c *rocky) TemplateScript() string {
 	return rockyTemplate
 }
 
-func (c rocky) URLs(_ Config, kr kernelrelease.KernelRelease) ([]string, error) {
+func (c *rocky) URLs(_ Config, kr kernelrelease.KernelRelease) ([]string, error) {
 	return fetchRockyKernelURLS(kr), nil
 }
 
-func (c rocky) TemplateData(cfg Config, kr kernelrelease.KernelRelease, urls []string) interface{} {
+func (c *rocky) TemplateData(cfg Config, kr kernelrelease.KernelRelease, urls []string) interface{} {
 	return rockyTemplateData{
-		commonTemplateData: cfg.toTemplateData(),
+		commonTemplateData: cfg.toTemplateData(c, kr),
 		KernelDownloadURL:  urls[0],
 	}
 }
diff --git a/pkg/driverbuilder/builder/templates/flatcar.sh b/pkg/driverbuilder/builder/templates/flatcar.sh
index bada9db..9a18ed0 100644
--- a/pkg/driverbuilder/builder/templates/flatcar.sh
+++ b/pkg/driverbuilder/builder/templates/flatcar.sh
@@ -20,9 +20,10 @@ rm -Rf /tmp/kernel
 mkdir -p /tmp/kernel
 mv /tmp/kernel-download/*/* /tmp/kernel
 
-curl --silent -o /tmp/kernel.config -SL {{ .KernelConfigURL }}
-
+# Prepare the kernel
 cd /tmp/kernel
+cp /driverkit/kernel.config /tmp/kernel.config
+
 sed -i -e 's|^\(EXTRAVERSION =\).*|\1 -flatcar|' Makefile
 make KCONFIG_CONFIG=/tmp/kernel.config oldconfig
 make KCONFIG_CONFIG=/tmp/kernel.config modules_prepare
diff --git a/pkg/driverbuilder/builder/ubuntu.go b/pkg/driverbuilder/builder/ubuntu.go
index 44d4d9e..bdeadd2 100644
--- a/pkg/driverbuilder/builder/ubuntu.go
+++ b/pkg/driverbuilder/builder/ubuntu.go
@@ -32,23 +32,23 @@ func init() {
 // ubuntu is a driverkit target.
 type ubuntu struct{}
 
-func (v ubuntu) Name() string {
+func (v *ubuntu) Name() string {
 	return TargetTypeUbuntu.String()
 }
 
-func (v ubuntu) TemplateScript() string {
+func (v *ubuntu) TemplateScript() string {
 	return ubuntuTemplate
 }
 
-func (v ubuntu) URLs(c Config, kr kernelrelease.KernelRelease) ([]string, error) {
+func (v *ubuntu) URLs(c Config, kr kernelrelease.KernelRelease) ([]string, error) {
 	return ubuntuHeadersURLFromRelease(kr, c.Build.KernelVersion)
 }
 
-func (v ubuntu) MinimumURLs() int {
+func (v *ubuntu) MinimumURLs() int {
 	return ubuntuRequiredURLs
 }
 
-func (v ubuntu) TemplateData(c Config, kr kernelrelease.KernelRelease, urls []string) interface{} {
+func (v *ubuntu) TemplateData(c Config, kr kernelrelease.KernelRelease, urls []string) interface{} {
 	// parse the flavor out of the kernelrelease extraversion
 	_, flavor := parseUbuntuExtraVersion(kr.Extraversion)
 
@@ -62,14 +62,14 @@ func (v ubuntu) TemplateData(c Config, kr kernelrelease.KernelRelease, urls []st
 	}
 
 	return ubuntuTemplateData{
-		commonTemplateData:   c.toTemplateData(),
+		commonTemplateData:   c.toTemplateData(v, kr),
 		KernelDownloadURLS:   urls,
 		KernelLocalVersion:   kr.FullExtraversion,
 		KernelHeadersPattern: headersPattern,
 	}
 }
 
-func (v ubuntu) GCCVersion(kr kernelrelease.KernelRelease) float64 {
+func (v *ubuntu) GCCVersion(kr kernelrelease.KernelRelease) float64 {
 	switch kr.Version {
 	case 3:
 		switch {
diff --git a/pkg/driverbuilder/builder/vanilla.go b/pkg/driverbuilder/builder/vanilla.go
index a898210..69f5f00 100644
--- a/pkg/driverbuilder/builder/vanilla.go
+++ b/pkg/driverbuilder/builder/vanilla.go
@@ -26,21 +26,21 @@ type vanillaTemplateData struct {
 	KernelLocalVersion string
 }
 
-func (v vanilla) Name() string {
+func (v *vanilla) Name() string {
 	return TargetTypeVanilla.String()
 }
 
-func (v vanilla) TemplateScript() string {
+func (v *vanilla) TemplateScript() string {
 	return vanillaTemplate
 }
 
-func (v vanilla) URLs(_ Config, kr kernelrelease.KernelRelease) ([]string, error) {
+func (v *vanilla) URLs(_ Config, kr kernelrelease.KernelRelease) ([]string, error) {
 	return []string{fetchVanillaKernelURLFromKernelVersion(kr)}, nil
 }
 
-func (v vanilla) TemplateData(c Config, kr kernelrelease.KernelRelease, urls []string) interface{} {
+func (v *vanilla) TemplateData(c Config, kr kernelrelease.KernelRelease, urls []string) interface{} {
 	return vanillaTemplateData{
-		commonTemplateData: c.toTemplateData(),
+		commonTemplateData: c.toTemplateData(v, kr),
 		KernelDownloadURL:  urls[0],
 		KernelLocalVersion: kr.FullExtraversion,
 	}
diff --git a/pkg/driverbuilder/docker.go b/pkg/driverbuilder/docker.go
index 2c82d23..36238a3 100644
--- a/pkg/driverbuilder/docker.go
+++ b/pkg/driverbuilder/docker.go
@@ -118,12 +118,7 @@ func (bp *DockerBuildProcessor) Start(b *builder.Build) error {
 	if err != nil {
 		return err
 	}
-	c := builder.Config{
-		DriverName:      b.ModuleDriverName,
-		DeviceName:      b.ModuleDeviceName,
-		DownloadBaseURL: "https://github.com/falcosecurity/libs/archive", // TODO: make this configurable
-		Build:           b,
-	}
+	c := b.ToConfig()
 
 	// Generate the build script from the builder
 	driverkitScript, err := builder.Script(v, c, kr)
diff --git a/pkg/driverbuilder/kubernetes.go b/pkg/driverbuilder/kubernetes.go
index e02403f..bb925f9 100644
--- a/pkg/driverbuilder/kubernetes.go
+++ b/pkg/driverbuilder/kubernetes.go
@@ -63,7 +63,7 @@ func (bp *KubernetesBuildProcessor) Start(b *builder.Build) error {
 	return bp.buildModule(b)
 }
 
-func (bp *KubernetesBuildProcessor) buildModule(build *builder.Build) error {
+func (bp *KubernetesBuildProcessor) buildModule(b *builder.Build) error {
 	deadline := int64(bp.timeout)
 	namespace := bp.namespace
 	uid := uuid.NewUUID()
@@ -72,20 +72,15 @@ func (bp *KubernetesBuildProcessor) buildModule(build *builder.Build) error {
 	podClient := bp.coreV1Client.Pods(namespace)
 	configClient := bp.coreV1Client.ConfigMaps(namespace)
 
-	kr := build.KernelReleaseFromBuildConfig()
+	kr := b.KernelReleaseFromBuildConfig()
 
 	// create a builder based on the chosen build type
-	v, err := builder.Factory(build.TargetType)
+	v, err := builder.Factory(b.TargetType)
 	if err != nil {
 		return err
 	}
 
-	c := builder.Config{
-		DriverName:      build.ModuleDriverName,
-		DeviceName:      build.ModuleDeviceName,
-		DownloadBaseURL: "https://github.com/falcosecurity/libs/archive", // TODO: make this configurable
-		Build:           build,
-	}
+	c := b.ToConfig()
 
 	// generate the build script from the builder
 	res, err := builder.Script(v, c, kr)
@@ -137,7 +132,7 @@ func (bp *KubernetesBuildProcessor) buildModule(build *builder.Build) error {
 		return err
 	}
 
-	configDecoded, err := base64.StdEncoding.DecodeString(build.KernelConfigData)
+	configDecoded, err := base64.StdEncoding.DecodeString(b.KernelConfigData)
 	if err != nil {
 		return err
 	}
@@ -169,7 +164,7 @@ func (bp *KubernetesBuildProcessor) buildModule(build *builder.Build) error {
 		)
 	}
 
-	builderImage := build.GetBuilderImage()
+	builderImage := b.GetBuilderImage()
 
 	secuContext := corev1.PodSecurityContext{
 		RunAsUser: &bp.runAsUser,
@@ -235,7 +230,7 @@ func (bp *KubernetesBuildProcessor) buildModule(build *builder.Build) error {
 		return err
 	}
 	defer podClient.Delete(ctx, pod.Name, metav1.DeleteOptions{})
-	return bp.copyModuleAndProbeFromPodWithUID(ctx, build, namespace, string(uid))
+	return bp.copyModuleAndProbeFromPodWithUID(ctx, b, namespace, string(uid))
 }
 
 func (bp *KubernetesBuildProcessor) copyModuleAndProbeFromPodWithUID(ctx context.Context, build *builder.Build, namespace string, falcoBuilderUID string) error {
diff --git a/pkg/driverbuilder/templates.go b/pkg/driverbuilder/templates.go
index 09ac10a..d320573 100644
--- a/pkg/driverbuilder/templates.go
+++ b/pkg/driverbuilder/templates.go
@@ -70,8 +70,7 @@ func renderMakefile(w io.Writer, md makefileData) error {
 }
 
 func LoadMakefileObjList(c builder.Config) (string, error) {
-	// TODO: make this configurable
-	makefileUrl := fmt.Sprintf("https://raw.githubusercontent.com/falcosecurity/libs/%s/driver/Makefile.in", c.DriverVersion)
+	makefileUrl := fmt.Sprintf("https://raw.githubusercontent.com/%s/%s/%s/driver/Makefile.in", c.RepoOrg, c.RepoName, c.DriverVersion)
 	resp, err := http.Get(makefileUrl)
 	if err != nil {
 		return "", err
diff --git a/validate/validate.go b/validate/validate.go
index b2e11f3..8cbb6dc 100644
--- a/validate/validate.go
+++ b/validate/validate.go
@@ -90,7 +90,7 @@ func init() {
 		"required_kernelconfigdata_with_target_vanilla",
 		T,
 		func(ut ut.Translator) error {
-			return ut.Add("required_kernelconfigdata_with_target_vanilla", "{0} is a required field when target is vanilla", true)
+			return ut.Add("required_kernelconfigdata_with_target_vanilla", "{0} is a required field when target is vanilla/minikube/flatcar", true)
 		},
 		func(ut ut.Translator, fe validator.FieldError) string {
 			t, _ := ut.T("required_kernelconfigdata_with_target_vanilla", "kernel config data") // fixme ? tag "name" does not work when used at struct level


Test patch:
diff --git a/cmd/testdata/docker-from-config-debug.txt b/cmd/testdata/docker-from-config-debug.txt
index 27717c1..4f4055a 100644
--- a/cmd/testdata/docker-from-config-debug.txt
+++ b/cmd/testdata/docker-from-config-debug.txt
@@ -1,3 +1,3 @@
 INFO using config file                             file=testdata/configs/1.yaml
-DEBU running with options                          arch={{ .CurrentArch }} driverversion=master kernelrelease=4.15.0-1057-aws kernelversion=59 output-module=/tmp/falco-ubuntu-aws.ko target=ubuntu
+DEBU running with options                          arch={{ .CurrentArch }} driverversion=master kernelrelease=4.15.0-1057-aws kernelversion=59 output-module=/tmp/falco-ubuntu-aws.ko repo-name=libs repo-org=falcosecurity target=ubuntu
 INFO driver building, it will take a few seconds   processor=docker
diff --git a/cmd/testdata/docker-override-from-config-debug.txt b/cmd/testdata/docker-override-from-config-debug.txt
index 29c0dcb..9a12db6 100644
--- a/cmd/testdata/docker-override-from-config-debug.txt
+++ b/cmd/testdata/docker-override-from-config-debug.txt
@@ -1,3 +1,3 @@
 INFO using config file                             file=testdata/configs/1.yaml
-DEBU running with options                          arch={{ .CurrentArch }} driverversion=master kernelrelease=4.15.0-1057-aws kernelversion=229 output-module=/tmp/override.ko target=ubuntu
+DEBU running with options                          arch={{ .CurrentArch }} driverversion=master kernelrelease=4.15.0-1057-aws kernelversion=229 output-module=/tmp/override.ko repo-name=libs repo-org=falcosecurity target=ubuntu
 INFO driver building, it will take a few seconds   processor=docker
diff --git a/cmd/testdata/docker-override-urls-from-config-debug.txt b/cmd/testdata/docker-override-urls-from-config-debug.txt
index 0069c9c..346fe5a 100644
--- a/cmd/testdata/docker-override-urls-from-config-debug.txt
+++ b/cmd/testdata/docker-override-urls-from-config-debug.txt
@@ -1,3 +1,3 @@
 INFO using config file                             file=testdata/configs/2.yaml
-DEBU running with options                          arch={{ .CurrentArch }} driverversion=master kernelrelease=4.15.0-1057-aws kernelurls="[https://mirrors.edge.kernel.org/ubuntu/pool/main/l/linux-aws/linux-aws-headers-4.15.0-1057_4.15.0-1057.59_all.deb https://mirrors.edge.kernel.org/ubuntu/pool/main/l/linux-aws/linux-headers-4.15.0-1057-aws_4.15.0-1057.59_amd64.deb]" kernelversion=59 output-module=/tmp/falco-ubuntu-aws.ko target=ubuntu
+DEBU running with options                          arch={{ .CurrentArch }} driverversion=master kernelrelease=4.15.0-1057-aws kernelurls="[https://mirrors.edge.kernel.org/ubuntu/pool/main/l/linux-aws/linux-aws-headers-4.15.0-1057_4.15.0-1057.59_all.deb https://mirrors.edge.kernel.org/ubuntu/pool/main/l/linux-aws/linux-headers-4.15.0-1057-aws_4.15.0-1057.59_amd64.deb]" kernelversion=59 output-module=/tmp/falco-ubuntu-aws.ko repo-name=libs repo-org=falcosecurity target=ubuntu
 INFO driver building, it will take a few seconds   processor=docker
diff --git a/cmd/testdata/docker-related-target-debug.txt b/cmd/testdata/docker-related-target-debug.txt
index a28a6d6..eb9d1c5 100644
--- a/cmd/testdata/docker-related-target-debug.txt
+++ b/cmd/testdata/docker-related-target-debug.txt
@@ -1,3 +1,3 @@
 DEBU running without a configuration file         
-DEBU running with options                          arch={{ .CurrentArch }} driverversion=master kernelrelease=4.15.0-1057-azure kernelurls="[http://mirrors.edge.kernel.org/ubuntu/pool/main/l/linux-azure/linux-azure-headers-4.15.0-1057_4.15.0-1057.62_all.deb http://mirrors.edge.kernel.org/ubuntu/pool/main/l/linux-azure/linux-headers-4.15.0-1057-azure_4.15.0-1057.62_amd64.deb]" kernelversion=62 output-module=/tmp/falco-ubuntu-azure.ko target=ubuntu
+DEBU running with options                          arch={{ .CurrentArch }} driverversion=master kernelrelease=4.15.0-1057-azure kernelurls="[http://mirrors.edge.kernel.org/ubuntu/pool/main/l/linux-azure/linux-azure-headers-4.15.0-1057_4.15.0-1057.62_all.deb http://mirrors.edge.kernel.org/ubuntu/pool/main/l/linux-azure/linux-headers-4.15.0-1057-azure_4.15.0-1057.62_amd64.deb]" kernelversion=62 output-module=/tmp/falco-ubuntu-azure.ko repo-name=libs repo-org=falcosecurity target=ubuntu
 INFO driver building, it will take a few seconds   processor=docker
diff --git a/cmd/testdata/docker-with-flags-debug.txt b/cmd/testdata/docker-with-flags-debug.txt
index eeb4e33..6c28c3b 100644
--- a/cmd/testdata/docker-with-flags-debug.txt
+++ b/cmd/testdata/docker-with-flags-debug.txt
@@ -1,3 +1,3 @@
 DEBU running without a configuration file         
-DEBU running with options                          arch={{ .CurrentArch }} driverversion=master kernelrelease=4.15.0-1057-aws kernelurls="[https://mirrors.edge.kernel.org/ubuntu/pool/main/l/linux-aws/linux-aws-headers-4.15.0-1057_4.15.0-1057.59_all.deb https://mirrors.edge.kernel.org/ubuntu/pool/main/l/linux-aws/linux-headers-4.15.0-1057-aws_4.15.0-1057.59_amd64.deb]" kernelversion=59 output-module=/tmp/falco-ubuntu-aws.ko target=ubuntu
+DEBU running with options                          arch={{ .CurrentArch }} driverversion=master kernelrelease=4.15.0-1057-aws kernelurls="[https://mirrors.edge.kernel.org/ubuntu/pool/main/l/linux-aws/linux-aws-headers-4.15.0-1057_4.15.0-1057.59_all.deb https://mirrors.edge.kernel.org/ubuntu/pool/main/l/linux-aws/linux-headers-4.15.0-1057-aws_4.15.0-1057.59_amd64.deb]" kernelversion=59 output-module=/tmp/falco-ubuntu-aws.ko repo-name=libs repo-org=falcosecurity target=ubuntu
 INFO driver building, it will take a few seconds   processor=docker
diff --git a/cmd/testdata/templates/flags.txt b/cmd/testdata/templates/flags.txt
index 124867d..fac5883 100644
--- a/cmd/testdata/templates/flags.txt
+++ b/cmd/testdata/templates/flags.txt
@@ -16,5 +16,7 @@ Flags:
       --output-module string      filepath where to save the resulting kernel module
       --output-probe string       filepath where to save the resulting eBPF probe
       --proxy string              the proxy to use to download data
+      --repo-name string          repository github name (default "libs")
+      --repo-org string           repository github organization (default "falcosecurity")
   -t, --target string             the system to target the build for, one of {{ .Targets }}
       --timeout int               timeout in seconds (default 120)
\ No newline at end of file
diff --git a/pkg/driverbuilder/builder/ubuntu_test.go b/pkg/driverbuilder/builder/ubuntu_test.go
index e7eb3d3..5b86dbb 100644
--- a/pkg/driverbuilder/builder/ubuntu_test.go
+++ b/pkg/driverbuilder/builder/ubuntu_test.go
@@ -297,7 +297,7 @@ func TestFetchUbuntuKernelURL(t *testing.T) {
 }
 
 func TestUbuntuGCCVersionFromKernelRelease(t *testing.T) {
-	b := ubuntu{}
+	b := &ubuntu{}
 	for _, test := range tests {
 		input := test.config
 		gotGCCVersion := b.GCCVersion(input)