Skip to content

Commit

Permalink
Fix the "dockerman" bug
Browse files Browse the repository at this point in the history
Checking groups in wrap_docker_command() is not reliable.
For example, the `dockerman` user in `dockerman` group makes this check fail.
Let's do it properly and try the `docker ps` command.

Thanks to @Willenst for finding this bug.
  • Loading branch information
a13xp0p0v committed Oct 26, 2024
1 parent 391cc4c commit d407b84
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions manage_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,21 @@ def check(self):
return self.id

def wrap_docker_command(self):
"""Check if the user is in the Docker group, wrap docker in 'sudo' if not"""
cmd = ['groups']
out = subprocess.run(cmd, capture_output = True, text = True, check = True)
if 'docker' in out.stdout:
return ['docker']
print('We need to use sudo to run the Docker')
return ['sudo', 'docker']
"""Check whether we need to run Docker with sudo"""
cmd = ['docker', 'ps']
out = None
try:
out = subprocess.run(cmd, capture_output = True, text = True)
if out.returncode == 0:
print('We don\'t need sudo to run Docker')
return ['docker']
elif 'permission denied' in out.stderr:
print('We need to use sudo to run Docker')
return ['sudo', 'docker']
else:
sys.exit(f'Testing "{" ".join(cmd)}" gives unknown error:\n{out.stderr}')
except FileNotFoundError:
sys.exit('[!] docker is not installed')

def add_containers(needed_compiler, containers):
"""Add the specified container(s) based on the provided compiler or add all of them"""
Expand Down

0 comments on commit d407b84

Please sign in to comment.