Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Conversation

priyawadhwa
Copy link
Contributor

Extract symlinks from the tarball, and also add support for a whitelist (files that would be ignored during extraction)

Copy link
Contributor

@dlorenc dlorenc left a comment

Choose a reason for hiding this comment

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

A few comments.

}

return path, getFileSystemFromReference(ref, p.ImageSource, path)
return path, GetFileSystemFromReference(ref, p.ImageSource, path, []string{})
Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to put nil here.


for _, layer := range layers {
if err = UnTar(bytes.NewReader(layerMap[layer]), target); err != nil {
if err = UnTar(bytes.NewReader(layerMap[layer]), target, []string{}); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

And here.

return err
}
} else {
// In some cases, MkdirAll doesn't change the permissions, so run Chmod
Copy link
Contributor

Choose a reason for hiding this comment

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

It's usually umask related, but I suppose if the dirs already exist it wouldn't change the permissions either

})
}

func checkWhitelist(target string, whitelist []string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you want something more precise than prefix matching. Something like /foo would block /foobar when it should only block /foo/bar

func HasFilepathPrefix(path, prefix string) bool {
path = filepath.Clean(path)
prefix = filepath.Clean(prefix)
pathArray := strings.Split(path, "/")
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 use filepath.Split here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it only splits along the last separator

Copy link
Contributor

Choose a reason for hiding this comment

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

D'oh. Right.


target := filepath.Join(path, header.Name)
// Make sure the target isn't part of the whitelist
if checkWhitelist(target, whitelist) {
Copy link
Contributor

Choose a reason for hiding this comment

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

A debug log here will come in handy later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added it in the checkWhitelist function


func walkAndRemove(p string) error {
return filepath.Walk(p, func(path string, info os.FileInfo, err error) error {
if e := os.Chmod(path, 0777); e != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to chmod before removal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah sorry, I was trying something out and meant to remove that

@priyawadhwa priyawadhwa merged commit 6267be2 into GoogleContainerTools:master Feb 15, 2018
@priyawadhwa priyawadhwa deleted the tar branch February 15, 2018 20:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants