Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"sudo" is not available for root user in docker container #91

Closed
vergissberlin opened this issue Sep 22, 2018 · 4 comments
Closed

"sudo" is not available for root user in docker container #91

vergissberlin opened this issue Sep 22, 2018 · 4 comments
Assignees
Labels
Milestone

Comments

@vergissberlin
Copy link

vergissberlin commented Sep 22, 2018

Hi!

and thank you for publishing your code!
I tried the application to get started with docker an get following exception:

Exception in thread Thread-10:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.7/site-packages/amazon_dash/listener.py", line 84, in execute
    result = self.execute_instance.execute(root_allowed)
  File "/usr/local/lib/python3.7/site-packages/amazon_dash/execute.py", line 167, in execute
    output = execute_cmd(cmd, self.data.get('cwd'))
  File "/usr/local/lib/python3.7/site-packages/amazon_dash/execute.py", line 58, in execute_cmd
    p = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  File "/usr/local/lib/python3.7/subprocess.py", line 756, in __init__
    restore_signals, start_new_session)
  File "/usr/local/lib/python3.7/subprocess.py", line 1499, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'sudo': 'sudo'

I think the last message No such file or directory: 'sudo': 'sudo'is the key. Everytime you log in or running a docker image, you are the user root inside of the running container. An root doesn't know the command sudo:

return ['sudo', '-s', '--set-home', '-u', user] + get_shell(shell) + [EXECUTE_SHELL_PARAM, cmd]

Is root really needed in this case?

My configuration file

settings:
  delay: 2
devices:
  7a:48:dd:53:99:a1:
    name: Kitchen button 1
    cmd: 'echo "1" >> /usr/src/app/amazon-dash.yml'

kind regards,
André

@Nekmo
Copy link
Owner

Nekmo commented Sep 22, 2018

Hi @vergissberlin. It seems that sudo is not installed in docker, but this has not given issues before. I will investigate this issue. Thanks!

Edit: Yes, root is required to run Amazon-dash. You can also make changes in your system. More info:
http://docs.nekmo.org/amazon-dash/troubleshooting.html#why-root-is-required

@bertobert
Copy link

The docker default user is root - so no need to use sudo.
The next issue you will run into is the usage of bash as the shell - this is also not installed in the provided DOCKERFILE.
On my local machine I patched the execute.py by removing the sudo in the command and used 'sh' instead of 'bash'.
But this is just a hack - for really fixing this you would first want to check the user running the script and second check whether you are missing something from sh which only bash can provide.

@Nekmo
Copy link
Owner

Nekmo commented Sep 25, 2018

Confirmed.

(amazon-dash) [nekmo@homura ~/Workspace/amazon-dash] (develop)$ docker run -it --network=host -v $PWD/amazon-dash.yml:/config/amazon-dash.yml nekmo/amazon-dash:latest amazon-dash --deg run --config /config/amazon-dash.yml --root-allowed --ignore-perms
Welcome to Amazon-dash v1.2.0a1 using Python 3.7.0
Listening for events. Amazon-dash will execute the events associated with the registered buttons.
2018-09-25 18:46:35,655 - amazon-dash - DEBUG   - Lounge device executed (mac 44:65:0d:16:8b:b8)
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.7/site-packages/amazon_dash/listener.py", line 84, in execute
    result = self.execute_instance.execute(root_allowed)
  File "/usr/local/lib/python3.7/site-packages/amazon_dash/execute.py", line 167, in execute
    output = execute_cmd(cmd, self.data.get('cwd'))
  File "/usr/local/lib/python3.7/site-packages/amazon_dash/execute.py", line 58, in execute_cmd
    p = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  File "/usr/local/lib/python3.7/subprocess.py", line 756, in __init__
    restore_signals, start_new_session)
  File "/usr/local/lib/python3.7/subprocess.py", line 1499, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'sudo': 'sudo'

Thanks!

@Nekmo Nekmo self-assigned this Sep 25, 2018
@Nekmo Nekmo added the bug label Sep 25, 2018
@Nekmo Nekmo added this to the v1.3.1 milestone Sep 25, 2018
@Nekmo
Copy link
Owner

Nekmo commented Oct 13, 2018

This fix will be included in the version v1.3.1. Thanks!

@Nekmo Nekmo closed this as completed Oct 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants
@vergissberlin @Nekmo @bertobert and others