Release 2.7.0: executable handbooks and native user-site workflows
This commit is contained in:
1 parent
aa0c4d0f55
commit
d9aef957f7
562 files changed
+21064
-20387
No files matched your search
+53
-3
@@ -26,6 +26,56 @@ We retain **`p` = [Locate the installed native plugin](plugin.native_path(name="
|
||||
We **[End this run with the selected exit status](sys.exit(code=1))**.
|
||||
Return *None*.
|
||||
|
||||
## attach
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| app | any | required | Prepared web application |
|
||||
| users | any | required | Credential table or native database-backed user configuration |
|
||||
| session_ttl | number | 3600 | Session lifetime in seconds |
|
||||
| admin_prefix | text | "/admin" | Native administration prefix |
|
||||
| login_path | text | "/login" | Declared login route |
|
||||
| login_redirect | text | "" | Optional successful login destination |
|
||||
| logout_redirect | text | "" | Optional logout destination |
|
||||
| register | bool | False | Explicitly enable user registration |
|
||||
| register_path | text | "/register" | Registration route when enabled |
|
||||
| default_role | text | "user" | Role assigned to a registered user |
|
||||
| session_url | text | "" | Optional session backend URL |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Updated app with native login/session policy |
|
||||
|
||||
Use `app`, `users`, `session_ttl`=3600, `admin_prefix`="/admin", `login_path`="/login", `login_redirect`="", `logout_redirect`="", `register`=False, `register_path`="/register", `default_role`="user" and `session_url`="" before web.listen. This resource owns the login/session policy, while Endpoint auth metadata and explicit gates decide which requests need a session or role. Retain the returned app; construction does not authenticate a request or start a server. Credential tables in local examples are fixtures; real user stores should contain the hashes produced by hash_password. Registration is off until deliberately enabled. Session lifetime is in seconds, and external session backends require their own connection configuration.
|
||||
|
||||
We **[Load the native authentication implementation](plugin.load(path=plugin.native_path(name="web")))**.
|
||||
Return *[Bind the selected login and session policy](web_app_auth(app=`app`, users=`users`, session_ttl=`session_ttl`, admin_prefix=`admin_prefix`, login_redirect=`login_redirect`, logout_redirect=`logout_redirect`, login_path=`login_path`, register=`register`, register_path=`register_path`, default_role=`default_role`, session_url=`session_url`))*.
|
||||
|
||||
|
||||
## gate
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| app | any | required | Prepared application retaining its actual resources |
|
||||
| path | text | required | Explicit URL path to protect |
|
||||
| roles | any | "admin" | Allowed role CSV or list |
|
||||
| permissions | text | "" | Optional permission CSV; native any-match policy |
|
||||
| match | text | "prefix" | prefix or exact path matching |
|
||||
| on_deny | text | "forbid" | forbid or redirect anonymous requests to login |
|
||||
| exclude | any | None | Explicit path exclusions; native login/logout exclusions remain |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | Updated app with a server-enforced gate; no listener starts |
|
||||
|
||||
Use `app`, `path`, `roles`="admin", `permissions`="", `match`="prefix", `on_deny`="forbid" and `exclude`=None before listening, with plugin permission. Retain the returned app. This security-owned operation protects real requests; hiding a navigation link does not do that. It reuses the existing native gate and does not mutate Document content or invent routes.
|
||||
|
||||
Prefix matching includes the selected path and its slash descendants. The runtime keeps login and logout available to avoid authentication loops. When permissions are supplied, native permission matching applies instead of the role list; any required permission may match. Redirect applies to anonymous denial, while a signed-in subject without access receives forbidden. Test both direct denied requests and authenticated access, and gate the actual form/API endpoint separately if its data is private.
|
||||
|
||||
We **[Load the native access-policy implementation](_load())**.
|
||||
Return *[Bind the explicit server access rule](web_app_gate(app=`app`, path=`path`, roles=`roles`, permissions=`permissions`, match=`match`, on_deny=`on_deny`, exclude=`exclude`))*.
|
||||
|
||||
|
||||
# auth
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
@@ -35,14 +85,14 @@ Return *None*.
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Session/auth helper. Constructs a config object; `login` validates against the users table. To gate `/admin` on this app, use `app.auth users=…` instead. |
|
||||
| result | any | Session/auth helper. Constructs a config object; `login` validates against the users table. To bind native login and protect `/admin`, call attach and gate before listening. |
|
||||
|
||||
Use `users`, `session_ttl`=3600 as the inputs for this operation.
|
||||
|
||||
Session/auth helper. Constructs a config object; `login` validates against the users table. To gate `/admin` on this app, use `app.auth users=…` instead.
|
||||
Session/auth helper. Constructs a config object; `login` validates against the users table. To bind native login and protect `/admin`, call attach and gate before listening.
|
||||
|
||||
We **[Load the native plugin required by this operation](_load())**.
|
||||
Return *[Session/auth helper. Constructs a config object; login validates against the users table. To gate /admin on this app, use app.auth users=… instead.](web_auth_new(users=`users`, session_ttl=`session_ttl`))*.
|
||||
Return *[Session/auth helper. Constructs a config object; login validates against the users table. To bind server login and gates, use this module's attach function before web.listen.](web_auth_new(users=`users`, session_ttl=`session_ttl`))*.
|
||||
|
||||
## login
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@ import:
|
||||
|
||||
Use [auth](auth.mq.md) for credential/session operations, [rbac](rbac.mq.md) for role permissions,
|
||||
and [OIDC](oidc.mq.md) for attaching an external identity provider to an existing web app.
|
||||
[Tenant selection](tenant.mq.md) supplies explicit request context for scoped data queries;
|
||||
it does not authenticate a subject or prove tenant membership.
|
||||
中文服务工作流使用[鉴权绑定](鉴权.mq.md),与 auth.attach 保持相同策略及默认值。
|
||||
Endpoint authorization remains explicit in the web artifact metadata; a script permission check
|
||||
does not automatically protect an HTTP route.
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: Request tenant selection for database-backed web resources
|
||||
import:
|
||||
plugin: lib/plugin.mq.md
|
||||
---
|
||||
|
||||
Tenant selection identifies a request context; authentication and membership are separate decisions. Pair this leaf with explicit scoped routes in ext/data/api.mq.md. Use it before listening and retain the returned application after every binding. The implementation reuses the existing native tenant resolver.
|
||||
|
||||
## attach
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| app | any | required | Prepared application to receive tenant context |
|
||||
| mode | text | "path" | path, subdomain or header |
|
||||
| param | text | "t" | Path capture/query key or header name; use X-Tenant-Id explicitly for header mode |
|
||||
| column | text | "tenant_id" | Database column used by scoped queries |
|
||||
| default_scope | bool | False | Native default scoping for supported database-backed request handlers |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | any | Updated application with native request tenant resolution |
|
||||
|
||||
Use `app`, `mode`="path", `param`="t", `column`="tenant_id" and `default_scope`=False. Path mode first resolves the named route capture, then its query key, then the documented path segments. Subdomain mode uses the first label of a host with at least three labels. Header mode reads the selected header. The native resolver lowercases and keeps ASCII letters, digits, underscores and hyphens; it is not a general tenant-name codec.
|
||||
|
||||
Grant plugin and keep the returned application. A later scoped JSON route rejects a missing resolved tenant and adds the tenant-column filter. The default flag applies only to native handlers that support it; ordinary direct database calls do not gain automatic request context. Tenant ids arriving from query parameters, headers or hostnames must be checked against authenticated membership by the application's actual policy.
|
||||
|
||||
The local two-tenant example intentionally allows anonymous selection to demonstrate filtering. That behavior cannot establish production access isolation between users. No database row is changed and no socket opens in this binding. Develop resolver behavior in the native tenant package, and verify both selected tenants plus a request without a selector.
|
||||
|
||||
We **native = [Resolve the maintained tenant implementation](plugin.native_path(name="web"))** and **[Load the existing request-context boundary](plugin.load(path=`native`))**.
|
||||
Return *[Attach the explicit request tenant policy](web_app_tenant(app=`app`, mode=`mode`, param=`param`, column=`column`, default_scope=`default_scope`))*.
|
||||
@@ -0,0 +1,57 @@
|
||||
---
|
||||
markup: occlusion
|
||||
title: 为准备好的应用绑定鉴权
|
||||
import:
|
||||
auth: ext/security/auth.mq.md
|
||||
---
|
||||
|
||||
本文件提供 auth.mq.md 的服务端绑定中文入口。凭据验证、会话和路径门禁是不同责任:本入口配置登录会话,业务端点与表单仍需显式访问策略。它不会把隐藏链接当作授权。账户表中的明文密码只适合本地夹具;真实用户应使用英文资源的 hash_password 生成受支持的口令散列,避免记录秘密。
|
||||
|
||||
## 绑定
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| 应用 | any | 必填 | 已准备并按需启用原生后台的应用 |
|
||||
| 用户 | any | 必填 | username、password、role 凭据表,或原生用户库配置 |
|
||||
| 会话时长 | number | 3600 | 会话寿命,单位为秒 |
|
||||
| 后台前缀 | text | "/admin" | 启用原生后台时安装默认门禁的路径前缀 |
|
||||
| 登录路径 | text | "/login" | 实际 GET 与 POST 登录地址 |
|
||||
| 登录返回 | text | "" | 成功登录后的可选目标 |
|
||||
| 退出返回 | text | "" | 退出后的可选目标 |
|
||||
| 注册 | bool | False | 明确启用用户注册;默认关闭 |
|
||||
| 注册路径 | text | "/register" | 启用注册后的系统地址 |
|
||||
| 默认角色 | text | "user" | 新注册用户的角色 |
|
||||
| 会话地址 | text | "" | 可选外部会话存储 URI |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| 结果 | map | 保留原有资源、附加登录和会话策略的新应用 |
|
||||
|
||||
使用`应用`、`用户`、`会话时长`=3600、`后台前缀`="/admin"、`登录路径`="/login"、`登录返回`=""、`退出返回`=""、`注册`=False、`注册路径`="/register"、`默认角色`="user"及`会话地址`=""。在监听前授权 plugin 并保留新应用。这里不认证某一次请求,也不启动监听。
|
||||
|
||||
原生后台应先启用再绑定鉴权,业务接口的 Endpoint 元数据或显式门禁继续决定所需的身份和角色。注册必须明确启用,外部会话后端另需可用连接。配置成功不能替代拒绝与接受凭据的真实验收;用户数据与口令不要写入检视结果或日志。
|
||||
|
||||
绑定完成后返回 *[配置原生登录与会话策略](auth.attach(app=`应用`, users=`用户`, session_ttl=`会话时长`, admin_prefix=`后台前缀`, login_path=`登录路径`, login_redirect=`登录返回`, logout_redirect=`退出返回`, register=`注册`, register_path=`注册路径`, default_role=`默认角色`, session_url=`会话地址`))*。
|
||||
|
||||
|
||||
## 门禁
|
||||
|
||||
| 参数 | 类型 | 默认 | 说明 |
|
||||
|---|---|---|---|
|
||||
| 应用 | any | 必填 | 已准备且保留实际资源的应用 |
|
||||
| 路径 | text | 必填 | 需实际保护的服务器路径 |
|
||||
| 角色 | any | "admin" | 允许的角色逗号文本或列表 |
|
||||
| 权限 | text | "" | 可选权限逗号文本,沿用原生任一匹配 |
|
||||
| 匹配 | text | "prefix" | prefix 前缀或 exact 精确匹配 |
|
||||
| 拒绝 | text | "forbid" | forbid 禁止或 redirect 让匿名访问转登录 |
|
||||
| 排除 | any | None | 可选路径排除;原生登录和退出仍保持可用 |
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|---|---|---|
|
||||
| result | map | 附加实际服务器访问策略的新应用,尚未监听 |
|
||||
|
||||
使用`应用`、`路径`、`角色`="admin"、`权限`=""、`匹配`="prefix"、`拒绝`="forbid"及`排除`=None,在监听前授权 plugin 并保留返回值。本安全资源保护实际请求,不因导航隐藏链接就认定地址安全。前缀覆盖本路径及其斜杠子路径,登录和退出按原生规则排除,避免鉴权循环。
|
||||
|
||||
给出权限时采用原生权限匹配,而不是角色清单;任一所需权限命中即可。redirect 只让匿名拒绝转向登录,已登录但不足权限仍收到禁止。表单与 API 还应按实际数据策略保护自己的提交路径;不能只给展示页面加门禁就宣称所有写入已私有化。
|
||||
|
||||
绑定完成后返回 *[将明确的访问规则交给安全资源](auth.gate(app=`应用`, path=`路径`, roles=`角色`, permissions=`权限`, match=`匹配`, on_deny=`拒绝`, exclude=`排除`))*。
|
||||
Reference in new issue
Block a user