qodalis-cli-server-plugin-users 1.0.0b26__tar.gz → 1.0.0b27__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.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/PKG-INFO +1 -1
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/pyproject.toml +1 -1
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/cli_users_builder.py +15 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/controllers/tokens_controller.py +6 -4
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/services/auth_service.py +26 -2
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/services/link_service.py +4 -1
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/.gitignore +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/LICENSE +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/__init__.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/_http.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/controllers/__init__.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/controllers/_routing.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/controllers/groups_controller.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/controllers/link_controller.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/controllers/sessions_controller.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/controllers/users_controller.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/errors.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/external_request.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/middleware/__init__.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/middleware/auth_middleware.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/models.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/permissions.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/server_protection.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/services/__init__.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/services/password_hasher.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/services/users_service.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/shell_access.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/stores/__init__.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/stores/in_memory_api_token_store.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/stores/in_memory_audit_store.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/stores/in_memory_credential_store.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/stores/in_memory_group_store.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/stores/in_memory_session_store.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/stores/in_memory_user_store.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/stores/interfaces.py +0 -0
- {qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/qodalis_cli_users/validation.py +0 -0
{qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/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.0b27
|
|
4
4
|
Summary: User management plugin for Qodalis CLI servers — authentication, sessions, groups and API tokens, recorded in the audit plugin's 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.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/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.0b27"
|
|
8
8
|
description = "User management plugin for Qodalis CLI servers — authentication, sessions, groups and API tokens, recorded in the audit plugin's log"
|
|
9
9
|
readme = { text = "", content-type = "text/plain" }
|
|
10
10
|
license = "MIT"
|
|
@@ -353,6 +353,7 @@ class CliUsersBuilder:
|
|
|
353
353
|
self._group_store: IGroupStore | None = None
|
|
354
354
|
self._api_token_store: IApiTokenStore | None = None
|
|
355
355
|
self._allow_non_expiring_tokens = False
|
|
356
|
+
self._allow_api_tokens = False
|
|
356
357
|
self._read_only_users = False
|
|
357
358
|
self._read_only_groups = False
|
|
358
359
|
self._auth_adapter: ExternalAuthAdapter | None = None
|
|
@@ -403,6 +404,19 @@ class CliUsersBuilder:
|
|
|
403
404
|
self._allow_non_expiring_tokens = allow
|
|
404
405
|
return self
|
|
405
406
|
|
|
407
|
+
def set_allow_api_tokens(self, allow: bool = True) -> CliUsersBuilder:
|
|
408
|
+
"""With an external auth adapter (:meth:`set_auth_adapter`), also
|
|
409
|
+
accept the plugin's API tokens: ``qcli_pat_`` bearer tokens are checked
|
|
410
|
+
before the adapter, and users signed in by the host create tokens
|
|
411
|
+
(``POST /tokens``) and approve terminal links
|
|
412
|
+
(``POST /link/code/{code}/approve``); both answer ``501`` without it.
|
|
413
|
+
The token's user is read from the user store by id, so the store must
|
|
414
|
+
find the adapter's users and report ``disabled``; keep the tokens in a
|
|
415
|
+
persistent store (:meth:`set_api_token_store`). Ignored without an
|
|
416
|
+
adapter (tokens are always on). Default ``False``."""
|
|
417
|
+
self._allow_api_tokens = allow
|
|
418
|
+
return self
|
|
419
|
+
|
|
406
420
|
def set_read_only_users(self, read_only: bool = True) -> CliUsersBuilder:
|
|
407
421
|
"""The host application owns the users (e.g. a read-only
|
|
408
422
|
``IUserStore`` over its own accounts): creating, updating and deleting
|
|
@@ -536,6 +550,7 @@ class CliUsersBuilder:
|
|
|
536
550
|
trust_proxy=self._trust_proxy,
|
|
537
551
|
allowed_origins=self._allowed_origins,
|
|
538
552
|
allow_non_expiring_tokens=self._allow_non_expiring_tokens,
|
|
553
|
+
api_tokens_with_external_auth=self._allow_api_tokens,
|
|
539
554
|
read_only_users=self._read_only_users,
|
|
540
555
|
read_only_groups=self._read_only_groups,
|
|
541
556
|
),
|
|
@@ -67,12 +67,14 @@ def scope_permissions(ctx: AuthContext, raw: Any) -> list[str] | None:
|
|
|
67
67
|
return perms
|
|
68
68
|
|
|
69
69
|
|
|
70
|
-
def ensure_can_create_tokens(ctx: AuthContext) -> None:
|
|
70
|
+
def ensure_can_create_tokens(ctx: AuthContext, allow_external: bool = False) -> None:
|
|
71
71
|
"""Only a signed-in session creates tokens: 403 for API tokens (a leaked
|
|
72
|
-
token must not mint more), 501 for external auth (no sessions)
|
|
72
|
+
token must not mint more), 501 for external auth (no sessions) unless the
|
|
73
|
+
host allows API tokens next to its sign-in (``allow_external``,
|
|
74
|
+
``api_tokens_with_external_auth``)."""
|
|
73
75
|
if ctx.api_token is not None:
|
|
74
76
|
raise forbidden(API_TOKENS_CANNOT_CREATE)
|
|
75
|
-
if ctx.session is None or ctx.external:
|
|
77
|
+
if ctx.session is None or (ctx.external and not allow_external):
|
|
76
78
|
raise UsersApiError(501, MANAGED_BY_HOST)
|
|
77
79
|
|
|
78
80
|
|
|
@@ -163,7 +165,7 @@ def create_tokens_router(
|
|
|
163
165
|
|
|
164
166
|
@collection(router, "POST", status_code=201)
|
|
165
167
|
async def create_token(body: CreateApiTokenRequest, ctx: AuthContext = Depends(get_auth)):
|
|
166
|
-
ensure_can_create_tokens(ctx)
|
|
168
|
+
ensure_can_create_tokens(ctx, auth_service.options.api_tokens_with_external_auth)
|
|
167
169
|
name = _validate_name(body.name)
|
|
168
170
|
expires_at = _expires_at(body, auth_service.options.allow_non_expiring_tokens, now_ms())
|
|
169
171
|
permissions = scope_permissions(ctx, body.permissions)
|
|
@@ -18,7 +18,7 @@ from typing import Any, Awaitable, Callable, Optional, Union
|
|
|
18
18
|
|
|
19
19
|
from qodalis_cli_server_abstractions.events import CliEventAudience, ICliEventBus
|
|
20
20
|
|
|
21
|
-
from .._http import forwarded_client_ip
|
|
21
|
+
from .._http import bearer_token, forwarded_client_ip
|
|
22
22
|
from ..external_request import ExternalRequestSnapshot
|
|
23
23
|
from ..errors import UsersApiError, forbidden, unauthorized
|
|
24
24
|
from ..models import (
|
|
@@ -189,6 +189,16 @@ class AuthServiceOptions:
|
|
|
189
189
|
#: The host owns the groups: group writes answer 501 and the built-in
|
|
190
190
|
#: groups are not seeded.
|
|
191
191
|
read_only_groups: bool = False
|
|
192
|
+
#: With an external auth adapter, also accept the plugin's API tokens
|
|
193
|
+
#: (``qcli_pat_…`` bearer tokens, checked before the adapter), so users
|
|
194
|
+
#: signed in by the host create tokens (``POST /tokens``) and approve
|
|
195
|
+
#: terminal links (``server add``). Off by default: the host owns
|
|
196
|
+
#: sign-in. The token's user is read from the user store by id on every
|
|
197
|
+
#: request and socket re-check, so the store must find the adapter's
|
|
198
|
+
#: users and report ``disabled``; keep the tokens in a persistent
|
|
199
|
+
#: ``IApiTokenStore`` (the default store forgets them on restart).
|
|
200
|
+
#: Ignored without an adapter (tokens are always on).
|
|
201
|
+
api_tokens_with_external_auth: bool = False
|
|
192
202
|
|
|
193
203
|
|
|
194
204
|
class AuthService:
|
|
@@ -253,6 +263,12 @@ class AuthService:
|
|
|
253
263
|
def external_auth(self) -> bool:
|
|
254
264
|
return self.auth_adapter is not None
|
|
255
265
|
|
|
266
|
+
@property
|
|
267
|
+
def api_tokens_enabled(self) -> bool:
|
|
268
|
+
"""Whether API tokens are accepted: always without an adapter, with
|
|
269
|
+
one only with ``api_tokens_with_external_auth``."""
|
|
270
|
+
return not self.external_auth or self.options.api_tokens_with_external_auth
|
|
271
|
+
|
|
256
272
|
# ------------------------------------------------------------------
|
|
257
273
|
# Passwords
|
|
258
274
|
# ------------------------------------------------------------------
|
|
@@ -744,7 +760,15 @@ class AuthService:
|
|
|
744
760
|
|
|
745
761
|
401 when the adapter returns no user, 401 ``account disabled`` for a
|
|
746
762
|
disabled user. The context keeps a snapshot of ``request`` so open
|
|
747
|
-
sockets can be re-checked against it (:meth:`revalidate_external`).
|
|
763
|
+
sockets can be re-checked against it (:meth:`revalidate_external`).
|
|
764
|
+
|
|
765
|
+
With ``api_tokens_with_external_auth`` a ``qcli_pat_`` bearer token is
|
|
766
|
+
the plugin's own: it is checked against the token store and the
|
|
767
|
+
adapter never sees it."""
|
|
768
|
+
if self.options.api_tokens_with_external_auth:
|
|
769
|
+
token = bearer_token(request.headers)
|
|
770
|
+
if token is not None and token.startswith(API_TOKEN_PREFIX):
|
|
771
|
+
return await self.authenticate_api_token(token)
|
|
748
772
|
result = await self.run_auth_adapter(request)
|
|
749
773
|
if not isinstance(result, ExternalAuthResult) or result.user is None:
|
|
750
774
|
raise unauthorized()
|
|
@@ -253,7 +253,10 @@ class LinkService:
|
|
|
253
253
|
link = self._find_pending(user_code)
|
|
254
254
|
if link is None:
|
|
255
255
|
raise not_found(NOT_FOUND)
|
|
256
|
-
|
|
256
|
+
# Adapter identities approve only when the host allows API tokens.
|
|
257
|
+
ensure_can_create_tokens(
|
|
258
|
+
ctx, bool(ctx.external) and self.auth_service.options.api_tokens_with_external_auth,
|
|
259
|
+
)
|
|
257
260
|
permissions = scope_permissions(ctx, link.permissions)
|
|
258
261
|
# Claimed before the token exists, so a parallel approval or deny gets 404
|
|
259
262
|
# instead of leaving a second token behind.
|
{qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/.gitignore
RENAMED
|
File without changes
|
{qodalis_cli_server_plugin_users-1.0.0b26 → qodalis_cli_server_plugin_users-1.0.0b27}/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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|