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

Unable to add local account to Unifi integration : "Failed to connect" message #119920

Open
XalaTheShepard opened this issue Jun 18, 2024 · 16 comments
Assignees

Comments

@XalaTheShepard
Copy link

The problem

Dear,

In July 2024, Unifi will require 2FA exept for local accounts.
I have created a local account with Administrator rights in my Unifi controller (Remote access disabled).
When trying to connect the local account to the Unifi integration, I always get the message "Failed to connect".
Please find enclosed the images with the setup of the account and the error.
Could you please assist me with this issue?

Many thanks.

Kind regards,

Robin
Schermafbeelding 2024-06-18 214243
Schermafbeelding 2024-06-18 214045

What version of Home Assistant Core has the issue?

2024.6.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

UniFi Network

Link to integration documentation on our website

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

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
Copy link

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

Code owner commands

Code owners of unifi can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign unifi Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


unifi documentation
unifi source
(message by IssueLinks)

@BlackRockCity
Copy link

BlackRockCity commented Jun 19, 2024

I am seeing the same failed to connect issue in the June release of HAOS/HA. My Unifi controller is remote, but I'm giving the correct credentials as verified by logging into the same hostname on my controller's web GUI.

This is my first time installing it. I've never tried to install the Unifi Integration previously.

Also, I recommend some documentation or a greyed out text in the host field showing example.com because its not clear if a leading https:// is needed in the hostname field.

Thanks for posting this OP.

@XalaTheShepard
Copy link
Author

I noticed that I forgot to mention that I am running the UniFi controller as a HA Add-on

@leeaash
Copy link

leeaash commented Jun 19, 2024

I also meet this problem even I have create a local authentication account. Any tips to resolve this problem?

@XalaTheShepard
Copy link
Author

In my case, the issue has been solved. I have logged in into both the Unifi controller and HA using the local IP address. Then I have created a local user in the Unifi controller. I deleted the Unifi Network integration in the local HA and afterwards added it again with the credentials of the local administrator account of the Unifi controller. Now I have both 1 local Unifi administrator and 1 remote Unifi administrator, of which the latter has to use the 2FA.

@Kane610
Copy link
Member

Kane610 commented Jun 20, 2024

Do you see any errors in the logs?

@XalaTheShepard
Copy link
Author

@BlackRockCity and @leeaash , this is a question for your issues as for me the issue has been resolved

@mindstorms6
Copy link

I've been hitting the same issue recently - however - it seems like my integration got in a bad state and was hitting the login endpoint on the controller too much. From the integration logs, the controller is now returning a 429 Too Many Requests error:

2024-06-21 16:35:17.775 DEBUG (MainThread) [aiounifi.interfaces.connectivity] data (from https://192.168.4.1:443) b'<!doctype html><html lang="en"><head><meta charset="utf-8"><link rel="icon" href="/favicon.ico?v3" sizes="any"><link rel="icon" href="/favicon.svg?v3" type="image/svg+xml"><link rel="apple-touch-icon" href="/apple-touch-icon.png?v3"><title>UniFi OS</title><meta name="viewport" content="width=device-width,initial-scale=1"><script>window.UNIFI_OS_MANIFEST = {"model":{"id":"UDW","shortName":"UDW","longName":"UniFi Dream Wall"},"images":{"small":"/assets/images/small.png?udw-2.0.0","medium":"/assets/images/medium.png?udw-2.0.0","large":"/assets/images/large.png?udw-2.0.0","huge":"/assets/images/huge.png?udw-2.0.0"}}</script><script defer="defer" src="/main.1f13cbe8ee4a4f1a0848.js"></script><link href="/main.0e9197a3.css" rel="stylesheet"></head><body><div id="root"></div></body></html>'
2024-06-21 16:35:17.775 DEBUG (MainThread) [aiounifi.interfaces.connectivity] Talking to UniFi OS device: True
2024-06-21 16:35:17.775 DEBUG (MainThread) [aiounifi.interfaces.connectivity] sending (to https://192.168.4.1:443/api/auth/login) post, {'username': 'viewonly', 'password': 'OMITTED', 'rememberMe': True}, {}
2024-06-21 16:35:17.792 DEBUG (MainThread) [aiounifi.interfaces.connectivity] received (from https://192.168.4.1:443/api/auth/login) 429 application/json <ClientResponse(https://192.168.4.1:443/api/auth/login) [429 Too Many Requests]>
<CIMultiDictProxy('Server': 'nginx', 'Date': 'Fri, 21 Jun 2024 20:35:17 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '113', 'Connection': 'keep-alive', 'X-Response-Time': '12ms', 'Access-Control-Allow-Credentials': 'false', 'Referrer-Policy': 'no-referrer', 'Strict-Transport-Security': 'max-age=15552000; includeSubDomains', 'X-Content-Type-Options': 'nosniff', 'X-DNS-Prefetch-Control': 'off', 'X-Frame-Options': 'SAMEORIGIN', 'X-XSS-Protection': '1; mode=block')>

2024-06-21 16:35:17.792 DEBUG (MainThread) [aiounifi.interfaces.connectivity] data (from https://192.168.4.1:443/api/auth/login) b'{"code":"AUTHENTICATION_FAILED_LIMIT_REACHED","message":"You\'ve reached the login attempt limit","level":"debug"}'
2024-06-21 16:35:17.792 ERROR (MainThread) [homeassistant.components.unifi] Error connecting to the UniFi Network at 192.168.4.1: Call https://192.168.4.1:443/api/auth/login received 429: b'{"code":"AUTHENTICATION_FAILED_LIMIT_REACHED","message":"You\'ve reached the login attempt limit","level":"debug"}'
2024-06-21 16:35:18.257 ERROR (MainThread) [homeassistant.components.unifiprotect.data] Auth error while updating
Traceback (most recent call last):
  File "/nix/store/sq3by8r3524slnqjm5cj09abg3q455zx-homeassistant-2024.6.3/lib/python3.12/site-packages/homeassistant/components/unifiprotect/data.py", line 133, in async_refresh
    updates = await self.api.update(force=force)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/v1x8g45h8ywwifv4jq4v5pdzh0svrl2y-python3.12-uiprotect-1.7.2/lib/python3.12/site-packages/uiprotect/api.py", line 799, in update
    self._bootstrap = await self.get_bootstrap()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/v1x8g45h8ywwifv4jq4v5pdzh0svrl2y-python3.12-uiprotect-1.7.2/lib/python3.12/site-packages/uiprotect/api.py", line 1127, in get_bootstrap
    data = await self.api_request_obj("bootstrap")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/v1x8g45h8ywwifv4jq4v5pdzh0svrl2y-python3.12-uiprotect-1.7.2/lib/python3.12/site-packages/uiprotect/api.py", line 427, in api_request_obj
    data = await self.api_request(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/v1x8g45h8ywwifv4jq4v5pdzh0svrl2y-python3.12-uiprotect-1.7.2/lib/python3.12/site-packages/uiprotect/api.py", line 406, in api_request
    data = await self.api_request_raw(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/v1x8g45h8ywwifv4jq4v5pdzh0svrl2y-python3.12-uiprotect-1.7.2/lib/python3.12/site-packages/uiprotect/api.py", line 381, in api_request_raw
    raise NotAuthorized(msg % (url, response.status, reason))
uiprotect.exceptions.NotAuthorized: Request failed: /proxy/protect/api/bootstrap - Status: 401 - Reason: {'code': 401, 'message': 'Unauthorized'}

I suspect something happened to my integration and got stuck in a tight auth loop. This manifests in the UI as Failed to connect

Not sure if this is what others are hitting but check your logs. We could consider doing some backoff in the integration if we see a 429.

@corey-klempner
Copy link

I'm having this issue. I'm trying to connect using the local IP address of the UDM and port 443. I'm able to log into unifi on a browser using that IP and the local user account I created. I tried deleting and creating a new local user account on Unifi and still I get the same issue.

Logs only show one line: "Error connecting to the UniFi Network at " (my local IP)

@mindstorms6
Copy link

Can you enable/download the diagnostic logs, restart the integration and post the resulting logs here? (Be sure to remove your password in the logs!)

@corey-klempner
Copy link

corey-klempner commented Jun 22, 2024

I can't get the integration to actually enable to the point that I can access the page and download the diagnostic logs. Basically, when I search for Protect and add the integration, it prompts me to enter host, username, password etc. but the submit form fails, and the integration never gets added.

Relevant: I'm using Protect application 4.0.33. I was in Early Access but I changed back to stable. I believe this is the official release

@BlackRockCity
Copy link

I can't get the integration to actually enable to the point that I can access the page and download the diagnostic logs.

Same here!

@Kane610
Copy link
Member

Kane610 commented Jun 23, 2024

I can't get the integration to actually enable to the point that I can access the page and download the diagnostic logs. Basically, when I search for Protect and add the integration, it prompts me to enter host, username, password etc. but the submit form fails, and the integration never gets added.

Relevant: I'm using Protect application 4.0.33. I was in Early Access but I changed back to stable. I believe this is the official release

Please open a separate issue for protect

@Kane610
Copy link
Member

Kane610 commented Jun 24, 2024

I've been hitting the same issue recently - however - it seems like my integration got in a bad state and was hitting the login endpoint on the controller too much. From the integration logs, the controller is now returning a 429 Too Many Requests error:

2024-06-21 16:35:17.775 DEBUG (MainThread) [aiounifi.interfaces.connectivity] data (from https://192.168.4.1:443) b'<!doctype html><html lang="en"><head><meta charset="utf-8"><link rel="icon" href="/favicon.ico?v3" sizes="any"><link rel="icon" href="/favicon.svg?v3" type="image/svg+xml"><link rel="apple-touch-icon" href="/apple-touch-icon.png?v3"><title>UniFi OS</title><meta name="viewport" content="width=device-width,initial-scale=1"><script>window.UNIFI_OS_MANIFEST = {"model":{"id":"UDW","shortName":"UDW","longName":"UniFi Dream Wall"},"images":{"small":"/assets/images/small.png?udw-2.0.0","medium":"/assets/images/medium.png?udw-2.0.0","large":"/assets/images/large.png?udw-2.0.0","huge":"/assets/images/huge.png?udw-2.0.0"}}</script><script defer="defer" src="/main.1f13cbe8ee4a4f1a0848.js"></script><link href="/main.0e9197a3.css" rel="stylesheet"></head><body><div id="root"></div></body></html>'
2024-06-21 16:35:17.775 DEBUG (MainThread) [aiounifi.interfaces.connectivity] Talking to UniFi OS device: True
2024-06-21 16:35:17.775 DEBUG (MainThread) [aiounifi.interfaces.connectivity] sending (to https://192.168.4.1:443/api/auth/login) post, {'username': 'viewonly', 'password': 'OMITTED', 'rememberMe': True}, {}
2024-06-21 16:35:17.792 DEBUG (MainThread) [aiounifi.interfaces.connectivity] received (from https://192.168.4.1:443/api/auth/login) 429 application/json <ClientResponse(https://192.168.4.1:443/api/auth/login) [429 Too Many Requests]>
<CIMultiDictProxy('Server': 'nginx', 'Date': 'Fri, 21 Jun 2024 20:35:17 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '113', 'Connection': 'keep-alive', 'X-Response-Time': '12ms', 'Access-Control-Allow-Credentials': 'false', 'Referrer-Policy': 'no-referrer', 'Strict-Transport-Security': 'max-age=15552000; includeSubDomains', 'X-Content-Type-Options': 'nosniff', 'X-DNS-Prefetch-Control': 'off', 'X-Frame-Options': 'SAMEORIGIN', 'X-XSS-Protection': '1; mode=block')>

2024-06-21 16:35:17.792 DEBUG (MainThread) [aiounifi.interfaces.connectivity] data (from https://192.168.4.1:443/api/auth/login) b'{"code":"AUTHENTICATION_FAILED_LIMIT_REACHED","message":"You\'ve reached the login attempt limit","level":"debug"}'
2024-06-21 16:35:17.792 ERROR (MainThread) [homeassistant.components.unifi] Error connecting to the UniFi Network at 192.168.4.1: Call https://192.168.4.1:443/api/auth/login received 429: b'{"code":"AUTHENTICATION_FAILED_LIMIT_REACHED","message":"You\'ve reached the login attempt limit","level":"debug"}'
2024-06-21 16:35:18.257 ERROR (MainThread) [homeassistant.components.unifiprotect.data] Auth error while updating
Traceback (most recent call last):
  File "/nix/store/sq3by8r3524slnqjm5cj09abg3q455zx-homeassistant-2024.6.3/lib/python3.12/site-packages/homeassistant/components/unifiprotect/data.py", line 133, in async_refresh
    updates = await self.api.update(force=force)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/v1x8g45h8ywwifv4jq4v5pdzh0svrl2y-python3.12-uiprotect-1.7.2/lib/python3.12/site-packages/uiprotect/api.py", line 799, in update
    self._bootstrap = await self.get_bootstrap()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/v1x8g45h8ywwifv4jq4v5pdzh0svrl2y-python3.12-uiprotect-1.7.2/lib/python3.12/site-packages/uiprotect/api.py", line 1127, in get_bootstrap
    data = await self.api_request_obj("bootstrap")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/v1x8g45h8ywwifv4jq4v5pdzh0svrl2y-python3.12-uiprotect-1.7.2/lib/python3.12/site-packages/uiprotect/api.py", line 427, in api_request_obj
    data = await self.api_request(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/v1x8g45h8ywwifv4jq4v5pdzh0svrl2y-python3.12-uiprotect-1.7.2/lib/python3.12/site-packages/uiprotect/api.py", line 406, in api_request
    data = await self.api_request_raw(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/v1x8g45h8ywwifv4jq4v5pdzh0svrl2y-python3.12-uiprotect-1.7.2/lib/python3.12/site-packages/uiprotect/api.py", line 381, in api_request_raw
    raise NotAuthorized(msg % (url, response.status, reason))
uiprotect.exceptions.NotAuthorized: Request failed: /proxy/protect/api/bootstrap - Status: 401 - Reason: {'code': 401, 'message': 'Unauthorized'}

I suspect something happened to my integration and got stuck in a tight auth loop. This manifests in the UI as Failed to connect

Not sure if this is what others are hitting but check your logs. We could consider doing some backoff in the integration if we see a 429.

Have you gotten it back to running?

@Blackduke77
Copy link

I had the same issue, the integration was working, then it wasn't I was complaining abut too many failed authentication attempts, however credentials had not changed, I removed the UDM controller from the integration and tried to re-add it, this failed to get past the add box with failed to connect. I removed the user from the local controller and waited a few hours, then re-added it all back and it worked.

@mindstorms6
Copy link

For the 429 - yes. Try disabling the integration and restarting the controller. Then re-enable the integration worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants