apache / superset

Apache Superset is a Data Visualization and Data Exploration Platform
https://superset.apache.org/
Apache License 2.0
61.97k stars 13.59k forks source link

ValueError: Invalid decryption key - multiple superset instance and single database #29829

Open Jarxinho opened 1 month ago

Jarxinho commented 1 month ago

Bug description

ValueError: Invalid decryption key (on second host with superset) While enter:

Settings > Database Connections

superset is deployed on two separate hosts, with different:

Traceback (most recent call last): File "/app/superset/views/base.py", line 251, in wraps return f(self, args, kwargs) File "/app/superset/views/base_api.py", line 487, in get_list_headless duration, response = time_function(super().get_list_headless, kwargs) File "/app/superset/utils/core.py", line 1463, in time_function response = func(args, **kwargs) File "/usr/local/lib/python3.10/site-packages/flask_appbuilder/api/init.py", line 1603, in get_list_headless count, lst = self.datamodel.query( File "/usr/local/lib/python3.10/site-packages/flask_appbuilder/models/sqla/interface.py", line 499, in query query_results = query.all() File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/query.py", line 2768, in all return self._iter().all() File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 1077, in all return self._allrows() File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 401, in _allrows rows = self._fetchall_impl() File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 1696, in _fetchall_impl return list(self.iterator) File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/loading.py", line 147, in chunks fetch = cursor._raw_all_rows() File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 393, in _raw_all_rows return [make_row(row) for row in rows] File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 393, in return [make_row(row) for row in rows] File "/usr/local/lib/python3.10/site-packages/sqlalchemy/sql/type_api.py", line 1681, in process return process_value(impl_processor(value), dialect) File "/usr/local/lib/python3.10/site-packages/sqlalchemy_utils/types/encrypted/encrypted_type.py", line 479, in process_result_value value = super().process_result_value(value=value, dialect=dialect) File "/usr/local/lib/python3.10/site-packages/sqlalchemy_utils/types/encrypted/encrypted_type.py", line 424, in process_result_value decrypted_value = self.engine.decrypt(value) File "/usr/local/lib/python3.10/site-packages/sqlalchemy_utils/types/encrypted/encrypted_type.py", line 128, in decrypt raise ValueError('Invalid decryption key') ValueError: Invalid decryption key 2024-08-01 14:31:27,526:ERROR:superset.views.base:Invalid decryption key Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/sqlalchemy_utils/types/encrypted/encrypted_type.py", line 126, in decrypt decrypted = decrypted.decode('utf-8') UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 1: invalid continuation byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/app/superset/views/base.py", line 251, in wraps return f(self, args, kwargs) File "/app/superset/views/base_api.py", line 487, in get_list_headless duration, response = time_function(super().get_list_headless, kwargs) File "/app/superset/utils/core.py", line 1463, in time_function response = func(args, **kwargs) File "/usr/local/lib/python3.10/site-packages/flask_appbuilder/api/init.py", line 1603, in get_list_headless count, lst = self.datamodel.query( File "/usr/local/lib/python3.10/site-packages/flask_appbuilder/models/sqla/interface.py", line 499, in query query_results = query.all() File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/query.py", line 2768, in all return self._iter().all() File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 1077, in all return self._allrows() File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 401, in _allrows rows = self._fetchall_impl() File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 1696, in _fetchall_impl return list(self.iterator) File "/usr/local/lib/python3.10/site-packages/sqlalchemy/orm/loading.py", line 147, in chunks fetch = cursor._raw_all_rows() File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 393, in _raw_all_rows return [make_row(row) for row in rows] File "/usr/local/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 393, in return [make_row(row) for row in rows] File "/usr/local/lib/python3.10/site-packages/sqlalchemy/sql/type_api.py", line 1681, in process return process_value(impl_processor(value), dialect) File "/usr/local/lib/python3.10/site-packages/sqlalchemy_utils/types/encrypted/encrypted_type.py", line 479, in process_result_value value = super().process_result_value(value=value, dialect=dialect) File "/usr/local/lib/python3.10/site-packages/sqlalchemy_utils/types/encrypted/encrypted_type.py", line 424, in process_result_value decrypted_value = self.engine.decrypt(value) File "/usr/local/lib/python3.10/site-packages/sqlalchemy_utils/types/encrypted/encrypted_type.py", line 128, in decrypt raise ValueError('Invalid decryption key') ValueError: Invalid decryption key

How to reproduce the bug

  1. Setup single database psql
  2. Create psql user1, user2
  3. Setup first instance superset with connection string user1 with SECRET_KEY = 'A'
  4. Setup second instance superset with connection string user2 with SECRET_KEY = 'B'

Screenshots/recordings

No response

Superset version

master / latest-dev

Python version

3.9

Node version

16

Browser

Chrome

Additional context

according to: https://github.com/apache/superset/issues/8538 Is it any known workaround to use the same database with multiple superset instances without 'Invalid decryption key' error?

Checklist

dosubot[bot] commented 1 month ago

Hey @Jarxinho! I'm here to help you with any bugs, questions, or contributions you might have. Let's dive in and resolve this issue together!

To avoid the 'Invalid decryption key' error when using the same database with multiple Superset instances, ensure that all instances use the same SECRET_KEY in their superset_config.py file:

# Set the same SECRET_KEY for all Superset instances
SECRET_KEY = 'YOUR_OWN_RANDOM_GENERATED_SECRET_KEY'

This key is used for securely signing session cookies and encrypting sensitive information stored in Superset's application metadata database. By using the same SECRET_KEY across all instances, you can avoid the 'Invalid decryption key' error [1].

To continue talking to Dosu, mention @dosu.