-
Notifications
You must be signed in to change notification settings - Fork 227
Add support of absolute paths #426
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
base: main
Are you sure you want to change the base?
Conversation
anonhostpi
left a comment
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.
Solid simple fix!
For testing, do you think it would be worth it to generate a tar with an absolute path in it using an external tar packer (probably GNU tar, since they are explicit with their absolute path support), unpack it with this crate, then verify the file actually exists?
Would require spawn/cli calls from the test process, but would be comprehensive.
|
@anonhostpi, thanks! Hm, yes, test unpack of GNU tar created archive sounds valid. I'll try to implement it. |
|
Another solution would be to leverage crate features. Adding to the #[cfg(not(feature = "absolute-paths"))]
(Component::Prefix(..), false) | (Component::RootDir, false) => return Err(other("paths in archives must be relative"));and #[cfg(feature = "absolute-paths")]
(_, false) => {}I'm also working on a k8s project where leveraging tar-rs with absolute paths would come in handy to (ironically enough) improve pipeline security. |
|
Hi @anonhostpi! What do you think? Actually @Pathal suggested pretty clean solution (probably even cleaner then mine, since there is no need to pass around |
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.
Hi @anonhostpi! What do you think?
Appreciate the added test. It will ensure that the library is at the same competency as other projects.
Actually @Pathal suggested pretty clean solution (probably even cleaner then mine, since there is no need to pass around allow_absolute flag). Does it make sense to refactor my implementation to that?
Yes and no. Using feature flags offloads tech debt and forces the developer to decide on opt-in, not the end-user.
I think @Pathal's solution is a good one, but it needs to be documented, that if someone uses tar-rs to develop a rust-based tar CLI (or other tar client) competitive with GNU tar:
- not only do they have to enable the feature-flag, but...
- should implement a feature-gate (much like your initial implementation) in their code to prevent insecure packing and unpacking after enabling the feature-flag
In short, I think it is good, but we should be clear on why we decided that, and what debt is offloaded to the end-developer.
Honestly, IMO tar absolute paths themselves aren't a security risk. It's the poor understanding of them that is. Absolute paths in tarballs are phenomenal for snapshots and patching, making them invaluable to security maintenance. They're really good for rollback functionality. I believe I've seen tar absolute paths used extensively in systems that offer "factory resets" to default settings/builds by destroying an overlayfs and rebuilding it with one of these tarballs. |
|
Agreed on all accounts. I'm fine with this as is (not that I have any say in the matter 😂). |
@cgwalters and @xzfc have been named as the maintainers. I'll try to poke them for code review. |
cgwalters
left a comment
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.
I said this elsewhere but what I think we want at some point is to split out a "tar-core" crate that's "sans io" and allows constructing nearly arbitrary tar streams (but of course still giving high level sugar by default to handle e.g. GNU long links and such).
Anyways I think the biggest blocker for this PR as is is that it's a semver break in changing the signature of at least pub fn append_data and I think that would require a lot of nontrivial ecosystem churn for a relatively niche use case.
I think we just need the global option, there's no need to allow it per-data addition?
Also we should add cargo-semver-checks here |
|
Thanks @cgwalters for your comments. Yes, you are right, it is really breaking semantic, which is not very good. I'll see how to rework it and come back with a new changes. :) |
Niche is a strong word. It seems niche, because a lot of tar users don't understand that it exists. I have seen absolute path usage used extensively in security tools and package management software. As far as I know, absolute pathing in tar has been a part of its standard abilities since its initial release with v7 Unix at Bell labs. The way I've seen it primarily used is for restoring and/or ensuring dependent paths when administering packages and/or performing secure "factory resets" Secure "factory resetting" is a huge use case for the feature. |
|
Hello @anonhostpi, @cgwalters! As promised, I'm back with some rework. However the Anyway, let me know what do you think about it. |
Add
preserve_absoluteto builder's options to let it add files with absolute path.By default
preserve_absolutesets false, to keep current behavior, but it can be set as true via passingtrueto builder's methodpreserve_absolute.Closes: #326, #413