mhogomchungu / zuluCrypt

zuluCrypt is a front end to cryptsetup and tcplay and it allows easy management of encrypted block devices
https://mhogomchungu.github.io/zuluCrypt
Other
496 stars 61 forks source link

zuluCrypt-cli --test fails when run via sudo #209

Closed ogayot closed 1 month ago

ogayot commented 1 year ago

Hello,

When zuluCrypt-cli --test is run via sudo, it fails with the following error:

$ sudo zuluCrypt-cli --test
[...]
create a luks type volume using a key: FAILED
ERROR: A non supported device encountered,device is missing or permission denied
Possible reasons for getting the error are:
1.Device path is invalid.
2.The device has LVM or MDRAID signature

Full log in Ubuntu: https://autopkgtest.ubuntu.com/results/autopkgtest-mantic/mantic/amd64/z/zulucrypt/20230506_063514_ac412@/log.gz

Analysis:

  1. The /tmp/zuluCrypt-luksTestVolume file gets created as root
  2. Then we seteuid(uid) where uid is determined via the SUDO_UID variable in this function https://github.com/mhogomchungu/zuluCrypt/blob/cf8de091cfb03b6dc1cd27195345f299aa3fdbea/zuluCrypt-cli/bin/security.c#L86)
  3. Then we attempt to open the file and it fails with EACCESS (Permission Denied).

excerpt from strace:

27422 setresuid(-1, 1000, -1)           = 0
27422 openat(AT_FDCWD, "/tmp/zuluCrypt-luksTestVolume", O_RDONLY) = -1 EACCES (Permission denied)
27422 newfstatat(1, "", {st_mode=S_IFIFO|0600, st_size=0, ...}, AT_EMPTY_PATH) = 0
27422 setresuid(-1, 0, -1)              = 0
27422 openat(AT_FDCWD, "/tmp/zuluCrypt-luksTestVolume", O_RDONLY) = 3

I found a workaround that I'm going to propose for the test-suite in Ubuntu:

$ sudo env -u SUDO_UID zuluCrypt-cli --test

But it feels like something is wrong in the logic itself.

Thanks, Olivier

ogayot commented 1 year ago

Possibly related to https://github.com/mhogomchungu/zuluCrypt/issues/106 ?

mhogomchungu commented 1 month ago

Sorry for taking a while to respond.

This is now fixed and the fix is also to unset sudo variable.