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
72.72k stars 30.45k forks source link

Proxmox VE integration - 401 Unauthorized: permission denied invalid PVE ticket #36853

Closed maxalbani closed 4 years ago

maxalbani commented 4 years ago

The problem

Exactly two hours after restarting HA, Proxmox integration no longer works with error: 401 Unauthorized: permission denied - invalid PVE ticket

Environment

Problem-relevant configuration.yaml

proxmoxve:
  - host: <ip address>
    username: <user>
    password: <pwd>
    verify_ssl: false
    realm: pam
    nodes:
      - node: pve
        vms:
          - 100
          - 102
          - 103
        containers:
          - 101

Traceback/Error logs

Logger: homeassistant.helpers.entity
Source: components/proxmoxve/binary_sensor.py:96
First occurred: 17:40:58 (1026 occurrences)
Last logged: 19:53:10

Update for binary_sensor.pve_hassio_running fails
Update for binary_sensor.pve_omv_running fails
Update for binary_sensor.pve_hassio_test_running fails
Update for binary_sensor.pve_lamp_running fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 279, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 472, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/proxmoxve/binary_sensor.py", line 83, in update
    item = self.poll_item()
  File "/usr/src/homeassistant/homeassistant/components/proxmoxve/binary_sensor.py", line 96, in poll_item
    .get(self._item_type.name)
  File "/usr/local/lib/python3.7/site-packages/proxmoxer/core.py", line 105, in get
    return self(args)._request("GET", params=params)
  File "/usr/local/lib/python3.7/site-packages/proxmoxer/core.py", line 94, in _request
    resp.reason, resp.content))
proxmoxer.core.ResourceException: 401 Unauthorized: permission denied - invalid PVE ticket - b''

Additional information

HassOS is a proxmox virtual machine

probot-home-assistant[bot] commented 4 years ago

Hey there @k4ds3, @jhollowe, mind taking a look at this issue as its been labeled with a integration (proxmoxve) you are listed as a codeowner for? Thanks! (message by CodeOwnersMention)

probot-home-assistant[bot] commented 4 years ago

proxmoxve documentation proxmoxve source (message by IssueLinks)

maxalbani commented 4 years ago

I tried in a test installation with version 0.110 and the integration works correctly renewing the ticket after 2 hours. So it is assumed that version 0.111 has corrupted the integration. @K4ds3, @jhollowe any ideas?

StealthChesnut commented 4 years ago

Same thing here. Rebooted my HomeAssistant install at 14:11 yesterday, at 16:11 I'm getting the exact same errors in the logs as @maxalbani but with different binary_sensor.names:

last line of each entry is the same 401: proxmoxer.core.ResourceException: 401 Unauthorized: permission denied - invalid PVE ticket - b''

I am on HomeAssistant 0.111.3

jhollowe commented 4 years ago

Interesting. How often is HA polling your PVE? the proxmoxer library should be renewing the ticket as long as it is polling at least once every two hours.

maxalbani commented 4 years ago

Interesting. How often is HA polling your PVE? the proxmoxer library should be renewing the ticket as long as it is polling at least once every two hours.

With the ticket valid in the first two hours, HA updates the sensors about every 30 seconds, so that's not the problem. Something has changed with the 0.111.x version of HA, because everything worked correctly up to 0.110.

jhollowe commented 4 years ago

I'll look at it after work today. I'm planning to add API token authentication for this integration to try to alleviate this problem.

maxalbani commented 4 years ago

I used this integration as a starting point for this my project: https://github.com/maxalbani/home-assistant-proxmox-management

jhollowe commented 4 years ago

The authentication renewal was removed from the integration because it is now handled by the connection library. I'm running hass with a debug build of the library to see where the issue is.

For now I would recommend reverting to 0.110 if you need this working currently. You could also manually re-add the integration's old renewal code if you want to use 0.111

maxalbani commented 4 years ago

For now I would recommend reverting to 0.110 if you need this working currently. You could also manually re-add the integration's old renewal code if you want to use 0.111

How can I manually re-add old renewal code on Hassio? Thank's for your job!

jhollowe commented 4 years ago

@maxalbani I'm not sure. With hassio (Home Assistant), it might be hard to do.

maxalbani commented 4 years ago

@maxalbani I'm not sure. With hassio (Home Assistant), it might be hard to do.

I thought so too ... Do you have a forecast on solving the problem?

jhollowe commented 4 years ago

It looks like something weird is happening with the library renewing the ticket. I think it is an issue with the library working within the async worker threads, so each thread is trying to renew and PVE is not liking it. I've got a test running now with only one container being polled. If that doesn't fail, I will know what the issue is. I just have to wait 2 hours every time I change something. I can just revert back in the integration's renewal code, but I would like to try to get it working with the library's built-in renewal.

jhollowe commented 4 years ago

found and have a fix for the issue. The library was renewing the authentication ticket, but would only send the original ticket (the session was not pulling the cookie from the auth).

I'll get a new version of the library out and then update the integration to use the fixed version (and do proper testing on it).

maxalbani commented 4 years ago

Is there any news? Thanks

jhollowe commented 4 years ago

Still waiting on the PR to be merged. You can also just manually update the proxmoxer dependency to version 1.1.1.