home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.65k stars 30.79k forks source link

Freebox - Docker - AuthorizationError: Authorization timed out #86393

Closed elcanux closed 3 months ago

elcanux commented 1 year ago

The problem

When updating the docker image or recreating the container, the container ID is taken into account on authentication and no longer works. It does not seem to take from the configuration file.

Example
: in .sensor/freebox/xxx.conf, the device_name is 41275ee166b5 Capture d’écran du 2023-01-22 18-34-55

On freebox application authentifcation, we can see the last device_name and the new id container created after update Capture d’écran du 2023-01-22 18-33-04

The last contenair id : Capture d’écran du 2023-01-22 18-40-54

What version of Home Assistant Core has the issue?

2023.1.6

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

freebox

Link to integration documentation on our website

https://www.home-assistant.io/integrations/freebox

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @hacf-fr, @quentame, mind taking a look at this issue as it has been labeled with an integration (freebox) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `freebox` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Change the title of the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign freebox` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


freebox documentation freebox source (message by IssueLinks)

Quentame commented 1 year ago

Hey !

Oh thanks ! I've had the same issue several times but did not notice how to reproduce 😅😅😅

I can take a look then.

Xavinooo commented 1 year ago

Any news on that one ?

Xavinooo commented 1 year ago

I think you miss something like

if os.path.exists(token_file):
    with open(token_file, "r") as f:
        data = json.load(f)
        APP_DESC["device_name"] = data["device_name"]

in the get_api function, just before the return.

(My very first python code ever ^^)

I even went a step further : when giving the freebox address, I added an optional field for the service name, defaulted to the hostname. Works for my case, absolutly no idea about non docker installs...

NicoIIT commented 1 year ago

The problem seems to be that on startup, the freebox component (in fact the freebox-api here) is re-requesting a new app Token to the freebox in case the device_name part of app_desc has changed. The freebox ha component is taking device_name from "socket.gethostname()", which in case you are running ha in a docker container is by default the ID of the container, and then is changing when the container is re created. An easy workaround to this issue is to give your docker container a fixed hostname, as for instance in docker compose: hostname: ha_raspberrypi You will need to re create the container to have the change take effect, and re authorize the app on the freebox when HA will restart / reload the freebox component with this new fixed hostname. Please note you could also re authorize the app on the freebox each time a newly created container is started, but it would be a pain at the end...

Quentame commented 1 year ago

No news sorry

issue-triage-workflows[bot] commented 1 year ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

Tronix117 commented 10 months ago

[...] The freebox ha component is taking device_name from "socket.gethostname()", which in case you are running ha in a docker container is by default the ID of the container, and then is changing when the container is re created. An easy workaround to this issue is to give your docker container a fixed hostname, as for instance in docker compose: hostname: ha_raspberrypi [...]

@NicoIIT there are some environments where the hostname may not be able to be modified as easily (for exemple when using charts on Kubernetes), nor is it a good solution.

However the fix for @Xavinoo is a better solution. But maybe using the name of the premises could be a better way instead of using socket.getsockethostname() or directly asking the user like @Xavinooo proposal.

I also have this issue, but using Kubernetes to orchestrate Docker containers. I have as of now to way to bypass it easily.

issue-triage-workflows[bot] commented 7 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

issue-triage-workflows[bot] commented 3 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.