Skip to content

Commit 2e39429

Browse files
committed
fix: move to default user when no username is provided
1 parent daf2ba6 commit 2e39429

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

bec_lib/bec_lib/acl_login.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ def _default_user_login_successful(self, full_access: bool) -> bool:
329329
Login using the default user account.
330330
331331
Args:
332-
full_access (bool): If True, the user has to have full access to the Redis
332+
full_access (bool): If True, the user has sufficient access to perform all user
333+
operations. If False, the user has limited access or no access to perform user operations.
333334
334335
Returns:
335336
bool: True if the login was successful, False otherwise.
@@ -339,8 +340,8 @@ def _default_user_login_successful(self, full_access: bool) -> bool:
339340
return True
340341

341342
try:
342-
self.connector.get(MessageEndpoints.acl_accounts())
343-
# ACLs are enabled but we have full access. No need to login.
343+
# We check an endpoint on level INFO to verify that the user has sufficient access to perform all user operations.
344+
self.connector.get(MessageEndpoints.device_config())
344345
return True
345346
# pylint: disable=broad-except
346347
except Exception:
@@ -366,7 +367,7 @@ def _user_service_login(self, username: str | None = None) -> None:
366367
raise BECAuthenticationError("Login information not available. Unable to login.")
367368
self._atlas_login = self._info.atlas_login
368369
if not username and not self._info.atlas_login:
369-
return self.login_with_token(username="user", token=None)
370+
return self.login_with_token(username="default", token=None)
370371
return self.login(username)
371372

372373
def _check_redis_auth(self, user: str | None, password: str | None) -> bool:

bec_lib/bec_lib/utils/user_acls_test.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,23 @@ def set_default_limited(self, limited: bool):
159159

160160
def set_default_non_admin(self):
161161
"""Grant the default user access to all non-admin endpoint namespaces."""
162-
allowed_namespaces = [
162+
read_write_namespaces = [
163163
EndpointType.PUBLIC.value,
164164
EndpointType.PERSONAL.value,
165165
EndpointType.USER.value,
166166
]
167+
read_only_namespaces = [EndpointType.INFO.value]
167168
self.connector._managed_connection._redis_conn.acl_setuser(
168169
"default",
169170
enabled=True,
170171
nopass=True,
171172
categories=["+@all", "-@dangerous"],
172-
keys=[f"%RW~{namespace}/*" for namespace in allowed_namespaces],
173-
channels=[f"{namespace}/*" for namespace in allowed_namespaces],
173+
keys=[f"%RW~{namespace}/*" for namespace in read_write_namespaces]
174+
+ [f"%R~{namespace}/*" for namespace in read_only_namespaces],
175+
channels=[
176+
f"{namespace}/*" for namespace in read_write_namespaces + read_only_namespaces
177+
]
178+
+ [MessageEndpoints.public_file("*", "*").endpoint],
174179
commands=["+keys"],
175180
reset_channels=True,
176181
reset_keys=True,

bec_lib/tests/test_acl_login.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ def test_access_demo_set_default_non_admin_allows_non_admin_namespaces(access_co
166166
f"&{EndpointType.PUBLIC.value}/*",
167167
f"&{EndpointType.PERSONAL.value}/*",
168168
f"&{EndpointType.USER.value}/*",
169+
f"&{EndpointType.INFO.value}/*",
170+
f"&{MessageEndpoints.public_file('*', '*').endpoint}",
169171
]
170172
)
171173
assert f"&{EndpointType.ADMIN.value}/*" not in acl_info["channels"]

0 commit comments

Comments
 (0)