Skip to navigation

Write Sandbox Policies in Cedar

View as MarkdownOpen in Claude

A sandbox policy can be written in Cedar instead of YAML. Cedar then decides every network connection, every inspected HTTP or JSON-RPC request, and the filesystem paths Landlock allows. A sandbox uses one format for its whole lifetime: YAML policies are evaluated by the built-in Rego engine, and Cedar policies by Cedar.

Cedar’s restricted language makes policies easier to analyze, for example to check that a revision grants no more access than the one it replaces. OpenShell accepts only Cedar policy shapes it can enforce exactly as written, and rejects the rest when you submit the policy.

Cedar policies are available only in development builds. Stable and prerelease gateways and supervisors reject them. The gateway validates Cedar policies and the supervisor enforces them. OpenShell tests Cedar end to end on the Docker runtime.

Apply a Cedar Policy

OpenShell treats a policy file as Cedar when its extension is .cedar, in any case. Any other extension is parsed as YAML.

Host selectors, including host globs, must not exceed 253 bytes.

The gateway and the sandbox supervisor must both be built with Cedar support. A gateway built without Cedar rejects Cedar policies on sandbox create and policy update; the CLI displays the gateway error. If it runs on state that already holds Cedar sandboxes, for example after you switch from a development build to a stable one, it refuses to start those sandboxes, deliver their configuration, change their policy or providers, or show their policy. Delete them with openshell sandbox delete, or switch back to a development build. A gateway with Cedar support does not deliver a Cedar policy to a supervisor without it. Stable CLIs read, send, and show Cedar policies, but only a gateway with Cedar support accepts them. Gateways predating Cedar support may ignore Cedar fields instead of rejecting them, so use a development gateway and supervisor that support Cedar.

To build Cedar support from source, enable the experimental feature bundle in both binaries:

cargo build -p openshell-gateway -p openshell-supervisor --features experimental

Deploy both binaries using your runtime’s normal configuration, or use published Release Dev artifacts. Local gateway and image build tasks do not automatically enable Cedar.

Create a sandbox with a Cedar policy:

openshell sandbox create --policy ./policy.cedar -- claude

Replace the policy on a running sandbox:

openshell policy set <name> --policy ./policy.cedar --wait

The CLI sends the file’s text to the gateway, which validates it and rejects an invalid policy with the reason. If the sandbox cannot load a revision, the policy_validation_failure_mode setting applies as it does for YAML policies. Refer to Manage Policies.

openshell policy get <name> prints the Cedar text of a Cedar sandbox’s policy.

The CLI does not currently configure middleware, endpoint settings, or a custom process identity for Cedar policies. YAML policies retain their existing configuration sections.

Policy Model

Every policy is evaluated against a fixed schema in the Sandbox namespace. The principal is always a Sandbox::Process. Sandbox identity attributes are not yet available to policies: every request carries the same placeholder user and group, so OpenShell rejects a policy that reads principal.user or principal.group. Every request is also evaluated as the same placeholder process, so OpenShell rejects a policy that tests which process the principal is, such as principal == Sandbox::Process::"..." or principal in ... in its scope or conditions. Write principal or principal is Sandbox::Process.

ActionResourceContext fieldsDecides
ReadFile, WriteFileFilesystemPathnoneLandlock grants, fixed at sandbox start.
NetworkConnectNetworkEndpointbinary_path, ancestors, binary_aliases, binary_globs, and optional destination_ipWhether a process may open a connection, and to which resolved addresses.
HttpRequestNetworkEndpointbinary_path, ancestors, binary_aliases, binary_globs, method, path, query, and the protocol fields belowEach request on an inspected connection.

A NetworkEndpoint id is "host:port", with a lowercase host. NetworkConnect has no method, path, or command, because no request has been read at connect time, so a connection policy that reads one fails validation. Put method and path conditions on HttpRequest. A policy with action in [Sandbox::Action::"NetworkConnect", Sandbox::Action::"HttpRequest"] that reads them also fails validation; split it into one policy per action. A has test of an attribute the schema does not declare, such as principal has workdir or context has method on NetworkConnect, could never hold and is rejected as well.

This example grants filesystem access, allows curl to connect to the GitHub API, and inspects each request on that connection:

permit (
principal is Sandbox::Process,
action in [Sandbox::Action::"ReadFile", Sandbox::Action::"WriteFile"],
resource is Sandbox::FilesystemPath
)
when { resource in Sandbox::FilesystemPath::"/sandbox" || resource in Sandbox::FilesystemPath::"/tmp" };
permit (
principal is Sandbox::Process,
action == Sandbox::Action::"ReadFile",
resource in Sandbox::FilesystemPath::"/usr"
);
permit (
principal is Sandbox::Process,
action == Sandbox::Action::"NetworkConnect",
resource == Sandbox::NetworkEndpoint::"api.github.com:443"
)
when { context.binary_path == "/usr/bin/curl" };
permit (
principal is Sandbox::Process,
action == Sandbox::Action::"HttpRequest",
resource == Sandbox::NetworkEndpoint::"api.github.com:443"
)
when { context.method == "GET" && context.path like("/repos/*/*", "/") };

Filesystem Rules

Landlock applies a flat allow-list of path subtrees when the sandbox starts, so OpenShell accepts only filesystem policies that mean exactly that. A policy that can apply to ReadFile or WriteFile must:

  • Be a permit. A forbid that can apply to files is rejected.
  • List only ReadFile and WriteFile in its action scope.
  • Use principal or principal is Sandbox::Process.
  • Name paths with resource in Sandbox::FilesystemPath::"/path", either in the scope or in a single when clause that only joins such tests with ||.

resource == is rejected because Landlock grants the whole subtree under a directory. Paths must be absolute, must not contain .., and / cannot be granted write access. A Landlock read-write grant includes read, so a policy that lists WriteFile must also list ReadFile; a policy that lists WriteFile alone is rejected.

As for a YAML policy with network rules, the supervisor adds its baseline runtime paths when a policy can permit NetworkConnect. A policy with no NetworkConnect permit and no filesystem permits applies no Landlock ruleset, like a YAML policy with no network rules and no filesystem paths. On a running sandbox, a policy update can add filesystem paths but cannot remove them, because Landlock cannot revoke access from a running process.

Network Rules

Cedar evaluates NetworkConnect for every outbound connection, with the calling binary in context.binary_path and its ancestors in context.ancestors. Conditions on these actions are evaluated by Cedar as written.

Cedar compares context.binary_path exactly, and the kernel reports the resolved executable, such as /usr/bin/python3.12, not a symlink such as /usr/bin/python3. To match a binary the way a YAML binary path matches it, symlink included, test all three fields:

permit (
principal is Sandbox::Process,
action == Sandbox::Action::"NetworkConnect",
resource == Sandbox::NetworkEndpoint::"pypi.org:443"
)
when {
context.binary_path == "/usr/bin/python3"
|| context.ancestors.contains("/usr/bin/python3")
|| context.binary_aliases.contains("/usr/bin/python3")
};

context.binary_aliases holds each path your policies test with .contains, .containsAny, or .containsAll that is a symlink in the sandbox resolving to the calling binary or one of its ancestors. The supervisor resolves these paths inside the sandbox once the entrypoint process starts, and again on each policy update, as it resolves YAML binary paths. Until then the set is empty, so a policy that needs it matches only the literal path. Paths must be literal absolute paths without *: like YAML, OpenShell never resolves a glob such as context.binary_path like("/usr/lib/postgresql/*/bin/psql", "/").

A YAML binary glob, such as /usr/lib/node_modules/@openai/**, matches the calling binary or any of its ancestors. context.binary_path like("/usr/lib/node_modules/@openai/**", "/") matches only the calling binary, because like tests one string, so write the glob as a member of context.binary_globs, which OpenShell matches against the binary and every ancestor:

permit (
principal is Sandbox::Process,
action == Sandbox::Action::"NetworkConnect",
resource == Sandbox::NetworkEndpoint::"api.openai.com:443"
)
when { context.binary_globs.contains("/usr/lib/node_modules/@openai/**") };

context.binary_globs holds each pattern your policies test with .contains, .containsAny, or .containsAll that matches the calling binary or one of its ancestors, with the matcher YAML applies to binary globs: * matches within one path segment, and ** matches across segments as a whole segment. Patterns must be literal absolute paths that contain * and are valid globs; OpenShell rejects any other use of the set.

Globs

Write globs with a delimiter, as like("pattern", "delimiter"). With a delimiter, * matches within one segment and ** matches across segments, as in YAML policies. Use "." for hosts and "/" for paths. Without a delimiter, like treats every * as matching across segments, so context.path like "/repos/*" also matches /repos/a/b/c.

In a delimited pattern, write ** only as a whole segment, such as /files/** or **.example.com. YAML reads a ** next to other characters, as in /files/report**, as * within one segment, while Cedar’s ** crosses segments, so OpenShell rejects such a pattern. Write * for the YAML meaning.

permit (
principal is Sandbox::Process,
action == Sandbox::Action::"NetworkConnect",
resource is Sandbox::NetworkEndpoint
)
when {
resource.host like("*.example.com", ".")
&& resource.port == 443
&& context.binary_path == "/usr/bin/curl"
};

Policy DNS

Policy DNS resolves a host when a NetworkConnect permit names it in its scope, such as resource == Sandbox::NetworkEndpoint::"pypi.org:443", or requires both the host and the port in its when conditions, as in the example above. The host condition can be an exact string or a host glob with a . delimiter that follows the YAML wildcard host rules: * or ** as the whole first label, * within the first label, * as a whole later label, and no wildcard top-level domain such as *.com. A when condition resource.host_port == "pypi.org:443", or ["pypi.org:443"].contains(resource.host_port) with one element, names the host and port together; the literal must be valid the way a scope literal is, with a lowercase host and a port, or the policy is rejected. A host_port set with several elements does not make its hosts eligible. Policy DNS does not resolve any other host, so the connection fails closed.

A host named exactly may resolve to a private address. A host matched by a glob may not, unless an allowing permit names it exactly or restricts its addresses.

Destination Addresses

context.destination_ip is the Cedar form of YAML allowed_ips. A NetworkConnect permit can require each address the host resolves to to lie in fixed ranges:

permit (
principal is Sandbox::Process,
action == Sandbox::Action::"NetworkConnect",
resource == Sandbox::NetworkEndpoint::"my-service.corp.net:8080"
)
when {
context.binary_path == "/usr/bin/curl"
&& context has destination_ip
&& context.destination_ip.isInRange(ip("10.0.5.0/24"))
};

Leave out the host to allow any host on the port whose addresses are in range, like a YAML endpoint with allowed_ips and no host. Such a permit does not make a host eligible for policy DNS.

OpenShell decides a connection twice. Before the host resolves, destination_ip is absent, and a permit counts as if its address conditions held. After the host resolves, Cedar decides again for each address, and every address must pass. Policy DNS drops answers outside a permit’s ranges.

An address is admitted only when:

  • It is not loopback, link-local (including cloud metadata), or unspecified. These stay blocked regardless of policy.
  • Every allowing permit with a destination_ip condition includes it.
  • For a private address, an allowing permit names the host exactly, or every allowing permit has a destination_ip condition. A permit without one admits only public addresses unless it names the host.
  • Every attached provider endpoint for the host and port that sets allowed_ips includes it. Provider ranges only narrow; they never admit an address the Cedar policy rejects.

Control-plane ports, such as 6443 and 2379, are blocked unless only public-only permits allow the connection and no matching provider endpoint sets allowed_ips, as in YAML.

When the operator sets proxy_connect_by_hostname, the upstream proxy resolves the host again, so destination_ip checks do not bind the address it connects to. YAML allowed_ips has the same limitation.

A permit must write its address condition as a top-level when conjunct: context has destination_ip, or isInRange tests joined with ||. Conditions in that form intersect. OpenShell rejects a permit that reads destination_ip in any other form, a range that overlaps loopback, link-local, or unspecified addresses, and any policy that reads destination_ip without exactly the NetworkConnect action in its scope.

A forbid takes part in both decisions as written. Before the host resolves, the address is absent and the context has destination_ip guard is false, so only the forbid’s other conditions can deny; after it resolves, the forbid applies again to each address. A forbid such as when { context.binary_path == "/usr/bin/curl" || (context has destination_ip && context.destination_ip.isInRange(ip("10.0.0.0/8"))) } therefore denies curl at connect time, which matters with proxy_connect_by_hostname, and denies private addresses for every other binary once the host resolves.

A forbid may read destination_ip only in when conditions, inside && chains that include context has destination_ip and are joined to the rest of the condition only by && and ||, or anywhere once a when condition has the guard as a top-level && conjunct. OpenShell rejects other forms, such as an unless body or a negated guard, because the absent address would make the forbid deny every connection it covers at connect time. To deny addresses outside a range, write when { context has destination_ip && !context.destination_ip.isInRange(ip("10.0.0.0/8")) }.

Native TCP

Add @transport("tcp") to a NetworkConnect permit to mark its endpoint as native TCP, like a YAML endpoint with protocol: tcp. The connection is allowed as plain L4 traffic and never inspected per request.

@transport("tcp")
permit (
principal is Sandbox::Process,
action == Sandbox::Action::"NetworkConnect",
resource == Sandbox::NetworkEndpoint::"db.example.com:5432"
)
when { context.binary_path == "/usr/bin/psql" };

As in YAML, OpenShell rejects a native TCP endpoint that:

  • Names an IP address or an invalid DNS host. Native TCP reaches hosts through policy DNS.
  • Names no host and port the way Policy DNS requires.
  • Overlaps, on a host and port, an endpoint that an HttpRequest policy inspects or that another NetworkConnect permit names without @transport("tcp"). Host globs overlap when some host matches both. A permit without @transport("tcp") whose host cannot be derived the way Policy DNS requires may allow any host, so OpenShell rejects it when a native TCP endpoint shares a port it may allow, or when it names no port either.

@transport applies only to permit policies whose action scope is exactly NetworkConnect.

Request Rules

The proxy decides at connect time whether to inspect a connection request by request. It inspects every endpoint that an HttpRequest policy names, whether the policy is a permit or a forbid, unless the policy is staged. An HttpRequest policy that names no endpoint is rejected, because the proxy could not tell which connections it applies to.

Cedar denies by default. Once any HttpRequest policy names an endpoint, each request to that endpoint needs a matching permit.

Wildcard hosts

Name an endpoint exactly in the scope, as resource == Sandbox::NetworkEndpoint::"api.example.com:443", or name a wildcard host in the when conditions with resource is Sandbox::NetworkEndpoint in the scope. A wildcard host inspects every host it matches, like a YAML endpoint host: "*.example.com" with request rules. Write it as exactly one host glob with a . delimiter and one port, each a top-level && operand, following the Policy DNS host rules:

permit (
principal is Sandbox::Process,
action == Sandbox::Action::"HttpRequest",
resource is Sandbox::NetworkEndpoint
)
when {
resource.host like("*.example.com", ".")
&& resource.port == 443
&& context.method == "GET"
};

Any other way of naming the host, such as an undelimited like, a wildcard top-level domain, two hosts joined with ||, or a glob without a port, is rejected. The request’s NetworkEndpoint is the actual host and port, so the glob condition decides the request as written. OpenShell denies a connection or request to a host with an empty label, such as .example.com or a..example.com, because no wildcard host inspects it.

A host matched by an exact endpoint and a wildcard host, or by two wildcard hosts, is inspected with the paths of all of them, and each request is routed to the most specific matching path, as for YAML endpoints sharing a host and port. Two such endpoints must inspect equally specific paths that can match the same request with the same protocol and enforcement, as YAML rejects overlapping endpoints that disagree. Comparing hosts has a fixed work budget, so a policy with hundreds of long, similar wildcard hosts on one port is rejected; wildcard hosts with different last labels are never compared.

Endpoints are parsed as REST by default. Add @protocol("json-rpc"), @protocol("mcp"), @protocol("graphql"), @protocol("websocket"), or @protocol("websocket-graphql") to an HttpRequest policy to inspect that protocol instead. All policies that declare a protocol for one endpoint path must agree. @protocol("sql") is rejected, because OpenShell does not inspect SQL traffic.

Fields that do not apply to a request are empty strings, false, or empty sets.

ProtocolContext fields
RESTmethod, path
JSON-RPCjsonrpc_method, jsonrpc_response
MCPjsonrpc_method, mcp_tool, mcp_method_class, jsonrpc_receive_stream, jsonrpc_response
GraphQLgraphql_operation_type, graphql_operation_name, graphql_fields
WebSocketmethod, path
GraphQL over WebSocketmethod, path, and the GraphQL fields

context.method is always uppercase. Unlike YAML, a GET condition does not also allow HEAD, so list HEAD when you want it allowed.

For JSON-RPC and MCP, each call is evaluated on its own, and method is empty for a call. OpenShell denies a request that fails JSON-RPC inspection, and a call or response frame that is not sent with POST, before evaluating it.

resource.protocol is the protocol a request is inspected with, such as "graphql" or "websocket-graphql". On NetworkConnect it is the protocol of the policies without @path, or empty.

Paths

Add @path("pattern") to HttpRequest policies to inspect one path of an endpoint with its own protocol and enforcement, as YAML endpoints that share a host and port do. The pattern uses the YAML endpoint path syntax: it starts with / or is **, /prefix/** matches /prefix and everything below it, and other patterns are globs. Each request is inspected as the most specific matching path declares, and policies without @path declare the inspection of every other path. When the policies name only paths, OpenShell denies a request that matches none of them.

@path chooses how a request is parsed and enforced, not which policies apply to it. Every policy for the endpoint is evaluated for every request, so write the path in the policy’s conditions:

@path("/repos/**")
permit (
principal is Sandbox::Process,
action == Sandbox::Action::"HttpRequest",
resource == Sandbox::NetworkEndpoint::"api.github.com:443"
)
when { context.method == "GET" && context.path like("/repos/**", "/") };
@path("/graphql")
@protocol("graphql")
permit (
principal is Sandbox::Process,
action == Sandbox::Action::"HttpRequest",
resource == Sandbox::NetworkEndpoint::"api.github.com:443"
)
when { context.path == "/graphql" && context.graphql_operation_type == "query" };

A YAML GraphQL endpoint is authoritative for the requests it parses, so a broader REST rule never allows a GraphQL operation. Cedar applies the same rule: for a request parsed as GraphQL on a graphql or websocket-graphql path, permits attached to other paths of the endpoint that neither read a graphql_* field nor test resource.protocol are left out of the decision. In the example above, the /repos/** permit never allows an operation on /graphql, while a permit that reads context.graphql_operation_type or tests resource.protocol applies wherever it is written. Forbids always apply. Two equally specific paths that can match the same request must declare the same protocol and enforcement.

Query Parameters

context.query holds the request’s decoded query parameters as tags, one per key. Check that a key is present with hasTag before reading its value with getTag. YAML query globs treat . as a delimiter, so write the same globs with like("pattern", "."):

permit (
principal is Sandbox::Process,
action == Sandbox::Action::"HttpRequest",
resource == Sandbox::NetworkEndpoint::"api.example.com:443"
)
when {
context.method == "GET" && context.path == "/download"
&& context.query.hasTag("tag") && context.query.getTag("tag") like("foo-*", ".")
};
forbid (
principal is Sandbox::Process,
action == Sandbox::Action::"HttpRequest",
resource == Sandbox::NetworkEndpoint::"api.example.com:443"
)
when { context.query.hasTag("force") && context.query.getTag("force") == "true" };

When a key repeats, as in ?tag=foo-a&tag=foo-b, OpenShell evaluates the request once for each combination of values. It allows the request only if no evaluation is denied and one permit allows every evaluation. This matches YAML: a permit must accept every value of each key it reads, and a forbid applies when each key it reads has one matching value. Write each YAML allow rule as its own permit, because two rules joined with || in one permit can together allow values that neither rule allows alone. OpenShell denies a request with too many combinations of the keys that deciding policies read; see Limitations. Staged policies have a separate comparison budget; exceeding it or encountering an evaluation error skips the staged comparison and preserves the enforced decision.

MCP

mcp_tool is the tool name of a tools/call request. mcp_method_class is available for a core method of the selected MCP revision, and extension for any other method. An MCP endpoint does not allow its receive stream or client response frames by itself, so permit them explicitly. The endpoint accepts the YAML default revision, 2025-11-25, unless the policy API supplies other revisions.

@protocol("mcp")
permit (
principal is Sandbox::Process,
action == Sandbox::Action::"HttpRequest",
resource == Sandbox::NetworkEndpoint::"mcp.example.com:443"
)
when {
context.path == "/mcp"
&& context.mcp_method_class == "available"
&& (["initialize", "tools/list"].contains(context.jsonrpc_method)
|| (context.jsonrpc_method == "tools/call" && context.mcp_tool like("github.*", ".")))
};
permit (
principal is Sandbox::Process,
action == Sandbox::Action::"HttpRequest",
resource == Sandbox::NetworkEndpoint::"mcp.example.com:443"
)
when {
context.path == "/mcp"
&& ((context.method == "GET" && context.jsonrpc_receive_stream) || context.jsonrpc_response)
};

GraphQL

OpenShell evaluates each operation in a request separately and denies the request if any operation is denied. graphql_operation_type is lowercase. Cedar policies created through the CLI do not configure a persisted-query registry, so hash-only persisted queries are denied. The policy API can supply a registry and enable registered queries with persisted_queries: allow_registered. Match exact field names with containsAll and containsAny:

@protocol("graphql")
permit (
principal is Sandbox::Process,
action == Sandbox::Action::"HttpRequest",
resource == Sandbox::NetworkEndpoint::"api.github.com:443"
)
when {
context.path == "/graphql"
&& (context.graphql_operation_type == "query"
|| (context.graphql_operation_type == "mutation"
&& context.graphql_fields.containsAny(["createIssue", "commentOnIssue"])
&& ["createIssue", "commentOnIssue"].containsAll(context.graphql_fields)))
};

Field globs, such as YAML fields: ["create*"], cannot be written, because they need every field to match a pattern. Operation name globs work with like.

WebSocket

On a @protocol("websocket") endpoint, the upgrade is a GET request, and each client text message is evaluated with method WEBSOCKET_TEXT and the path of the upgrade. A request that is not a WebSocket upgrade is denied. A message that Cedar denies closes the connection, or is logged and forwarded on an audit endpoint.

@protocol("websocket-graphql") is a WebSocket endpoint whose client messages carry GraphQL operations, as a YAML WebSocket endpoint with GraphQL operation rules. Each operation message is evaluated with method WEBSOCKET_TEXT, the upgrade path, and the GraphQL fields. Control messages such as connection_init and ping pass without evaluation, and a message that is not a valid GraphQL-over-WebSocket client message is denied:

@path("/graphql")
@protocol("websocket-graphql")
permit (
principal is Sandbox::Process,
action == Sandbox::Action::"HttpRequest",
resource == Sandbox::NetworkEndpoint::"realtime.example.com:443"
)
when {
context.path == "/graphql"
&& (context.method == "GET"
|| (context.graphql_operation_type == "subscription"
&& ["messageAdded"].containsAll(context.graphql_fields)))
};

A permit that allows a WEBSOCKET_TEXT message on a websocket-graphql path without a GraphQL condition would allow every GraphQL operation, so OpenShell rejects it, as YAML rejects a generic WEBSOCKET_TEXT rule there. Condition message permits on the GraphQL fields, and permit the upgrade alone with context.method == "GET".

Audit Mode

Add @enforcement("audit") to an HttpRequest policy to make it an audit policy, the Cedar form of a YAML enforcement: audit endpoint. The policy’s action scope must be exactly HttpRequest.

When every deciding HttpRequest policy for an endpoint path is an audit policy, that path runs in audit mode: OpenShell logs a request its policies deny with decision audit and forwards it. Policies with @path set the mode of their path, and policies without it set the mode of the path-less endpoint. Audit policies still decide requests like enforced ones, on every path of their endpoint: as YAML applies the rules of every matching endpoint, an audit policy’s forbid blocks a request routed to an enforced path of the same host:port, and its permit allows one. The routed path’s mode alone decides whether a denial blocks, even when the denying policy is an enforced one attached to another path, or to another endpoint that selects the same host, such as a wildcard host. OpenShell warns when it loads or validates a policy with an audit path beside enforced policies of the same host and port or of such an endpoint.

Add @enforcement("staged") to try a policy without changing anything. A staged policy never changes a path’s mode and never takes part in a decision. OpenShell logs each request whose decision it would change, with cedar_audit:staged_deny or cedar_audit:staged_allow and the policies that would decide it. Only deciding policies make an endpoint inspected or declare its paths and protocols, so a staged policy is evaluated on the requests that deciding HttpRequest policies inspect, as they parse and route them. OpenShell warns when a staged policy names an endpoint that no deciding HttpRequest policy inspects, because it is never evaluated, and when it declares a @path or @protocol that no deciding policy declares for its endpoint. Use a staged forbid to see what a new restriction would block before you enforce it:

@enforcement("staged")
@id("no-webhook-changes")
forbid (
principal is Sandbox::Process,
action == Sandbox::Action::"HttpRequest",
resource == Sandbox::NetworkEndpoint::"api.github.com:443"
)
when { context.path like("/repos/*/*/hooks/**", "/") };

Logs name policies by their @id annotation when they have one.

Providers and Credentials

Providers attached to a Cedar sandbox supply credentials but never grant access. The Cedar policy alone decides which endpoints a process can reach and which addresses they may resolve to. A provider endpoint’s allowed_ips can only narrow the addresses its connections reach (see Destination Addresses), and a provider endpoint without a host supplies no credentials. Attaching a provider makes its credentials available on connections that Cedar already allows to the provider’s endpoints, with the provider’s credential settings, such as request signing and body rewriting.

A provider endpoint that carries credentials must be inspected per request, so write an HttpRequest policy for it. OpenShell refuses connections to a credentialed endpoint that Cedar does not inspect, unless the provider allows uninspected credentials.

A provider’s token grant applies to a request only when Cedar allows the request and the provider’s own endpoint also allows it under the provider’s rules, as in a YAML sandbox. OpenShell compiles the provider rules to Cedar and evaluates them with the same request, and any provider’s deny rule withholds every token. Provider rules can only withhold a token; they never allow a request that Cedar denies. A request denied on an audit path gets no token.

A few provider rule forms cannot be expressed in Cedar, and OpenShell compiles them so they withhold tokens rather than grant them: allow rules with ? in a glob, GraphQL fields globs, or an endpoint path glob other than * or a trailing /** grant no token, and deny rules with them withhold tokens more broadly; and a glob with [, {, or \ withholds every token. The sandbox logs each such rule when it loads the policy. JSON-RPC requests whose method is not uppercase and hash-only GraphQL persisted queries also get no token.

Use openshell policy get <name> --full --output json to inspect the provider credential rules delivered to the sandbox. --base omits provider-derived rules.

permit (
principal is Sandbox::Process,
action == Sandbox::Action::"NetworkConnect",
resource == Sandbox::NetworkEndpoint::"api.github.com:443"
)
when { context.binary_path == "/usr/bin/gh" };
permit (
principal is Sandbox::Process,
action == Sandbox::Action::"HttpRequest",
resource == Sandbox::NetworkEndpoint::"api.github.com:443"
)
when { context.method == "GET" };

Limitations

  • A sandbox cannot switch between YAML and Cedar after creation. Recreate the sandbox to change formats.
  • Global policies must be YAML.
  • Incremental openshell policy update merges are not available for Cedar policies. Use openshell policy set with the full policy.
  • Policy templates are not supported.
  • A policy cannot nest brackets more than 64 deep or chain more than 1,024 operators in one policy. Replace a long || chain with a set literal such as ["a", "b"].contains(context.path), or split the policy.
  • A request whose path, query key or value, method, or other inspected field is longer than 16 KiB is denied.
  • A request whose repeated query values have more than 4,096 combinations, or more than 16,384 divided by the number of policies, is denied, because each combination evaluates every policy. With 201 policies, the limit is 81 combinations.

Next Steps