qodalis-cli-server-plugin-users 1.0.0b14__tar.gz → 1.0.0b15__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/PKG-INFO +1 -1
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/pyproject.toml +1 -1
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/controllers/audit_controller.py +19 -1
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/models.py +15 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/services/auth_service.py +4 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/services/users_service.py +8 -5
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/stores/in_memory_audit_store.py +14 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/stores/interfaces.py +6 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/.gitignore +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/LICENSE +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/__init__.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/_http.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/cli_users_builder.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/controllers/__init__.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/controllers/_routing.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/controllers/groups_controller.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/controllers/sessions_controller.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/controllers/tokens_controller.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/controllers/users_controller.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/errors.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/external_request.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/middleware/__init__.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/middleware/auth_middleware.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/permissions.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/server_protection.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/services/__init__.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/services/password_hasher.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/shell_access.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/stores/__init__.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/stores/in_memory_api_token_store.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/stores/in_memory_credential_store.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/stores/in_memory_group_store.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/stores/in_memory_session_store.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/stores/in_memory_user_store.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/qodalis_cli_users/validation.py +0 -0
{qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: qodalis-cli-server-plugin-users
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.0b15
|
|
4
4
|
Summary: User management plugin for Qodalis CLI servers — authentication, sessions, groups, and audit log
|
|
5
5
|
Project-URL: Homepage, https://github.com/qodalis-solutions/cli-server-python
|
|
6
6
|
Project-URL: Repository, https://github.com/qodalis-solutions/cli-server-python
|
{qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/pyproject.toml
RENAMED
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "qodalis-cli-server-plugin-users"
|
|
7
|
-
version = "1.0.
|
|
7
|
+
version = "1.0.0b15"
|
|
8
8
|
description = "User management plugin for Qodalis CLI servers — authentication, sessions, groups, and audit log"
|
|
9
9
|
readme = { text = "", content-type = "text/plain" }
|
|
10
10
|
license = "MIT"
|
|
@@ -12,6 +12,13 @@ from ..services.auth_service import AuthContext, AuthService
|
|
|
12
12
|
from ._routing import collection, new_router
|
|
13
13
|
|
|
14
14
|
|
|
15
|
+
#: Audit entries returned when the request names no limit.
|
|
16
|
+
DEFAULT_AUDIT_LIMIT = 100
|
|
17
|
+
|
|
18
|
+
#: The most audit entries one request returns.
|
|
19
|
+
MAX_AUDIT_LIMIT = 1000
|
|
20
|
+
|
|
21
|
+
|
|
15
22
|
def create_audit_router(
|
|
16
23
|
auth_service: AuthService,
|
|
17
24
|
require_permission: Callable[[str], Callable],
|
|
@@ -23,11 +30,22 @@ def create_audit_router(
|
|
|
23
30
|
async def list_entries(
|
|
24
31
|
event: str | None = None,
|
|
25
32
|
username: str | None = None,
|
|
33
|
+
actor: str | None = None,
|
|
26
34
|
limit: int | None = Query(default=None, ge=0),
|
|
35
|
+
offset: int | None = Query(default=None, ge=0),
|
|
27
36
|
ctx: AuthContext = Depends(require_permission(AUDIT_READ)),
|
|
28
37
|
):
|
|
38
|
+
"""Audit entries, newest first (``?event=&username=&actor=&limit=&offset=``):
|
|
39
|
+
the newest 100 without a limit, at most 1000, so a database store never
|
|
40
|
+
loads the whole log for one request."""
|
|
29
41
|
entries = await audit_store.get_entries(
|
|
30
|
-
AuditQueryOptions(
|
|
42
|
+
AuditQueryOptions(
|
|
43
|
+
event=event or None,
|
|
44
|
+
username=username or None,
|
|
45
|
+
actor=actor or None,
|
|
46
|
+
limit=DEFAULT_AUDIT_LIMIT if limit is None else min(limit, MAX_AUDIT_LIMIT),
|
|
47
|
+
offset=offset or None,
|
|
48
|
+
),
|
|
31
49
|
)
|
|
32
50
|
return [e.to_dict() for e in entries]
|
|
33
51
|
|
|
@@ -193,6 +193,12 @@ class AuditEntry:
|
|
|
193
193
|
metadata: dict[str, Any] | None = None
|
|
194
194
|
user_id: str | None = None
|
|
195
195
|
actor_id: str | None = None
|
|
196
|
+
#: What the event is about when it is not a user: a group
|
|
197
|
+
#: (``group:admins``), a job, or a host's own object such as a role.
|
|
198
|
+
target: str | None = None
|
|
199
|
+
#: The host's own values for this entry (e.g. the old and new value of a
|
|
200
|
+
#: setting), returned by the audit API. Values must serialize to JSON.
|
|
201
|
+
properties: dict[str, Any] | None = None
|
|
196
202
|
|
|
197
203
|
def to_dict(self) -> dict[str, Any]:
|
|
198
204
|
result: dict[str, Any] = {
|
|
@@ -209,6 +215,10 @@ class AuditEntry:
|
|
|
209
215
|
result["details"] = self.details
|
|
210
216
|
if self.actor is not None:
|
|
211
217
|
result["actor"] = self.actor
|
|
218
|
+
if self.target is not None:
|
|
219
|
+
result["target"] = self.target
|
|
220
|
+
if self.properties is not None:
|
|
221
|
+
result["properties"] = self.properties
|
|
212
222
|
if self.metadata is not None:
|
|
213
223
|
result["metadata"] = self.metadata
|
|
214
224
|
return result
|
|
@@ -218,7 +228,12 @@ class AuditEntry:
|
|
|
218
228
|
class AuditQueryOptions:
|
|
219
229
|
limit: int | None = None
|
|
220
230
|
event: str | None = None
|
|
231
|
+
#: The user the events are about (exact, case-insensitive).
|
|
221
232
|
username: str | None = None
|
|
233
|
+
#: The user who performed the actions (exact, case-insensitive).
|
|
234
|
+
actor: str | None = None
|
|
235
|
+
#: Entries to skip, for paging (newest first).
|
|
236
|
+
offset: int | None = None
|
|
222
237
|
|
|
223
238
|
|
|
224
239
|
@dataclass
|
|
@@ -418,6 +418,8 @@ class AuthService:
|
|
|
418
418
|
metadata: dict[str, Any] | None = None,
|
|
419
419
|
user_id: str | None = None,
|
|
420
420
|
actor_id: str | None = None,
|
|
421
|
+
target: str | None = None,
|
|
422
|
+
properties: dict[str, Any] | None = None,
|
|
421
423
|
) -> None:
|
|
422
424
|
try:
|
|
423
425
|
await self.audit_store.log(AuditEntry(
|
|
@@ -428,6 +430,8 @@ class AuthService:
|
|
|
428
430
|
metadata=metadata,
|
|
429
431
|
user_id=user_id,
|
|
430
432
|
actor_id=actor_id,
|
|
433
|
+
target=sanitize(target, 256),
|
|
434
|
+
properties=properties,
|
|
431
435
|
))
|
|
432
436
|
except Exception:
|
|
433
437
|
logger.exception("Failed to write audit entry %s", event)
|
|
@@ -271,7 +271,8 @@ class UsersService:
|
|
|
271
271
|
group = await self.groups.create_group(name, description, perms)
|
|
272
272
|
except ValueError as exc:
|
|
273
273
|
raise conflict(str(exc)) from exc
|
|
274
|
-
await self.auth.audit("group_created", ctx.user.name if ctx else "", details=group.name,
|
|
274
|
+
await self.auth.audit("group_created", ctx.user.name if ctx else "", details=group.name,
|
|
275
|
+
target=f"group:{group.name}", **_actor(ctx))
|
|
275
276
|
return group
|
|
276
277
|
|
|
277
278
|
async def update_group(
|
|
@@ -294,7 +295,8 @@ class UsersService:
|
|
|
294
295
|
)
|
|
295
296
|
except KeyError as exc:
|
|
296
297
|
raise not_found(f"group not found: {group.name}") from exc
|
|
297
|
-
await self.auth.audit("group_updated", ctx.user.name if ctx else "", details=updated.name,
|
|
298
|
+
await self.auth.audit("group_updated", ctx.user.name if ctx else "", details=updated.name,
|
|
299
|
+
target=f"group:{updated.name}", **_actor(ctx))
|
|
298
300
|
return updated
|
|
299
301
|
|
|
300
302
|
async def delete_group(self, ctx: AuthContext | None, group: Group) -> None:
|
|
@@ -308,7 +310,8 @@ class UsersService:
|
|
|
308
310
|
groups=[g for g in user.groups if g.lower() != group.name.lower()],
|
|
309
311
|
)
|
|
310
312
|
await self.groups.delete_group(group.name)
|
|
311
|
-
await self.auth.audit("group_deleted", ctx.user.name if ctx else "", details=group.name,
|
|
313
|
+
await self.auth.audit("group_deleted", ctx.user.name if ctx else "", details=group.name,
|
|
314
|
+
target=f"group:{group.name}", **_actor(ctx))
|
|
312
315
|
|
|
313
316
|
async def add_member(self, ctx: AuthContext | None, group: Group, user: User) -> None:
|
|
314
317
|
if ctx is not None:
|
|
@@ -318,7 +321,7 @@ class UsersService:
|
|
|
318
321
|
return
|
|
319
322
|
await self.users.update_user(user.id, groups=[*user.groups, group.name])
|
|
320
323
|
await self.auth.audit("group_member_added", user.name, details=group.name,
|
|
321
|
-
user_id=user.id, **_actor(ctx))
|
|
324
|
+
user_id=user.id, target=f"group:{group.name}", **_actor(ctx))
|
|
322
325
|
|
|
323
326
|
async def remove_member(self, ctx: AuthContext | None, group: Group, user: User) -> None:
|
|
324
327
|
if ctx is not None:
|
|
@@ -332,4 +335,4 @@ class UsersService:
|
|
|
332
335
|
groups=[g for g in user.groups if g.lower() != group.name.lower()],
|
|
333
336
|
)
|
|
334
337
|
await self.auth.audit("group_member_removed", user.name, details=group.name,
|
|
335
|
-
user_id=user.id, **_actor(ctx))
|
|
338
|
+
user_id=user.id, target=f"group:{group.name}", **_actor(ctx))
|
|
@@ -41,10 +41,24 @@ class InMemoryAuditStore(IAuditStore):
|
|
|
41
41
|
if options.username:
|
|
42
42
|
un = options.username.lower()
|
|
43
43
|
result = [e for e in result if e.username.lower() == un]
|
|
44
|
+
if options.actor:
|
|
45
|
+
actor = options.actor.lower()
|
|
46
|
+
result = [e for e in result if (e.actor or "").lower() == actor]
|
|
47
|
+
if options.offset is not None and options.offset > 0:
|
|
48
|
+
result = result[options.offset:]
|
|
44
49
|
if options.limit is not None and options.limit > 0:
|
|
45
50
|
result = result[: options.limit]
|
|
46
51
|
return result
|
|
47
52
|
|
|
53
|
+
async def prune(self, before: int) -> int:
|
|
54
|
+
removed = 0
|
|
55
|
+
for entries in (self._entries, self._failed):
|
|
56
|
+
kept = [item for item in entries if item[1].timestamp >= before]
|
|
57
|
+
removed += len(entries) - len(kept)
|
|
58
|
+
entries.clear()
|
|
59
|
+
entries.extend(kept)
|
|
60
|
+
return removed
|
|
61
|
+
|
|
48
62
|
async def clear(self) -> None:
|
|
49
63
|
self._entries.clear()
|
|
50
64
|
self._failed.clear()
|
|
@@ -161,6 +161,12 @@ class IAuditStore(ABC):
|
|
|
161
161
|
async def clear(self) -> None:
|
|
162
162
|
...
|
|
163
163
|
|
|
164
|
+
async def prune(self, before: int) -> int:
|
|
165
|
+
"""Deletes the entries recorded before ``before`` (Unix time in ms);
|
|
166
|
+
returns how many. Run it on a schedule to keep the log bounded. The
|
|
167
|
+
default keeps everything and returns 0."""
|
|
168
|
+
return 0
|
|
169
|
+
|
|
164
170
|
|
|
165
171
|
class IGroupStore(ABC):
|
|
166
172
|
"""Persistence interface for user groups. Lookups are case-insensitive."""
|
{qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/.gitignore
RENAMED
|
File without changes
|
{qodalis_cli_server_plugin_users-1.0.0b14 → qodalis_cli_server_plugin_users-1.0.0b15}/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|