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

cmd/entrypoint/subcommands/cp test does not respect umask #4099

Closed
wlynch opened this issue Jul 15, 2021 · 3 comments · Fixed by #4100
Closed

cmd/entrypoint/subcommands/cp test does not respect umask #4099

wlynch opened this issue Jul 15, 2021 · 3 comments · Fixed by #4100
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@wlynch
Copy link
Member

wlynch commented Jul 15, 2021

Expected Behavior

TestCp passes on main branch.

Actual Behavior

$ go test .
--- FAIL: TestCp (0.00s)
    cp_test.go:54: expected permissions 0311 for destination file but found 0310
FAIL
FAIL    github.com/tektoncd/pipeline/cmd/entrypoint/subcommands 0.017s
FAIL

Steps to Reproduce the Problem

This appears to be caused by an assumption that the system umask would be fully permissive, and the cp func would fully preserve permissions. On my system, the default umask is:

$ umask
027

This strips out the all-read permissions on the file, since os.OpenFile will set permissions post-mask -

If the file does not exist, and the O_CREATE flag is passed, it is created with mode perm (before umask).

Some potential fixes-

  1. Make a manual os.Chmod after the file creation, though this would not respect any existing permissions on the file.
  2. Set the umask via unix.Umask but this is also problematic since IIUC this will set it for system and would only work for unix environments.
  3. Loosen the test requirements to be less sensitive to permissions.

@sbwsg Any preferences between these options?

Additional Info

/assign @wlynch

@wlynch wlynch added the kind/bug Categorizes issue or PR as related to a bug. label Jul 15, 2021
@wlynch
Copy link
Member Author

wlynch commented Jul 15, 2021

/cc @sbwsg in case the edit above didn't send a notification

@ghost
Copy link

ghost commented Jul 15, 2021

Hm, couple alternatives spring to mind:

  1. Could we infer what the user's equivalent of 0311 would be by attempting to pre-write a file with dstPermissions and then reading that back to set our expectations for the test?
  2. Could we pre-calculate the eventual on-disk perms by reading the current processes' umask value and performing the calc ourselves in code? (unix-specific, example of reading the umask here: https://www.yesthatblog.com/post/0072-go-and-umask/)

(1) strikes me as the most pragmatic solution (with accompanying code comment describing why we're doing it). (2) feels like it'll be a lot of unix-specific code in the unit test. I like "loosening the test requirements" if (1) isn't feasible (or if I'm missing why it's a bad choice in the first place).

wdyt?

@wlynch
Copy link
Member Author

wlynch commented Jul 15, 2021

I liked (1) at first, but after writing it, I think it's tautological so it doesn't provide much value (e.g. the permissions could be 0777 and it would still pass).

(2) is problematic for any non-unix systems, and I'm not exactly sure what happens if a unix syscall is performed on a non-unix system.

I'm thinking we can get away with checking if the resulting file has any permissions we don't expect. This loosens the check without completely removing it, but I think it is still good enough for what we need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant