Skip to content

Latest commit

 

History

History
171 lines (114 loc) · 7.62 KB

DIRECTIVES.md

File metadata and controls

171 lines (114 loc) · 7.62 KB

@openshell directives

A directive is a source comment whose text starts with @openshell. It must be the first thing in the comment line (after the comment leader), so prose that merely mentions @openshell is ignored. Unknown directives and attributes are errors, mirroring OpenShell's strict schema.

Grammar

directive = "@openshell" , ws , body ;
body      = egress | provider | fs | bin | process | ignore ;
egress    = "egress" , ws , target , { ws , attr } ;
target    = host , ":" , ports ;            (* port is mandatory *)
ports     = port , { "," , port } ;
provider  = "provider" , ws , env-name , { ws , attr } ;
fs        = "fs" , ws , ( "read" | "write" ) , ws , path , { ws , attr } ;
bin       = "bin" , ws , path , { ws , attr } ;
process   = "process" , { ws , attr } ;
ignore    = "ignore" , { ws , attr } ;
attr      = key , "=" , value ;
value     = bare | '"' , { any - '"' | '\"' } , '"' ;

Values containing spaces must be quoted: reason="LLM calls". Absolute paths may contain =.

Directives

Directive Summary reason Lint category
egress Allow outbound network access to a host and port(s). required net
provider Declare that an environment variable is a credential supplied by an OpenShell provider. optional env
fs Grant filesystem access inside the sandbox. required fs (write only)
bin Set the binary allowed to use the egress rules in this file. optional exec
process Choose the identity the sandboxed process runs as. optional -
ignore Tell lint that a call site needs no policy entry (or that a denial is declined on purpose). required the category named by kind

Attributes accepted by every directive

Attribute Values Repeatable Meaning
reason text no Why this is needed. Becomes the comment above the generated entry; required where marked.
scope file | next no file makes the directive cover the whole file for lint; the default covers the call sites within [lint] window lines below it.

egress

Allow outbound network access to a host and port(s).

@openshell egress <host>:<port>[,<port>...] reason="..." [access=read-only|read-write|full] [protocol=rest|...] [allow="METHOD:/path"]... [bin=/path] [rule=name] [enforce=enforce|audit] [tls=skip]

Arguments:

  • host:port[,port...]: Destination. A port is mandatory (OpenShell rejects endpoints without one); the host is lower-cased.

Attributes:

Attribute Values Repeatable Meaning
access read-only | read-write | full no OpenShell access preset; turns on request inspection (protocol defaults to rest). Mutually exclusive with allow. For protocol=mcp the preset is not written out (MCP rejects access presets); it is emitted as mcp.allow_all_known_mcp_methods: true.
protocol rest | websocket | graphql | mcp | json-rpc | tcp no L7 protocol. tcp is uninspected L4 and cannot be combined with access/allow/deny. rest, websocket, and graphql need access or allow (a protocol alone is rejected). mcp never emits access; an access value becomes mcp.allow_all_known_mcp_methods: true. Since OpenShell v0.1.8 a rest endpoint answers WebSocket upgrade requests with 403, so a WebSocket client needs protocol=websocket.
enforce enforce | audit no Enforcement mode for inspected endpoints (default from [policy] enforcement, itself defaulting to enforce).
allow METHOD:/path | query | mutation | subscription yes Explicit allowed request, e.g. GET:/v1/**. Repeatable. Implies inspection. For protocol=graphql the value is query, mutation, or subscription, optionally :operationName. That is emitted as rules[].allow.operation_type and only for GraphQL.
deny METHOD:/path | query | mutation | subscription yes Request subtracted from what is allowed. Repeatable; needs allow or access. For protocol=graphql the value is an operation type (query, mutation, or subscription), emitted as deny_rules[].operation_type and only for GraphQL.
bin /absolute/real/path no Binary that opens the connection. Overrides the nearest @openshell bin and [languages] in the config.
rule [A-Za-z0-9_-]+ no Name of the network_policies entry (default: slug of the host). Must not start with _provider_.
tls skip no Relay without TLS termination. Cannot be combined with request inspection. Use it for clients that do not trust the OpenShell CA. openshell-prover check reported such policies as unsupported with OpenShell 0.1.6 (tracked in #19).

reason is required.

Becomes: network_policies.<rule>.endpoints[] (host, port/ports, protocol, enforcement, access or rules/deny_rules, or mcp.allow_all_known_mcp_methods for MCP) plus binaries[].

provider

Declare that an environment variable is a credential supplied by an OpenShell provider.

@openshell provider <ENV_VAR> [profile=<id>] [name=<instance>]

Arguments:

  • ENV_VAR: Environment variable name, [A-Z_][A-Z0-9_]*.

Attributes:

Attribute Values Repeatable Meaning
profile profile id no Provider profile to use instead of the one resolved from the profile YAML's credentials[].env_vars.
name instance name no Name of the provider instance to create.

reason is optional.

Becomes: Not part of policy.yaml: a provider setup in the providers.json / providers.sh output (openshell provider create ... --credential ENV).

fs

Grant filesystem access inside the sandbox.

@openshell fs read|write <absolute-path> reason="..."

Arguments:

  • read|write: Access mode.
  • path: Absolute in-sandbox path.

reason is required.

Becomes: filesystem_policy.read_only or read_write (plus include_workdir). Startup-only in OpenShell: it does not reload live.

bin

Set the binary allowed to use the egress rules in this file.

@openshell bin <absolute-path-of-interpreter-or-binary>

Arguments:

  • path: Absolute real path of the interpreter or binary inside the sandbox image (OpenShell does not follow symlinks).

reason is optional.

Becomes: binaries[].path of egress rules in the same file that have no bin=.

process

Choose the identity the sandboxed process runs as.

@openshell process [user=<sandbox|uid>] [group=<sandbox|gid>]

Attributes:

Attribute Values Repeatable Meaning
user sandbox | uid no process.run_as_user.
group sandbox | gid no process.run_as_group. Conflicting values across directives are an error.

reason is optional.

Becomes: process.run_as_user / process.run_as_group. Startup-only in OpenShell.

ignore

Tell lint that a call site needs no policy entry (or that a denial is declined on purpose).

@openshell ignore kind=net|fs|env|exec|all reason="..." [scope=file]

Attributes:

Attribute Values Repeatable Meaning
kind net | fs | env | exec | all no Lint category to silence (default all).
host hostname no With kind=net: also mark denials of this host in diff-logs as declined.

reason is required.

Becomes: Nothing; affects lint and diff-logs only.

Value sets

  • protocol: rest, websocket, graphql, mcp, json-rpc, tcp
  • access: read-only, read-write, full
  • ignore kind: net, fs, env, exec, all