-
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(follow): handle directories in tar.gz artifacts #716
base: main
Are you sure you want to change the base?
fix(follow): handle directories in tar.gz artifacts #716
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: TiagoJMartins The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Welcome @TiagoJMartins! It looks like this is your first PR to falcosecurity/falcoctl 🎉 |
9c6f709
to
1ef75d7
Compare
|
1ef75d7
to
48f8bfb
Compare
48f8bfb
to
d1e9252
Compare
Tested with this (amd64) image: |
Hi @TiagoJMartins, thansk for the PR. Could you please have a look at the CI? Linting and tests are failing. |
6424fab
to
1ba880a
Compare
I think the issues should be fixed now. I'll wait until someone approves the next CI run 👍🏻 |
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.
Hey @TiagoJMartins, thanks for the contribution!
I left some comments.
// Always create temporary directories at the root level to avoid nesting issues. | ||
// If TmpDir points to a subdirectory (e.g., /tmp/foo/bar), we use its parent (/tmp/foo) | ||
// to prevent creating temporary directories inside artifact directories. | ||
baseDir := conf.TmpDir | ||
if baseDir != "" { | ||
baseDir = filepath.Clean(baseDir) | ||
if filepath.Base(baseDir) != "." { | ||
baseDir = filepath.Dir(baseDir) | ||
} | ||
} | ||
|
||
tmpDir, err := os.MkdirTemp(baseDir, "falcoctl-") |
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.
Why do we need this? The temporary dir is given by the user, and is the same for all the followers/artifacts.
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.
@TiagoJMartins, could you please provide more info about this change?
Signed-off-by: Tiago Martins <tiago.martins@hotjar.com>
1ba880a
to
1e715bb
Compare
What type of PR is this?
/kind bug
Any specific area of the project related to this PR?
/area cli
What this PR does / why we need it:
A bit of background on my use-case:
I've configured Falco to load all rules from a given sub-directory within
/etc/falco
, e.g.:/etc/falco/subdir/rules1.yaml
, and packaged multiple rules files into separaterulesfile
artifacts intar.gz
format.During packaging, I'll generate the final directory structure I want and archive it, knowing that
falcoctl artifact
will extract the contents onto/etc/falco
.The issue is that while
falco artifact install
works great,falco artifact follow
seems to break when processing the file path as it expects base paths to always be files, so it'll always fail when the rules gets updated and then it tries to move a directory.Which issue(s) this PR fixes:
This PR addresses the issue above by modifying the file path handling in a way that preserves the artifact directory structure, and also slightly modifies the tar.gz extraction logic by only appending to
files
if it's handling an actual file and not a directory/symlink.I've added tests for these use cases to ensure that the previous behavior remains unchanged.
The error below is printed when trying to update an artifact pushed as
.tar.gz
, that includes the file:/rules.csq.d/kubernetes.yaml
, which gets installed at/etc/falco/rules.csq.d/kubernetes.yaml
(because/rulesfiles
is mounted at/etc/falco
by the Helm chart).