-
Notifications
You must be signed in to change notification settings - Fork 60
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
fix(pkg/driver): fixup kernel headers download #499
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ | |
package driverdistro | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"compress/gzip" | ||
"errors" | ||
"fmt" | ||
|
@@ -140,8 +142,18 @@ func loadKernelHeadersFromDk(distro string, kr kernelrelease.KernelRelease) (str | |
if err != nil { | ||
return "", nil, err | ||
} | ||
script += "\necho $KERNELDIR" | ||
out, err := exec.Command("bash", "-c", script).Output() //nolint:gosec // false positive | ||
path := strings.TrimSuffix(string(out), "\n") | ||
var path string | ||
if err == nil { | ||
// Scan all stdout line by line and | ||
// store last line as KERNELDIR path. | ||
reader := bytes.NewReader(out) | ||
scanner := bufio.NewScanner(reader) | ||
for scanner.Scan() { | ||
path = scanner.Text() | ||
} | ||
} | ||
return path, func() { | ||
_ = os.RemoveAll("/tmp/kernel-download") | ||
_ = os.RemoveAll(path) | ||
|
@@ -208,7 +220,12 @@ func Build(ctx context.Context, | |
// try to load kernel headers urls from driverkit. | ||
if _, found := env[drivertype.KernelDirEnv]; !found { | ||
printer.Logger.Debug("Trying to automatically fetch kernel headers.") | ||
kernelHeadersPath, cleaner, err := loadKernelHeadersFromDk(d.String(), kr) | ||
// KernelVersion needs to be fixed up; it is only used by driverkit Ubuntu builder | ||
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. |
||
// and we must ensure that it is correctly set. | ||
fixedKr := d.FixupKernel(kr) | ||
kVerFixedKr := kr | ||
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. Don't overwrite 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. While this is a bit ugly rn, it will be much better once #356 lands. |
||
kVerFixedKr.KernelVersion = fixedKr.KernelVersion | ||
kernelHeadersPath, cleaner, err := loadKernelHeadersFromDk(d.String(), kVerFixedKr) | ||
if cleaner != nil { | ||
defer cleaner() | ||
} | ||
|
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.
Same change as https://github.com/falcosecurity/driverkit/pull/330/files#diff-65b73ea131a56dc0c89be2bdab7cfdd41144cf4549ecb9ddad27ffa3daf18d5dR78