According to man 7 capabilities
CAP_DAC_READ_SEARCH
* Bypass file read permission checks and directory read and execute permission checks;
* Invoke open_by_handle_at(2).
This worked for me. (lines beginning with '#' are root, those with '$' are non-root) in this case the non-root user is in the wheel
group.
# cp /usr/bin/find /usr/bin/sudofind
# chmod 710 /usr/bin/sudofind
# chown root:wheel /usr/bin/sudofind
# setcap cap_dac_read_search+ep /usr/bin/sudofind
# exit
$ find /root
find: ‘/root’: Permission denied
$ sudofind /root
/root /root
/root/Testbed
...
...
$ sudofind /root -exec cat {} \;
cat: /root: Permission denied
cat: /root/Testbed: Permission denied
$ sudofind /root -printf "%u %g %m %c %p\n"
root root 644 Mon Apr 20 09:20:48.0457518493 2015 /root
root root 755 Fri Dec 4 02:34:03.0016294644 2015 /root/Testbed
...
...
$ # Capability inheritance test..
$ sudofind /root -exec /bin/sleep 10 \; &
[1] 17017
$ getpcaps $(pgrep find)
Capabilities for `17017': = cap_dac_read_search+ep
$ getpcaps $(pgrep sleep)
Capabilities for `17019': =
Given what the capability grants, it fits in with exactly what you want.
I've not exhaustively checked whether find
has a feature which allows you to read bytes inside of files, but obvious stuff like LD_PRELOAD
and library shim attacks shouldn't work due to the nature of setuid checks in Linux, and the capability bits don't get inherited by child processes either (unlike raw setuid) so that's another bonus.
Bear in mind that what you want to do does raise possible privacy concerns in regards to temporary file creation or access, and the program could be used as a basis to mounting a race condition / privilege escalation attempt (against programs that create well-known filenames but don't do correct security checks).
Also, some poorly written applications may rely on file metadata or tree structure as a way to convey meaning or hide data. This might cause release of restricted information or reveal privileged documents not otherwise known about (security through obscurity I know, but this is a thing that closed-source vendors in particular like to do, unfortunately).
Therefore, take care and be wary about doing it and understand there is still risk associated with this even if the obvious things don't work.
Oh, and I'd be interested to see if someone has a proof of concept attack which uses this mechanism as a basis for privilege escalation in the comments!