generate-sandbox-policy
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGenerate Sandbox Policy
生成沙箱策略
Generate YAML sandbox network policies and network middleware configuration from API documentation and natural-language user requirements.
基于API文档和用户的自然语言需求,生成YAML格式的沙箱网络策略及网络中间件配置。
Overview
概述
This skill translates a user's plain-language policy intent into a valid sandbox policy. The amount of detail the user provides determines the granularity of the generated policy — from broad L4 or preset-based policies (just a host:port) up to fine-grained per-endpoint L7 rules (full API docs).
The output is a YAML block, an optional block, and optionally a full policy file that conforms to the sandbox policy schema.
network_policiesnetwork_middlewares本技能将用户的自然语言策略意图转化为有效的沙箱策略。用户提供的细节程度决定了生成策略的粒度——从宽泛的L4或基于预设的策略(仅需主机:端口),到细粒度的按端点L7规则(需完整API文档)。
输出内容包括 YAML块、可选的块,以及可选的符合沙箱策略Schema的完整策略文件。
network_policiesnetwork_middlewaresStep 1: Gather Inputs
步骤1:收集输入
Determine the Detail Tier
确定细节层级
The user's input falls into one of three tiers. Work with whatever the user provides — do not require a higher tier than needed.
| Tier | User provides | What you can generate |
|---|---|---|
| Minimal | Host(s) and plain-language intent | L4-only policies, or L7 with access presets ( |
| Moderate | Host(s) + some known URL paths or resources | L7 with targeted glob rules for known paths, presets for the rest |
| Full | Complete API docs (OpenAPI, Swagger, markdown, URL) | Fine-grained per-endpoint L7 rules with specific method+path combinations |
用户的输入属于三个层级之一。使用用户提供的任何信息即可——不要要求用户提供超出必要的更高层级信息。
| 层级 | 用户提供内容 | 可生成内容 |
|---|---|---|
| 基础级 | 主机和自然语言意图 | 仅L4策略,或带访问预设的L7策略( |
| 中等级 | 主机 + 部分已知URL路径或资源 | 针对已知路径的定向glob规则L7策略,其余部分使用预设 |
| 完整级 | 完整API文档(OpenAPI、Swagger、markdown、URL) | 带特定方法+路径组合的细粒度按端点L7规则 |
Minimal Tier (host + intent only)
基础级(仅主机+意图)
The user provides API endpoints and a broad intent. No API docs needed.
Examples:
- "Allow curl to hit api.github.com, read-only"
- "Give claude full access to api.anthropic.com"
- "Let /usr/bin/myapp talk to internal-svc:8080 but only for reading"
This is sufficient for:
- L4-only policies (host:port + binary checks, no method or path rules)
- Preset-based L7 policies (,
read-only,read-writeon all paths)full
For this tier, default to:
- when the user says "read", "browse", "view", "query", "fetch"
access: read-only - when the user says "read-write", "create", "update" (but not "delete")
access: read-write - when the user says "full access", "everything", "unrestricted"
access: full - L4-only when the user says "just allow it", "pass through", or "no
inspection". Omit for explicit-proxy clients. Use
protocolonly when the workload must use native DNS and direct socket calls, the endpoint has a valid DNS hostname, and the selected runtime support (currently Docker and Podman).protocol: tcp
用户提供API端点和宽泛的意图,无需API文档。
示例:
- "允许curl访问api.github.com,只读权限"
- "授予claude对api.anthropic.com的完全访问权限"
- "让/usr/bin/myapp与internal-svc:8080通信,但仅允许读操作"
这足以支持:
- 仅L4策略(主机:端口 + 二进制程序检查,无方法或路径规则)
- 基于预设的L7策略(所有路径使用、
read-only、read-write预设)full
对于该层级,默认规则如下:
- 当用户提到“读”、“浏览”、“查看”、“查询”、“获取”时,使用
access: read-only - 当用户提到“读写”、“创建”、“更新”(但未提及“删除”)时,使用
access: read-write - 当用户提到“完全访问”、“所有权限”、“无限制”时,使用
access: full - 当用户提到“直接允许”、“透传”或“不检查”时,使用仅L4模式。对于显式代理客户端,省略字段。仅当工作负载必须使用原生DNS和直接套接字调用、端点具有有效的DNS主机名,且所选运行时支持(目前为Docker和Podman)时,才使用
protocol。protocol: tcp
Moderate Tier (host + partial path knowledge)
中等级(主机 + 部分路径信息)
The user knows some API paths but doesn't have full docs.
Examples:
- "Allow GET on /api/v1/models and POST on /api/v1/completions at integrate.api.nvidia.com"
- "Read-only on /repos/** at api.github.com, but also allow POST on /repos/*/issues"
Generate explicit for the known paths. If the user also wants broader access beyond the specific paths, combine with a catch-all rule or suggest a preset instead.
rules用户了解部分API路径,但没有完整文档。
示例:
- "允许对integrate.api.nvidia.com的/api/v1/models执行GET请求,对/api/v1/completions执行POST请求"
- "对api.github.com的/repos/**路径只读,但同时允许对/repos/*/issues执行POST请求"
为已知路径生成显式。如果用户除了特定路径外还需要更宽泛的访问权限,可结合通用规则或建议使用预设。
rulesFull Tier (complete API docs)
完整级(完整API文档)
The user provides full API documentation. Accepted formats:
| Format | How to consume |
|---|---|
| URL | Fetch with the agent's web access and parse the endpoint list |
| File path | Read the file (OpenAPI JSON/YAML, markdown, etc.) |
| Pasted text | Parse inline from the conversation |
| OpenAPI/Swagger spec | Extract |
From the API docs, build an endpoint inventory — a list of tuples. Group them logically (e.g., by resource or tag). Then generate precise rules that allow only what the user's intent requires.
(method, path, description)用户提供完整的API文档,支持的格式包括:
| 格式 | 处理方式 |
|---|---|
| URL | 通过Agent的网页访问能力获取并解析端点列表 |
| 文件路径 | 读取文件(OpenAPI JSON/YAML、markdown等) |
| 粘贴文本 | 从对话中直接解析内联内容 |
| OpenAPI/Swagger规范 | 提取 |
从API文档中构建端点清单——即元组的列表。按逻辑分组(例如按资源或标签),然后生成精确的规则,仅允许用户意图所需的访问。
(方法, 路径, 描述)Policy Intent
策略意图
Regardless of tier, extract (or infer) these from the user's description:
| Aspect | What to identify | Required? |
|---|---|---|
| Scope | Which API host(s) and port(s) | Yes — always needed |
| Access level | Broad intent: read-only, read-write, full, or custom | Yes — ask if unclear |
| Methods | Specific HTTP methods to allow | Only for custom/fine-grained |
| Paths | Specific URL paths or patterns | Only for custom/fine-grained |
| Enforcement | | No — has a default |
| Binary | Which binary/process should have access | Yes — ask if not stated |
| Middleware | Whether admitted HTTP requests, final HTTP responses, or client WebSocket text messages need an ordered built-in or operator-run processing stage | No |
If the host and access level are clear but binaries are not specified, ask the user which binary or process will be making the requests. Suggest common defaults like , , etc.
/usr/bin/curl/usr/local/bin/claude无论哪个层级,都需要从用户描述中提取(或推断)以下信息:
| 维度 | 需识别的内容 | 是否必填? |
|---|---|---|
| 范围 | 哪些API主机和端口 | 是 —— 始终需要 |
| 访问级别 | 宽泛意图:只读、读写、完全或自定义 | 是 —— 不明确时需询问 |
| 方法 | 允许的特定HTTP方法 | 仅自定义/细粒度策略需要 |
| 路径 | 特定URL路径或模式 | 仅自定义/细粒度策略需要 |
| 执行模式 | | 否 —— 有默认值 |
| 二进制程序 | 哪些二进制程序/进程有权访问 | 是 —— 未说明时需询问 |
| 中间件 | 准入的HTTP请求、最终HTTP响应或客户端WebSocket文本消息是否需要有序的内置或运维人员运行的处理阶段 | 否 |
如果主机和访问级别明确,但未指定二进制程序,需询问用户哪个二进制程序或进程将发起请求。可建议常见的默认值,如、等。
/usr/bin/curl/usr/local/bin/claudeStep 2: Refine Scope (Clarification Loop)
步骤2:细化范围(澄清循环)
Before generating the policy, proactively ask clarifying questions to help the user scope the policy down as narrowly as possible. The goal is the most restrictive policy that still satisfies the user's needs.
在生成策略之前,主动提出澄清问题,帮助用户尽可能缩小策略范围。目标是生成既能满足用户需求、又最严格的策略。
Required Clarifications
必要澄清项
Always ask about these if the user hasn't already specified them:
| Missing info | Question to ask |
|---|---|
| Binary not specified | "Which binary or process will make these requests? (e.g., |
| Port not specified | "Which port does this API use? (443 for HTTPS is typical)" |
| Enforcement not stated | "Should policy violations be blocked ( |
如果用户未指定以下内容,必须询问:
| 缺失信息 | 询问的问题 |
|---|---|
| 未指定二进制程序 | "哪个二进制程序或进程将发起这些请求?(例如 |
| 未指定端口 | "这个API使用哪个端口?(HTTPS通常使用443)" |
| 未说明执行模式 | "策略违规应该被阻止( |
Scoping-Down Questions
缩小范围的问题
Ask these when the user's intent is broad and more specificity is possible:
| User says | Ask to narrow |
|---|---|
| "Full access" / "allow everything" | "Do you actually need DELETE access, or would read-write (everything except DELETE) be enough?" |
| "Allow access to api.example.com" (no method/path detail) | "Do you know which specific API paths or operations you need? If so, I can lock the policy down to just those. Otherwise I'll use a broad preset." |
| L4-only / "just pass it through" | "L4-only means the proxy applies no method or path rules — any method and path will be allowed. Are you sure you don't want at least read-only or read-write restriction?" |
Wildcard binary ( | "A wildcard binary pattern means any binary in that directory can use this policy. Can you narrow it to specific binaries?" |
| Multiple hosts in one policy | "Do all of these hosts need the same access level? If some need tighter restrictions, I can split them into separate policies." |
| "Full access in audit mode means nothing is actually restricted — all traffic flows through and violations are only logged. Is that intentional, or did you want to enforce restrictions?" |
| "Using |
| Private/internal IP destination | "Does this service resolve to a private IP (10.x, 172.16.x, 192.168.x)? An exact hostname can reach its private addresses without |
当用户意图较为宽泛,有可能进一步明确时,询问以下问题:
| 用户表述 | 用于缩小范围的询问 |
|---|---|
| "完全访问" / "允许所有操作" | "您是否真的需要DELETE权限?读写权限(除DELETE外的所有操作)是否足够?" |
| "允许访问api.example.com"(无方法/路径细节) | "您是否知道需要哪些特定的API路径或操作?如果知道,我可以将策略限制为仅这些路径。否则我将使用宽泛的预设。" |
| 仅L4 / "直接透传" | "仅L4模式意味着代理不应用任何方法或路径规则——任何方法和路径都将被允许。您确定不需要至少只读或读写限制吗?" |
通配符二进制程序( | "通配符二进制程序模式意味着该目录中的任何二进制程序都可以使用此策略。您能否缩小到特定的二进制程序?" |
| 一个策略包含多个主机 | "所有这些主机都需要相同的访问级别吗?如果某些主机需要更严格的限制,我可以将它们拆分为单独的策略。" |
| "审计模式下的完全访问意味着没有实际限制——所有流量都将通过,仅记录违规行为。这是您的本意吗?还是您希望强制执行限制?" |
所有规则都使用 | "在所有路径上使用 |
| 私有/内部IP目标 | "此服务是否解析为私有IP(10.x、172.16.x、192.168.x)?精确的主机名无需 |
Auto-Discovery of API Docs for Well-Known Services
知名服务API文档自动发现
When the user mentions a recognizable API host but hasn't provided docs, and the current tier is Minimal, attempt to upgrade to Full by searching for the API documentation online.
When to trigger:
- The host is a well-known public API (e.g., ,
api.github.com,api.anthropic.com,api.openai.com,integrate.api.nvidia.com,api.stripe.com,api.slack.com)api.gitlab.com - The user has NOT already provided API docs
- The user has NOT explicitly asked for a broad preset ("just read-only, nothing fancy")
How to do it:
- Tell the user: "I can look up the REST API docs for [service] to help generate a more precise policy. Want me to do that?"
- If the user agrees (or hasn't declined), search for the docs:
- Search the web with a query like or
"[service name] REST API documentation endpoints""[service name] OpenAPI spec" - Look for official documentation URLs in the results
- Search the web with a query like
- Fetch the documentation page and extract the endpoint inventory (method + path pairs)
- Use the discovered endpoints to offer tighter scoping: "I found [N] endpoints in the [service] API. Based on your intent, I can narrow the policy to just [subset]. Want me to do that, or keep the broader preset?"
When to skip:
- The user explicitly asked for a broad preset or said "don't bother with docs"
- The API is internal, private, or not publicly documented
- The host is not recognizable as a well-known service
- A previous search attempt for this host returned no useful results
Graceful fallback: If the search doesn't return usable API docs (results are irrelevant, docs are behind authentication, the page is too large to parse), fall back to the current tier without stalling. Say: "I couldn't find usable API docs for [host], so I'll generate the policy using a [preset/L4] approach. You can always provide docs later to tighten it."
当用户提到可识别的API主机但未提供文档,且当前层级为基础级时,尝试通过在线搜索API文档升级到完整级。
触发条件:
- 主机是知名的公共API(例如、
api.github.com、api.anthropic.com、api.openai.com、integrate.api.nvidia.com、api.stripe.com、api.slack.com)api.gitlab.com - 用户尚未提供API文档
- 用户未明确要求使用宽泛预设(“只要只读,不用太复杂”)
操作方式:
- 告知用户:“我可以查找[服务]的REST API文档,帮助生成更精确的策略。需要我这么做吗?”
- 如果用户同意(或未拒绝),搜索文档:
- 使用类似“[服务名称] REST API 文档 端点”或“[服务名称] OpenAPI 规范”的查询词搜索网页
- 在结果中查找官方文档URL
- 获取文档页面并提取端点清单(方法+路径对)
- 利用发现的端点提供更严格的范围选项:“我在[服务] API中找到了[N]个端点。根据您的意图,我可以将策略缩小到仅[子集]。需要我这么做,还是保留更宽泛的预设?”
跳过条件:
- 用户明确要求使用宽泛预设或表示“不用找文档了”
- API是内部的、私有的或没有公开文档
- 主机无法识别为知名服务
- 之前对该主机的搜索尝试未返回有用结果
优雅降级: 如果搜索未返回可用的API文档(结果不相关、文档需要认证、页面太大无法解析),则回退到当前层级,不要停滞。告知用户:“我找不到[主机]的可用API文档,因此我将使用[预设/L4]方式生成策略。您以后随时可以提供文档以进一步收紧策略。”
When the User Can't Narrow Further
当用户无法进一步缩小范围时
If the user confirms the policy must stay broad (they don't know the paths, need genuinely broad access, etc.), accept it but flag the breadth. Do not block policy generation — just make sure the warnings are visible in the output (see Step 6).
如果用户确认策略必须保持宽泛(他们不知道路径、确实需要宽泛访问等),接受该情况但标记范围过宽的问题。不要阻止策略生成——只需确保警告在输出中可见(见步骤6)。
Iteration
迭代
You may need to go back and forth a few times. Keep the loop tight:
- Ask one batch of clarifying questions (group related questions together)
- Update your understanding based on the answer
- If the answer reveals further scoping opportunities, ask a follow-up
- Stop when the user confirms the scope or says to proceed
Do not over-interrogate. If the user has given a clear, specific request, skip clarification and go straight to generation. Only ask when there is genuine ambiguity or an opportunity to meaningfully reduce the attack surface.
可能需要来回沟通几次。保持循环高效:
- 一次性提出一批澄清问题(将相关问题分组)
- 根据回答更新理解
- 如果回答揭示了进一步缩小范围的机会,提出后续问题
- 当用户确认范围或表示可以继续时停止
不要过度询问。 如果用户给出了清晰、具体的请求,跳过澄清直接进入生成阶段。仅在存在真正的歧义或有机会显著缩小攻击面时才询问。
Step 3: Read the Policy Schema
步骤3:阅读策略Schema
Read the published policy schema reference before generating or changing a policy. Published documentation is the authority for the current schema; do not infer fields from examples in this skill.
Key sections to reference:
- Policy Schema Reference — top-level structure
- — rule structure
network_policies - fields — host, port, protocol, tls, enforcement, access, rules, allowed_ips
NetworkEndpoint - /
L7Rule— method + path matchingL7Allow - Access Presets — ,
read-only,read-writefull - Private IP Access via — CIDR allowlist for private IP space
allowed_ips - Network Middleware - top-level middleware configs, ordering, host selection, and failure behavior
- Validation Rules — what combinations are valid/invalid
When middleware is requested, also read the published supervisor middleware guide.
For enforcement concepts and the shipped baseline, read sandbox policies and the default policy reference. The default policy is built into the OpenShell runtime and applies when no explicit policy is supplied.
Validate the intended provider combination as well as the authored policy.
An image endpoint can become credentialed after provider composition and block
startup with . Repair the complete policy or provider
selection using the published policy workflow; do not add
merely to bypass a startup error.
ConfigurationInvalidallow_uninspected_credentials在生成或修改策略之前,请阅读已发布的策略Schema参考。已发布的文档是当前Schema的权威来源;不要从本技能的示例中推断字段。
需要参考的关键章节:
- 策略Schema参考 —— 顶层结构
- —— 规则结构
network_policies - 字段 —— host、port、protocol、tls、enforcement、access、rules、allowed_ips
NetworkEndpoint - /
L7Rule—— 方法+路径匹配L7Allow - 访问预设 —— 、
read-only、read-writefull - 通过访问私有IP —— 私有IP空间的CIDR白名单
allowed_ips - 网络中间件 —— 顶层中间件配置、排序、主机选择和故障行为
- 验证规则 —— 哪些组合有效/无效
当需要中间件时,还需阅读已发布的supervisor中间件指南。
验证预期的提供商组合以及编写的策略。镜像端点在提供商组合后可能会变为带凭证的,并以错误阻止启动。使用已发布的策略工作流修复完整策略或提供商选择;不要仅仅为了绕过启动错误而添加。
ConfigurationInvalidallow_uninspected_credentialsStep 4: Choose Policy Shape
步骤4:选择策略形态
Follow this decision tree based on the detail tier and user intent:
Is L7 inspection needed?
├─ No (user wants pass-through / "just allow it")
│ ├─ Explicit-proxy client → omit protocol
│ └─ Native DNS/socket client with a DNS hostname on a supported runtime → protocol: tcp
│
└─ Yes (user wants method/path control)
│
├─ Does a preset match the intent exactly?
│ ├─ Read-only (GET, HEAD, OPTIONS) → access: read-only
│ ├─ Read-write (no DELETE) → access: read-write
│ └─ Everything → access: full
│
└─ No preset fits (specific paths, mixed broad+narrow, exclude certain paths)
└─ Build explicit rules list
└─ Requires either known paths from the user or full API docsPrinciple: always choose the simplest representation that satisfies the intent. A preset is preferable to explicit rules when it covers the use case.
根据细节层级和用户意图,遵循以下决策树:
Is L7 inspection needed?
├─ No (user wants pass-through / "just allow it")
│ ├─ Explicit-proxy client → omit protocol
│ └─ Native DNS/socket client with a DNS hostname on a supported runtime → protocol: tcp
│
└─ Yes (user wants method/path control)
│
├─ Does a preset match the intent exactly?
│ ├─ Read-only (GET, HEAD, OPTIONS) → access: read-only
│ ├─ Read-write (no DELETE) → access: read-write
│ └─ Everything → access: full
│
└─ No preset fits (specific paths, mixed broad+narrow, exclude certain paths)
└─ Build explicit rules list
└─ Requires either known paths from the user or full API docs原则:始终选择能满足意图的最简单表示形式。当预设可以覆盖用例时,优先使用预设而非显式规则。
TLS Decision
TLS决策
Omit on every endpoint, regardless of port: the proxy auto-detects TLS and terminates it for inspection. is the only accepted non-empty value, reserved for upstreams requiring client-certificate mTLS or a non-HTTP protocol.
tlsskipDo not "fix" a rejected value — including the removed and spellings — by changing it to ; remove the field instead. stops inspection, credential injection, and L7 rule enforcement for that endpoint, so it silently widens what the endpoint allows.
terminatepassthroughskipskip无论端口如何,所有端点都省略字段:代理会自动检测TLS并终止以进行检查。是唯一接受的非空值,保留给需要客户端证书mTLS或非HTTP协议的上游服务。
tlsskip不要通过将被拒绝的值(包括已移除的和写法)更改为来“修复”;而是直接删除该字段。会停止该端点的检查、凭证注入和L7规则执行,因此会悄无声息地扩大端点允许的范围。
terminatepassthroughskipskipMiddleware Decision
中间件决策
Add only when the user asks to inspect, transform, redact, or independently authorize admitted HTTP requests, final HTTP responses, or client WebSocket text messages. Request middleware runs after network and L7 policy admission and before provider credential injection. Response middleware runs on the matching final response before it returns to the sandbox.
network_middlewares- Use without gateway registration for fixed-pattern redaction of UTF-8 HTTP request bodies or complete client-to-upstream WebSocket text messages.
openshell/regex - Use an operator-owned middleware name only when it is already registered under and reachable from both the gateway and sandbox supervisors.
[[openshell.supervisor.middleware]] - Confirm that the implementation advertises the requested binding: ,
HTTP_REQUEST/PRE_CREDENTIALS, orHTTP_RESPONSE/PRE_RETURN. A host match alone does not enable inspection.WEBSOCKET_MESSAGE/PRE_CREDENTIALS - WebSocket middleware inspects client text messages only, over both and
ws://. Binary and upstream-to-client messages pass without inspection, even withwss://.fail_closed - controls selected-stage failures. Explicit denials always block traffic. A failed WebSocket stage with
on_errorcan remain bypassed for the rest of the connection.fail_open - Default to
on_error. Usefail_closedonly when bypassing the stage preserves the user's stated security requirement.fail_open - Assign unique values across the complete policy. Lower values run first, and at most 10 configs may be selected.
order - Match the narrowest destination hosts possible with ; use
endpoints.includewhen a broad selector has trusted exceptions.exclude - Do not select fail-closed middleware for endpoints because the supervisor cannot inspect that traffic.
tls: skip
仅当用户要求对准入的HTTP请求、最终HTTP响应或客户端WebSocket文本消息进行检查、转换、脱敏或独立授权时,才添加。请求中间件在网络和L7策略准入之后、提供商凭证注入之前运行。响应中间件在匹配的最终响应返回沙箱之前运行。
network_middlewares- 对于UTF-8 HTTP请求体或完整的客户端到上游WebSocket文本消息的固定模式脱敏,使用无需网关注册的。
openshell/regex - 仅当运维人员拥有的中间件名称已在下注册,且网关和沙箱supervisor都可以访问时,才使用该名称。
[[openshell.supervisor.middleware]] - 确认实现声明了所请求的绑定:、
HTTP_REQUEST/PRE_CREDENTIALS或HTTP_RESPONSE/PRE_RETURN。仅主机匹配不会启用检查。WEBSOCKET_MESSAGE/PRE_CREDENTIALS - WebSocket中间件仅检查客户端文本消息,支持和
ws://。即使启用wss://,二进制消息和上游到客户端的消息也会不经检查通过。fail_closed - 控制所选阶段的故障。显式拒绝始终会阻止流量。如果WebSocket阶段失败且配置为
on_error,则在连接的剩余时间内可能会一直绕过该阶段。fail_open - 默认为
on_error。仅当绕过该阶段符合用户声明的安全要求时,才使用fail_closed。fail_open - 在整个策略中分配唯一的值。值越小越先运行,最多可选择10个配置。
order - 使用匹配尽可能窄的目标主机;当宽泛选择器有可信的例外情况时,使用
endpoints.include。exclude - 不要为端点选择故障关闭(fail-closed)的中间件,因为supervisor无法检查该流量。
tls: skip
Mapping Paths to Glob Patterns (when building explicit rules)
路径到Glob模式的映射(构建显式规则时)
Only needed for the Moderate and Full tiers. Translate API path parameters to glob patterns:
| API path | Glob pattern |
|---|---|
| |
| |
| |
| |
All sub-paths under | |
Path matching uses the runtime engine. Both and may cross
boundaries; matches one character, and bracket classes such as and
are supported. Prefer segment-shaped patterns such as
for readability, but do not rely on to stop at .
glob***/?[0-9][!0]/repos/*/issues*/仅中等级和完整级需要。将API路径参数转换为glob模式:
| API路径 | Glob模式 |
|---|---|
| |
| |
| |
| |
| |
路径匹配使用运行时引擎。和都可以跨越边界;匹配单个字符,支持和等括号类。为了可读性,优先使用分段模式如,但不要假设会在处停止。
glob***/?[0-9][!0]/repos/*/issues*/Building the Explicit Rules List
构建显式规则列表
For each allowed operation, create an entry:
allowyaml
rules:
- allow:
method: GET
path: "/api/v1/models/*"
- allow:
method: POST
path: "/api/v1/completions"Use the most specific pattern that covers the intent. Prefer narrow globs over when the API structure is known.
**对于每个允许的操作,创建一个条目:
allowyaml
rules:
- allow:
method: GET
path: "/api/v1/models/*"
- allow:
method: POST
path: "/api/v1/completions"使用能覆盖意图的最具体模式。当API结构已知时,优先使用窄范围的glob而非。
**Step 5: Generate the Policy
步骤5:生成策略
Output Format
输出格式
Generate a complete entry. Use this template:
network_policiesyaml
network_policies:
<policy_key>:
name: <policy_key>
endpoints:
- host: <api_host>
port: <port>
protocol: rest # Required for L7 inspection
enforcement: enforce # or audit
# Use ONE of: access OR rules (never both)
access: <preset> # read-only | read-write | full
# OR
rules:
- allow:
method: <METHOD>
path: "<glob_pattern>"
# Optional: restrict resolved addresses (CIDR or exact IP). Required
# for private IPs on wildcard or hostless endpoints.
# allowed_ips:
# - "10.0.5.0/24"
binaries:
- { path: <binary_path> }When middleware is requested, add it as a separate top-level map rather than nesting it under a network policy:
yaml
network_middlewares:
<config_key>:
name: <human_readable_name>
middleware: <built_in_or_registered_name>
order: 10
config: {}
on_error: fail_closed
endpoints:
include: ["<api_host>"]
# exclude: ["<trusted_host>"]The map key is the stable policy-local identity. Middleware selection is independent of the network policy entry that admitted the request.
生成完整的条目,使用以下模板:
network_policiesyaml
network_policies:
<policy_key>:
name: <policy_key>
endpoints:
- host: <api_host>
port: <port>
protocol: rest # Required for L7 inspection
enforcement: enforce # or audit
# Use ONE of: access OR rules (never both)
access: <preset> # read-only | read-write | full
# OR
rules:
- allow:
method: <METHOD>
path: "<glob_pattern>"
# Optional: restrict resolved addresses (CIDR or exact IP). Required
# for private IPs on wildcard or hostless endpoints.
# allowed_ips:
# - "10.0.5.0/24"
binaries:
- { path: <binary_path> }当需要中间件时,将其作为单独的顶层映射添加,而不是嵌套在网络策略下:
yaml
network_middlewares:
<config_key>:
name: <human_readable_name>
middleware: <built_in_or_registered_name>
order: 10
config: {}
on_error: fail_closed
endpoints:
include: ["<api_host>"]
# exclude: ["<trusted_host>"]映射键是策略内稳定的标识符。中间件选择与准入请求的网络策略条目无关。
Deny Rules
拒绝规则
Use to block specific dangerous operations while allowing broad access. Deny rules are evaluated after allow rules and take precedence. This is the inverse of the approach — instead of enumerating every allowed operation, you grant broad access and block a small set of dangerous ones.
deny_rulesrulesyaml
undefined使用在允许宽泛访问的同时阻止特定的危险操作。拒绝规则在允许规则之后评估,且优先级更高。这与方法相反——您不需要枚举每个允许的操作,而是授予宽泛访问权限,然后阻止一小部分危险操作。
deny_rulesrulesyaml
undefinedExample: Allow full access to GitHub but block admin operations
Example: Allow full access to GitHub but block admin operations
github_api:
name: github_api
endpoints:
- host: api.github.com
port: 443
protocol: rest
enforcement: enforce
access: read-write
deny_rules:
- method: POST
path: "/repos//pulls//reviews"
- method: PUT
path: "/repos//branches//protection"
- method: ""
path: "/repos//rulesets"
binaries:
- { path: /usr/bin/curl }
Deny rules support the same matching capabilities as allow rules: `method`, `path`, and `query` parameter matchers. When generating policies, prefer deny rules when the user needs broad access with a small set of blocked operations — it produces a shorter, more maintainable policy than enumerating 60+ allow rules.github_api:
name: github_api
endpoints:
- host: api.github.com
port: 443
protocol: rest
enforcement: enforce
access: read-write
deny_rules:
- method: POST
path: "/repos//pulls//reviews"
- method: PUT
path: "/repos//branches//protection"
- method: ""
path: "/repos//rulesets"
binaries:
- { path: /usr/bin/curl }
拒绝规则支持与允许规则相同的匹配能力:`method`、`path`和`query`参数匹配器。生成策略时,当用户需要宽泛访问但有少量操作需要阻止时,优先使用拒绝规则——与枚举60多条允许规则相比,这样生成的策略更短、更易维护。Private IP Destinations
私有IP目标
The proxy's SSRF protection treats private (RFC 1918) destinations differently depending on how the endpoint names its host:
- Exact hostname () — the connection may reach the private addresses the hostname resolves to without
host: api.internal.corp.allowed_ips - Wildcard host, hostless endpoint, or policy-advisor proposal — private resolved addresses are blocked unless covers them.
allowed_ips
Use to pin the addresses an endpoint may reach. When it is set, every resolved address must fall within the list, including public addresses:
allowed_ips- Host + allowlist: +
host— domain must resolve to an IP in the allowlistallowed_ips - Hostless allowlist: only (no
allowed_ips) — any domain on the port is allowed if it resolves to an IP in the allowlisthost
Loopback (), link-local (), unspecified, and cloud metadata addresses are always blocked regardless of .
127.0.0.0/8169.254.0.0/16allowed_ipsyaml
undefined代理的SSRF保护根据端点命名主机的方式,对私有(RFC 1918)目标有不同的处理方式:
- 精确主机名()——无需
host: api.internal.corp,连接即可到达主机名解析出的私有地址。allowed_ips - 通配符主机、无主机端点或策略顾问提议——除非覆盖,否则私有解析地址将被阻止。
allowed_ips
使用固定端点可以到达的地址。设置该字段后,所有解析出的地址(包括公共地址)都必须在列表范围内:
allowed_ips- 主机 + 白名单:+
host—— 域名必须解析为白名单中的IPallowed_ips - 无主机白名单:仅(无
allowed_ips)—— 该端口上的任何域名只要解析为白名单中的IP就被允许host
环回地址()、链路本地地址()、未指定地址和云元数据地址始终被阻止,无论如何配置。
127.0.0.0/8169.254.0.0/16allowed_ipsyaml
undefinedExample: Pin an internal service to a known private IP range
Example: Pin an internal service to a known private IP range
internal_api:
name: internal_api
endpoints:
- host: api.internal.corp
port: 8080
allowed_ips:
- "10.0.5.0/24"
binaries:
- { path: /usr/bin/curl }
undefinedinternal_api:
name: internal_api
endpoints:
- host: api.internal.corp
port: 8080
allowed_ips:
- "10.0.5.0/24"
binaries:
- { path: /usr/bin/curl }
undefinedPolicy Key Naming
策略键命名
Use descriptive snake_case keys: , , .
github_apinvidia_inferenceinternal_service_readonly使用具有描述性的snake_case键:、、。
github_apinvidia_inferenceinternal_service_readonlyMultiple Endpoints
多端点
If the user needs access to multiple hosts or the same host with different rules, either:
- Same policy — multiple entries in if the binary set is the same
endpoints - Separate policies — different policy keys if the binary sets differ
如果用户需要访问多个主机,或同一主机有不同规则,可以选择:
- 同一策略——如果二进制程序集合相同,在中添加多个条目
endpoints - 独立策略——如果二进制程序集合不同,使用不同的策略键
Step 6: Validate and Warn
步骤6:验证和警告
Before presenting the policy to the user, verify correctness and flag breadth concerns.
在向用户展示策略之前,验证正确性并标记范围过宽的问题。
Hard Errors (would block sandbox startup)
严重错误(会阻止沙箱启动)
- and
rulesare NOT both present on the same endpointaccess - If an L7 is set, either
protocolorrulesis also present;accessis L4-only and must not contain either fieldprotocol: tcp - Every endpoint has a valid DNS hostname; it is not hostless, an IP literal, a trailing-dot name, or a malformed DNS selector
protocol: tcp - is either omitted or set to
tls; no other value is acceptedskip - list is not empty when present
rules - Every middleware config has a non-empty name and non-empty
middlewareendpoints.include - Middleware values are unique and no selected chain exceeds 10 stages
order - No fail-closed middleware selector can cover a endpoint
tls: skip - Any required WebSocket control advertises , and the user understands that V1 does not inspect binary messages
WEBSOCKET_MESSAGE/PRE_CREDENTIALS - Any required response control advertises
HTTP_RESPONSE/PRE_RETURN - Endpoints contributed by a credentialed provider are not L4-only or unless
tls: skipexplicitly records the exceptionallow_uninspected_credentials: true
- 同一端点上不同时存在和
rulesaccess - 如果设置了L7 ,则必须同时存在
protocol或rules;access是仅L4模式,不得包含这两个字段中的任何一个protocol: tcp - 每个端点都有有效的DNS主机名;不能是无主机、IP字面量、带尾点的名称或格式错误的DNS选择器
protocol: tcp - 要么省略,要么设置为
tls;不接受其他值skip - 列表存在时不为空
rules - 每个中间件配置都有非空的名称和非空的
middlewareendpoints.include - 中间件值唯一,且所选链不超过10个阶段
order - 故障关闭的中间件选择器不得覆盖端点
tls: skip - 任何所需的WebSocket控制都声明了,且用户理解V1不检查二进制消息
WEBSOCKET_MESSAGE/PRE_CREDENTIALS - 任何所需的响应控制都声明了
HTTP_RESPONSE/PRE_RETURN - 由带凭证的提供商提供的端点不是仅L4模式或,除非
tls: skip显式记录了该例外allow_uninspected_credentials: true
Schema Warnings (log-only, but should be fixed)
Schema警告(仅记录,但应修复)
- is not combined with L7 rules on port 443; inspection cannot work on encrypted traffic
tls: skip - HTTP methods are standard: GET, HEAD, POST, PUT, DELETE, PATCH, OPTIONS, or
* - Credentialed destinations are also covered by the attached provider profile endpoint; policy admission alone does not authorize credential resolution
- 未与443端口的L7规则结合使用;检查无法在加密流量上工作
tls: skip - HTTP方法是标准的:GET、HEAD、POST、PUT、DELETE、PATCH、OPTIONS或
* - 带凭证的目标也被附加的提供商配置文件端点覆盖;仅策略准入并不授权凭证解析
Structural Checks
结构检查
- Every policy has ,
name, andendpointsbinaries - Every endpoint has and
hostport - Every binary has
path - Policy key matches field
name - Every middleware selector has at most 32 combined and
includepatternsexclude
- 每个策略都有、
name和endpointsbinaries - 每个端点都有和
hostport - 每个二进制程序都有
path - 策略键与字段匹配
name - 每个中间件选择器的和
include模式加起来最多32个exclude
Breadth Warnings
范围过宽警告
Evaluate the generated policy for overly broad access and include warnings in the output to the user. These do not block generation, but the user must see them.
| Condition | Warning to show |
|---|---|
L4-only (no | "This policy allows all application methods and paths. An omitted protocol uses explicit-proxy behavior and applies no method or path rules. With default TLS handling, the proxy terminates detected TLS and checks the authority of the HTTP requests it parses, but other CONNECT payloads, such as HTTP/2 prior knowledge or non-HTTP protocols, can pass through a raw relay; |
| "This policy allows all HTTP methods (including DELETE) on all paths. If you don't need DELETE, |
| "Full access in audit mode provides no actual restriction — all traffic flows through. This is effectively a monitoring-only policy." |
| "This policy allows POST, PUT, and PATCH on all paths. If you only need to read data, |
Wildcard binary ( | "This policy allows any binary matching the glob pattern. A compromised or unexpected binary in that directory could use this policy. Consider listing specific binary paths." |
| "All rules use |
| Multiple broad endpoints in one policy | "This policy grants the same broad access to N different hosts. If any of these hosts needs tighter restrictions later, you'll need to split the policy." |
Hostless | "This endpoint has no |
Broad CIDR in | "This |
| "This middleware can be bypassed when it is unavailable, rejects configuration, returns an invalid result, or exceeds its body limit. Use |
| Broad middleware host selector | "This middleware attaches independently of the admitting network rule to every matching destination, then runs only for operation bindings its implementation advertises. Narrow |
| "This endpoint may carry provider credentials on traffic OpenShell cannot inspect or rewrite. Prefer an inspected protocol and credential rewrite; keep this exception only when raw traffic is required." |
Format breadth warnings clearly in the output, e.g.:
⚠️ Breadth warning: This policy uses `access: full`, which allows all HTTP
methods (including DELETE) on all paths. If you don't need DELETE, consider
using `read-write` instead.If there are no breadth warnings, say so explicitly: "No breadth concerns — this policy is well-scoped."
评估生成的策略是否存在访问范围过宽的问题,并在输出中向用户包含警告。这些警告不会阻止生成,但用户必须看到。
| 条件 | 显示的警告 |
|---|---|
仅L4(无 | "此策略允许所有应用方法和路径。省略protocol时使用显式代理行为,不应用任何方法或路径规则。在默认TLS处理下,代理会终止检测到的TLS并检查其解析的HTTP请求的权威标识,但其他CONNECT负载(如HTTP/2先验知识或非HTTP协议)可以通过原始中继传递; |
| "此策略允许所有HTTP方法(包括DELETE)在所有路径上使用。如果您不需要DELETE, |
| "审计模式下的完全访问没有实际限制——所有流量都将通过。这实际上是一个仅监控的策略。" |
用户未确认写入需求时的** | "此策略允许在所有路径上使用POST、PUT和PATCH方法。如果您只需要读取数据, |
通配符二进制程序(二进制路径中包含 | "此策略允许任何匹配glob模式的二进制程序使用。该目录中被入侵或意外的二进制程序可能会使用此策略。考虑列出特定的二进制程序路径。" |
所有显式规则都使用 | "所有规则都使用 |
| 一个策略中有多个宽泛端点 | "此策略向N个不同的主机授予相同的宽泛访问权限。如果其中任何主机以后需要更严格的限制,您将需要拆分策略。" |
无主机 | "此端点没有 |
| "此 |
| "当中间件不可用、拒绝配置、返回无效结果或超出其主体限制时,可能会被绕过。除非可用性比此控制更重要,否则请使用 |
| 宽泛的中间件主机选择器 | "此中间件独立于准入网络规则附加到每个匹配的目标,然后仅针对其实现声明的操作绑定运行。如果不是每个匹配主机都需要附加,请缩小 |
| "此端点可能在OpenShell无法检查或重写的流量上携带提供商凭证。优先使用可检查的协议和凭证重写;仅在需要原始流量时才保留此例外。" |
在输出中清晰地格式化范围过宽警告,例如:
⚠️ Breadth warning: This policy uses `access: full`, which allows all HTTP
methods (including DELETE) on all paths. If you don't need DELETE, consider
using `read-write` instead.如果没有范围过宽警告,需明确说明:“无范围过宽问题——此策略范围合理。”
Step 7: Determine Output Mode
步骤7:确定输出模式
The policy needs to go somewhere. Determine which mode applies:
| Signal | Mode |
|---|---|
| User names an existing policy file (e.g., "add to my-sandbox-policy.yaml") | Update existing file |
| User says "update my policy", "add this to my policy file" | Update existing file — ask which file to update |
| User asks to modify an existing policy rule by name | Update existing file — edit the named policy in place |
| User says "create a new policy file" or names a file that doesn't exist | Create new file |
| No file context given | Present only — show the YAML and ask if the user wants it written to a file |
策略需要输出到某个位置,确定适用的模式:
| 信号 | 模式 |
|---|---|
| 用户指定了现有策略文件(例如“添加到my-sandbox-policy.yaml中”) | 更新现有文件 |
| 用户说“更新我的策略”、“把这个添加到我的策略文件中” | 更新现有文件 —— 询问要更新哪个文件 |
| 用户要求按名称修改现有策略规则 | 更新现有文件 —— 就地编辑指定的策略 |
| 用户说“创建新的策略文件”或指定了不存在的文件 | 创建新文件 |
| 未提供文件上下文 | 仅展示 —— 显示YAML并询问用户是否要写入文件 |
Mode A: Update an Existing Policy File
模式A:更新现有策略文件
-
Read the existing file to understand current state:
- What policies already exist under
network_policies - What the ,
filesystem_policy, andlandlocksections look likeprocess - Whether the file uses compact () or expanded YAML style
{ host: ..., port: ... }
- What policies already exist under
-
Check for conflicts:
- Does a policy with the same key already exist? If so, ask the user whether to replace it, merge new endpoints/binaries into it, or use a different key.
- Does an existing endpoint selector overlap the new selector? Compatible overlaps are allowed and can intentionally aggregate allow and deny rules. Reject or revise equally specific overlaps that disagree on connection or request-processing metadata, including TLS, destination constraints, protocol/parser behavior, enforcement, or credential handling. A more-specific path selector may override broader request-processing metadata.
- If the sandbox uses an attached provider credential, confirm the provider profile also declares the intended host, port, and path. A sandbox policy allow cannot expand the profile's static credential binding.
- For , confirm an attached endpoint-bearing profile declares
credential_signingandAWS_ACCESS_KEY_IDand covers the signed endpoint. For an endpointless AWS profile, addAWS_SECRET_ACCESS_KEYwith the exact attached provider name.credential_binding.provider
-
Apply the change:
- Adding a new policy: Insert the new policy block under , maintaining the file's existing indentation and style.
network_policies - Modifying an existing policy: Edit the specific policy in place — add/remove endpoints, change access presets, update rules, add binaries, etc. A rule authorizes every binary it lists to reach every endpoint and port it lists, so adding one binary grants it all of that rule's endpoints, and adding one endpoint grants it to all of that rule's binaries. State the resulting pairs to the user before writing them. When the user wants a binary to reach only part of a rule's endpoints, put that binary and those endpoints in a separate rule instead of extending the existing one. An empty list means any binary, so leaving it off widens the rule to every process.
binaries - Removing a policy: Delete the policy block if the user asks.
- Adding a new policy: Insert the new policy block under
-
Preserve everything else: Do not modify,
filesystem_policy,landlock, or other policies unless the user explicitly asks.process
-
读取现有文件以了解当前状态:
- 下已存在哪些策略
network_policies - 、
filesystem_policy和landlock部分的内容process - 文件使用紧凑式()还是展开式YAML风格
{ host: ..., port: ... }
-
检查冲突:
- 是否已存在相同键的策略?如果是,询问用户是要替换它、将新端点/二进制程序合并进去,还是使用不同的键。
- 现有端点选择器是否与新选择器重叠?兼容的重叠是允许的,并且可以有意地聚合允许和拒绝规则。对于在连接或请求处理元数据(包括TLS、目标约束、协议/解析器行为、执行模式或凭证处理)上存在分歧的同等具体的重叠,应拒绝或修改。更具体的路径选择器可以覆盖更宽泛的请求处理元数据。
- 如果沙箱使用附加的提供商凭证,请确认提供商配置文件也声明了预期的主机、端口和路径。沙箱策略允许不能扩展配置文件的静态凭证绑定。
- 对于,确认附加的带端点配置文件声明了
credential_signing和AWS_ACCESS_KEY_ID并覆盖已签名的端点。对于无端点的AWS配置文件,添加AWS_SECRET_ACCESS_KEY并使用附加提供商的确切名称。credential_binding.provider
-
应用更改:
- 添加新策略:在下插入新的策略块,保持文件现有的缩进和风格。
network_policies - 修改现有策略:就地编辑特定策略——添加/删除端点、更改访问预设、更新规则、添加二进制程序等。一条规则授权其列出的每个二进制程序访问其列出的每个端点和端口,因此添加一个二进制程序将授予其该规则的所有端点访问权限,添加一个端点将授予该规则的所有二进制程序访问权限。在写入之前,向用户说明最终的配对结果。当用户希望某个二进制程序仅访问规则的部分端点时,将该二进制程序和这些端点放在单独的规则中,而不是扩展现有规则。空的列表意味着任何二进制程序,因此省略该字段会将规则范围扩大到所有进程。
binaries - 删除策略:如果用户要求,删除策略块。
- 添加新策略:在
-
保留其他所有内容:除非用户明确要求,否则不要修改、
filesystem_policy、landlock或其他策略。process
Mode B: Create a New Policy File
模式B:创建新策略文件
Generate a complete, standalone policy file. Use the full schema scaffolding:
yaml
version: 1
filesystem_policy:
include_workdir: true
read_only:
- /usr
- /lib
- /proc
- /dev/urandom
- /app
- /etc
- /var/log
read_write:
- /tmp
- /dev/null
landlock:
compatibility: best_effort
network_policies:
# <generated policies go here>The and sections above are sensible defaults.
Process identity is omitted so the selected compute driver can choose it. For
Docker and Podman, each omitted identity field falls back to the image's OCI
. Tell the user these are defaults and may need adjustment for their
environment. Gateway inference is configured separately through . The generated block is the primary
output.
filesystem_policylandlockUSERopenshell inference set/getnetwork_policiesWhen the user explicitly requests or
, accept or a numeric UID/GID from through
. Reject root () and the invalid identity sentinel
(). Warn that a low numeric identity inherits permissions granted
to the same ID on image files, mounted volumes, or devices.
process.run_as_userprocess.run_as_groupsandbox1429496729404294967295If the user provides a file path, write to it. Otherwise, ask where to place it. A common convention is a project-local policy file (e.g., ) passed to or set via the env var.
sandbox-policy.yamlopenshell sandbox create --policy <path>OPENSHELL_SANDBOX_POLICY生成完整的独立策略文件,使用完整的Schema框架:
yaml
version: 1
filesystem_policy:
include_workdir: true
read_only:
- /usr
- /lib
- /proc
- /dev/urandom
- /app
- /etc
- /var/log
read_write:
- /tmp
- /dev/null
landlock:
compatibility: best_effort
network_policies:
# <generated policies go here>上述和部分是合理的默认值。进程标识被省略,以便所选的计算驱动程序可以选择。对于Docker和Podman,每个省略的标识字段都会回退到镜像的OCI 。告知用户这些是默认值,可能需要根据其环境进行调整。网关推理通过单独配置。生成的块是主要输出。
filesystem_policylandlockUSERopenshell inference set/getnetwork_policies当用户明确要求或时,接受或到之间的数字UID/GID。拒绝root()和无效标识哨兵值()。警告:低数字标识会继承授予镜像文件、挂载卷或设备上相同ID的权限。
process.run_as_userprocess.run_as_groupsandbox1429496729404294967295如果用户提供了文件路径,则写入该路径。否则,询问放置位置。常见的约定是项目本地的策略文件(例如),通过传递或通过环境变量设置。
sandbox-policy.yamlopenshell sandbox create --policy <path>OPENSHELL_SANDBOX_POLICYMode C: Present Only (no file write)
模式C:仅展示(不写入文件)
Show the generated policy YAML with:
- Summary — what the policy allows and denies, in plain language
- The YAML — the complete block, ready to paste
network_policies - Integration guidance:
- Save to a local file and pass via or set
openshell sandbox create --policy <path>OPENSHELL_SANDBOX_POLICY=<path> - For production: configure via the gateway
- Save to a local file and pass via
- Caveats — any assumptions made, anything the user should verify
展示生成的策略YAML,包含以下内容:
- 摘要 —— 用自然语言说明策略允许和拒绝的内容
- YAML内容 —— 完整的块,可直接粘贴
network_policies - 集成指南:
- 保存到本地文件,通过传递,或设置
openshell sandbox create --policy <path>OPENSHELL_SANDBOX_POLICY=<path> - 生产环境:通过网关配置
- 保存到本地文件,通过
- 注意事项 —— 所做的任何假设,用户需要验证的内容
Step 8: Confirm and Refine
步骤8:确认和优化
After presenting or applying the policy, ask if the user wants to:
- Tighten or loosen any rules
- Add more endpoints or binaries
- Switch between enforce/audit mode
- Move from a preset to explicit rules (or vice versa)
- Apply the policy to a file (if presented only)
- Create additional policies for other APIs
在展示或应用策略后,询问用户是否想要:
- 收紧或放宽任何规则
- 添加更多端点或二进制程序
- 在强制/审计模式之间切换
- 从预设切换到显式规则(或反之)
- 将策略应用到文件(如果仅展示)
- 为其他API创建额外的策略
Quick Reference: Common Patterns
快速参考:常见模式
L4-Only (no method or path rules)
仅L4(无方法或路径规则)
yaml
my_api:
name: my_api
endpoints:
- { host: api.example.com, port: 443 }
binaries:
- { path: /usr/bin/curl }yaml
my_api:
name: my_api
endpoints:
- { host: api.example.com, port: 443 }
binaries:
- { path: /usr/bin/curl }HTTPS API with Read-Only Preset
带只读预设的HTTPS API
yaml
my_api_readonly:
name: my_api_readonly
endpoints:
- host: api.example.com
port: 443
protocol: rest
enforcement: enforce
access: read-only
binaries:
- { path: /usr/bin/curl }yaml
my_api_readonly:
name: my_api_readonly
endpoints:
- host: api.example.com
port: 443
protocol: rest
enforcement: enforce
access: read-only
binaries:
- { path: /usr/bin/curl }HTTPS API with Explicit Rules
带显式规则的HTTPS API
yaml
my_api_custom:
name: my_api_custom
endpoints:
- host: api.example.com
port: 443
protocol: rest
enforcement: enforce
rules:
- allow:
method: GET
path: "/api/v1/**"
- allow:
method: POST
path: "/api/v1/data"
binaries:
- { path: /usr/bin/curl }
- { path: /usr/local/bin/myapp }yaml
my_api_custom:
name: my_api_custom
endpoints:
- host: api.example.com
port: 443
protocol: rest
enforcement: enforce
rules:
- allow:
method: GET
path: "/api/v1/**"
- allow:
method: POST
path: "/api/v1/data"
binaries:
- { path: /usr/bin/curl }
- { path: /usr/local/bin/myapp }HTTP (non-TLS) Internal API
HTTP(非TLS)内部API
yaml
internal_svc:
name: internal_svc
endpoints:
- host: api.internal.svc
port: 8080
protocol: rest
enforcement: enforce
rules:
- allow:
method: GET
path: "/health"
- allow:
method: POST
path: "/api/v1/jobs"
binaries:
- { path: /usr/bin/curl }yaml
internal_svc:
name: internal_svc
endpoints:
- host: api.internal.svc
port: 8080
protocol: rest
enforcement: enforce
rules:
- allow:
method: GET
path: "/health"
- allow:
method: POST
path: "/api/v1/jobs"
binaries:
- { path: /usr/bin/curl }Private IP Access (Host + Allowlist)
私有IP访问(主机 + 白名单)
yaml
internal_db:
name: internal_db
endpoints:
- host: db.internal.corp
port: 5432
allowed_ips:
- "10.0.5.0/24"
binaries:
- { path: /usr/bin/curl }yaml
internal_db:
name: internal_db
endpoints:
- host: db.internal.corp
port: 5432
allowed_ips:
- "10.0.5.0/24"
binaries:
- { path: /usr/bin/curl }Private IP Access (Hostless — Any Domain in Range)
私有IP访问(无主机 —— 范围内任意域名)
yaml
private_services:
name: private_services
endpoints:
- port: 8080
allowed_ips:
- "10.0.5.0/24"
- "10.0.6.0/24"
binaries:
- { path: /usr/bin/curl }yaml
private_services:
name: private_services
endpoints:
- port: 8080
allowed_ips:
- "10.0.5.0/24"
- "10.0.6.0/24"
binaries:
- { path: /usr/bin/curl }Additional Resources
其他资源
- Policy schema
- Sandbox policies
- Default policy
- Supervisor middleware
- Default policy: built into the OpenShell runtime
- For translation examples from real API docs, see examples.md
- 策略Schema
- 沙箱策略
- 默认策略
- Supervisor中间件
- 默认策略:内置在OpenShell运行时中
- 有关来自真实API文档的转换示例,请参阅examples.md