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

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

Open
3 tasks done
Jarxinho opened this issue Aug 1, 2024 · 1 comment
Open
3 tasks done

Comments

@Jarxinho
Copy link

Jarxinho commented Aug 1, 2024

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:

  • SECRET_KEY,
  • username pass (db),

but the same host & database name

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:
#8538
Is it any known workaround to use the same database with multiple superset instances without 'Invalid decryption key' error?

Checklist

  • I have searched Superset docs and Slack and didn't find a solution to my problem.
  • I have searched the GitHub issue tracker and didn't find a similar bug report.
  • I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.
@Jarxinho Jarxinho changed the title ValueError: Invalid decryption key ValueError: Invalid decryption key - multiple superset instance and single database Aug 1, 2024
Copy link

dosubot bot commented Aug 1, 2024

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.

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

No branches or pull requests

1 participant