Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions pkg/capabilities/v2/actions/confidentialrelay/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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".
Expand Down
50 changes: 50 additions & 0 deletions pkg/capabilities/v2/actions/confidentialrelay/types_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package confidentialrelay

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -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)
}
}
Loading