Skip to content

Commit

Permalink
keystonev2: populate user.name into UserInformation (#440)
Browse files Browse the repository at this point in the history
The behavior between keystonev2 and keystonev3 is different today.
In keystonev3 implementation, the username comes from [user.name][1],
but keystonev2 just uses the incoming `username_or_email`.

Also, by reading `user.name`, we can use keystone APIKeys to do
authentication which is necessary due to potential 2FA requirements.

[1]: https://github.com/quay/quay/blob/f4179e5e719ebc8e795064b8703da8a29d877b3b/data/users/keystone.py#L316
  • Loading branch information
zhouhaibing089 authored Jun 17, 2020
1 parent c1b3ac2 commit 4c42968
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion data/users/keystone.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def verify_credentials(self, username_or_email, password):
return (None, "Missing email field for user %s" % user_id)

email = user.email if hasattr(user, "email") else None
return (UserInformation(username=username_or_email, email=email, id=user_id), None)
return (UserInformation(username=user.name, email=email, id=user_id), None)

def query_users(self, query, limit=20):
return (None, self.federated_service, "Unsupported in Keystone V2")
Expand Down
1 change: 1 addition & 0 deletions test/test_keystone_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def getuser(userid):
for user in users:
if user["username"] == userid:
user_data = {}
user_data["name"] = userid
if requires_email:
user_data["email"] = user.get("email") or userid + "@example.com"
return json.dumps({"user": user_data})
Expand Down

0 comments on commit 4c42968

Please sign in to comment.