1
0
mirror of https://git.yoctoproject.org/poky synced 2026-06-02 01:19:52 +00:00

bitbake: hashserv: Add become-user API

Adds API that allows a user admin to impersonate another user in the
system. This makes it easier to write external services that have
external authentication, since they can use a common user account to
access the server, then impersonate the logged in user.

(Bitbake rev: 71e2f5b52b686f34df364ae1f2fc058f45cd5e18)

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Joshua Watt
2023-11-03 08:26:32 -06:00
committed by Richard Purdie
parent 1af725b2ec
commit 8cfb94c06c
4 changed files with 97 additions and 5 deletions
+18
View File
@@ -255,6 +255,7 @@ class ServerClient(bb.asyncrpc.AsyncServerConnection):
"auth": self.handle_auth,
"get-user": self.handle_get_user,
"get-all-users": self.handle_get_all_users,
"become-user": self.handle_become_user,
}
)
@@ -707,6 +708,23 @@ class ServerClient(bb.asyncrpc.AsyncServerConnection):
return {"username": username}
@permissions(USER_ADMIN_PERM, allow_anon=False)
async def handle_become_user(self, request):
username = str(request["username"])
user = await self.db.lookup_user(username)
if user is None:
raise bb.asyncrpc.InvokeError(f"User {username} doesn't exist")
self.user = user
self.logger.info("Became user %s", username)
return {
"username": self.user.username,
"permissions": self.return_perms(self.user.permissions),
}
class Server(bb.asyncrpc.AsyncServer):
def __init__(