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

Merge slice fixes into main #340

Merged
merged 21 commits into from
Jul 24, 2020
Merged

Merge slice fixes into main #340

merged 21 commits into from
Jul 24, 2020

Conversation

ekcasey
Copy link
Member

@ekcasey ekcasey commented Jul 20, 2020

This PR includes slices fixes for symlinks from 0.8.1 (#335). Additional work was required to fix symlink handling in windows. The archive package now adds PAX records to windows archives headers so that we can properly make directory or file type symlinks even when the link target does not exist (for context: golang/go#39183).

This PR runs the windows unit and acceptance tests in GHA without the docker-run-windows wrapper. That wrapper removes permissions from test fixtures that are required to properly test handling of directory symlinks.

ekcasey added 10 commits July 9, 2020 13:15
Signed-off-by: Emily Casey <ecasey@vmware.com>
* Add matched symlinks to the slice instead of the resolved target
* Slice layers should not include files globbing through a symlink
* Only clean up links to dirs, not the target dirs
* Normalize uid/gid of the parents of a matched file only if they are within the app dir

Signed-off-by: Emily Casey <ecasey@vmware.com>
Signed-off-by: Emily Casey <ecasey@vmware.com>
Signed-off-by: Emily Casey <ecasey@vmware.com>
* Removes unused test helpers

Signed-off-by: Emily Casey <ecasey@vmware.com>
…complete

Signed-off-by: Emily Casey <ecasey@vmware.com>
Fix handling of symlinks in slices
* Fixes cache log messages

Signed-off-by: Emily Casey <ecasey@vmware.com>
refactors windows logic to use new layers package

Signed-off-by: Emily Casey <ecasey@vmware.com>
@ekcasey ekcasey requested a review from a team as a code owner July 20, 2020 22:59
Signed-off-by: Emily Casey <ecasey@vmware.com>
@ekcasey ekcasey marked this pull request as draft July 20, 2020 23:17
Signed-off-by: Emily Casey <ecasey@vmware.com>
@ekcasey ekcasey force-pushed the merge-slice-fix branch 10 times, most recently from a8e0fbe to 963d735 Compare July 22, 2020 14:18
ekcasey added 2 commits July 22, 2020 10:28
Signed-off-by: Emily Casey <ecasey@vmware.com>
Docker copy removes file attributes for windows symlink directories that need to be preserved for certain tests

Signed-off-by: Emily Casey <ecasey@vmware.com>
Signed-off-by: Emily Casey <ecasey@vmware.com>
@ekcasey ekcasey changed the title Merge 0.8.1 into main Merge slice fixes into main Jul 22, 2020
@ekcasey ekcasey marked this pull request as ready for review July 22, 2020 16:17
Copy link
Member

@micahyoung micahyoung left a comment

Choose a reason for hiding this comment

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

This looks great! Slices/layer refactor is so much easier to follow. I just added notes of approval and some thoughts below.

My only outstanding quesiton. Will the NormalizingTarWriter get used in pack?

.github/workflows/build.yml Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
layers/extract.go Outdated Show resolved Hide resolved
archive/writer.go Outdated Show resolved Hide resolved
Comment on lines +25 to +46
func createSymlink(hdr *tar.Header) error {
var flags uint32 = symbolicLinkFlagAllowUnprivilegedCreate
if attrStr, ok := hdr.PAXRecords[hdrFileAttributes]; ok {
attr, err := strconv.ParseUint(attrStr, 10, 32)
if err != nil {
return errors.Wrapf(err, "failed to parse file attributes for header %q", hdr.Name)
}
if attr&syscall.FILE_ATTRIBUTE_DIRECTORY != 0 {
flags |= syscall.SYMBOLIC_LINK_FLAG_DIRECTORY
}
}

name, err := syscall.UTF16PtrFromString(hdr.Name)
if err != nil {
return err
}
target, err := syscall.UTF16PtrFromString(hdr.Linkname)
if err != nil {
return err
}
return syscall.CreateSymbolicLink(name, target, flags)
}
Copy link
Member

Choose a reason for hiding this comment

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

It's a bummer to have to do all this to work around the divergent Windows/POSIX golang behavior. After reading that thread it sounds like a wontfix so os.Symlink won't change anytime soon. This implementation feels like it follows one of the suggestions there:

For the few programs that actually do need to create symlinks to nonexistent targets, windows.CreateSymbolicLink seems sufficient, and it's easy enough for users to write their own portable wrappers using +build constraints.

Workaround broken directory symlink behavior in docker build

Signed-off-by: Micah Young <ymicah@vmware.com>
ekcasey added 2 commits July 23, 2020 09:45
Fix make docker-run-windows branch merge-slice-fix
Signed-off-by: Emily Casey <ecasey@vmware.com>
@ekcasey ekcasey requested review from jabrown85 and yaelharel July 23, 2020 15:04
Copy link
Member

@natalieparellano natalieparellano left a comment

Choose a reason for hiding this comment

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

@ekcasey this looks great! I'm not too familiar with how slices worked before, but the new organization is very clear and easy to follow.

testhelpers/testhelpers.go Show resolved Hide resolved
layers/layers_windows_test.go Show resolved Hide resolved
it("creates a layer from the directory", func() {
// parent layers should have uid/gid matching the filesystem
// the dir and it's children should have normalized uid/gid
assertTarEntries(t, dirLayer.TarPath, append(parents(t, dir), []*tar.Header{
Copy link
Member

Choose a reason for hiding this comment

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

I might be missing something but it doesn't seem that we test the permissions of the parent directory anywhere, no? Is this possible?

Copy link
Member Author

Choose a reason for hiding this comment

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

The expected parent headers have UID/GID set on them but the assertions are missing (!) and we don't do this for windows headers. I will clean this up.

https://github.com/buildpacks/lifecycle/blob/merge-slice-fix/layers/layers_unix_test.go#L18-L20

Copy link
Member Author

@ekcasey ekcasey Jul 23, 2020

Choose a reason for hiding this comment

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

Actually, we do test UID/GID but only for linux layers. https://github.com/buildpacks/lifecycle/blob/merge-slice-fix/layers/layers_unix_test.go#L28-L36

We currently aren't setting the SID on windows layer entries properly (looks like setting header.Uid doesn't do the trick) but that was true before this PR and I would like to fix it separately. I believe the SID should be set to the value of CNB_USER_ID for windows layers using PAX records.

ekcasey added 3 commits July 23, 2020 17:05
Signed-off-by: Emily Casey <ecasey@vmware.com>
Signed-off-by: Emily Casey <ecasey@vmware.com>
@ekcasey ekcasey requested a review from natalieparellano July 23, 2020 21:33
@ekcasey ekcasey merged commit f76b3e6 into main Jul 24, 2020
@ekcasey ekcasey deleted the merge-slice-fix branch July 24, 2020 17:45
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.

3 participants