From fab8a1459a68b11ceb48e17eb86cc52afded6ecb Mon Sep 17 00:00:00 2001 From: Bolek Kulbabinski <1416262+bolekk@users.noreply.github.com> Date: Thu, 15 Oct 2026 23:01:40 -0400 Subject: [PATCH] cre-6798: add DonName to confidential relay request params With ShardIndex alone the gateway cannot tell which DON's shard is meant when a service has several DONs. DonName is the node's GatewayConnector DonID minus the _shard-N suffix. Co-Authored-By: Claude Sonnet 5.5 --- .../v2/actions/confidentialrelay/types.go | 16 +++--- .../actions/confidentialrelay/types_test.go | 50 +++++++++++++++++++ 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/pkg/capabilities/v2/actions/confidentialrelay/types.go b/pkg/capabilities/v2/actions/confidentialrelay/types.go index 0380ecdb17..0813a0e94d 100644 --- a/pkg/capabilities/v2/actions/confidentialrelay/types.go +++ b/pkg/capabilities/v2/actions/confidentialrelay/types.go @@ -96,10 +96,11 @@ type SecretsRequestParams struct { // Attestation, it is authorization input and is excluded from the response hash. SignedComputeRequests []SignedComputeRequest `json:"signed_compute_requests,omitempty"` - // ShardIndex selects which gateway DON shard relays this request. It is gateway - // routing metadata: the relay DON does not read it and it is excluded from - // the response hash. A request that omits it defaults to shard 0. - ShardIndex int `json:"shard_index,omitempty"` + // Gateway routing metadata: name and shard index of the workflow DON that + // started the execution. Set by the enclave and excluded from the response + // hash. They are covered by the enclave attestation (JSON of the full params). + WorkflowDonName string `json:"workflow_don_name,omitempty"` + WorkflowDONShardIndex int `json:"workflow_don_shard_index,omitempty"` } // SecretEntry is a single secret in the relay DON's response. @@ -234,8 +235,11 @@ type CapabilityRequestParams struct { EnclaveConfig *EnclaveConfig `json:"enclave_config,omitempty"` Attestation string `json:"attestation,omitempty"` - // ShardIndex selects which gateway DON shard relays this request. - ShardIndex int `json:"shard_index,omitempty"` + // Gateway routing metadata: name and shard index of the workflow DON that + // started the execution. Set by the enclave and excluded from the response + // hash. They are covered by the enclave attestation (JSON of the full params). + WorkflowDonName string `json:"workflow_don_name,omitempty"` + WorkflowDONShardIndex int `json:"workflow_don_shard_index,omitempty"` } // CapabilityResponseResult is the JSON-RPC result for "confidential.capability.execute". diff --git a/pkg/capabilities/v2/actions/confidentialrelay/types_test.go b/pkg/capabilities/v2/actions/confidentialrelay/types_test.go index 68eeeea34c..4e8ab83ae9 100644 --- a/pkg/capabilities/v2/actions/confidentialrelay/types_test.go +++ b/pkg/capabilities/v2/actions/confidentialrelay/types_test.go @@ -1,6 +1,7 @@ package confidentialrelay import ( + "encoding/json" "testing" "github.com/stretchr/testify/require" @@ -576,3 +577,52 @@ func TestSecretsResponseHash_StableUnderSignerReordering(t *testing.T) { reversed.EnclaveConfig = &rc require.Equal(t, base, mustSecretsHash(t, result, reversed)) } + +func TestResponseHash_IgnoresRoutingFields(t *testing.T) { + secretsResult := SecretsResponseResult{ + Secrets: []SecretEntry{ + {ID: SecretIdentifier{Key: "alpha", Namespace: "ns-a"}, Ciphertext: "c", EncryptedShares: []string{"s"}}, + }, + } + sp := validSecretsParams() + spRouted := validSecretsParams() + spRouted.WorkflowDonName = "workflow_1_zone-a" + spRouted.WorkflowDONShardIndex = 2 + require.Equal(t, mustSecretsHash(t, secretsResult, sp), mustSecretsHash(t, secretsResult, spRouted)) + + capResult := CapabilityResponseResult{Payload: "out"} + cp := validCapabilityParams() + cpRouted := validCapabilityParams() + cpRouted.WorkflowDonName = "workflow_1_zone-a" + cpRouted.WorkflowDONShardIndex = 2 + require.Equal(t, mustCapabilityHash(t, capResult, cp), mustCapabilityHash(t, capResult, cpRouted)) +} + +// The attestation covers the JSON of the full params, so zero-valued routing +// fields must not appear in it: older relay nodes re-marshal without them. +func TestRequestParamsJSON_OmitsZeroRoutingFields(t *testing.T) { + keys := func(t *testing.T, v any) map[string]json.RawMessage { + t.Helper() + b, err := json.Marshal(v) + require.NoError(t, err) + var m map[string]json.RawMessage + require.NoError(t, json.Unmarshal(b, &m)) + return m + } + + sp := validSecretsParams() + cp := validCapabilityParams() + for name, v := range map[string]any{"secrets": sp, "capability": cp} { + m := keys(t, v) + require.NotContains(t, m, "workflow_don_name", name) + require.NotContains(t, m, "workflow_don_shard_index", name) + } + + sp.WorkflowDonName, sp.WorkflowDONShardIndex = "workflow_1_zone-a", 2 + cp.WorkflowDonName, cp.WorkflowDONShardIndex = "workflow_1_zone-a", 2 + for name, v := range map[string]any{"secrets": sp, "capability": cp} { + m := keys(t, v) + require.JSONEq(t, `"workflow_1_zone-a"`, string(m["workflow_don_name"]), name) + require.JSONEq(t, `2`, string(m["workflow_don_shard_index"]), name) + } +}