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

Replace tar (cli) with code-only packing #808

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

astef
Copy link

@astef astef commented Dec 3, 2024

What type of PR is this?
/kind feature

What this PR does / why we need it:

  • Removes dependency on the presence of tar utility in the system. This is beneficial for distroless containers
  • New packing/unpacking gives more control over the content of snapshots and make developers think about what exactly is being snapshotted/restored

Special notes for your reviewer:

  • One of the important cases I've tried to support - proper symlink support. Unfortunately, symlinks happen to be not supported in the testing solution I've chosen (golang.org/x/mod/sumdb/dirhash), so this functionality is only tested by me manually. This can be improved, if we'll find a way to hash the resulting directories considering symlinks. I've also tried to byte-compare the resulting archives, but they contain non-deterministic information, and, therefore, not comparable.

  • Another important case was reported by an automatic check - Arbitrary file access during archive extraction ("Zip Slip"). Issue was reproduced in test and fixed. I've chosen the error, which won't change in future versions of Go (after they will finally "turn on" their fix by default, see issue)

Does this PR introduce a user-facing change?:

tar is no longer needed to be present in the environment for snapshots to work

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. labels Dec 3, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: astef
Once this PR has been reviewed and has the lgtm label, please assign xing-yang for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 3, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @astef!

It looks like this is your first PR to kubernetes-csi/csi-driver-nfs 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-csi/csi-driver-nfs has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @astef. Thanks for your PR.

I'm waiting for a kubernetes-csi member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Dec 3, 2024
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note-none Denotes a PR that doesn't merit a release note. labels Dec 3, 2024
pkg/nfs/tar.go Fixed Show fixed Hide fixed
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 6, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 11, 2024
@andyzhangx
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 12, 2024
@coveralls
Copy link

coveralls commented Dec 12, 2024

Pull Request Test Coverage Report for Build 12367443998

Details

  • 130 of 171 (76.02%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.4%) to 78.188%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/nfs/tar.go 124 165 75.15%
Totals Coverage Status
Change from base Build 12364997568: -0.4%
Covered Lines: 1079
Relevant Lines: 1380

💛 - Coveralls

Copy link

linux-foundation-easycla bot commented Dec 12, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: astef / name: Aleksandr Stefurishin (3f15d4d)

@k8s-ci-robot k8s-ci-robot removed the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Dec 12, 2024
@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Dec 12, 2024
@andyzhangx
Copy link
Member

@astef can you sign the cla first? thx

@astef
Copy link
Author

astef commented Dec 12, 2024

I had to change my email in GitHub, that's why EasyCLA now fails. Will fix it soon.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Dec 12, 2024
@astef astef changed the title WIP: Replace tar (cli) with code-only packing Replace tar (cli) with code-only packing Dec 13, 2024
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 13, 2024
@astef
Copy link
Author

astef commented Dec 13, 2024

@andyzhangx I've just finished manual test in my cluster (snapshot/restore, checked integrity of content, folder structure inside controller), and removed "WIP" prefix. Sorry for delay and back-and-forth.

@andyzhangx
Copy link
Member

@astef thanks for the contribution, does original tar command supports symlink?

@astef
Copy link
Author

astef commented Dec 16, 2024

does original tar command supports symlink?

Yes it does, here's how I check:

# setup
mkdir input && date > input/d.txt && cd input && ln -s -T ./d.txt ./symlink_to_d.txt && cd ..

# pack
tar -C input/ -czvf output.tar.gz .

# unpack
mkdir output && tar -xzvf output.tar.gz -C output

# check
ls -la input && ls -la output && cat input/symlink_to_d.txt && cat output/symlink_to_d.txt

@andyzhangx
Copy link
Member

does original tar command supports symlink?

Yes it does, here's how I check:

# setup
mkdir input && date > input/d.txt && cd input && ln -s -T ./d.txt ./symlink_to_d.txt && cd ..

# pack
tar -C input/ -czvf output.tar.gz .

# unpack
mkdir output && tar -xzvf output.tar.gz -C output

# check
ls -la input && ls -la output && cat input/symlink_to_d.txt && cat output/symlink_to_d.txt

@astef then this is a regression and blocker.

@astef
Copy link
Author

astef commented Dec 16, 2024

But proposed solution supports symlinks too. In "special notes" I've meant that I'm not testing symlinks in unit-tests, but they're suppored.

Actually, now I think that I can write a more concrete unit-test, without golang.org/x/mod/sumdb/dirhash, and this will demonstrate the support of symlinks, and increase coverage.

@astef astef changed the title Replace tar (cli) with code-only packing WIP: Replace tar (cli) with code-only packing Dec 16, 2024
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 16, 2024
@astef
Copy link
Author

astef commented Dec 16, 2024

@andyzhangx you were right, there was a regression. Up to this moment I didn't realize that io.Copy won't create a symlink's "content" automatically. I saw it was created, but missed that it's empty. Fixed and covered with test. Thank you!

@astef astef changed the title WIP: Replace tar (cli) with code-only packing Replace tar (cli) with code-only packing Dec 16, 2024
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 16, 2024
@astef
Copy link
Author

astef commented Dec 16, 2024

/test pull-csi-driver-nfs-external-e2e


fileInfo := tarHeader.FileInfo()

filePath := filepath.Join(dstDirPath, tarHeader.Name)

Check failure

Code scanning / CodeQL

Arbitrary file write extracting an archive containing symbolic links High

Unresolved path from an archive header, which may point outside the archive root, is used in
symlink creation
.
Copy link
Author

Choose a reason for hiding this comment

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

Expected, since we want to preserve such links in snapshots.

}

if fileInfo.Mode()&fs.ModeSymlink != 0 {
if err := os.Symlink(tarHeader.Linkname, filePath); err != nil {

Check failure

Code scanning / CodeQL

Arbitrary file write extracting an archive containing symbolic links High

Unresolved path from an archive header, which may point outside the archive root, is used in
symlink creation
.
Copy link
Author

Choose a reason for hiding this comment

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

Expected, since we want to preserve such links in snapshots.

@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants