puckel / docker-airflow

Docker Apache Airflow
Apache License 2.0
3.77k stars 535 forks source link

Incorrect padding errors from Fernet encryption #290

Open gagejustins opened 5 years ago

gagejustins commented 5 years ago

No matter what password I use or where (what OS) I run the container, adding an Airflow connection through the CLI returns this error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/airflow/models.py", line 171, in get_fernet
    _fernet = Fernet(fernet_key.encode('utf-8'))
  File "/usr/local/lib/python3.6/site-packages/cryptography/fernet.py", line 34, in __init__
    key = base64.urlsafe_b64decode(key)
  File "/usr/local/lib/python3.6/base64.py", line 133, in urlsafe_b64decode
    return b64decode(s)
  File "/usr/local/lib/python3.6/base64.py", line 87, in b64decode
    return binascii.a2b_base64(s)
binascii.Error: Incorrect padding

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/airflow", line 32, in <module>
    args.func(args)
  File "/usr/local/lib/python3.6/site-packages/airflow/utils/cli.py", line 74, in wrapper
    return f(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/airflow/bin/cli.py", line 1151, in connections
    new_conn = Connection(conn_id=args.conn_id, uri=args.conn_uri)
  File "<string>", line 4, in __init__
  File "/usr/local/lib/python3.6/site-packages/sqlalchemy/orm/state.py", line 414, in _initialize_instance
    manager.dispatch.init_failure(self, args, kwargs)
  File "/usr/local/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py", line 66, in __exit__
    compat.reraise(exc_type, exc_value, exc_tb)
  File "/usr/local/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 187, in reraise
    raise value
  File "/usr/local/lib/python3.6/site-packages/sqlalchemy/orm/state.py", line 411, in _initialize_instance
    return manager.original_init(*mixed[1:], **kwargs)
  File "/usr/local/lib/python3.6/site-packages/airflow/models.py", line 695, in __init__
    self.parse_from_uri(uri)
  File "/usr/local/lib/python3.6/site-packages/airflow/models.py", line 717, in parse_from_uri
    self.password = temp_uri.password
  File "<string>", line 1, in __set__
  File "/usr/local/lib/python3.6/site-packages/airflow/models.py", line 735, in set_password
    fernet = get_fernet()
  File "/usr/local/lib/python3.6/site-packages/airflow/models.py", line 174, in get_fernet
    raise AirflowException("Could not create Fernet object: {}".format(ve))
airflow.exceptions.AirflowException: Could not create Fernet object: Incorrect padding

BUT: adding the login info through the UI Connections tab works totally fine. I've tried changing passwords but that doesn't help. The command I'm using:

airflow connections -a --conn_id first_conn --conn_uri postgresql://jgage:password@domain:port/schema

Any ideas?

jeremy-page commented 4 years ago

To update for folks who may find this for a google search, this was happening for me because my key was not base64 encoded (no = at the end). Changing AIRFLOWCOREFERNET_KEY= so it had a proper value allowed me to resetdb

MeeshCompBio commented 4 years ago

I will add this as another alternative if people want to still pull the image and use the SequentialExecutor for quick demos.

docker pull puckel/docker-airflow
YOUR_FERNET_KEY=$(openssl rand -base64 32)
docker run -d -e AIRFLOW__CORE__FERNET_KEY=$YOUR_FERNET_KEY -p 8080:8080 puckel/docker-airflow webserver
gabidoye commented 2 years ago

@javidy and @zachliu I followed the steps you stated and I was able to run /entrypoint.sh airflow db reset but still when I click on connection I get the error again.

Please I need help resolving this.

venuktan commented 2 years ago

Can you send me the error logs

Regards, Vénu Kasyap Tangirala

On Mar 14, 2022, at 10:43 PM, gabidoye @.***> wrote:

 @javidy and @zachliu I followed the steps you stated and I was able to run /entrypoint.sh airflow db reset but still when I click on connection I get the error again.

Please I need help resolving this.

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.

gabidoye commented 2 years ago

@venuktan here is the log

Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1952, in full_dispatch_request rv = self.handle_user_exception(e) File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1821, in handle_user_exception reraise(exc_type, exc_value, tb) File "/usr/local/lib/python3.9/site-packages/flask/_compat.py", line 39, in reraise raise value File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request return self.view_functionsrule.endpoint File "/usr/local/lib/python3.9/site-packages/flask_appbuilder/security/decorators.py", line 148, in wraps return f(self, *args, *kwargs) File "/usr/local/lib/python3.9/site-packages/flask_appbuilder/views.py", line 554, in list widgets = self._list() File "/usr/local/lib/python3.9/site-packages/flask_appbuilder/baseviews.py", line 1129, in _list widgets = self._get_list_widget( File "/usr/local/lib/python3.9/site-packages/flask_appbuilder/baseviews.py", line 1028, in _get_list_widget count, lst = self.datamodel.query( File "/usr/local/lib/python3.9/site-packages/flask_appbuilder/models/sqla/interface.py", line 471, in query queryresults = query.all() File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/query.py", line 3341, in all return list(self) File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/loading.py", line 101, in instances cursor.close() File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 68, in exit compat.raise( File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 178, in raise_ raise exception File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/loading.py", line 81, in instances rows = [proc(row) for row in fetch] File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/loading.py", line 81, in rows = [proc(row) for row in fetch] File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/loading.py", line 602, in _instance state.manager.dispatch.load(state, context) File "/usr/local/lib/python3.9/site-packages/sqlalchemy/event/attr.py", line 322, in call fn(args, **kw) File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/mapper.py", line 3378, in _event_on_load instrumenting_mapper._reconstructor(state.obj()) File "/usr/local/lib/python3.9/site-packages/airflow/models/connection.py", line 153, in on_db_load if self.password: File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/attributes.py", line 358, in get retval = self.descriptor.get(instance, owner) File "/usr/local/lib/python3.9/site-packages/airflow/models/connection.py", line 238, in get_password return fernet.decrypt(bytes(self._password, 'utf-8')).decode() File "/usr/local/lib/python3.9/site-packages/cryptography/fernet.py", line 195, in decrypt raise InvalidToken cryptography.fernet.InvalidToken