Core: Synology DSM no longer working with 2FA authentication from 0.117.0b5

Created on 27 Oct 2020  ·  37Comments  ·  Source: home-assistant/core

The problem

My Synology integration has stopped working since upgrading to 0.117.0b5. Everything has worked fine previously, but I know have no devices & no entities tied to the intregration.

Environment

  • Home Assistant Core release with the issue: 0.117.0b5
  • Last working Home Assistant Core release (if known): 0.116.4
  • Operating environment (OS/Container/Supervised/Core): Supervised
  • Integration causing this issue: SynologyDSM
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/synology_dsm

Problem-relevant configuration.yaml

  - platform: synology_dsm
    host: <<IP_ADDRESS>>
    username: !secret synology_username
    password: !secret synology_password

Traceback/Error logs

Logger: homeassistant.config_entries
Source: components/synology_dsm/__init__.py:262
First occurred: 9:34:19 (2 occurrences)
Last logged: 9:35:47

Error setting up entry 192.168.1.221 for synology_dsm
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 234, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/synology_dsm/__init__.py", line 168, in async_setup_entry
    await api.async_setup()
  File "/usr/src/homeassistant/homeassistant/components/synology_dsm/__init__.py", line 262, in async_setup
    await self._hass.async_add_executor_job(
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.8/site-packages/synology_dsm/synology_dsm.py", line 160, in login
    raise switcher.get(
synology_dsm.exceptions.SynologyDSMLogin2SAFailedException: {'api': 'SYNO.API.Auth', 'code': 404, 'reason': 'One time password authenticate failed', 'details': 'Two-step authentication failed, retry with a new pass code'}
Home Assistant has started!

Additional information

I have removed and re-added the integration several times, also tried adding via UI and via configuration, both show the same error.

I have tried creating an entirely new user in DSM, still the same result.

synology_dsm need-more-information

Most helpful comment

ditto - restarted and everything came back!! YAY!!!

The programmers are confirmed AWESOME 👍

All 37 comments

Hey there @hacf-fr, @quentame, mind taking a look at this issue as its been labeled with an integration (synology_dsm) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

What is the latest working version ?
monitored_conditions does not exist for a long time now.

Do you have the Surveillance Station package installed ?
If yes, do you have cameras linked to it ?

There is also an issue when 2SA is loosing its authentication, but it's not linked to 0.117.0

See https://github.com/ProtoThis/python-synology/issues/49

I've rolled back to 0.116.4 and all working again.

No Surveillance Station package is not installed.

I usually configure via the UI, the config example above was just from me trying to get this to work again so you can ignore the monitored_conditions element.

FYI, I've just upgraded to 0.117 and the issue is back 😥

Yep, did not fix the beta sorry.

What DSM are you using ?
Synology official ?
Virtual DSM ?

NAS Model: DS918+, running Synology Official
DSM Version: 6.2.3-25426 Update 2

Hi,

I was browsing around, and I too have this EXACT same issue where I get the 2FA error. I've also did what @robearlam do and nothing works, and I also get the error below too:

* Error setting up entry myDSMserver.com for synology_dsm Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 234, in async_setup result = await component.async_setup_entry(hass, self) # type: ignore File "/usr/src/homeassistant/homeassistant/components/synology_dsm/__init__.py", line 168, in async_setup_entry await api.async_setup() File "/usr/src/homeassistant/homeassistant/components/synology_dsm/__init__.py", line 262, in async_setup await self._hass.async_add_executor_job( File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/usr/local/lib/python3.8/site-packages/synology_dsm/synology_dsm.py", line 160, in login raise switcher.get( synology_dsm.exceptions.SynologyDSMLogin2SAFailedException: {'api': 'SYNO.API.Auth', 'code': 404, 'reason': 'One time password authenticate failed', 'details': 'Two-step authentication failed, retry with a new pass code'}

I've posted this issue on HA forums too:

https://community.home-assistant.io/t/issues-with-synology-dsm-on-latest-hassio-0-117-0/240050

This seems to stem from how 0.117.0 deals with the synology DSM 2fa. Also I too am running the exact OS and Hardware that @robearlam is using funny enough.

The only thing different is I am using the surveillance station package on my DSM, and it was working on the older version before upgrading today.

If anyone has ideas, i'm all ears, or need to test this.

One other side note, just like @robearlam I just tested rolling back to 0.116.4 and the camera streams are back online and working, so there is something definitely related with the 0.117.0 release.

Let me know if you want to test or try something.

Hi, here the same error after update do 0.117.0

synology_dsm.exceptions.SynologyDSMLogin2SAFailedException: {'api': 'SYNO.API.Auth', 'code': 404, 'reason': 'One time password authenticate failed', 'details': 'Two-step authentication failed, retry with a new pass code'}
Integration already configured before update.

Having same problem. My synology NAS connection is no longer working since updating to Home Assistant 0.117.0

I've deleted the integration and reinstalled it...and then logged in successfully with my 2FA, but it shows 0 devices still. Something broke in 0.117.0

Also broken with 2FA enabled.

Having same problem. My synology NAS connection is no longer working since updating to Home Assistant 0.117.0

I've deleted the integration and reinstalled it...and then logged in successfully with my 2FA, but it shows 0 devices still. Something broke in 0.117.0

Ditto for me.
Running a DS1815+ NAS, talking to HASS on a R-Pi4B

Once I upgraded to 0.117.0 the monitoring of all NAS entities broke.
I tried removing and re-adding the integration and whilst it accepted the password and the 2FA, it didn't populate with any entities or devices.

BROKE BROKE BROKE

same 4 me - i can but confirm this issue

I've done right now the update to 0.117.1 and the problem persist :( i don't have reconfigured the integration..

Hi there,

yes, definitely since the update to 117.1 my DS integration stopps working, even though it tells "success" after it has been re-added via the Integrations. Log error is always:
[code]
synology_dsm.exceptions.SynologyDSMLogin2SAFailedException: {'api': 'SYNO.API.Auth', 'code': 404, 'reason': 'One time password authenticate failed', 'details': 'Two-step authentication failed, retry with a new pass code'}
[/code]

I am using the Hass.io DSM package from @fredrike running in Docker on latest DSM release.

Same problem here with the same log response, it has been non-functional since 0.117.0, 0.117.1 doesn't fix the problem with 2FA

0.117.1 did not fix my issue with Synology DSM 2FA either.

On Fri, Oct 30, 2020 at 7:20 AM DNKROZ notifications@github.com wrote:

Same problem here with the same log response, it has been non-functional
since 0.117.0, 0.117.1 doesn't fix the problem with 2FA


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/home-assistant/core/issues/42493#issuecomment-719520595,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AEIZISVXKHM3LU2LIXZOUN3SNKVQDANCNFSM4TBQJOKQ
.

I reverted to 116.4 by snapshot which basically works, however, I now get continuous and massive errors related to SQL, like:

2020-10-30 14:59:05 ERROR (Recorder) [homeassistant.components.recorder] Error saving events: (sqlite3.DatabaseError) database disk image is malformed [SQL: INSERT INTO events (event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)] [parameters: ('state_changed', '{}', 'LOCAL', '2020-10-30 13:59:04.312154', '2020-10-30 13:59:05.053055', '11fe604e1ab811eba104ff6d9be6d741', None, None)] (Background on this error at: http://sqlalche.me/e/13/4xp6) Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context self.dialect.do_execute( File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute cursor.execute(statement, parameters) sqlite3.DatabaseError: database disk image is malformed The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/recorder/__init__.py", line 442, in _commit_event_session_or_retry self._commit_event_session() File "/usr/src/homeassistant/homeassistant/components/recorder/__init__.py", line 493, in _commit_event_session self.event_session.flush() File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 2523, in flush self._flush(objects) File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 2664, in _flush transaction.rollback(_capture_exception=True) File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__ compat.raise_( File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise_ raise exception File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 2624, in _flush flush_context.execute() File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py", line 419, in execute n.execute_aggregate(self, set_) File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py", line 521, in execute_aggregate self.execute(uow) File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py", line 586, in execute persistence.save_obj( File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 239, in save_obj _emit_insert_statements( File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 1135, in _emit_insert_statements result = cached_connections[connection].execute( File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1011, in execute return meth(self, multiparams, params) File "/usr/local/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection return connection._execute_clauseelement(self, multiparams, params) File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1124, in _execute_clauseelement ret = self._execute_context( File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context self._handle_dbapi_exception( File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1510, in _handle_dbapi_exception util.raise_( File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise_ raise exception File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context self.dialect.do_execute( File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute cursor.execute(statement, parameters) sqlalchemy.exc.DatabaseError: (sqlite3.DatabaseError) database disk image is malformed [SQL: INSERT INTO events (event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)] [parameters: ('state_changed', '{}', 'LOCAL', '2020-10-30 13:59:04.312154', '2020-10-30 13:59:05.053055', '11fe604e1ab811eba104ff6d9be6d741', None, None)] (Background on this error at: http://sqlalche.me/e/13/4xp6)

I was running the Synology DSM integration with 2FA just fine on 116. Watched the issues on 117 and waited for 117.1. It promptly broke the integration - not talking. Deleted integration and re-installed it. Asked for 2FA which provided (and works when logging in via native web/DSM). HA Synology integration add says "it worked" but doesn't not let me assign my drives and cameras to a zone. Furthermore no entities are created. I repeated this twice and same symptom.

I've removed 2FA from this account and re-added the Synology DSM Integration and the proper behavior returned and entities are added.

Running this version of DSM: DSM 6.2.3-25426 Update 2
Also running current Surveillance though not really relevant.

`Logger: homeassistant.config_entries
Source: components/synology_dsm/__init__.py:262
First occurred: 8:09:39 AM (1 occurrences)
Last logged: 8:09:39 AM

Error setting up entry 192.168.1.1 for synology_dsm
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 234, in async_setup
result = await component.async_setup_entry(hass, self) # type: ignore
File "/usr/src/homeassistant/homeassistant/components/synology_dsm/__init__.py", line 168, in async_setup_entry
await api.async_setup()
File "/usr/src/homeassistant/homeassistant/components/synology_dsm/__init__.py", line 262, in async_setup
await self._hass.async_add_executor_job(
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(self.args, *self.kwargs)
File "/usr/local/lib/python3.8/site-packages/synology_dsm/synology_dsm.py", line 160, in login
raise switcher.get(
synology_dsm.exceptions.SynologyDSMLogin2SAFailedException: {'api': 'SYNO.API.Auth', 'code': 404, 'reason': 'One time password authenticate failed', 'details': 'Two-step authentication failed, retry with a new pass code'}`

Hi, same issue here after removing and re-adding the integration.
I'm asked for the 2FA password, dialog says "configuration completed" but sensors are not created and error below shows up-

2020-11-01 18:12:01 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry homenas for synology_dsm
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 234, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/usr/src/homeassistant/homeassistant/components/synology_dsm/__init__.py", line 168, in async_setup_entry
    await api.async_setup()
  File "/usr/src/homeassistant/homeassistant/components/synology_dsm/__init__.py", line 262, in async_setup
    await self._hass.async_add_executor_job(
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.8/site-packages/synology_dsm/synology_dsm.py", line 160, in login
    raise switcher.get(
synology_dsm.exceptions.SynologyDSMLogin2SAFailedException: {'api': 'SYNO.API.Auth', 'code': 404, 'reason': 'One time password authenticate failed', 'details': 'Two-step authentication failed, retry with a new pass code'}

Simone

Same issue for me...
The 0.117.2 don't fix it...

Same issue on 0.117.2, running hass.io on an Raspberry Pi 4.

All the synology entities are 'unavailable' before i removed it. I tried to remove and add it again, now i see no entities. I just waited for the scan of 15 minutes but they still disappeared

2020-11-02 09:08:22 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry 192.168.0.1 for synology_dsm Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 234, in async_setup result = await component.async_setup_entry(hass, self) # type: ignore File "/usr/src/homeassistant/homeassistant/components/synology_dsm/__init__.py", line 168, in async_setup_entry await api.async_setup() File "/usr/src/homeassistant/homeassistant/components/synology_dsm/__init__.py", line 262, in async_setup await self._hass.async_add_executor_job( File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/usr/local/lib/python3.8/site-packages/synology_dsm/synology_dsm.py", line 160, in login raise switcher.get( synology_dsm.exceptions.SynologyDSMLogin2SAFailedException: {'api': 'SYNO.API.Auth', 'code': 404, 'reason': 'One time password authenticate failed', 'details': 'Two-step authentication failed, retry with a new pass code'}

Hi guys!

Nothing was made for this issue on 0.117.X

I'll check that in the next few days.

Also @mib1185, did you reproduce that ?
@oncleben31 told me it was when he activates 2SA on his account, before it was on the group.

Sorry for the delay.

Same issue here, Syn 920+

Same here. Integration fails in 0.117+ with 2FA enabled (works in 0.116).

Removing integration and re-adding does not solve the issue. Same error as mentioned earlier.

Hi @Quentame ,

did not analysed the issue yet, but can try to reproduce it on my "lab" later ... will keep you all updated.

regards,
Michael

analyse of code changes:

with following change by commit 7469bd92664c8c

@@ -253,10 +258,11 @@ async def async_setup(self):
            self._entry.data[CONF_PASSWORD],
            self._entry.data[CONF_SSL],
            timeout=self._entry.options.get(CONF_TIMEOUT),
-            device_token=self._entry.data.get("device_token"),
+        )
+       await self._hass.async_add_executor_job(
+            self.dsm.login, self._entry.data.get("device_token")
+        )

the affective call to login API (source) was changed so far that device_id has been replaced by otp_code, because entry.data.get("device_token") is no longer provided during setup of SynoApi(), but later at call self.dsm.login

EDIT:
device_id is not replaced by otp_code, but otp_code is additional set and filled with entry.data.get("device_token")

Thanks all for looking into the issue, appreciate the efforts.

I'll report the results one 0.117.3 is released

Fixed in 0.117.4 for me! Many Thanks.

Thanks guys on working on this, I've tested this and it works as expected now!

Working fine here as well. Thx a lot!

Simone

ditto - restarted and everything came back!! YAY!!!

The programmers are confirmed AWESOME 👍

Agreed; re-instated 2fA on Synology DSM, removed and re-installed this integration and provided the one time password and its working now. Thanks as it's vital for me to keep 2FA on this key asset...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Elmardus picture Elmardus  ·  3Comments

Konstigt picture Konstigt  ·  3Comments

i-am-shodan picture i-am-shodan  ·  3Comments

ofuangka picture ofuangka  ·  3Comments

sogeniusio picture sogeniusio  ·  3Comments