alex3305 / home-assistant-addons

Alex's Home Assistant Add-ons
https://alex3305.github.io/home-assistant-docs/
MIT License
47 stars 29 forks source link

Only replace secrets.yaml if passwords are found in Bitwarden #18

Closed ElVit closed 3 years ago

ElVit commented 3 years ago

Hi, I tried your Addon Bitwarden secrets for Home Assistant and I like it a lot. But last time I restarted my Intel Nuc something went wrong and Home Assistant started in safe mode because the secrets.yaml was empty. Maybe it’s because Bitwarden started to late and your addon could not get the passwords. After I restarted just Home Assistant all worked fine.

Is there a possibility to check if Bitwarden is completely loaded before your addon gets the secrets?

Or maybe only rewrite the secrets.yaml file if there is really a password found in Bitwarden?

alex3305 commented 3 years ago

Hi, thanks for the feedback and creating the issue. As a matter of fact, I recently migrated to a larger SSD and encountered the same issue!

Is there a possibility to check if Bitwarden is completely loaded before your addon gets the secrets?

Perhaps that would be possible with the Home Assistant hassio_api that is exposed to the application. I will have to look into that to be certain.

Or maybe only rewrite the secrets.yaml file if there is really a password found in Bitwarden?

This functionality is currently implemented in version 1.3.0 (efb28ce5f4178fb4a887eeec6ff7c7bb51787b69) in an effort to mitigate the issue you are describing. So I really like to know if you were using this version of the add-on when this issue occurred?

ElVit commented 3 years ago

Hi Alex, Yes I am using the newest version 1.3.0 of your addon. I have just tested it and it looks like the addon is still replacing the secrets.yaml even if there are no passwords found in Bitwarden. I tried to changed the username, password and organization. In all cases I get an empty secrets.yaml.

In my logs I see also the following lines:

[14:14:23] INFO: Start retrieving your Home Assistant secrets from Bitwarden
Could not find dir, "/root/.config/Bitwarden CLI"; creating it instead.
Could not find data file, "/root/.config/Bitwarden CLI/data.json"; creating it instead.
[14:14:28] INFO: Bitwarden login succesful!
[14:14:47] INFO: Changed from Bitwarden detected, replacing secrets.yaml...
[14:14:49] INFO: Secret files created.

Maybe that's the issue?

alex3305 commented 3 years ago

Don't worry. I haven't forgot about this issue. Things were rather busy for me, sorry for not responding.

Maybe that's the issue?

The issue is that my script doesn't check whether or not secrets.yaml is filled or not. That's still on my TODO list though. When this is implemented, this issue should be mitigated.

Perhaps unrelated to this issue, but you can enable log_level: debug to get a bit more information about what the add-on is doing.

ElVit commented 3 years ago

No problem. I will wait. My workaround for now is to disable the "start on boot" option and start the addon manually.

alex3305 commented 3 years ago

@ElVit The PR automatically closed this issue. But I would really like it if you can test it and report back. I think the aforementioned PR solves this issue btw. If it doesn't I will of course re-open this issue.

Basically I've added a check to test whether or not Bitwarden returns at least a single secret. Also I've changed the boot order so that this add-on will start after Home Assistant. That would probably also help a bit.

ElVit commented 3 years ago

@alex3305 Thank you for the new update. Now it's working correct 🤩.

There are only two things which I found that may be improved: