Repository navigation
Conversation
Implement step 1 of RFC 0027. The scanner walks raw protobuf bytes against the compiled public and storage descriptors before prost decodes them, reporting unknown tags, reserved tags, and unrecognized enum values with dotted field paths. It bounds nesting at 32 levels and stops after 16 violations, never echoes field contents, and redacts enum values on fields marked secret. Rejections map to INVALID_ARGUMENT with ErrorInfo reason UNKNOWN_PROTOBUF_FIELD and BadRequest field violations. Add helpers that extract, scan, and splice raw Sandbox.spec.policy bytes so read-modify-writes on an older gateway can preserve policy fields a newer gateway wrote. Ingress and persistence callers follow in later steps. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Implement step 2 of RFC 0027. A wrapper ahead of the gateway interceptors scans every request frame of strict RPCs against the method's input descriptor before interceptors or tonic decode it. Strict RPCs are those with unauthenticated, bearer, operator, or dual auth, plus any RPC whose request reaches a policy type, such as SubmitPolicyAnalysis. Non-policy sandbox, peer, and supervisor RPCs stay exempt during 0.x. Unary and server-streaming requests are reassembled and validated before dispatch, so a rejected request never reaches durable request admission. Client streams are validated frame by frame and end with the scanner's status. Compressed frames return UNIMPLEMENTED and frames above the route's decoding limit return RESOURCE_EXHAUSTED. Keep the exact status and details when a request body fails: interceptor body collection, the interactive exec start frame, and ForwardTcp relay frames now pass the validation status to the client. Rejections count in openshell_server_grpc_unknown_fields_total. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Implement step 3 of RFC 0027. Stored payloads that carry policy are scanned before prost decodes them, so a policy written by a newer gateway is refused instead of silently broadened: - Policy revisions and the global policy setting are scanned on load and fail with FAILED_PRECONDITION, which configuration delivery turns into a not-admitted configuration. Only the legacy NetworkBinary advisor flag is tolerated. - Draft chunks scan proposed_rule and both effective policies before the proposed rule is re-encoded. - Stored provider profiles scan their endpoint restrictions. - Sandbox.spec.policy is scanned from the raw row wherever it is evaluated, canonicalized, compared, or delivered. Sandbox writes through the store, and the policy-revision projection, keep the stored spec.policy bytes when the update leaves the policy this build understands unchanged, so an unrelated status or label update on an older gateway no longer erases newer restrictions. A test pins the durable roots that reach policy types. Make the oversized-configuration delivery test truncate providers with compare-and-swap. Its unconditional write raced the gateway's concurrent admission update and could be lost. Rejections count in openshell_server_stored_policy_unknown_fields_total. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Implement the release-train check from RFC 0027 step 4. train_policy() now classifies the active train as none, patch, or minor instead of returning one allows_breaks flag: - none: no pre-release train is active. Additive changes may merge so a feat change can start the next minor train; breaking changes fail. - patch: proto/ is frozen. Added services, RPCs, messages, fields, extensions, enums, or enum values fail alongside breaking changes. - minor: additive changes pass and breaking changes are warnings during 0.x. Additions are found by comparing definition inventories from buf JSON images, keyed by number so renames are not additions. Add unit tests, including an end-to-end buf check when buf is installed, and run them with test:python-scripts. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Describe RFC 0027 for operators and API authors: - The support matrix gains the gateway-first upgrade order, the collector-settings exception, version-skew behavior, and rollback guidance, and notes that new protobuf definitions ship only in minor releases. - proto/README.md asks authors to add definitions only on minor trains, leave unset fields at defaults, and gate new policy restrictions on a supervisor capability. - Gateway metrics list the ingress and stored-policy rejection counters. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Cover the RFC 0027 acceptance case for the two RPCs that carry policy: UpdateConfig, which sandboxes may call, and SubmitPolicyAnalysis, which is sandbox-authenticated but strict because its proposed rule reaches a policy type. A restriction nested inside the policy is rejected before dispatch with UNKNOWN_PROTOBUF_FIELD and its field path. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
|
🌿 Preview your docs: https://nvidia-preview-pr-6114.docs.buildwithfern.com/openshell |
| //! | ||
| //! A gateway that decodes a `Sandbox` written by a newer gateway drops the | ||
| //! newer policy restrictions. Re-encoding that `Sandbox` after an unrelated | ||
| //! change (status, labels, image state) would erase them from storage. These |
There was a problem hiding this comment.
🤖 blocking 🔴 – Image updates still erase newer policy fields. ImageTransaction::write_projection in persistence/sandbox_image.rs calls sandbox.encode_to_vec() and writes directly to SQLite or PostgreSQL. Carry the policy bytes from the locked row through both begin and complete, and test that the stored bytes survive each operation.
There was a problem hiding this comment.
Fixed in 924ce73. lock_sandbox now returns the migrated stored payload with the decoded sandbox, and write_projection encodes through encode_preserving_spec_policy, so both begin and complete keep the stored spec.policy bytes. image_updates_preserve_newer_spec_policy_bytes checks the stored bytes after each operation.
| return Ok(()); | ||
| } | ||
| let Some(record) = store | ||
| .get(Sandbox::object_type(), sandbox.object_id()) |
There was a problem hiding this comment.
🤖 blocking 🔴 – This fetch can validate a different revision from the Sandbox the caller evaluates. If the row is replaced or deleted between reads, the check can succeed and the caller can deliver the earlier policy with unknown fields already stripped. Validate and decode the same row, or require matching resource versions and retry the whole read on a mismatch.
There was a problem hiding this comment.
Fixed in 924ce73. with_known_spec_policy replaces require_known_spec_policy, and callers use the sandbox it returns. When the caller's policy equals the known fields of the stored row, that row is scanned. When a sandbox read from storage no longer matches the row, it returns ABORTED so the caller reads again; a deleted row returns NOT_FOUND. I compare policies rather than resource versions because unconditional put does not bump the version. Unsaved sandboxes (version 0) keep their in-memory policy, which create validation needs. spec_policy_check_and_use_share_one_stored_row covers the stripped copy, the replaced row, a deleted row, and an unsaved sandbox.
| source: StoredPolicySource, | ||
| ) -> Result<(), Status> { | ||
| match scan_named(SANDBOX_POLICY, payload, LEGACY) { | ||
| Ok(()) | Err(WireRejection::Malformed(_)) => Ok(()), |
There was a problem hiding this comment.
🤖 blocking 🔴 – A scanner error does not guarantee a prost decode error. For example, prost supports unknown protobuf groups while FieldIter reports them as malformed. Returning Ok(()) lets a policy pass without a complete scan. Reject unscannable stored data before decoding it, including in the draft and provider-profile loaders.
There was a problem hiding this comment.
Fixed in 924ce73. Any scan error now refuses the stored payload: require_known_stored_policy for revisions, global and spec policy, plus the draft and provider-profile loaders. unscannable_stored_policy_is_refused uses an unknown group that prost decodes successfully, to show the scanner is the only guard.
| .await | ||
| .map_err(|e| { | ||
| Status::internal(format!("list platform provider profiles failed: {e}")) | ||
| crate::grpc::persistence_error_to_status(e, "list platform provider profiles") |
There was a problem hiding this comment.
🤖 should-fix 🟡 – One incompatible platform profile now rejects configuration for every sandbox, including sandboxes with no providers. load_sandbox_config_inputs snapshots the entire catalog, and collect_messages stops on the first incompatible row. Keep the incompatibility associated with that profile and reject configurations that depend on it. Cover an unrelated sandbox in the same test.
There was a problem hiding this comment.
Fixed in 924ce73. The user profile source decodes rows one at a time. An unreadable profile is left out of the catalog and recorded with its scope. load_sandbox_config_inputs refuses only sandboxes whose providers resolve to it, using the same workspace/platform resolution as get_type_profile_for_scope. unreadable_provider_profile_rejects_only_dependent_configurations builds a dependent sandbox (not admitted) and an unrelated one (built). I also made DeleteProviderProfile read the raw row, so an operator can still remove an unreadable profile.
|
|
||
| let sandbox_id_in = sandbox_id.to_string(); | ||
| let channel_id_in = channel_id.to_string(); | ||
| let tx_in = tx.clone(); |
There was a problem hiding this comment.
🤖 should-fix 🟡 – tx_in keeps the response channel open after relay EOF if the client leaves its request stream open. The detached task can wait indefinitely in inbound.message() while the client waits for response EOF. Tie the task to the relay reader’s lifetime, and test relay EOF with the request sender still open.
There was a problem hiding this comment.
Fixed in 924ce73. The request reader now holds a WeakSender and upgrades it only to report a rejected frame, so the response ends when the relay reader drops its sender. I left the reader running after relay EOF so TCP half-close still delivers late client data. forward_tcp_response_ends_at_relay_eof_while_request_stream_stays_open would hang with the previous strong sender.
| match crate::wire_validation::stored::scan_draft_chunk_payload(payload) { | ||
| Ok(()) | Err(crate::wire_validation::WireRejection::Malformed(_)) => {} | ||
| Err(rejection) => { | ||
| return Err(PersistenceError::UnknownFields(format!( |
There was a problem hiding this comment.
🤖 should-fix 🟡 – GetDraftPolicy and ApproveDraftChunk wrap this new UnknownFields error in Status::internal. Use persistence_error_to_status at the draft RPC boundaries so clients receive FAILED_PRECONDITION for an incompatible stored draft. Assert the status through the RPC.
There was a problem hiding this comment.
Fixed in 924ce73. Every draft read in grpc/policy.rs (11 sites, including GetDraftPolicy and ApproveDraftChunk) now goes through persistence_error_to_status. draft_rpcs_refuse_drafts_with_newer_restrictions asserts FAILED_PRECONDITION through both RPCs.
|
|
||
| @property | ||
| def allows_breaks(self) -> bool: | ||
| return self.kind == MINOR |
There was a problem hiding this comment.
🤖 should-fix 🟡 – Every minor train permits breaking changes here, including v1.0.x to v1.1.0. The RFC requires additive-only changes within 1.x. Include the major version in this decision and test a breaking change on a 1.x minor train.
There was a problem hiding this comment.
Fixed in 7a8d05f. Added a major train kind. Breaking changes are allowed only on 0.x minor trains and on major trains (including 1.0.0); 1.x minor trains are additive-only. Tests cover the classification and an end-to-end breaking change on a 1.x minor train with real buf.
Address review feedback on RFC 0027 persistence-boundary validation: - Image update begin and complete keep the locked row's spec.policy bytes; they wrote the sandbox directly and erased newer restrictions. - The spec policy check and its use share one stored row. A sandbox read from storage whose policy no longer matches the row gets ABORTED so the caller reads again, and a deleted row gets NOT_FOUND. Resource versions alone cannot detect this because unconditional writes keep them. - Stored policies, drafts, and profile endpoints the scanner cannot parse are refused, even where prost would decode them, such as unknown groups. - An unreadable provider profile no longer fails the whole catalog. It is left out, configurations whose providers resolve to it are not admitted, and DeleteProviderProfile can still remove it. - Draft RPCs map an unreadable stored draft to FAILED_PRECONDITION instead of INTERNAL. - ForwardTcp holds a weak response sender in its request reader, so the response still ends at relay EOF while the client keeps sending. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Breaking changes are now allowed only on 0.x minor trains and on major trains, including 1.0.0. Within 1.x and later majors, a minor train is additive-only, as RFC 0027 requires. Add a major train kind and test a breaking change on a 1.x minor train. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
| return Ok(policy); | ||
| } | ||
| sandbox | ||
| Box::pin(with_known_spec_policy(store, sandbox)) |
There was a problem hiding this comment.
🤖 blocking 🔴 – A single incompatible sandbox policy can still prevent the gateway from starting. With provider composition enabled, startup calls current_base_policy_for_sandbox for every sandbox with providers and propagates the first error out of run_server. Handle the stored-policy incompatibility per sandbox during preflight and retain the refusal on delivery. Cover startup with one affected sandbox and one healthy sandbox.
There was a problem hiding this comment.
Fixed in 6ac8a47. Stored-data incompatibility refusals now carry ErrorInfo reason UNKNOWN_PROTOBUF_FIELD (wire_validation::stored::is_incompatible). The startup preflight sets aside a sandbox whose stored policy, or whose provider profile, this gateway cannot read, and keeps validating the rest; configuration delivery still refuses that sandbox. startup_preflight_sets_aside_a_sandbox_with_an_unreadable_policy runs the preflight with one affected and one healthy sandbox and checks that delivery refuses the affected one; startup_preflight_still_checks_sandboxes_beside_an_unreadable_policy checks that a real violation elsewhere still fails startup.
| }); | ||
| } | ||
| build_effective_profiles(snapshots) | ||
| let mut catalog = build_effective_profiles(snapshots)?; |
There was a problem hiding this comment.
🤖 blocking 🔴 – The token broker reads this catalog through get_type_profile_for_scope, which ignores incompatible. When a workspace profile is unreadable and a same-ID platform profile exists, GetSandboxProviderAccessToken can authorize a grant from the platform profile. Enforce incompatibility in scoped resolution itself and test this case through the token RPC.
There was a problem hiding this comment.
Fixed in 6ac8a47. scoped_type_profile_for_scope now calls require_compatible_profile first and returns None when the profile in the resolving scope is unreadable, so it never falls back to a same-ID platform profile. Every caller already treats None as fail-closed. unreadable_workspace_profile_never_falls_back_to_the_platform_grant drives grant_configuration, the profile-authorization step of GetSandboxProviderAccessToken: the grant is authorized with only the platform profile, and refused with PERMISSION_DENIED once an unreadable workspace profile shadows it. I tested that step rather than the full RPC because the full RPC needs a signed sandbox session and a persisted session lineage.
| warn_incompatible_profile(&name, &reason); | ||
| incompatible.push((name, resource_version)); | ||
| } | ||
| Err(error) => { |
There was a problem hiding this comment.
🤖 should-fix 🟡 – An unreadable endpoint can still take down the whole catalog. decode_record runs legacy_time_wire::migrate before the profile scanner. A group inside an endpoint fails migration as PersistenceError::Decode and takes this branch, so unrelated sandboxes get INTERNAL. Classify unscannable raw endpoint bytes before migration and extend the isolation test to cover this path.
There was a problem hiding this comment.
Fixed in 6ac8a47. decode_record now scans provider-profile endpoints on the raw row before legacy migration. Endpoints contain no messages the time-field migration rewrites, so the raw and migrated scans agree. An endpoint group now surfaces as UnknownFields and stays isolated to its profile. The isolation test runs both an unknown endpoint field and an endpoint group, and checks that an unrelated sandbox still builds.
| // Read the row without decoding it: a profile this build cannot read | ||
| // safely (RFC 0027) must still be removable. | ||
| let existing = state | ||
| .store |
There was a problem hiding this comment.
🤖 should-fix 🟡 – Raw lookup makes an unused incompatible profile deletable, but an in-use profile still cannot be repaired in place. profile_update_target_diagnostics and handle_update_provider_profiles both decode the old profile and return INTERNAL, even for a full compatible replacement with the correct resource version. Read the row metadata independently and retain the existing version check on replacement.
There was a problem hiding this comment.
Fixed in 6ac8a47. stored_profile_metadata reads only StoredProviderProfile.metadata (tag 1) from the raw row, migrates and decodes that, and takes the resource version from the row. profile_update_target_diagnostics and handle_update_provider_profiles use it, so a compatible full replacement can repair an unreadable profile, and the MatchResourceVersion check is unchanged. unreadable_custom_profile_can_be_replaced_in_place checks that a stale version gets ABORTED, the correct version repairs the profile, and labels and the ID are kept.
Address the second round of RFC 0027 review feedback: - Startup preflight sets aside a sandbox whose stored policy or provider profile this gateway cannot read, instead of failing run_server. Delivery still refuses it. Such refusals now carry ErrorInfo reason UNKNOWN_PROTOBUF_FIELD so callers can tell them apart. - Scoped profile resolution enforces incompatibility itself, so an unreadable workspace profile never falls back to a same-ID platform profile, including for brokered token grants. - Provider profile endpoints are scanned before legacy migration, so an unreadable endpoint, such as one with a group, stays isolated to that profile instead of failing the whole catalog. - UpdateProviderProfiles reads only the stored metadata and row version, so a compatible full replacement can repair an unreadable profile in place while keeping the version check. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
|
|
||
| let raw = hex::decode(encoded) | ||
| .map_err(|e| Status::internal(format!("global policy decode failed: {e}")))?; | ||
| crate::wire_validation::stored::require_known_stored_policy( |
There was a problem hiding this comment.
🤖 blocking 🔴 – An incompatible global policy still prevents gateway startup. validate_provider_composition_startup_preflight decodes the global override to decide whether composition is enabled. This rejection reaches run_server before it can serve repair requests. Treat the incompatible override as present for preflight, keep refusing configuration delivery, and test that a compatible replacement restores delivery.
There was a problem hiding this comment.
Fixed in a867864. provider_policy_composition_enabled now treats a global policy this gateway cannot read as a present global override (composition off), so neither the startup preflight nor profile changes fail on it. Configuration delivery still refuses it. unreadable_global_policy_starts_the_gateway_and_can_be_replaced stores an unreadable global policy, runs the preflight, checks that delivery is refused, replaces the policy through UpdateConfig with global: true, and checks that delivery recovers. I also checked the other startup step, endpoint-status reconciliation: it does not decode policies.
| .await | ||
| .unwrap() | ||
| .unwrap() | ||
| .resource_version; |
There was a problem hiding this comment.
🤖 should-fix 🟡 – This test gets the repair version directly from the store. Operators get it through GetProviderProfile or CLI export. An unreadable workspace profile is absent from that lookup, so export returns NOT_FOUND or the same-ID platform profile and its version. Return the incompatibility with the affected row’s resource version and exercise repair using only public RPCs.
There was a problem hiding this comment.
Fixed in a867864. IncompatibleProfile now records its row resource version. GetProviderProfile calls require_compatible_profile for the requested scope before the catalog lookup, so an unreadable profile is reported with UNKNOWN_PROTOBUF_FIELD, resource_version in ErrorInfo metadata, and the version in the message, never NOT_FOUND or the same-ID platform profile. The repair test now uses public RPCs only, with a same-ID platform profile present: GetProviderProfile (refused, with version), LintProviderProfiles, UpdateProviderProfiles with that version (a stale version gets ABORTED), then GetProviderProfile returns the repaired workspace profile. The CLI shows the message, which includes the version; it does not yet parse the metadata itself.
| .get_message_by_name::<StoredProviderProfile>(workspace, target_id) | ||
| .await | ||
| .map_err(|e| Status::internal(format!("fetch provider profile failed: {e}")))? | ||
| if stored_profile_metadata(store, workspace, target_id) |
There was a problem hiding this comment.
🤖 should-fix 🟡 – A CLI update containing a stable_placeholder credential calls LintProviderProfiles before the update RPC. Its profile_conflict_diagnostics still does a typed read to check existence, so an unreadable existing profile returns INTERNAL even with the correct version and a compatible replacement. Use a metadata-only existence check there too.
There was a problem hiding this comment.
Fixed in a867864. Both existence checks in profile_conflict_diagnostics use stored_profile_metadata. The repair test calls LintProviderProfiles with the replacement and gets the normal "already exists" diagnostic instead of INTERNAL.
| .await | ||
| { | ||
| Ok(policy) => policy, | ||
| Err(error) if crate::wire_validation::stored::is_incompatible(&error) => { |
There was a problem hiding this comment.
🤖 should-fix 🟡 – The same isolation is missing in profile_attached_sandbox_diagnostics. It reads each sandbox’s base policy before checking whether any attached provider uses the profile being changed. An unreadable policy on an unrelated sandbox can block every platform profile import or update. Identify affected sandboxes before loading their policies and retain validation for actual dependents.
There was a problem hiding this comment.
Fixed in a867864. profile_attached_sandbox_diagnostics now fetches a sandbox's providers first and skips the sandbox before loading its base policy unless a provider uses a changed profile, which is the condition the old imported_profiles_used.is_empty() check applied after the load. unreadable_policy_blocks_only_profile_changes_its_sandbox_depends_on checks that a platform import succeeds beside an unrelated sandbox with an unreadable policy, while an import a dependent sandbox uses is still refused with the incompatibility.
Address the third round of RFC 0027 review feedback: - An unreadable global policy counts as a global override, so provider composition is treated as off. Startup and profile changes no longer fail on it, delivery still refuses it, and a compatible UpdateConfig replacement restores delivery. - GetProviderProfile reports an unreadable profile in the requested scope with its row resource_version in ErrorInfo metadata and the message, instead of NOT_FOUND or a same-ID platform profile. Operators can repair it using public RPCs alone. - LintProviderProfiles checks profile existence from stored metadata only, so linting a replacement for an unreadable profile works. - Profile change diagnostics load a sandbox's base policy only when the sandbox uses a changed profile, so an unrelated unreadable policy no longer blocks platform profile imports or updates. Refs #6097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Summary
Implement RFC 0027: the gateway rejects protobuf fields and enum values it does not know, both at gRPC ingress and when loading stored policies, so version skew can no longer silently drop policy restrictions. Patch release trains now freeze
proto/.Related Issue
Part of #6097. Not closing yet: the
supported_policy_capabilitiesdiscovery field and the RFC 0014 companion edit are still open.Changes
Each step is a separate commit for review.
bytes/stringpayloads by length, and never echoes field contents.SubmitPolicyAnalysis. Unary and server-streaming requests are fully checked before dispatch, so a rejected request never consumes itsrequest_id. Rejections returnINVALID_ARGUMENTwithErrorInforeasonUNKNOWN_PROTOBUF_FIELDandBadRequestviolations. Interceptor body collection, theExecSandboxInteractivestart frame, andForwardTcpnow keep that status instead of turning it intoINTERNALor closing silently.Sandbox.spec.policyare scanned beforeprostdecodes them. Unknown restrictions returnFAILED_PRECONDITION, which yields a not-admitted configuration. Sandbox writes through theStore, and the policy-revision projection, keep the storedspec.policybytes when an update leaves the known policy unchanged. A test pins the five durable roots that reach policy types.check_proto_compatibility.pyclassifies the train asnone,patch, orminor. On patch trains, added services, RPCs, messages, fields, enums, or enum values fail.UNKNOWN_PROTOBUF_FIELDin API errors; authoring rules inproto/README.md; two new metrics.Review notes:
Storewrites to an existing sandbox row now do one extra read to preserve the stored policy bytes.oversized_configuration_is_rejected_over_grpc_and_smaller_configuration_recoversnow truncates providers with compare-and-swap. Its unconditional write could lose to the gateway's concurrent admission update, and the extra read made that race reproducible.mainis in a patch train (v0.1.11), so PRs that add protobuf definitions fail the compatibility check until that train ships.Release Notes
The gateway now rejects requests and stored policies that use protobuf fields or enum values it does not know, returning
UNKNOWN_PROTOBUF_FIELDinstead of silently dropping them. Upgrade gateways before clients and supervisors.Testing
cargo clippy -p openshell-server --tests, ruff, markdownlint,docs:navopenshell-servertests pass. The 8 that failed locally also fail without this change, because the local sandbox blocks Unix-socket binds and writes under~/.local/state. The newcheck_proto_compatibility_test.pyincludes end-to-endbufcases.Checklist
🤖 Generated with Claude Code