Replace the service bearer tokens with [tls] ca_file and cert_dir. Caller identity comes from the verified certificate, not metadata. Without TLS, services listen and dial on loopback only. Task containers get only the CA and keep their grant.
61 lines
2.1 KiB
Go
61 lines
2.1 KiB
Go
package staterpc
|
|
|
|
import (
|
|
"context"
|
|
"crypto/sha256"
|
|
"strings"
|
|
"testing"
|
|
|
|
"google.golang.org/grpc"
|
|
grpccreds "google.golang.org/grpc/credentials"
|
|
"google.golang.org/grpc/metadata"
|
|
"google.golang.org/grpc/peer"
|
|
|
|
pb "github.com/samcharles93/archie-core/internal/contracts/state/v1"
|
|
)
|
|
|
|
// TestTaskCredentialCannotReplaceItsPin pins that an Update made with a
|
|
// task's own credential reaches the store without a workflow definition, so
|
|
// the stored pin (where the run's package authority is read from) stays. The
|
|
// workflow name still moves for a handoff; the daemon's credential re-pins.
|
|
func TestTaskCredentialCannotReplaceItsPin(t *testing.T) {
|
|
taskToken := strings.Repeat("ab", 32)
|
|
grants := &TaskGrants{Store: credentials{sha256.Sum256([]byte(taskToken)): 7}}
|
|
intercept := grants.UnaryInterceptor()
|
|
tests := []struct {
|
|
name, token, wantYAML string
|
|
peer *peer.Peer
|
|
}{
|
|
{"task credential", taskToken, "", &peer.Peer{AuthInfo: grpccreds.TLSInfo{}}},
|
|
{"daemon", "", "yaml-b", &peer.Peer{}},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
ctx := peer.NewContext(metadata.NewIncomingContext(context.Background(), metadata.Pairs(tokenMetadataKey, tt.token)), tt.peer)
|
|
req := &pb.UpdateRequest{Task: &pb.Task{
|
|
Id: 7, Workflow: "handoff-target",
|
|
WorkflowDefinitionVersion: 4, WorkflowDefinitionDigest: "digest-b", WorkflowDefinitionYaml: "yaml-b",
|
|
}}
|
|
var got *pb.Task
|
|
_, err := intercept(ctx, req, &grpc.UnaryServerInfo{FullMethod: pb.StateStoreService_Update_FullMethodName},
|
|
func(_ context.Context, r any) (any, error) {
|
|
update, ok := r.(*pb.UpdateRequest)
|
|
if !ok {
|
|
t.Fatalf("handler got %T", r)
|
|
}
|
|
got = update.Task
|
|
return &pb.UpdateResponse{}, nil
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got.WorkflowDefinitionYaml != tt.wantYAML || (tt.wantYAML == "" && got.WorkflowDefinitionDigest != "") {
|
|
t.Fatalf("definition reaching the store = %q/%q, want %q", got.WorkflowDefinitionYaml, got.WorkflowDefinitionDigest, tt.wantYAML)
|
|
}
|
|
if got.Workflow != "handoff-target" {
|
|
t.Fatalf("workflow = %q, want handoff-target", got.Workflow)
|
|
}
|
|
})
|
|
}
|
|
}
|