Skip to content

Commit c9acbf2

Browse files
authored
Merge pull request #5975 from oasisprotocol/peternose/trivial/simplify-create-provisioner
go/runtime/registry: Simplify creation of provisioners
2 parents 4aa7157 + 00d4b91 commit c9acbf2

File tree

14 files changed

+195
-99
lines changed

14 files changed

+195
-99
lines changed

.buildkite/code.pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ steps:
354354
- .buildkite/scripts/test_e2e.sh --timeout 20m --scenario e2e/runtime/runtime-encryption
355355
env:
356356
OASIS_TEE_HARDWARE: intel-sgx
357-
OASIS_UNSAFE_MOCK_SGX: "1"
357+
OASIS_UNSAFE_MOCK_TEE: "1"
358358
OASIS_UNSAFE_SKIP_AVR_VERIFY: "1"
359359
OASIS_E2E_COVERAGE: enable
360360
TEST_BASE_DIR: /tmp

.changelog/5975.cfg.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
go/runtime/config: Support selection of TEE kind
2+
3+
The node operator can now specify the kind of Trusted Execution Environment
4+
(TEE) in which the runtime component should run. If no TEE is specified,
5+
it is automatically selected, with TDX and SGX taking precedence over ELF.
6+
7+
The following configuration option has been deprecated:
8+
9+
- `runtime.environment`
10+
11+
The following configuration options have been added:
12+
13+
- `runtime.debug_mock_tee` to enable TEE mocking for testing,
14+
15+
- `runtime.runtimes.components.tee` to specify the TEE for a component.
16+
17+
These changes affect the configuration of the client node if the runtime
18+
bundle contains both TEE and non-TEE binaries. In such cases, the node
19+
operator must explicitly configure the runtime to avoid running in a TEE
20+
environment.
21+
22+
Configuring non-TEE Paratime Client Node:
23+
24+
```
25+
mode: client
26+
# ... sections not relevant are omitted ...
27+
runtime:
28+
paths:
29+
- {{ runtime_orc_path }}
30+
runtimes:
31+
- id: {{ runtime_id }}
32+
components:
33+
- id: ronl
34+
tee: none # Don't run in SGX or TDX!
35+
```
36+
37+
Configuring TEE Paratime Client Node:
38+
39+
```
40+
mode: client
41+
# ... sections not relevant are omitted ...
42+
runtime:
43+
paths:
44+
- {{ runtime_orc_path }}
45+
sgx_loader: /node/bin/oasis-core-runtime-loader
46+
# environment: sgx # Deprecated, can be removed.
47+
```

.changelog/5975.internal.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
go/oasis-test-runner: Generalize OASIS_UNSAFE_MOCK_SGX flag
2+
3+
Flag OASIS_UNSAFE_MOCK_SGX was renamed to OASIS_UNSAFE_MOCK_TEE.

common.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ endif
352352
# https://goreleaser.com/customization/build/#define-build-tag
353353
export GORELEASER_CURRENT_TAG := $(RELEASE_TAG)
354354

355-
# If mock SGX is configured, define extra runtime build flags.
356-
ifdef OASIS_UNSAFE_MOCK_SGX
355+
# If mock TEE is configured, define extra runtime build flags.
356+
ifdef OASIS_UNSAFE_MOCK_TEE
357357
OASIS_RUNTIME_NONSGX_FLAGS := --features debug-mock-sgx
358358
else
359359
OASIS_RUNTIME_NONSGX_FLAGS :=

go/oasis-test-runner/oasis/network.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import (
4141
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/log"
4242
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/oasis/cli"
4343
roothash "github.com/oasisprotocol/oasis-core/go/roothash/api"
44-
runtimeConfig "github.com/oasisprotocol/oasis-core/go/runtime/config"
4544
scheduler "github.com/oasisprotocol/oasis-core/go/scheduler/api"
4645
staking "github.com/oasisprotocol/oasis-core/go/staking/api"
4746
)
@@ -683,8 +682,8 @@ func (net *Network) startOasisNode(
683682
if os.Getenv("OASIS_UNSAFE_LAX_AVR_VERIFY") != "" {
684683
extraArgs = extraArgs.debugTCBLaxVerify()
685684
}
686-
if os.Getenv("OASIS_UNSAFE_MOCK_SGX") != "" {
687-
cfg.Runtime.Environment = runtimeConfig.RuntimeEnvironmentSGXMock
685+
if os.Getenv("OASIS_UNSAFE_MOCK_TEE") != "" {
686+
cfg.Runtime.DebugMockTEE = true
688687
}
689688
} else {
690689
baseArgs = append(baseArgs, "--"+cmdFlags.CfgGenesisFile, net.GenesisPath())

go/runtime/bundle/component.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import (
1414
type ExplodedComponent struct {
1515
*Component
1616

17+
// TEEKind specifies the kind of Trusted Execution Environment (TEE)
18+
// in which the component should run.
19+
TEEKind component.TEEKind
20+
1721
// Detached is true iff the bundle containing the component does not
1822
// include a RONL component.
1923
Detached bool
@@ -132,11 +136,6 @@ func (c *Component) IsNetworkAllowed() bool {
132136
}
133137
}
134138

135-
// IsTEERequired returns true iff the component only provides TEE executables.
136-
func (c *Component) IsTEERequired() bool {
137-
return c.Executable == "" && c.ELF == nil && c.TEEKind() != component.TEEKindNone
138-
}
139-
140139
// TEEKind returns the kind of TEE supported by the component.
141140
func (c *Component) TEEKind() component.TEEKind {
142141
switch {

go/runtime/bundle/registry.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/oasisprotocol/oasis-core/go/config"
1818
cmdFlags "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/flags"
1919
"github.com/oasisprotocol/oasis-core/go/runtime/bundle/component"
20+
rtConfig "github.com/oasisprotocol/oasis-core/go/runtime/config"
2021
)
2122

2223
// CfgDebugMockIDs configures mock runtime IDs for the purpose of testing.
@@ -153,6 +154,22 @@ func (r *registry) AddBundle(path string, manifestHash hash.Hash) error {
153154

154155
// Add components to the registry.
155156
for compID, comp := range components {
157+
teeKind := comp.TEEKind()
158+
if compCfg, ok := config.GlobalConfig.Runtime.GetComponent(bnd.Manifest.ID, compID); ok {
159+
if kind, ok := compCfg.TEEKind(); ok {
160+
teeKind = kind
161+
}
162+
} else {
163+
// Support legacy configuration where the runtime environment determines
164+
// whether the client node should run the runtime in an SGX environment.
165+
isEnvAuto := config.GlobalConfig.Runtime.Environment == rtConfig.RuntimeEnvironmentAuto
166+
hasSGXLoader := config.GlobalConfig.Runtime.SGXLoader != ""
167+
insecureMock := config.GlobalConfig.Runtime.DebugMockTEE
168+
if comp.ID().IsRONL() && config.GlobalConfig.Mode.IsClientOnly() && isEnvAuto && !hasSGXLoader && !insecureMock {
169+
teeKind = component.TEEKindNone
170+
}
171+
}
172+
156173
runtimeComponents, ok := r.components[bnd.Manifest.ID]
157174
if !ok {
158175
runtimeComponents = make(map[component.ID]map[version.Version]*ExplodedComponent)
@@ -167,6 +184,7 @@ func (r *registry) AddBundle(path string, manifestHash hash.Hash) error {
167184

168185
componentVersions[comp.Version] = &ExplodedComponent{
169186
Component: comp,
187+
TEEKind: teeKind,
170188
Detached: detached,
171189
ExplodedDataDir: explodedDataDir,
172190
}

go/runtime/config/config.go

Lines changed: 75 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,27 @@ const (
6161
// Use of this runtime environment is only allowed if DebugDontBlameOasis flag is set.
6262
RuntimeEnvironmentSGXMock RuntimeEnvironment = "sgx-mock"
6363

64-
// RuntimeEnvironmentELF specifies to run the runtime in the OS address space.
65-
//
66-
// Use of this runtime environment is only allowed if DebugDontBlameOasis flag is set.
67-
RuntimeEnvironmentELF RuntimeEnvironment = "elf"
68-
6964
// RuntimeEnvironmentAuto specifies to run the runtime in the most appropriate location.
7065
RuntimeEnvironmentAuto RuntimeEnvironment = "auto"
7166
)
7267

68+
// TEESelectMode is the selection mode for the Trusted Execution Environment (TEE).
69+
type TEESelectMode string
70+
71+
const (
72+
// TEESelectModeAuto specifies that the runtime should run in the most appropriate TEE.
73+
TEESelectModeAuto TEESelectMode = ""
74+
75+
// TEESelectModeNone specifies that the runtime should run without using any TEE.
76+
TEESelectModeNone TEESelectMode = "none"
77+
78+
// TEESelectModeSGX specifies that the runtime should run in an SGX environment.
79+
TEESelectModeSGX TEESelectMode = "sgx"
80+
81+
// TEESelectModeTDX specifies that the runtime should run in a TDX environment.
82+
TEESelectModeTDX TEESelectMode = "tdx"
83+
)
84+
7385
// Config is the runtime registry configuration structure.
7486
type Config struct {
7587
// Runtimes is the list of runtimes to configure.
@@ -84,10 +96,11 @@ type Config struct {
8496
// Path to the sandbox binary (bubblewrap).
8597
SandboxBinary string `yaml:"sandbox_binary,omitempty"`
8698

87-
// Path to SGXS runtime loader binary (for SGX runtimes).
99+
// Path to SGX runtime loader binary (for SGX runtimes).
88100
SGXLoader string `yaml:"sgx_loader,omitempty"`
89101

90102
// The runtime environment (sgx, elf, auto).
103+
// NOTE: This may go away in the future, use `DebugMockTEE` instead.
91104
Environment RuntimeEnvironment `yaml:"environment,omitempty"`
92105

93106
// History pruner configuration.
@@ -122,6 +135,11 @@ type Config struct {
122135
//
123136
// If not specified, a default value is used.
124137
MaxBundleSize string `yaml:"max_bundle_size,omitempty"`
138+
139+
// DebugMockTEE enables mocking of the Trusted Execution Environment (TEE).
140+
//
141+
// This flag can only be used if the DebugDontBlameOasis flag is set.
142+
DebugMockTEE bool `yaml:"debug_mock_tee,omitempty"`
125143
}
126144

127145
// GetComponent returns the configuration for the given component
@@ -170,16 +188,61 @@ type RuntimeConfig struct {
170188
Repositories []string `yaml:"repositories,omitempty"`
171189
}
172190

191+
// Validate validates the runtime configuration.
192+
func (c *RuntimeConfig) Validate() error {
193+
for _, comp := range c.Components {
194+
if err := comp.Validate(); err != nil {
195+
return err
196+
}
197+
}
198+
return nil
199+
}
200+
173201
// ComponentConfig is the component configuration.
174202
type ComponentConfig struct {
175203
// ID is the component identifier.
176204
ID component.ID `yaml:"id"`
177205

206+
// TEE specifies the kind of Trusted Execution Environment (TEE)
207+
// in which the component should run (none, sgx, tdx).
208+
//
209+
// If not provided, the TEE kind is selected automatically.
210+
TEE TEESelectMode `yaml:"tee,omitempty"`
211+
178212
// Disabled specifies whether the component is disabled. If a component is specified and not
179213
// disabled, it is enabled.
180214
Disabled bool `yaml:"disabled,omitempty"`
181215
}
182216

217+
// Validate validates the component configuration.
218+
func (c *ComponentConfig) Validate() error {
219+
switch c.TEE {
220+
case TEESelectModeAuto:
221+
case TEESelectModeNone:
222+
case TEESelectModeSGX:
223+
case TEESelectModeTDX:
224+
default:
225+
return fmt.Errorf("unknown TEE select mode: %s", c.TEE)
226+
}
227+
228+
return nil
229+
}
230+
231+
// TEEKind returns the kind of Trusted Execution Environment (TEE)
232+
// in which the component should run, if it is specified.
233+
func (c *ComponentConfig) TEEKind() (component.TEEKind, bool) {
234+
switch c.TEE {
235+
case TEESelectModeNone:
236+
return component.TEEKindNone, true
237+
case TEESelectModeSGX:
238+
return component.TEEKindSGX, true
239+
case TEESelectModeTDX:
240+
return component.TEEKindTDX, true
241+
default:
242+
return 0, false
243+
}
244+
}
245+
183246
// UnmarshalYAML implements yaml.Unmarshaler.
184247
func (c *ComponentConfig) UnmarshalYAML(value *yaml.Node) error {
185248
switch value.ShortTag() {
@@ -231,7 +294,6 @@ func (c *Config) Validate() error {
231294
return fmt.Errorf("sgx_loader must be set when using sgx environment")
232295
}
233296
case RuntimeEnvironmentSGXMock:
234-
case RuntimeEnvironmentELF:
235297
case RuntimeEnvironmentAuto:
236298
default:
237299
return fmt.Errorf("unknown runtime environment: %s", c.Environment)
@@ -251,6 +313,12 @@ func (c *Config) Validate() error {
251313
return fmt.Errorf("cannot specify more than 128 instances for load balancing")
252314
}
253315

316+
for _, rt := range c.Runtimes {
317+
if err := rt.Validate(); err != nil {
318+
return err
319+
}
320+
}
321+
254322
return nil
255323
}
256324

go/runtime/host/composite/composite.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ func (p *provisioner) NewRuntime(cfg host.Config) (host.Runtime, error) {
203203
if comp == nil {
204204
return nil, fmt.Errorf("host/composite: component not available")
205205
}
206-
provisioner, ok := p.kinds[comp.TEEKind()]
206+
provisioner, ok := p.kinds[comp.TEEKind]
207207
if !ok {
208-
return nil, fmt.Errorf("host/composite: provisioner for kind '%s' is not available", comp.TEEKind())
208+
return nil, fmt.Errorf("host/composite: provisioner for kind '%s' is not available", comp.TEEKind)
209209
}
210210
return provisioner.NewRuntime(cfg)
211211
}

go/runtime/host/sgx/sgx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ func (s *sgxProvisioner) getSandboxConfig(rtCfg host.Config, conn sandbox.Connec
284284
return cfg, nil
285285
}
286286

287-
if comp.TEEKind() != component.TEEKindSGX {
287+
if comp.SGX == nil {
288288
return process.Config{}, fmt.Errorf("component '%s' is not an SGX component", comp.ID())
289289
}
290290

0 commit comments

Comments
 (0)