Skip to content

fix(ra-rpc): bound the error text a failed call returns, and return it in the caller's representation - #1234

Merged
kvinwang merged 3 commits into
nextfrom
fix/ra-rpc-error-shape
Sep 24, 2026
Merged

kvinwang merged 3 commits into
nextfrom
fix/ra-rpc-error-shape

Conversation

@kvinwang

@kvinwang kvinwang commented Sep 20, 2026 •

Copy link
Copy Markdown
Collaborator

Two defects on the shared pRPC error path (every service: guest agent, gateway, KMS, VMM).

  1. Error text was unbounded. A deserializer error quotes the rejected value, so a 9 MiB malformed field produced a 9 MiB reply and a 9 MiB rpc error: log line (reachable unauthenticated via /var/run/dstack.sock). Error text is now capped at 2 KiB, dropping the middle so the error kind and input position both survive.
  2. Pre-dispatch errors ignored the JSON content type. PrpcHandler::handle only checked ?json/GET, so a JSON POST rejected before dispatch (payload too large, bad cert, invalid quote) got a protobuf body with application/octet-stream. Both paths now use one wants_json().

Verification

  • New tests a_json_request_is_refused_in_json_before_the_dispatcher_runs and a_rejection_does_not_echo_the_whole_offending_value fail on next (content-type application/octet-stream; a rejection echoed 1048664 bytes) and pass here; a unit test covers multi-byte char boundaries.
  • cargo test -p ra-rpc, cargo clippy -p ra-rpc --all-features -- -D warnings, cargo fmt --check: clean.

A deserializer names the value it rejected, so the message is as long as
the request field that produced it. Both the reply body and the log line
carry it verbatim:

    $ curl --unix-socket /var/run/dstack.sock -X POST \
        -H 'Content-Type: application/json' --data-binary @9mib.json \
        http://localhost/prpc/Tappd.DeriveKey
    http=400 size=9437272
    $ awk '{ print length($0) }' simulator.log | sort -rn | head -1
    9437466

One malformed request is a 9 MiB reply and a 9 MiB log line, at the
default 10 MiB request limit. That is a response amplifier on every
network-facing listener, and a way to fill a service's disk from a
listener that needs no credential -- the guest agent's socket is
bind-mounted into application containers by design.

Bound the text at 2 KiB, dropping the middle rather than the tail: a
deserializer puts the failure kind in front of the value and the input
position behind it, so both ends carry information the caller needs. No
real dstack error is anywhere near the bound, so nothing legitimate is
truncated.
`handle` encoded a pre-dispatch failure using `request.json`, which is
only `true` for a GET or an explicit `?json`. `handle_prpc_impl` decided
the same question with the content type as well. So a plain

    POST /prpc/Tappd.DeriveKey
    Content-Type: application/json

whose failure was raised before the dispatcher ran came back as

    HTTP/1.1 413 Payload Too Large
    content-type: application/octet-stream

    \n&failed to read data: payload too large

-- a protobuf `ProtoError` that no JSON client can read, under a content
type it did not ask for. Everything raised on that path is affected:
`payload too large`, a certificate that will not parse, and `invalid
quote`, which is the one an attested caller most needs to see.

Resolve the representation once, before anything moves out of the
request, and use it on both paths.
kvinwang added a commit that referenced this pull request Sep 20, 2026
Every RPC case in this suite names api-inventory.json as mandatory test
data and states that the method is exercised with its request fields
"absent/default, valid, boundary-invalid and combined with an unknown
field" in both representations. The harnesses behind those cases send
one valid request and one wrong-typed value for the *first* request
field. So the input classes where a service actually breaks -- an
out-of-range integer, an oversized string, a wrong protobuf wire type, a
truncated body -- are untested for all 110 indexed methods.

Add a harness that implements the stated matrix once, driven by the same
inventory, and nine cases that apply it to the guest agent's four
services, the KMS's two, and the gateway's three. It asserts the
invariants that hold for every method whatever it means: a malformed
request is never a 5xx or a dropped connection, a rejection is
structured and bounded and carries the caller's own representation, no
call outlives its deadline, and the listener still answers afterwards.
That last one is a real assertion here: the workspace builds release
binaries with `panic = "abort"`, so a reachable panic is a process abort.

api-contract-matrix-policy.json says how far each method may be driven.
`full` is for a method whose effect stays inside the lease;
`rejection-only` sends only what a service must refuse before it
dispatches, so nothing can mutate; `skip` is for a method whose valid
invocation ends the process or consumes an external resource, and the
file records the reason for each. Every method in the inventory must
carry a policy -- one added without one fails the case rather than being
silently skipped.

Two product defects found while building this are fixed separately:
a `not_after` of u64::MAX aborted the guest agent (#1232), and a
rejection echoed the whole rejected value back to the caller and into
the log under a content type the caller did not ask for (#1234).
@kvinwang

Copy link
Copy Markdown
Collaborator Author

tdxlab hardware run: before and after

The new tc-gos-contract-00{1..4} acceptance cases (test/core-coverage-expansion) drive the full adversarial request-contract matrix against a lease-owned guest agent. Run on tdxlab (phala-tdx-lab), 2 workers, local-simulator fixture, prepared binaries built from the revision under test.

Against the suite branch alone (no product fix — run cov841-4572fb4eb-gos):

case status
tc-gos-contract-001 (Tappd) FAIL — 2 violations
tc-gos-contract-002 (DstackGuest) FAIL — 225 violations
tc-gos-contract-003 (Worker) PASS
tc-gos-contract-004 (GuestApi) PASS
tc-gos-contract-002: {"detail": "transport failure: curl: (52) Empty reply from server",
                      "invariant": "L1", "label": "DstackGuest.GetTlsKey|not_after=u64-max|json"}
                     {"detail": "rejection body is 1048664 bytes",
                      "invariant": "L4", "label": "DstackGuest.GetTlsKey|alt_names=long-1m|json"}

The 225 is one abort plus the cascade: every later call in that sweep failed to connect, because the process was gone.

With #1232 and #1234 merged in (run cov841v-1280b81da, same host, same fixture):

PASS tc-gos-contract-001   The request-contract matrix held for every indexed method.
PASS tc-gos-contract-002   The request-contract matrix held for every indexed method.
PASS tc-gos-contract-003   The request-contract matrix held for every indexed method.
PASS tc-gos-contract-004   The request-contract matrix held for every indexed method.
PASS tc-gos-concurrency-001
PASS tc-gos-concurrency-003
PASS tc-gos-observability-slow-consumer
SWEEP_DONE rc=0

kvinwang added a commit that referenced this pull request Sep 24, 2026
Every RPC case in this suite names api-inventory.json as mandatory test
data and states that the method is exercised with its request fields
"absent/default, valid, boundary-invalid and combined with an unknown
field" in both representations. The harnesses behind those cases send
one valid request and one wrong-typed value for the *first* request
field. So the input classes where a service actually breaks -- an
out-of-range integer, an oversized string, a wrong protobuf wire type, a
truncated body -- are untested for all 110 indexed methods.

Add a harness that implements the stated matrix once, driven by the same
inventory, and nine cases that apply it to the guest agent's four
services, the KMS's two, and the gateway's three. It asserts the
invariants that hold for every method whatever it means: a malformed
request is never a 5xx or a dropped connection, a rejection is
structured and bounded and carries the caller's own representation, no
call outlives its deadline, and the listener still answers afterwards.
That last one is a real assertion here: the workspace builds release
binaries with `panic = "abort"`, so a reachable panic is a process abort.

api-contract-matrix-policy.json says how far each method may be driven.
`full` is for a method whose effect stays inside the lease;
`rejection-only` sends only what a service must refuse before it
dispatches, so nothing can mutate; `skip` is for a method whose valid
invocation ends the process or consumes an external resource, and the
file records the reason for each. Every method in the inventory must
carry a policy -- one added without one fails the case rather than being
silently skipped.

Two product defects found while building this are fixed separately:
a `not_after` of u64::MAX aborted the guest agent (#1232), and a
rejection echoed the whole rejected value back to the caller and into
the log under a content type the caller did not ask for (#1234).
@kvinwang
kvinwang merged commit cbdfa90 into next Sep 24, 2026
11 checks passed
@kvinwang
kvinwang deleted the fix/ra-rpc-error-shape branch September 24, 2026 14:20
kvinwang added a commit that referenced this pull request Sep 24, 2026
Every RPC case in this suite names api-inventory.json as mandatory test
data and states that the method is exercised with its request fields
"absent/default, valid, boundary-invalid and combined with an unknown
field" in both representations. The harnesses behind those cases send
one valid request and one wrong-typed value for the *first* request
field. So the input classes where a service actually breaks -- an
out-of-range integer, an oversized string, a wrong protobuf wire type, a
truncated body -- are untested for all 110 indexed methods.

Add a harness that implements the stated matrix once, driven by the same
inventory, and nine cases that apply it to the guest agent's four
services, the KMS's two, and the gateway's three. It asserts the
invariants that hold for every method whatever it means: a malformed
request is never a 5xx or a dropped connection, a rejection is
structured and bounded and carries the caller's own representation, no
call outlives its deadline, and the listener still answers afterwards.
That last one is a real assertion here: the workspace builds release
binaries with `panic = "abort"`, so a reachable panic is a process abort.

api-contract-matrix-policy.json says how far each method may be driven.
`full` is for a method whose effect stays inside the lease;
`rejection-only` sends only what a service must refuse before it
dispatches, so nothing can mutate; `skip` is for a method whose valid
invocation ends the process or consumes an external resource, and the
file records the reason for each. Every method in the inventory must
carry a policy -- one added without one fails the case rather than being
silently skipped.

Two product defects found while building this are fixed separately:
a `not_after` of u64::MAX aborted the guest agent (#1232), and a
rejection echoed the whole rejected value back to the caller and into
the log under a content type the caller did not ask for (#1234).
kvinwang added a commit that referenced this pull request Sep 25, 2026
Every RPC case in this suite names api-inventory.json as mandatory test
data and states that the method is exercised with its request fields
"absent/default, valid, boundary-invalid and combined with an unknown
field" in both representations. The harnesses behind those cases send
one valid request and one wrong-typed value for the *first* request
field. So the input classes where a service actually breaks -- an
out-of-range integer, an oversized string, a wrong protobuf wire type, a
truncated body -- are untested for all 110 indexed methods.

Add a harness that implements the stated matrix once, driven by the same
inventory, and nine cases that apply it to the guest agent's four
services, the KMS's two, and the gateway's three. It asserts the
invariants that hold for every method whatever it means: a malformed
request is never a 5xx or a dropped connection, a rejection is
structured and bounded and carries the caller's own representation, no
call outlives its deadline, and the listener still answers afterwards.
That last one is a real assertion here: the workspace builds release
binaries with `panic = "abort"`, so a reachable panic is a process abort.

api-contract-matrix-policy.json says how far each method may be driven.
`full` is for a method whose effect stays inside the lease;
`rejection-only` sends only what a service must refuse before it
dispatches, so nothing can mutate; `skip` is for a method whose valid
invocation ends the process or consumes an external resource, and the
file records the reason for each. Every method in the inventory must
carry a policy -- one added without one fails the case rather than being
silently skipped.

Two product defects found while building this are fixed separately:
a `not_after` of u64::MAX aborted the guest agent (#1232), and a
rejection echoed the whole rejected value back to the caller and into
the log under a content type the caller did not ask for (#1234).
kvinwang added a commit that referenced this pull request Sep 25, 2026
…ct matrix

PR #1234 caps pRPC error text at 2 KiB and answers a JSON request refused
before dispatch in JSON; L4 now bounds the decoded error text and L6
covers the pre-dispatch refusal. PR #1401 keeps caller text from starting
a log line; the gateway contract cases send a method segment carrying a
percent-encoded line break and require no log line to begin with the
marker (L7).

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 8, 2026
Every RPC case in this suite names api-inventory.json as mandatory test
data and states that the method is exercised with its request fields
"absent/default, valid, boundary-invalid and combined with an unknown
field" in both representations. The harnesses behind those cases send
one valid request and one wrong-typed value for the *first* request
field. So the input classes where a service actually breaks -- an
out-of-range integer, an oversized string, a wrong protobuf wire type, a
truncated body -- are untested for all 110 indexed methods.

Add a harness that implements the stated matrix once, driven by the same
inventory, and nine cases that apply it to the guest agent's four
services, the KMS's two, and the gateway's three. It asserts the
invariants that hold for every method whatever it means: a malformed
request is never a 5xx or a dropped connection, a rejection is
structured and bounded and carries the caller's own representation, no
call outlives its deadline, and the listener still answers afterwards.
That last one is a real assertion here: the workspace builds release
binaries with `panic = "abort"`, so a reachable panic is a process abort.

api-contract-matrix-policy.json says how far each method may be driven.
`full` is for a method whose effect stays inside the lease;
`rejection-only` sends only what a service must refuse before it
dispatches, so nothing can mutate; `skip` is for a method whose valid
invocation ends the process or consumes an external resource, and the
file records the reason for each. Every method in the inventory must
carry a policy -- one added without one fails the case rather than being
silently skipped.

Two product defects found while building this are fixed separately:
a `not_after` of u64::MAX aborted the guest agent (#1232), and a
rejection echoed the whole rejected value back to the caller and into
the log under a content type the caller did not ask for (#1234).
kvinwang added a commit that referenced this pull request Nov 8, 2026
…ct matrix

PR #1234 caps pRPC error text at 2 KiB and answers a JSON request refused
before dispatch in JSON; L4 now bounds the decoded error text and L6
covers the pre-dispatch refusal. PR #1401 keeps caller text from starting
a log line; the gateway contract cases send a method segment carrying a
percent-encoded line break and require no log line to begin with the
marker (L7).

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 8, 2026
Every RPC case in this suite names api-inventory.json as mandatory test
data and states that the method is exercised with its request fields
"absent/default, valid, boundary-invalid and combined with an unknown
field" in both representations. The harnesses behind those cases send
one valid request and one wrong-typed value for the *first* request
field. So the input classes where a service actually breaks -- an
out-of-range integer, an oversized string, a wrong protobuf wire type, a
truncated body -- are untested for all 110 indexed methods.

Add a harness that implements the stated matrix once, driven by the same
inventory, and nine cases that apply it to the guest agent's four
services, the KMS's two, and the gateway's three. It asserts the
invariants that hold for every method whatever it means: a malformed
request is never a 5xx or a dropped connection, a rejection is
structured and bounded and carries the caller's own representation, no
call outlives its deadline, and the listener still answers afterwards.
That last one is a real assertion here: the workspace builds release
binaries with `panic = "abort"`, so a reachable panic is a process abort.

api-contract-matrix-policy.json says how far each method may be driven.
`full` is for a method whose effect stays inside the lease;
`rejection-only` sends only what a service must refuse before it
dispatches, so nothing can mutate; `skip` is for a method whose valid
invocation ends the process or consumes an external resource, and the
file records the reason for each. Every method in the inventory must
carry a policy -- one added without one fails the case rather than being
silently skipped.

Two product defects found while building this are fixed separately:
a `not_after` of u64::MAX aborted the guest agent (#1232), and a
rejection echoed the whole rejected value back to the caller and into
the log under a content type the caller did not ask for (#1234).
kvinwang added a commit that referenced this pull request Nov 8, 2026
…ct matrix

PR #1234 caps pRPC error text at 2 KiB and answers a JSON request refused
before dispatch in JSON; L4 now bounds the decoded error text and L6
covers the pre-dispatch refusal. PR #1401 keeps caller text from starting
a log line; the gateway contract cases send a method segment carrying a
percent-encoded line break and require no log line to begin with the
marker (L7).

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 10, 2026
Every RPC case in this suite names api-inventory.json as mandatory test
data and states that the method is exercised with its request fields
"absent/default, valid, boundary-invalid and combined with an unknown
field" in both representations. The harnesses behind those cases send
one valid request and one wrong-typed value for the *first* request
field. So the input classes where a service actually breaks -- an
out-of-range integer, an oversized string, a wrong protobuf wire type, a
truncated body -- are untested for all 110 indexed methods.

Add a harness that implements the stated matrix once, driven by the same
inventory, and nine cases that apply it to the guest agent's four
services, the KMS's two, and the gateway's three. It asserts the
invariants that hold for every method whatever it means: a malformed
request is never a 5xx or a dropped connection, a rejection is
structured and bounded and carries the caller's own representation, no
call outlives its deadline, and the listener still answers afterwards.
That last one is a real assertion here: the workspace builds release
binaries with `panic = "abort"`, so a reachable panic is a process abort.

api-contract-matrix-policy.json says how far each method may be driven.
`full` is for a method whose effect stays inside the lease;
`rejection-only` sends only what a service must refuse before it
dispatches, so nothing can mutate; `skip` is for a method whose valid
invocation ends the process or consumes an external resource, and the
file records the reason for each. Every method in the inventory must
carry a policy -- one added without one fails the case rather than being
silently skipped.

Two product defects found while building this are fixed separately:
a `not_after` of u64::MAX aborted the guest agent (#1232), and a
rejection echoed the whole rejected value back to the caller and into
the log under a content type the caller did not ask for (#1234).
kvinwang added a commit that referenced this pull request Nov 10, 2026
…ct matrix

PR #1234 caps pRPC error text at 2 KiB and answers a JSON request refused
before dispatch in JSON; L4 now bounds the decoded error text and L6
covers the pre-dispatch refusal. PR #1401 keeps caller text from starting
a log line; the gateway contract cases send a method segment carrying a
percent-encoded line break and require no log line to begin with the
marker (L7).

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 11, 2026
Every RPC case in this suite names api-inventory.json as mandatory test
data and states that the method is exercised with its request fields
"absent/default, valid, boundary-invalid and combined with an unknown
field" in both representations. The harnesses behind those cases send
one valid request and one wrong-typed value for the *first* request
field. So the input classes where a service actually breaks -- an
out-of-range integer, an oversized string, a wrong protobuf wire type, a
truncated body -- are untested for all 110 indexed methods.

Add a harness that implements the stated matrix once, driven by the same
inventory, and nine cases that apply it to the guest agent's four
services, the KMS's two, and the gateway's three. It asserts the
invariants that hold for every method whatever it means: a malformed
request is never a 5xx or a dropped connection, a rejection is
structured and bounded and carries the caller's own representation, no
call outlives its deadline, and the listener still answers afterwards.
That last one is a real assertion here: the workspace builds release
binaries with `panic = "abort"`, so a reachable panic is a process abort.

api-contract-matrix-policy.json says how far each method may be driven.
`full` is for a method whose effect stays inside the lease;
`rejection-only` sends only what a service must refuse before it
dispatches, so nothing can mutate; `skip` is for a method whose valid
invocation ends the process or consumes an external resource, and the
file records the reason for each. Every method in the inventory must
carry a policy -- one added without one fails the case rather than being
silently skipped.

Two product defects found while building this are fixed separately:
a `not_after` of u64::MAX aborted the guest agent (#1232), and a
rejection echoed the whole rejected value back to the caller and into
the log under a content type the caller did not ask for (#1234).
kvinwang added a commit that referenced this pull request Nov 11, 2026
…ct matrix

PR #1234 caps pRPC error text at 2 KiB and answers a JSON request refused
before dispatch in JSON; L4 now bounds the decoded error text and L6
covers the pre-dispatch refusal. PR #1401 keeps caller text from starting
a log line; the gateway contract cases send a method segment carrying a
percent-encoded line break and require no log line to begin with the
marker (L7).

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 11, 2026
Every RPC case in this suite names api-inventory.json as mandatory test
data and states that the method is exercised with its request fields
"absent/default, valid, boundary-invalid and combined with an unknown
field" in both representations. The harnesses behind those cases send
one valid request and one wrong-typed value for the *first* request
field. So the input classes where a service actually breaks -- an
out-of-range integer, an oversized string, a wrong protobuf wire type, a
truncated body -- are untested for all 110 indexed methods.

Add a harness that implements the stated matrix once, driven by the same
inventory, and nine cases that apply it to the guest agent's four
services, the KMS's two, and the gateway's three. It asserts the
invariants that hold for every method whatever it means: a malformed
request is never a 5xx or a dropped connection, a rejection is
structured and bounded and carries the caller's own representation, no
call outlives its deadline, and the listener still answers afterwards.
That last one is a real assertion here: the workspace builds release
binaries with `panic = "abort"`, so a reachable panic is a process abort.

api-contract-matrix-policy.json says how far each method may be driven.
`full` is for a method whose effect stays inside the lease;
`rejection-only` sends only what a service must refuse before it
dispatches, so nothing can mutate; `skip` is for a method whose valid
invocation ends the process or consumes an external resource, and the
file records the reason for each. Every method in the inventory must
carry a policy -- one added without one fails the case rather than being
silently skipped.

Two product defects found while building this are fixed separately:
a `not_after` of u64::MAX aborted the guest agent (#1232), and a
rejection echoed the whole rejected value back to the caller and into
the log under a content type the caller did not ask for (#1234).
kvinwang added a commit that referenced this pull request Nov 11, 2026
…ct matrix

PR #1234 caps pRPC error text at 2 KiB and answers a JSON request refused
before dispatch in JSON; L4 now bounds the decoded error text and L6
covers the pre-dispatch refusal. PR #1401 keeps caller text from starting
a log line; the gateway contract cases send a method segment carrying a
percent-encoded line break and require no log line to begin with the
marker (L7).

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 16, 2026
Every RPC case in this suite names api-inventory.json as mandatory test
data and states that the method is exercised with its request fields
"absent/default, valid, boundary-invalid and combined with an unknown
field" in both representations. The harnesses behind those cases send
one valid request and one wrong-typed value for the *first* request
field. So the input classes where a service actually breaks -- an
out-of-range integer, an oversized string, a wrong protobuf wire type, a
truncated body -- are untested for all 110 indexed methods.

Add a harness that implements the stated matrix once, driven by the same
inventory, and nine cases that apply it to the guest agent's four
services, the KMS's two, and the gateway's three. It asserts the
invariants that hold for every method whatever it means: a malformed
request is never a 5xx or a dropped connection, a rejection is
structured and bounded and carries the caller's own representation, no
call outlives its deadline, and the listener still answers afterwards.
That last one is a real assertion here: the workspace builds release
binaries with `panic = "abort"`, so a reachable panic is a process abort.

api-contract-matrix-policy.json says how far each method may be driven.
`full` is for a method whose effect stays inside the lease;
`rejection-only` sends only what a service must refuse before it
dispatches, so nothing can mutate; `skip` is for a method whose valid
invocation ends the process or consumes an external resource, and the
file records the reason for each. Every method in the inventory must
carry a policy -- one added without one fails the case rather than being
silently skipped.

Two product defects found while building this are fixed separately:
a `not_after` of u64::MAX aborted the guest agent (#1232), and a
rejection echoed the whole rejected value back to the caller and into
the log under a content type the caller did not ask for (#1234).
kvinwang added a commit that referenced this pull request Nov 16, 2026
…ct matrix

PR #1234 caps pRPC error text at 2 KiB and answers a JSON request refused
before dispatch in JSON; L4 now bounds the decoded error text and L6
covers the pre-dispatch refusal. PR #1401 keeps caller text from starting
a log line; the gateway contract cases send a method segment carrying a
percent-encoded line break and require no log line to begin with the
marker (L7).

Signed-off-by: Kevin Wang <wy721@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant