Skip to content
This repository was archived by the owner on Oct 10, 2020. It is now read-only.

Commit 50b0df1

Browse files
giusepperh-atomic-bot
authored andcommitted
util: add list of capabilities
the capsh approach doesn't work on RHEL as the version of libcap is not updated and doesn't know all the possible capabilities available on the system. This is the output I get with getpcaps on RHELAH 7.4.2: Capabilities for `1': = cap_chown,cap_dac_override,cap_dac_read_search,cap_fowner,cap_fsetid,cap_kill,cap_setgid,cap_setuid,cap_setpcap,cap_linux_immutable,cap_net_bind_service,cap_net_broadcast,cap_net_admin,cap_net_raw,cap_ipc_lock,cap_ipc_owner,cap_sys_module,cap_sys_rawio,cap_sys_chroot,cap_sys_ptrace,cap_sys_pacct,cap_sys_admin,cap_sys_boot,cap_sys_nice,cap_sys_resource,cap_sys_time,cap_sys_tty_config,cap_mknod,cap_lease,cap_audit_write,cap_audit_control,cap_setfcap,cap_mac_override,cap_mac_admin,cap_syslog,35,36+ep Fallback to the capsh method if there will be more capabilities that we know of, and hopefully libcap does. Signed-off-by: Giuseppe Scrivano <[email protected]> Closes: #1130 Approved by: rhatdan
1 parent 436cf5d commit 50b0df1

File tree

1 file changed

+48
-7
lines changed

1 file changed

+48
-7
lines changed

Atomic/util.py

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,45 @@ def remove_skopeo_prefixes(image):
11361136
image = image.replace(remove, '')
11371137
return image
11381138

1139+
KNOWN_CAPS = ['CAP_CHOWN',
1140+
'CAP_DAC_OVERRIDE',
1141+
'CAP_DAC_READ_SEARCH',
1142+
'CAP_FOWNER',
1143+
'CAP_FSETID',
1144+
'CAP_KILL',
1145+
'CAP_SETGID',
1146+
'CAP_SETUID',
1147+
'CAP_SETPCAP',
1148+
'CAP_LINUX_IMMUTABLE',
1149+
'CAP_NET_BIND_SERVICE',
1150+
'CAP_NET_BROADCAST',
1151+
'CAP_NET_ADMIN',
1152+
'CAP_NET_RAW',
1153+
'CAP_IPC_LOCK',
1154+
'CAP_IPC_OWNER',
1155+
'CAP_SYS_MODULE',
1156+
'CAP_SYS_RAWIO',
1157+
'CAP_SYS_CHROOT',
1158+
'CAP_SYS_PTRACE',
1159+
'CAP_SYS_PACCT',
1160+
'CAP_SYS_ADMIN',
1161+
'CAP_SYS_BOOT',
1162+
'CAP_SYS_NICE',
1163+
'CAP_SYS_RESOURCE',
1164+
'CAP_SYS_TIME',
1165+
'CAP_SYS_TTY_CONFIG',
1166+
'CAP_MKNOD',
1167+
'CAP_LEASE',
1168+
'CAP_AUDIT_WRITE',
1169+
'CAP_AUDIT_CONTROL',
1170+
'CAP_SETFCAP',
1171+
'CAP_MAC_OVERRIDE',
1172+
'CAP_MAC_ADMIN',
1173+
'CAP_SYSLOG',
1174+
'CAP_WAKE_ALARM',
1175+
'CAP_BLOCK_SUSPEND',
1176+
'CAP_AUDIT_READ']
1177+
11391178
def get_all_known_process_capabilities():
11401179
"""
11411180
Get all the known process capabilities
@@ -1147,14 +1186,16 @@ def get_all_known_process_capabilities():
11471186
with open("/proc/sys/kernel/cap_last_cap", 'r') as f:
11481187
last_cap = int(f.read())
11491188

1150-
mask = hex((1 << (last_cap + 1)) - 1)
1151-
1152-
out = subprocess.check_output([CAPSH_PATH, '--decode={}'.format(mask)], stderr=DEVNULL)
1189+
if last_cap < len(KNOWN_CAPS):
1190+
caps = KNOWN_CAPS[:last_cap+1]
1191+
else:
1192+
mask = hex((1 << (last_cap + 1)) - 1)
1193+
out = subprocess.check_output([CAPSH_PATH, '--decode={}'.format(mask)], stderr=DEVNULL)
11531194

1154-
# The output looks like 0x0000003fffffffff=cap_chown,cap_dac_override,...
1155-
# so take only the part after the '='
1156-
caps = str(out.decode().split("=")[1].strip())
1195+
# The output looks like 0x0000003fffffffff=cap_chown,cap_dac_override,...
1196+
# so take only the part after the '='
1197+
caps = str(out.decode().split("=")[1].strip()).split(',')
11571198

1158-
caps_list = [i.upper() for i in caps.split(',')]
1199+
caps_list = [i.upper() for i in caps]
11591200

11601201
return [i for i in caps_list if not i[0].isdigit()]

0 commit comments

Comments
 (0)