Skip to content

feat: propose gRPC and stored policy field validation (RFC 0027) #6097

In review

Description

@mrunalp

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 UpdateConfig caller, or supervisor calling SubmitPolicyAnalysis sends an unknown field to an older gateway. In SubmitPolicyAnalysis, draft_chunk_record_from_parts decodes DraftChunkPayload and re-encodes proposed_rule before 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.policy during an unrelated Sandbox read-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 0014 and docs/about/support-matrix.mdx define maintenance lines (latest and N-1) and API compatibility, but not supported CLI/SDK, gateway, and supervisor version pairs, upgrade order, rollback floor, or proto/ 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.v1 in feat(policy): match GraphQL arguments and nested fields #5996) on the poll path.
  • Writes and stored policies rely on validate_endpoint_mode_values and validate_and_canonicalize_stored_policy rejecting unknown enum values on tls, enforcement, and access (since v0.1.0). feat(policy): match GraphQL arguments and nested fields #5996 adds synthetic NetworkEnforcementMode values to mark field_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 0014 release 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:

  1. Enforce strict server-side gRPC frame validation on the gateway. Validate uncompressed protobuf wire frames against FileDescriptorSet before prost or Gateway Interceptors decode them, returning INVALID_ARGUMENT (UNKNOWN_PROTOBUF_FIELD) with google.rpc.BadRequest field violations on unknown tags or unrecognized proto3 enum values. Apply unconditionally to public and dual-authenticated RPCs ("unauthenticated", "bearer", "operator", "dual") across OpenShell, SandboxUpdates, and ServiceDiscovery, plus every policy-bearing RPC regardless of auth_mode (SubmitPolicyAnalysis). Keep non-policy "sandbox", "peer", and "supervisor" RPCs exempt during 0.x behind capability negotiation until 1.0.0.
  2. 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, and StoredProviderProfile endpoints before prost decodes or re-encodes them. Preserve Sandbox.spec.policy wire bytes verbatim across unrelated Sandbox updates, and fail closed (not admitted) whenever a gateway evaluates a stored policy containing unknown fields.
  3. Keep capability advertisement for discovery and supervisor delivery. Add repeated string supported_policy_capabilities to GetGatewayInfoResponse so the CLI and SDKs can fail early with a documented error, and enforce require_policy_capabilities on both supervisor poll (GetSandboxConfig) and push (ConnectSupervisor bootstrap and ConfigUpdate) paths.
  4. Publish component version skew, upgrade order, release X, and patch-train rules. Define release X as 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 as 0.x collector TLS/headers), define safe rollback rules for >= X versus < X, and freeze proto/ additions on patch release trains in check_proto_compatibility.py.
  5. Document schema evolution conventions in proto/README.md for 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.md following the repository RFC template.
  • The RFC specifies ingress gRPC validation scope (including unary and streaming framing, error status preservation across interceptors, and request_id replay semantics before and after admission), persistence-boundary validation and Sandbox read-modify-write preservation, capability discovery and supervisor poll/push delivery checks, and release X rollout, 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 < X gateways remain in service, but requires new enum variants for every restriction and leaves unmarked raw-client calls unprotected.
  • Declared requirements only (SandboxPolicy.required_policy_capabilities without strict decoding). A raw client can omit the declaration, and once prost discards an unknown restriction the gateway cannot detect what was lost.
  • Configurable mode header (strict, warn, ignore). Kubernetes (KEP-2885) needed Warn for legacy YAML manifests; OpenShell uses typed gRPC stubs where warn leaves callers exposed to silent restriction loss and complicates SDKs and mutation_replay hashing.
  • Comparing gateway_version or 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, and RpcAuthOptions.
  • 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, and SubmitPolicyAnalysis.
  • crates/openshell-server/src/persistence/mod.rs, sandbox_image.rs, crates/openshell-server/src/policy_store.rs: draft_chunk_record_from_parts (DraftChunkPayload decode/re-encode) and Sandbox read-modify-write paths.
  • crates/openshell-gateway-interceptors/src/layer.rs, crates/openshell-server/src/grpc/exec.rs, port_forward.rs: request-body collection, ExecSandboxInteractive post-Start admission, and ForwardTcp stream error handling.
  • tasks/scripts/check_proto_compatibility.py and rfc/0014-release-stability/: current train_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

  1. self-assigned this
    on Nov 30, 2026
  2. added
    area:platform
    topic:api
    topic:architecture
    topic:policy
    on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:platformneeds-rfctopic:apitopic:architecturetopic:policy

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions