Skip to content
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/driverbuilder): properly export KERNELDIR in kernel-download scripts #330

Merged
merged 2 commits into from
Mar 29, 2024

Conversation

FedeDP
Copy link
Contributor

@FedeDP FedeDP commented Mar 29, 2024

What type of PR is this?

/kind bug

Any specific area of the project related to this PR?

/area pkg

What this PR does / why we need it:

Fix on top of #324 (this comment was highly specific: #324 (comment) :D)
It also fixes vanilla kernel builds; see libs CI that is badly failing since we released driverkit v0.18.0: https://github.com/falcosecurity/libs/actions/workflows/latest-kernel.yml

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@FedeDP
Copy link
Contributor Author

FedeDP commented Mar 29, 2024

/cc @EXONER4TED

…scripts.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>

Co-authored-by: Aldo Lacuku <aldo@lacuku.eu>
@FedeDP
Copy link
Contributor Author

FedeDP commented Mar 29, 2024

/hold
need to fix local builder.

@FedeDP
Copy link
Contributor Author

FedeDP commented Mar 29, 2024

/unhold fixed

export KERNELDIR=/tmp/kernel
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All kernel scripts will now export KERNELDIR at the end.
This way, they are also free to echo whatever they wish to stdout since stdout is no more used.

@@ -242,7 +249,8 @@ chmod +x /driverkit/download-headers.sh
chmod +x /driverkit/driverkit.sh

/driverkit/download-libs.sh
KERNELDIR=$(/driverkit/download-headers.sh) /driverkit/driverkit.sh
. /driverkit/download-headers.sh
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source the download-headers script so that KERNELDIR gets set.

// then finally runs the build script.
res = fmt.Sprintf("%s\nexport KERNELDIR=$(%s)\n%s", libsDownloadScript, kernelDownloadScript, res)
res = fmt.Sprintf("%s\n%s\n%s", libsDownloadScript, kernelDownloadScript, res)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since everything is put in a single bash script here, we don't even need to source kernel-download script.

@@ -69,10 +69,21 @@ func (lbp *LocalBuildProcessor) Start(b *builder.Build) error {
if err == nil {
slog.Info("Trying automatic kernel headers download.")
kernelDownloadScript, err := builder.KernelDownloadScript(realBuilder, nil, kr)
// Patch kernel download script to echo KERNELDIR.
// We need to capture KERNELDIR to later pass it as env variable to the build.
kernelDownloadScript += "\necho $KERNELDIR"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local executor needs to fetch KERNELDIR after exec.Command runs.
The only way is to fallback at the old method of echoing KERNELDIR at the end of the script; then we will parse script stdout line by line and the last one will be our KERNELDIR path.

…LDIR.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
@FedeDP FedeDP force-pushed the fix/properly_export_kerneldir branch from 7a2fd7b to 613fb9b Compare March 29, 2024 10:47
@@ -67,24 +67,35 @@ func (lbp *LocalBuildProcessor) Start(b *builder.Build) error {
// if an unsupported target is passed.
// Go on skipping automatic kernel headers download.
if err == nil {
slog.Info("Trying automatic kernel headers download.")
slog.Info("Trying automatic kernel headers download")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped some . at the end of log strings for local executor, for consistency.

@FedeDP
Copy link
Contributor Author

FedeDP commented Mar 29, 2024

/unhold

FedeDP added a commit to falcosecurity/falcoctl that referenced this pull request Mar 29, 2024
…adjust kernel-download script helper.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
Copy link
Contributor

@EXONER4TED EXONER4TED left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@poiana
Copy link

poiana commented Mar 29, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: EXONER4TED, FedeDP

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana poiana merged commit 8ea62ad into master Mar 29, 2024
5 checks passed
@poiana poiana deleted the fix/properly_export_kerneldir branch March 29, 2024 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants