Skip to content

Commit 8e592bb

Browse files
KJTsanaktsidishsbt
authored andcommitted
Skip some tests which don't work under permissionless containers
When running as UID 0 but without CAP_DAC_OVERRIDE (for example, in a docker container running with --uid 0 but --cap-drop=all), these tests won't work because of hard-coded assumptions about what uid 0 can and can't do.
1 parent 9e32a88 commit 8e592bb

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

test/fileutils/test_fileutils.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,24 @@ def no_broken_symlink?
9393
@@no_broken_symlink
9494
end
9595

96+
def has_capsh?
97+
!!system('capsh', '--print', out: File::NULL, err: File::NULL)
98+
end
99+
100+
def has_root_file_capabilities?
101+
!!system(
102+
'capsh', '--has-p=CAP_DAC_OVERRIDE', '--has-p=CAP_CHOWN', '--has-p=CAP_FOWNER',
103+
out: File::NULL, err: File::NULL
104+
)
105+
end
106+
96107
def root_in_posix?
97108
if /cygwin/ =~ RUBY_PLATFORM
98109
# FIXME: privilege if groups include root user?
99110
return Process.groups.include?(0)
100-
end
101-
if Process.respond_to?('uid')
111+
elsif has_capsh?
112+
return has_root_file_capabilities?
113+
elsif Process.respond_to?('uid')
102114
return Process.uid == 0
103115
else
104116
return false

0 commit comments

Comments
 (0)