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

Extract tarballs in Ubuntu:14.04 #435

Closed
wants to merge 1 commit into from

Conversation

PrajwalM2212
Copy link
Contributor

Some tarballs cannot be extracted without running as root. Hence tar will be extracted by running the root command

Resolves #433

Signed-off-by: Prajwal M [email protected]

with tarfile.open(layer_tar_path) as tar:
tar.extractall(directory_path)
os.makedirs(directory_path)
root_command(extract_tar, layer_tar_path, '-C', directory_path)

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch! The trouble with shelling out to the system's tar utility is that it won't check for empty tarballs as we have seen in #430. I wonder if we can use tarfile to see if the tarball is empty or not before shelling out to it. If you can do this, I can close #226 as this change will resolve that one as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I will check for empty tarballs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nishakm tarfile module is not helping. tar -tf helps. But there are some security warnings associated with this. Any clue how to resolve them ?

If they can't be resolved then we may have to find another way to validate tar files.

Copy link
Contributor

Choose a reason for hiding this comment

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

@PrajwalM2212 do you get any warnings when running tar -tf on an ubuntu image? I don't see any.

@nishakm
Copy link
Contributor

nishakm commented Aug 30, 2019

@PrajwalM2212 on line 61

else:
        return result

Can you remove the else: and just return result?

Some tarballs cannot be extracted without running as root.
Hence tar will be extracted by running the root command

Resolves tern-tools#433

Signed-off-by: Prajwal M <[email protected]>
tar.extractall(directory_path)
os.makedirs(directory_path)
with open(os.devnull, 'w') as test:
result = subprocess.call(['tar', '-tf', layer_tar_path],
Copy link
Contributor

@nishakm nishakm Sep 3, 2019

Choose a reason for hiding this comment

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

Oh! This is what you meant by security warning. You can use root_command here as well and check to see if there is an error or if the result is an empty string.

Copy link
Contributor

Choose a reason for hiding this comment

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

root_command will take care of the pipe redirection for you and will return the result and an error message.

@nishakm
Copy link
Contributor

nishakm commented Sep 4, 2019

Closing this as the commit is in the PR #440

@nishakm nishakm closed this Sep 4, 2019
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.

Cannot extract tarballs in Ubuntu:14.04 image
2 participants