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

many: container validation improvements #13682

Merged

Conversation

ZeyadYasser
Copy link
Contributor

No description provided.

@ZeyadYasser ZeyadYasser added this to the 2.62 milestone Mar 11, 2024
@ZeyadYasser ZeyadYasser requested review from pedronis and ernestl March 11, 2024 08:06
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 92.10526% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 78.90%. Comparing base (29a6e75) to head (7be84b7).
Report is 10 commits behind head on master.

Files Patch % Lines
snap/container.go 92.30% 4 Missing and 2 partials ⚠️
snap/squashfs/squashfs.go 90.32% 2 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #13682      +/-   ##
==========================================
+ Coverage   78.87%   78.90%   +0.02%     
==========================================
  Files        1039     1040       +1     
  Lines      133603   133966     +363     
==========================================
+ Hits       105381   105704     +323     
- Misses      21637    21665      +28     
- Partials     6585     6597      +12     
Flag Coverage Δ
unittests 78.90% <92.10%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

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

thanks

Copy link
Collaborator

@ernestl ernestl left a comment

Choose a reason for hiding this comment

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

Thanks

@alexmurray
Copy link
Contributor

LGTM!

Copy link
Contributor

@zyga zyga left a comment

Choose a reason for hiding this comment

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

I didn't read test code but I have some comments on the evaluation details. Have a look please.

func evalSymlink(c Container, path string) (symlinkInfo, error) {
var naiveTarget string

const maxDepth = 10
Copy link
Contributor

Choose a reason for hiding this comment

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

This limit should be documented somewhere. It would be good if there was a matching kernel-side limit so that our limit is not surprising to people.


const maxDepth = 10
currentDepth := 0
for currentDepth < maxDepth {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use the long form of for here?

target = filepath.Join(filepath.Dir(path), target)

// target escapes container, cannot evaluate further, let's return
if strings.Split(target, string(os.PathSeparator))[0] == ".." {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is somewhat costly for what is requested. Is this somehow different than strings.HasPrefix or am I missing something subtle?

func shouldValidateSymlink(path string) bool {
// we only check meta directory for now
pathTokens := strings.Split(path, string(os.PathSeparator))
if pathTokens[0] == "meta" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this strings.HasPrefix?

}

func evalAndValidateSymlink(c Container, path string) (symlinkInfo, error) {
pathTokens := strings.Split(path, string(os.PathSeparator))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this strings.HasPrefix again?

return symlinkInfo{}, fmt.Errorf("external symlink found: %s -> %s", path, info.naiveTarget)
}

// symlinks like this don't look innocent
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you clarify what is innocent here?

if mode&os.ModeSymlink != 0 && shouldValidateSymlink(path) {
symlinkInfo, err := evalAndValidateSymlink(c, path)
if err != nil {
logf("%s", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would add a context here, like "Cannot evaluate and validate symbolic link: %s"

@ZeyadYasser ZeyadYasser force-pushed the refactor-container-validation branch from 7be84b7 to 358ca95 Compare March 14, 2024 08:53
Signed-off-by: Zeyad Gouda <zeyad.gouda@canonical.com>
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.

7 participants