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

pkg/sca/sca.go: Implement getLdSoConfDLibPaths #1850

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sergiodj
Copy link
Contributor

This PR implements the machinery necessary for SCA to consider files under /etc/ld.so.conf.d/.

The idea is that, if there is a configuration for ld.so.conf.d being installed by the package on hand, then the libraries shipped by the package should be listed as provides if they're installed inside the paths listed in the ld.so.conf.d configuration file.

This commit also implements a simple test to make sure that the new function is properly parsing the configuration file inside /etc/ld.so.conf.d/.

Notes:

SCA Changes

  • Examining several representative APKs show no regression / the desired effect (details in notes)

Notes:

As of this writing no packages are actually using ld.so.conf.d on Wolfi OS. I built /nvidia-cudnn-9 (from extra-packages) and it works as expected:

2025/03/10 17:31:12 INFO scanning for ld.so.conf.d files...
2025/03/10 17:31:12 INFO   found ld.so.conf.d file etc/ld.so.conf.d/nvidia-cudnn-9.conf
2025/03/10 17:31:12 INFO     found extra lib path /usr/local/cudnn-9/lib64

Relates: https://github.com/chainguard-dev/internal-dev/issues/7609

dannf
dannf previously approved these changes Mar 10, 2025
Copy link
Contributor

@dannf dannf left a comment

Choose a reason for hiding this comment

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

very cool! a couple comments inline, but I'm not sure either is a real issue.

pkg/sca/sca.go Outdated
return err
}

if !fi.Mode().IsRegular() {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we support symlinks to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hah, it's awesome that you thought about that :-).

I spent some time implementing support for symlinks, but unfortunately I could not get it to work the way I wanted. The problem is that if you have a symlink inside /etc/ld.so.conf.d pointing to a file outside of it, I could not figure out how to obtain the full path of said file using the filesystem functions that are at my disposal. I'm sure it's possible, but I'm still learning as I go (pun intended)...

@sergiodj sergiodj force-pushed the add-ld-so-conf-d-support branch 3 times, most recently from ab035fc to 44693f0 Compare March 11, 2025 01:57
@sergiodj sergiodj requested a review from dannf March 11, 2025 01:57
@sergiodj sergiodj force-pushed the add-ld-so-conf-d-support branch from 44693f0 to a0b7ae1 Compare March 11, 2025 02:44
@sergiodj sergiodj requested a review from jonjohnsonjr March 11, 2025 16:37
@sergiodj
Copy link
Contributor Author

Hi @jonjohnsonjr!

I'd be delighted if you could offer your review here as well.

Thanks!

Copy link
Contributor

@dannf dannf left a comment

Choose a reason for hiding this comment

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

Looks like there's some test failures that need addressing, but this LGTM!

This commit implements the machinery necessary for SCA to consider
files under /etc/ld.so.conf.d/.

The idea is that, if there is a configuration for ld.so.conf.d being
installed by the package on hand, then the libraries shipped by the
package should be listed as "provides" if they're installed inside the
paths listed in the ld.so.conf.d configuration file.

Signed-off-by: Sergio Durigan Junior <sergiodj@chainguard.dev>
@sergiodj sergiodj force-pushed the add-ld-so-conf-d-support branch from a0b7ae1 to faecd8e Compare March 11, 2025 22:33
@sergiodj
Copy link
Contributor Author

Looks like there's some test failures that need addressing, but this LGTM!

Thanks, @dannf! I pushed a small change to fix the failure.

This commit implements a simple test to make sure that the new
function is properly parsing the configuration file inside
/etc/ld.so.conf.d/.

A small modification had to be made to the (th *testHandle)
RelativeNames() function in order to make TestDocSca pass,
because (th *testHandle) FilesystemForRelative() isn't implemented.

Signed-off-by: Sergio Durigan Junior <sergiodj@chainguard.dev>
@sergiodj sergiodj force-pushed the add-ld-so-conf-d-support branch from faecd8e to d040dd1 Compare March 11, 2025 22:51
@@ -804,5 +894,9 @@ func Analyze(ctx context.Context, hdl SCAHandle, generated *config.Dependencies)
generated.Provides = nil
}

if oldLibDirs != nil {
libDirs = oldLibDirs
Copy link
Contributor

Choose a reason for hiding this comment

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

This frightens me a bit -- instead of mutating the global here do you mind plumbing this around everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For sure. But let me take the opportunity and ask a broader question.

I thought about moving libDirs inside the SCABuildInterface, because this really should be a per-package variable. However, SCABuildInterface only represents one single entity in the package (either the sole package, or one of its subpackages if they exist). I couldn't find a way to say "hey, this applies to the package and its subpackages".

The reason I wanted to do it is because, as you can see now, getLdSoConfDLibPaths is being invoked for the package and its subpackages, and it iterates over all files from them, every time. This is suboptimal.

Something else I thought about is that we could have a global flag to signal whether getLdSoConfDLibPaths was already invoked. But then I have another question: is it guaranteed that we will be dealing with only one package (and its subpackages)?

Sorry for the barrage of questions and thoughts; this code is new to me and I'm trying to make sense of how to best implement what I need here. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants