vincbeck commented on code in PR #77660:
URL: https://github.com/apache/airflow/pull/77660#discussion_r4720866249
##########
providers/fab/tests/unit/fab/auth_manager/test_security.py:
##########
@@ -1354,6 +1355,63 @@ def test_add_user_uses_configured_hash_method(mock_hash,
app, security_manager):
delete_user(app, "hash_method_add_test")
+USERNAME_WITHOUT_PASSWORD = "user_without_password"
+
+
[email protected]("hash_method", ["scrypt", "pbkdf2:sha256"])
Review Comment:
This fails in the lowest-deps job: werkzeug 2.2.2 has no `scrypt`
(`ValueError: unsupported hash type scrypt`). You probably want to skip the
`scrypt` case when werkzeug < 3, as `override.py` does for the default hash
method.
##########
providers/fab/src/airflow/providers/fab/auth_manager/security_manager/passwords.py:
##########
@@ -0,0 +1,28 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+
+def is_empty_password(password: str) -> bool:
Review Comment:
CI fails because this new module has no `test_passwords.py`
(`test_providers_modules_should_have_tests`). Either add one or move
`is_empty_password` into an existing module.
##########
providers/fab/src/airflow/providers/fab/auth_manager/security_manager/override.py:
##########
@@ -1587,6 +1588,8 @@ def add_user(
user.groups = groups or []
if hashed_password:
user.password = hashed_password
+ elif is_empty_password(password):
Review Comment:
Should `set_user_password` follow the same rule? `reset_password` and `PATCH
/users` with an empty password still store a hash of `""`.
##########
providers/fab/src/airflow/providers/fab/auth_manager/security_manager/override.py:
##########
@@ -2323,9 +2338,7 @@ def auth_user_db(self, username, password,
rotate_session_id=True) -> User | Non
)
log.info(LOGMSG_WAR_SEC_LOGIN_FAILED, username)
return None
- if user.password is None:
- return None
- if check_password_hash(user.password, password):
+ if self._verify_password(user, password):
Review Comment:
With `AUTH_LDAP` and the basic auth backend, a wrong password now counts as
two failed logins. `basic_auth.auth_current_user` calls `auth_user_ldap` first,
which already calls `update_user_auth_stat(user, False)`, then falls back to
`auth_user_db`. Before, the `user.password is None` branch returned early. Now
it calls `update_user_auth_stat(user, False)` a second time. Example: an LDAP
user with no local password sends `Basic alice:wrong` and `fail_login_count`
goes from 0 to 2. Fix: skip the stats update in `auth_user_db` for a user
without a stored password, or skip the DB fallback in `basic_auth` when the
auth type is LDAP.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]