Repository navigation
Description
User Story
I review and maintain OpenShell policy features. When I approve a policy, I need to know that the policy a supervisor enforces is the one I approved, or that OpenShell refuses it. While reviewing GraphQL field_rules (#5986, #5996), I found that each new policy restriction and API constraint needs its own guard to work across gateway versions.
Problem Statement
prost discards unknown wire fields and decodes unrecognized proto3 enum values as raw i32 integers before gateway handlers or interceptors run. For example, GraphQL field_rules can restrict a query to one repository and a set of fields; without a guard, an older gateway could discard field_rules and store or deliver the remaining operation_type: query rule, granting broader access than the author approved.
This gap spans four paths:
- Ingress writes and advisor drafts. A newer CLI, SDK, raw gRPC client, sandbox
UpdateConfigcaller, or supervisor callingSubmitPolicyAnalysissends an unknown field to an older gateway. InSubmitPolicyAnalysis,draft_chunk_record_from_partsdecodesDraftChunkPayloadand re-encodesproposed_rulebefore persisting, stripping unknown restrictions before approval checks run. - Persistence reads and read-modify-writes during rollout or rollback. A newer gateway stores a restricted policy revision, global policy setting, draft chunk, or provider profile endpoint. An older replica during a rolling upgrade—or an older gateway after a rollback—reads shared storage and could strip unknown restrictions on decode or overwrite
Sandbox.spec.policyduring an unrelatedSandboxread-modify-write. - Delivery to supervisors. A gateway that understands a restriction can still deliver effective policy over poll (
GetSandboxConfig) or push (ConnectSupervisor) to a supervisor that cannot enforce it unless both paths check capabilities. - Unpublished component skew and patch-train rules.
RFC 0014anddocs/about/support-matrix.mdxdefine maintenance lines (latest andN-1) and API compatibility, but not supported CLI/SDK, gateway, and supervisor version pairs, upgrade order, rollback floor, orproto/rules on patch trains.
Today's protections are partial and ad hoc:
- Supervisor delivery uses
GetSandboxConfigRequest.supported_capabilities(openshell.policy.cedar.v1,openshell.policy.graphql-field-rules.v1in feat(policy): match GraphQL arguments and nested fields #5996) on the poll path. - Writes and stored policies rely on
validate_endpoint_mode_valuesandvalidate_and_canonicalize_stored_policyrejecting unknown enum values ontls,enforcement, andaccess(sincev0.1.0). feat(policy): match GraphQL arguments and nested fields #5996 adds syntheticNetworkEnforcementModevalues to markfield_rules, which protects converter-encoded policies on older gateways but leaves unmarked raw-client calls unprotected and requires new enum variants per feature. - Feature activation uses default-off gateway settings plus a best-effort PostgreSQL replica liveness snapshot (
image_activation.rs) for sandbox image updates and workspace secrets. - Discovery uses one-off booleans such as
LintProviderProfilesResponse.supports_stable_placeholder, which fail early on the client but cannot protect a write routed to a different replica.
Impact / Why This Matters
RFC 0014release qualification requires that "unsupported capabilities must return documented errors rather than fail silently." Silently dropping a restriction on an allow rule can widen sandbox access.- Encoding feature markers in validated enums mixes enforcement behavior with feature signaling, adds equivalent variants that every SDK and tool must handle, and requires bespoke guards for every new restriction.
- Without a published component skew, upgrade-order, and rollback policy, operators and reviewers cannot tell which version combinations a feature must handle or when downgrades are safe.
Proposed Design
Propose RFC 0027 — gRPC and Stored Policy Field Validation (rfc/0027-grpc-field-validation/README.md) to establish a uniform validation and skew contract:
- Enforce strict server-side gRPC frame validation on the gateway. Validate uncompressed protobuf wire frames against
FileDescriptorSetbeforeprostor Gateway Interceptors decode them, returningINVALID_ARGUMENT(UNKNOWN_PROTOBUF_FIELD) withgoogle.rpc.BadRequestfield violations on unknown tags or unrecognizedproto3enum values. Apply unconditionally to public and dual-authenticated RPCs ("unauthenticated","bearer","operator","dual") acrossOpenShell,SandboxUpdates, andServiceDiscovery, plus every policy-bearing RPC regardless ofauth_mode(SubmitPolicyAnalysis). Keep non-policy"sandbox","peer", and"supervisor"RPCs exempt during0.xbehind capability negotiation until1.0.0. - Validate policies and drafts at the persistence boundary and preserve raw policy bytes across read-modify-writes. Scan raw stored bytes for policy revisions, global policy settings,
DraftChunkPayload, andStoredProviderProfileendpoints beforeprostdecodes or re-encodes them. PreserveSandbox.spec.policywire bytes verbatim across unrelatedSandboxupdates, and fail closed (not admitted) whenever a gateway evaluates a stored policy containing unknown fields. - Keep capability advertisement for discovery and supervisor delivery. Add
repeated string supported_policy_capabilitiestoGetGatewayInfoResponseso the CLI and SDKs can fail early with a documented error, and enforcerequire_policy_capabilitieson both supervisor poll (GetSandboxConfig) and push (ConnectSupervisorbootstrap andConfigUpdate) paths. - Publish component version skew, upgrade order, release
X, and patch-train rules. Define releaseXas the first strict-reader boundary, establish Gateway-First as the default rolling upgrade order for compatible(N, N+1)pairs (documenting per-connection exceptions such as0.xcollector TLS/headers), define safe rollback rules for>= Xversus< X, and freezeproto/additions onpatchrelease trains incheck_proto_compatibility.py. - Document schema evolution conventions in
proto/README.mdfor adding new policy restrictions and API fields.
This issue covers the RFC 0027 deliverable and design review. Implementation work will be tracked in separate scoped issues once the RFC is accepted.
RFC number: 0027 (main contains RFCs through 0024; 0025 is assigned in #5852 / #5856, and 0026 is claimed in #6092 / #6093 and #6024).
Acceptance Criteria
- RFC 0027 is open for review at
rfc/0027-grpc-field-validation/README.mdfollowing the repository RFC template. - The RFC specifies ingress gRPC validation scope (including unary and streaming framing, error status preservation across interceptors, and
request_idreplay semantics before and after admission), persistence-boundary validation andSandboxread-modify-write preservation, capability discovery and supervisor poll/push delivery checks, and releaseXrollout, rollback, and patch-train compatibility rules. - Maintainers accept or reject the RFC, and follow-on implementation work is tracked in separate issues.
Alternatives Considered
- A
supports_*boolean per feature. Gives early client errors, but grows without bound and cannot protect writes routed to another replica or stored policies. - Feature markers in validated enums (the feat(policy): match GraphQL arguments and nested fields #5996 approach). Useful as a bridge while
< Xgateways remain in service, but requires new enum variants for every restriction and leaves unmarked raw-client calls unprotected. - Declared requirements only (
SandboxPolicy.required_policy_capabilitieswithout strict decoding). A raw client can omit the declaration, and onceprostdiscards an unknown restriction the gateway cannot detect what was lost. - Configurable mode header (
strict,warn,ignore). Kubernetes (KEP-2885) neededWarnfor legacy YAML manifests; OpenShell uses typed gRPC stubs wherewarnleaves callers exposed to silent restriction loss and complicates SDKs andmutation_replayhashing. - Comparing
gateway_versionor relying on process alone. Fragile across dev builds, backports, mixed-replica routing, raw API clients, and mistaken rollbacks.
Kubernetes publishes a component skew policy, while its protobuf serializer uses ordinary decoding even for strict requests.
Agent Investigation
Source inspection across protobuf, gateway ingress, persistence, and CI checks:
proto/sandbox.proto,proto/openshell.proto,proto/datamodel.proto,proto/options.proto:NetworkEnforcementMode,GetSandboxConfigRequest.supported_capabilities,GetGatewayInfoResponse,DURABLE_ROOTS, andRpcAuthOptions.crates/openshell-server/src/grpc/policy.rs,crates/openshell-server/src/grpc/sandbox_mux.rs:validate_and_canonicalize_stored_policy,require_policy_capabilities, poll (GetSandboxConfig) and push (ConnectSupervisor) delivery, andSubmitPolicyAnalysis.crates/openshell-server/src/persistence/mod.rs,sandbox_image.rs,crates/openshell-server/src/policy_store.rs:draft_chunk_record_from_parts(DraftChunkPayloaddecode/re-encode) andSandboxread-modify-write paths.crates/openshell-gateway-interceptors/src/layer.rs,crates/openshell-server/src/grpc/exec.rs,port_forward.rs: request-body collection,ExecSandboxInteractivepost-Startadmission, andForwardTcpstream error handling.tasks/scripts/check_proto_compatibility.pyandrfc/0014-release-stability/: currenttrain_policy()predicate and release stability rules.
Checklist
- I've reviewed existing issues and the published docs.
- This is a design proposal, not a "please build this" request.
Activity
fix(server): close gaps in stored policy validation
ci(proto): keep 1.x minor trains additive-only
fix(server): isolate unreadable stored policies and profiles
fix(server): keep repair paths open for unreadable stored data
fix(server): resolve profile dependents and global override in one place
fix(server): close remaining stored policy preservation gaps
fix(server): make sandbox policy preservation atomic with the write