Skip to content

Commit 7fdc582

Browse files
Merge pull request #6568 from oasisprotocol/martin/clean-up-before-kma-policy
go: Clean up before key manager access policy
2 parents 9f50f1a + 6278c72 commit 7fdc582

17 files changed

Lines changed: 246 additions & 110 deletions

File tree

.changelog/6568.trivial.md

Whitespace-only changes.

go/common/node/node.go

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
beacon "github.com/oasisprotocol/oasis-core/go/beacon/api"
1515
"github.com/oasisprotocol/oasis-core/go/common"
1616
"github.com/oasisprotocol/oasis-core/go/common/cbor"
17-
"github.com/oasisprotocol/oasis-core/go/common/crypto/hash"
1817
"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
1918
"github.com/oasisprotocol/oasis-core/go/common/prettyprint"
2019
"github.com/oasisprotocol/oasis-core/go/common/version"
@@ -46,8 +45,6 @@ var (
4645
// to be from the future.
4746
ErrAttestationFromFuture = errors.New("node: TEE attestation from the future")
4847

49-
teeHashContext = []byte("oasis-core/node: TEE RAK binding")
50-
5148
// AttestationSignatureContext is the signature context used for TEE attestation signatures.
5249
AttestationSignatureContext = signature.NewContext("oasis-core/node: TEE attestation signature")
5350

@@ -550,6 +547,27 @@ func (h *TEEHardware) FromString(str string) error {
550547
return nil
551548
}
552549

550+
// CapabilityTEEVerifyParams contains parameters required to verify a TEE attestation.
551+
type CapabilityTEEVerifyParams struct {
552+
// Features are the TEE features and defaults advertised by the consensus layer.
553+
Features *TEEFeatures
554+
555+
// Time is the current consensus time.
556+
Time time.Time
557+
558+
// Height is the current consensus height.
559+
Height uint64
560+
561+
// Constraints are the serialized TEE constraints.
562+
Constraints []byte
563+
564+
// NodeID is the node identity the TEE capability must be bound to.
565+
NodeID signature.PublicKey
566+
567+
// IsFeatureVersion261 is true for consensus at version 26.1 or higher.
568+
IsFeatureVersion261 bool
569+
}
570+
553571
// CapabilityTEE represents the node's TEE capability.
554572
type CapabilityTEE struct {
555573
// TEE hardware type.
@@ -565,38 +583,38 @@ type CapabilityTEE struct {
565583
Attestation []byte `json:"attestation"`
566584
}
567585

568-
// HashRAK computes the expected report data hash bound to a given public RAK.
569-
func HashRAK(rak signature.PublicKey) hash.Hash {
570-
hData := make([]byte, 0, len(teeHashContext)+signature.PublicKeySize)
571-
hData = append(hData, teeHashContext...)
572-
hData = append(hData, rak[:]...)
573-
return hash.NewFromBytes(hData)
574-
}
575-
576586
// Verify verifies the node's TEE capabilities, at the provided timestamp and height.
577-
func (c *CapabilityTEE) Verify(teeCfg *TEEFeatures, ts time.Time, height uint64, constraints []byte, nodeID signature.PublicKey, isFeatureVersion261 bool) error {
587+
func (c *CapabilityTEE) Verify(params CapabilityTEEVerifyParams) error {
578588
switch c.Hardware {
579589
case TEEHardwareIntelSGX:
580590
// Parse SGX remote attestation.
581591
var sa SGXAttestation
582592
if err := cbor.Unmarshal(c.Attestation, &sa); err != nil {
583593
return fmt.Errorf("node: malformed SGX attestation: %w", err)
584594
}
585-
if err := sa.ValidateBasic(teeCfg); err != nil {
595+
if err := sa.ValidateBasic(params.Features); err != nil {
586596
return fmt.Errorf("node: malformed SGX attestation: %w", err)
587597
}
588598

589599
// Parse SGX constraints.
590600
var sc SGXConstraints
591-
if err := cbor.Unmarshal(constraints, &sc); err != nil {
601+
if err := cbor.Unmarshal(params.Constraints, &sc); err != nil {
592602
return fmt.Errorf("node: malformed SGX constraints: %w", err)
593603
}
594-
if err := sc.ValidateBasic(teeCfg, isFeatureVersion261); err != nil {
604+
if err := sc.ValidateBasic(params.Features, params.IsFeatureVersion261); err != nil {
595605
return fmt.Errorf("node: malformed SGX constraints: %w", err)
596606
}
597607

598608
// Verify SGX remote attestation.
599-
return sa.Verify(teeCfg, ts, height, &sc, c.RAK, c.REK, nodeID)
609+
return sa.Verify(
610+
params.Features,
611+
params.Time,
612+
params.Height,
613+
&sc,
614+
c.RAK,
615+
c.REK,
616+
params.NodeID,
617+
)
600618
default:
601619
return ErrInvalidTEEHardware
602620
}

go/common/node/sgx.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,15 @@ func (sa *SGXAttestation) verifyAttestationSignature(
286286
return nil
287287
}
288288

289+
// HashRAK computes the expected report data hash bound to a given public RAK.
290+
func HashRAK(rak signature.PublicKey) hash.Hash {
291+
const teeHashContext = "oasis-core/node: TEE RAK binding"
292+
hData := make([]byte, 0, len(teeHashContext)+signature.PublicKeySize)
293+
hData = append(hData, teeHashContext...)
294+
hData = append(hData, rak[:]...)
295+
return hash.NewFromBytes(hData)
296+
}
297+
289298
// HashAttestation hashes the required data that needs to be signed by RAK producing the attestation
290299
// signature. The hash is computed as follows:
291300
//

go/consensus/cometbft/apps/scheduler/scheduler.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -437,14 +437,14 @@ func isSuitableExecutorWorker(
437437
if nrt.Capabilities.TEE.Hardware != rt.TEEHardware {
438438
return false
439439
}
440-
if err := nrt.Capabilities.TEE.Verify(
441-
registryParams.TEEFeatures,
442-
ctx.Now(),
443-
uint64(ctx.LastHeight()),
444-
activeDeployment.TEE,
445-
n.node.ID,
446-
isFeatureVersion261,
447-
); err != nil {
440+
if err := nrt.Capabilities.TEE.Verify(node.CapabilityTEEVerifyParams{
441+
Features: registryParams.TEEFeatures,
442+
Time: ctx.Now(),
443+
Height: uint64(ctx.LastHeight()),
444+
Constraints: activeDeployment.TEE,
445+
NodeID: n.node.ID,
446+
IsFeatureVersion261: isFeatureVersion261,
447+
}); err != nil {
448448
ctx.Logger().Warn("failed to verify node TEE attestation",
449449
"err", err,
450450
"node_id", n.node.ID,

go/oasis-node/cmd/debug/byzantine/steps_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,13 @@ func TestFakeCapabilitySGX(t *testing.T) {
3131

3232
ias.SetSkipVerify()
3333
ias.SetAllowDebugEnclaves()
34-
require.NoError(t, fakeCapabilitiesSGX.TEE.Verify(&teeCfg, time.Now(), 1, cs, nodeID, true), "fakeCapabilitiesSGX not valid")
34+
err = fakeCapabilitiesSGX.TEE.Verify(node.CapabilityTEEVerifyParams{
35+
Features: &teeCfg,
36+
Time: time.Now(),
37+
Height: 1,
38+
Constraints: cs,
39+
NodeID: nodeID,
40+
IsFeatureVersion261: true,
41+
})
42+
require.NoError(t, err, "fakeCapabilitiesSGX not valid")
3543
}

go/oasis-node/cmd/node/node.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,15 @@ func (n *Node) initRuntimeWorkers(genesisDoc *genesisAPI.Document) error {
199199
}
200200

201201
// Initialize runtime provisioner.
202+
policyProvider := &runtimeRegistry.QuotePolicyProvider{Consensus: n.Consensus}
202203
var err error
203-
n.Provisioner, err = provisioner.New(n.dataDir, n.commonStore, n.Identity, n.Consensus, genesisDoc)
204+
n.Provisioner, err = provisioner.New(
205+
n.dataDir,
206+
n.commonStore,
207+
n.Identity,
208+
genesisDoc,
209+
policyProvider,
210+
)
204211
if err != nil {
205212
return err
206213
}

go/registry/api/api.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,14 @@ func VerifyNodeRuntimeEnclaveIDs(
840840
continue
841841
}
842842

843-
if err := rt.Capabilities.TEE.Verify(teeCfg, ts, height, rtVersionInfo.TEE, nodeID, isFeatureVersion261); err != nil {
843+
if err := rt.Capabilities.TEE.Verify(node.CapabilityTEEVerifyParams{
844+
Features: teeCfg,
845+
Time: ts,
846+
Height: height,
847+
Constraints: rtVersionInfo.TEE,
848+
NodeID: nodeID,
849+
IsFeatureVersion261: isFeatureVersion261,
850+
}); err != nil {
844851
logger.Error("VerifyNodeRuntimeEnclaveIDs: failed to validate attestation",
845852
"node_id", nodeID,
846853
"runtime_id", rt.ID,

go/runtime/host/host.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/oasisprotocol/oasis-core/go/common"
88
"github.com/oasisprotocol/oasis-core/go/common/node"
99
"github.com/oasisprotocol/oasis-core/go/common/pubsub"
10+
"github.com/oasisprotocol/oasis-core/go/common/sgx/quote"
1011
"github.com/oasisprotocol/oasis-core/go/common/version"
1112
"github.com/oasisprotocol/oasis-core/go/runtime/bundle"
1213
"github.com/oasisprotocol/oasis-core/go/runtime/bundle/component"
@@ -38,6 +39,12 @@ type Config struct {
3839
Log *log.Log
3940
}
4041

42+
// QuotePolicyProvider provides quote policies for provisioned components.
43+
type QuotePolicyProvider interface {
44+
// Get returns the applicable quote policy, or nil if there is none.
45+
Get(ctx context.Context, runtimeID common.Namespace, compID component.ID, version version.Version) (*quote.Policy, error)
46+
}
47+
4148
// Provisioner is the runtime provisioner interface.
4249
type Provisioner interface {
4350
// NewRuntime provisions a new runtime.

go/runtime/host/provisioner/provisioner.go

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
package provisioner
22

33
import (
4-
"context"
54
"fmt"
65

7-
"github.com/oasisprotocol/oasis-core/go/common"
8-
"github.com/oasisprotocol/oasis-core/go/common/cbor"
96
"github.com/oasisprotocol/oasis-core/go/common/identity"
10-
"github.com/oasisprotocol/oasis-core/go/common/node"
117
"github.com/oasisprotocol/oasis-core/go/common/persistent"
128
"github.com/oasisprotocol/oasis-core/go/common/sgx/pcs"
13-
sgxQuote "github.com/oasisprotocol/oasis-core/go/common/sgx/quote"
149
"github.com/oasisprotocol/oasis-core/go/common/version"
1510
"github.com/oasisprotocol/oasis-core/go/config"
16-
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
1711
genesisAPI "github.com/oasisprotocol/oasis-core/go/genesis/api"
1812
cmdFlags "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/flags"
19-
registry "github.com/oasisprotocol/oasis-core/go/registry/api"
2013
"github.com/oasisprotocol/oasis-core/go/runtime/bundle/component"
2114
rtConfig "github.com/oasisprotocol/oasis-core/go/runtime/config"
2215
runtimeHost "github.com/oasisprotocol/oasis-core/go/runtime/host"
@@ -26,7 +19,6 @@ import (
2619
hostProtocol "github.com/oasisprotocol/oasis-core/go/runtime/host/protocol"
2720
hostSandbox "github.com/oasisprotocol/oasis-core/go/runtime/host/sandbox"
2821
hostSgx "github.com/oasisprotocol/oasis-core/go/runtime/host/sgx"
29-
sgxCommon "github.com/oasisprotocol/oasis-core/go/runtime/host/sgx/common"
3022
hostTdx "github.com/oasisprotocol/oasis-core/go/runtime/host/tdx"
3123
)
3224

@@ -39,8 +31,8 @@ func New(
3931
dataDir string,
4032
commonStore *persistent.CommonStore,
4133
identity *identity.Identity,
42-
consensus consensus.Service,
4334
genesisDoc *genesisAPI.Document,
35+
policyProvider runtimeHost.QuotePolicyProvider,
4436
) (runtimeHost.Provisioner, error) {
4537
// Configure host environment information.
4638
hostInfo, err := createHostInfo(genesisDoc)
@@ -54,8 +46,6 @@ func New(
5446
return nil, err
5547
}
5648

57-
policyProvider := &quotePolicyProvider{consensus}
58-
5949
// Create runtime provisioner.
6050
return createProvisioner(dataDir, commonStore, identity, hostInfo, qs, policyProvider)
6151
}
@@ -87,7 +77,7 @@ func createProvisioner(
8777
identity *identity.Identity,
8878
hostInfo *hostProtocol.HostInfo,
8979
qs pcs.QuoteService,
90-
policyProvider sgxCommon.QuotePolicyProvider,
80+
policyProvider runtimeHost.QuotePolicyProvider,
9181
) (runtimeHost.Provisioner, error) {
9282
var err error
9383
var insecureNoSandbox bool
@@ -202,26 +192,3 @@ func createProvisioner(
202192

203193
return provisioner, nil
204194
}
205-
206-
type quotePolicyProvider struct {
207-
cs consensus.Service
208-
}
209-
210-
func (p *quotePolicyProvider) Get(ctx context.Context, runtimeID common.Namespace, version version.Version) (*sgxQuote.Policy, error) {
211-
rt, err := p.cs.Registry().GetRuntime(ctx, &registry.GetRuntimeQuery{
212-
Height: consensus.HeightLatest,
213-
ID: runtimeID,
214-
IncludeSuspended: true,
215-
})
216-
if err != nil {
217-
return nil, fmt.Errorf("failed to query runtime descriptor: %w", err)
218-
}
219-
if d := rt.DeploymentForVersion(version); d != nil {
220-
var sc node.SGXConstraints
221-
if err = cbor.Unmarshal(d.TEE, &sc); err != nil {
222-
return nil, fmt.Errorf("malformed runtime SGX constraints: %w", err)
223-
}
224-
return sc.Policy, nil
225-
}
226-
return nil, nil
227-
}

go/runtime/host/sgx/common/common.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,18 @@ import (
88

99
"github.com/cenkalti/backoff/v4"
1010

11-
"github.com/oasisprotocol/oasis-core/go/common"
1211
"github.com/oasisprotocol/oasis-core/go/common/cbor"
1312
"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
1413
"github.com/oasisprotocol/oasis-core/go/common/identity"
1514
"github.com/oasisprotocol/oasis-core/go/common/logging"
1615
"github.com/oasisprotocol/oasis-core/go/common/node"
1716
"github.com/oasisprotocol/oasis-core/go/common/sgx/pcs"
1817
sgxQuote "github.com/oasisprotocol/oasis-core/go/common/sgx/quote"
19-
"github.com/oasisprotocol/oasis-core/go/common/version"
2018
"github.com/oasisprotocol/oasis-core/go/runtime/host"
2119
"github.com/oasisprotocol/oasis-core/go/runtime/host/protocol"
2220
"github.com/oasisprotocol/oasis-core/go/runtime/host/sandbox"
2321
)
2422

25-
// QuotePolicyProvider provides quote policies.
26-
type QuotePolicyProvider interface {
27-
// Get returns the quote policy for the specified RONL deployment.
28-
Get(ctx context.Context, runtimeID common.Namespace, version version.Version) (*sgxQuote.Policy, error)
29-
}
30-
3123
// EndorseCapabilityTEE endorses the given CapabilityTEE and submits the signed endorsement to the
3224
// runtime over the given connection.
3325
func EndorseCapabilityTEE(

0 commit comments

Comments
 (0)