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

Emulated Hue Permission Issue #4737

Closed
bruhautomation opened this issue Dec 5, 2016 · 18 comments
Closed

Emulated Hue Permission Issue #4737

bruhautomation opened this issue Dec 5, 2016 · 18 comments

Comments

@bruhautomation
Copy link

Hello! I'm having an issue with the emulated hue component. Not sure if this is localized issue or something more widespread. In my quick googling, looks like Python doesn't like binding ports lower than 1024 or so without giving it more permissions as a privileged user.

I'm running HA in a venv via the All-In-One script.

Thanks much for any feedback and/or help!

Home Assistant release (hass --version): 0.34.1

Python release (python3 --version): 3.4.2

Component/platform:
Emulated Hue

Description of problem:
Emulated Hue won't start. Throwing an error in the log.

16-12-04 19:16:57 homeassistant.core: Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/base_events.py", line 757, in create_server
    sock.bind(sa)
PermissionError: [Errno 13] Permission denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 235, in _step
    result = coro.send(value)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/emulated_hue/__init__.py", line 99, in start_emulated_hue_bridge
    yield from server.start()
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/http/__init__.py", line 309, in start
    self._handler, self.server_host, self.server_port, ssl=context)
  File "/usr/lib/python3.4/asyncio/base_events.py", line 761, in create_server
    % (sa, err.strerror.lower()))
PermissionError: [Errno 13] error while attempting to bind on address ('192.168.1.126', 80): permission denied

Expected:
Emulated Hue runs

Problem-relevant configuration.yaml entries and steps to reproduce:

emulated_hue:
  type: google_home
  listen_port: 80
@sdague
Copy link
Contributor

sdague commented Dec 5, 2016

It's actually a Linux safeguard. Binding to < 1024 requires being root. The solution is probably going to be making home-assistant understand how to drop privs back to a normal user after binding to the port.

@algorythmic
Copy link

One could also grant the capability to bind to privileged ports for the python binary in the virtualenv like

sudo setcap 'cap_net_bind_service=+ep' /srv/hass/bin/python3

@bruhautomation
Copy link
Author

@algorythmic, good call. The only issue is that to my knowledge sudo access is turned off inside the venv that the AiO script makes.

@ronvl
Copy link

ronvl commented Dec 5, 2016

same here.
Also : sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8300
doesn't work for Google Home. In a web browser you get the valid response on http://192.168.2.192/description.xml but GH doesn't find it

@demonspork
Copy link

@ronvl I think that is because it is being advertised on port 8300 if the config is set to 8300. What we would need support for is having the emulated_hue component think it is on port 80, but actually be bound to port 8300

@ronvl
Copy link

ronvl commented Dec 6, 2016

as I'm not running virtuelenv I used:
sudo setcap 'cap_net_bind_service=+ep' /usr/bin/python3.4

and it works .... cool 👍

@bruhautomation
Copy link
Author

For people who are following this thread, after a little research the setcap command does work for the AiO method.

The magic sauce for people running HA in a venv via the AiO script is

sudo setcap 'cap_net_bind_service=+ep' /srv/hass/hass_venv/bin/python3

After running that, I was able to spin up the component no problem which both Google Home and the Amazon Echo can see. Sick!

@balloob, is this something that can be added to the component or would it be easiest to update the Emulated Hue component page?

Cheers!

@balloob
Copy link
Member

balloob commented Dec 13, 2016

I think this would fit best at the emulated_hue page

@bruhautomation
Copy link
Author

Sweet! I'll try and get a pull pulled together on that page soon. Cheers!

@Antexa
Copy link

Antexa commented Mar 1, 2017

Hi,
I don't know if it's worth mentioning it but for fresh hassbian users they need to set the setcap command for launching the http component properly
sudo setcap 'cap_net_bind_service=+ep' /usr/bin/python3.4

@bobbynobble
Copy link

What would be the equivalent command to get Google Home working on a Mac HA install?

@brendanheyu
Copy link

Thanks Antexa - I needed that!

@mohaggag
Copy link

not working for me i cannot get google home to work the port 80 not working for me after using all commands

@demonspork
Copy link

@mohaggag Google Home updated to require a Hue account to be registered to add Phillips hue devices. It is no longer possible to add new emulated hue setups to Google Home, but existing ones will still work.

We would have to register the Home Assistant as if it were a full fledged Phillips Hue hub tying into their cloud and everything in order to fix this problem.

@kerbysj
Copy link

kerbysj commented Apr 9, 2017

This morning i setup HA and my google home it worked fine with my vera + emulated bridge. Had to run as root get get it to run over port 80 however.

@mohaggag
Copy link

mohaggag commented Apr 9, 2017

@kerbysj how did you make it .. i got port 80 to work but emulated hue now using hue account as @demonspork mention so it cann't be done ..

@kerbysj
Copy link

kerbysj commented Apr 12, 2017

Well i just setup the emulated hub on port 80 and then paired in google home and it all just worked...

Google Home example configuration.yaml entry

emulated_hue:
type: google_home

Google Home does not work on different ports.

listen_port: 80

@shaun-ba
Copy link

shaun-ba commented Apr 20, 2017

@kerbysj not sure how you did this as nobody else can. You can't bind to port 80 without being root or the above commands, and i just received a google home and you have to sign into Hue to add the device

I bought a google home specifically for HA, so really disappointed right now!

@home-assistant home-assistant locked and limited conversation to collaborators Aug 12, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests