Add support of absolute paths#426
Conversation
anonhostpi
left a comment
There was a problem hiding this comment.
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.
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.
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. |
...
The change is either semver breaking or not, it's a binary thing. I think both of the current maintainers would prefer to avoid semver breaking changes in this crate at this time. I am not inherently opposed to the idea - but if we do do it we should do it holistically and gather a bunch of other breaking changes and improvements - I had one in #392 for example that was subtly breaking. |
|
#429 adds a CI check for this I'd like to be gating.
Anyways, to avoid the semver break - and I know it'd be a bit painful but it seems tractable, we could add I did something much like this btw in #274 |
|
@cgwalters, yeah, I see I see. Actually, your idea to add a Good to see that soon repo will have a workflow to catching a semver breaks! |
|
Or is it better to just add a method Otherwise, But here is the other question regarding the |
|
Hi there again (@anonhostpi, @cgwalters)! I've revert changes for the public Header's methods for set a path and add a new methods for absolute paths. |
anonhostpi
left a comment
There was a problem hiding this comment.
Changes since last review are sylistic, so my review remains the same. LGTM 👍
|
I'd tenatively be OK with this but needs a rebase on origin/main and also please keep it to a single commit. |
|
@cgwalters, got it! Will post an update soon! |
32c5a6d to
d798b7e
Compare
Fix failed on windows test Add test to verify unpacking of archive with absolute path Remove allow_absolute parameter from public Builder methods Fix semver; Add methods to header to set absolute path
d798b7e to
442dfc5
Compare
|
Hi @cgwalters! The branch is rebased on the latest main and commits are squashed! |
What other checks are there? I guess I don't have a really strong opinion here...ultimately anyone who wants to write arbitrary tar headers can now also use https://docs.rs/tar-core/latest/tar_core/builder/index.html which very intentionally supports writing whatever bytes one wants as the path. |
As far as I can see, My point is that if a programmer wants to set an absolute path, they shouldn't need to bypass all validation to do 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