Skip to content

Commit 49b6f25

Browse files
authored
Merge pull request #634 from oasisprotocol/matevz/feat/rofl-init-reset
Add `oasis rofl init --reset`, cleanup TDX leftovers in SGX manifest
2 parents e99d389 + a842b81 commit 49b6f25

File tree

3 files changed

+64
-26
lines changed

3 files changed

+64
-26
lines changed

build/rofl/manifest.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func (m *Manifest) Validate() error {
167167
return fmt.Errorf("unsupported app kind: %s", m.Kind)
168168
}
169169

170-
if err := m.Resources.Validate(); err != nil {
170+
if err := m.Resources.Validate(m.TEE); err != nil {
171171
return fmt.Errorf("bad resources config: %w", err)
172172
}
173173

@@ -443,13 +443,18 @@ type ResourcesConfig struct {
443443
}
444444

445445
// Validate validates the resources configuration for correctness.
446-
func (r *ResourcesConfig) Validate() error {
446+
func (r *ResourcesConfig) Validate(tee string) error {
447447
if r.Memory < 16 {
448448
return fmt.Errorf("memory size must be at least 16M")
449449
}
450450
if r.CPUCount < 1 {
451451
return fmt.Errorf("vCPU count must be at least 1")
452452
}
453+
454+
if tee == TEETypeSGX && r.Storage != nil {
455+
return fmt.Errorf("SGX apps do not support disk storage")
456+
}
457+
453458
if r.Storage != nil {
454459
err := r.Storage.Validate()
455460
if err != nil {

cmd/rofl/mgmt.go

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var (
4141

4242
appTEE string
4343
appKind string
44+
reset bool
4445

4546
//go:embed init_artifacts/compose.yaml
4647
initArtifactCompose []byte
@@ -64,38 +65,59 @@ var (
6465
err = os.Chdir(appPath)
6566
cobra.CheckErr(err)
6667

67-
// Fail in case there is an existing manifest.
68-
if buildRofl.ManifestExists() {
69-
cobra.CheckErr("refusing to overwrite existing manifest")
70-
}
68+
var manifest *buildRofl.Manifest
69+
if !reset {
70+
// Fail in case there is an existing manifest.
71+
if buildRofl.ManifestExists() {
72+
cobra.CheckErr("Refusing to overwrite existing manifest.\nHint: To reset existing ROFL manifest, pass --reset flag.")
73+
}
7174

72-
// Create a default manifest without any deployments.
73-
// TODO: Extract author and repository from Git configuration if available.
74-
manifest := buildRofl.Manifest{
75-
Name: appName,
76-
Version: "0.1.0",
77-
TEE: appTEE,
78-
Kind: appKind,
79-
Resources: buildRofl.ResourcesConfig{
80-
Memory: 512,
81-
CPUCount: 1,
82-
Storage: &buildRofl.StorageConfig{
83-
Kind: buildRofl.StorageKindDiskPersistent,
84-
Size: 512,
75+
fmt.Printf("Creating a new app with default policy...\n")
76+
77+
// Create a default manifest without any deployments.
78+
manifest = &buildRofl.Manifest{
79+
Name: appName,
80+
Version: "0.1.0",
81+
TEE: appTEE,
82+
Kind: appKind,
83+
Resources: buildRofl.ResourcesConfig{
84+
Memory: 512,
85+
CPUCount: 1,
8586
},
86-
},
87+
}
88+
} else {
89+
manifest, err = buildRofl.LoadManifest()
90+
cobra.CheckErr(err)
91+
92+
fmt.Printf("\n")
93+
if !common.GetAnswerYes() {
94+
common.Confirm("Reset existing app manifest file by removing all configured ROFL deployments, secrets and policies", "not resetting")
95+
}
96+
97+
manifest.Name = appName
98+
manifest.Deployments = make(map[string]*buildRofl.Deployment)
8799
}
100+
101+
// TODO: Extract author and repository from Git configuration if available.
102+
88103
err = manifest.Validate()
89104
cobra.CheckErr(err)
90105

91-
fmt.Printf("Creating a new ROFL app with default policy...\n")
92106
fmt.Printf("Name: %s\n", manifest.Name)
93107
fmt.Printf("Version: %s\n", manifest.Version)
94108
fmt.Printf("TEE: %s\n", manifest.TEE)
95109
fmt.Printf("Kind: %s\n", manifest.Kind)
96110

97111
switch manifest.TEE {
98112
case buildRofl.TEETypeTDX:
113+
// TDX requires storage settings.
114+
if !reset {
115+
manifest.Resources.Storage = &buildRofl.StorageConfig{
116+
Kind: buildRofl.StorageKindDiskPersistent,
117+
Size: 512,
118+
}
119+
}
120+
99121
switch appKind {
100122
case buildRofl.AppKindRaw:
101123
artifacts := buildRofl.LatestBasicArtifacts // Copy.
@@ -221,6 +243,12 @@ var (
221243
debugMode = params.DebugAllowTestRuntimes
222244
}
223245

246+
// For TDX assign empty quote policies by default.
247+
var tdxQuotePolicy *pcs.TdxQuotePolicy
248+
if manifest.TEE == buildRofl.TEETypeTDX {
249+
tdxQuotePolicy = &pcs.TdxQuotePolicy{}
250+
}
251+
224252
// Generate manifest and a default policy which does not accept any enclaves.
225253
deployment = &buildRofl.Deployment{
226254
Network: npa.NetworkName,
@@ -232,7 +260,7 @@ var (
232260
PCS: &pcs.QuotePolicy{
233261
TCBValidityPeriod: 30,
234262
MinTCBEvaluationDataNumber: 18,
235-
TDX: &pcs.TdxQuotePolicy{},
263+
TDX: tdxQuotePolicy,
236264
},
237265
},
238266
Endorsements: []rofl.AllowedEndorsement{
@@ -828,6 +856,8 @@ func detectOrCreateComposeFile() string {
828856
func init() {
829857
initCmd.Flags().StringVar(&appTEE, "tee", "tdx", "TEE kind [tdx, sgx]")
830858
initCmd.Flags().StringVar(&appKind, "kind", "container", "ROFL app kind [container, raw]")
859+
initCmd.Flags().BoolVar(&reset, "reset", false, "reset the existing ROFL manifest")
860+
initCmd.Flags().AddFlagSet(common.AnswerYesFlag)
831861

832862
createCmd.Flags().AddFlagSet(common.SelectorFlags)
833863
createCmd.Flags().AddFlagSet(common.RuntimeTxFlags)

docs/rofl.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@ OFfchain Logic (ROFL)][rofl] apps:
1818

1919
## Initialize a new ROFL app manifest {#init}
2020

21-
The `rofl init` command will prepare a new ROFL app manifest in the given
22-
directory (defaults to the current directory). The manifest is a YAML file named
21+
The `rofl init` command will prepare a new ROFL manifest in the given directory
22+
(defaults to the current directory). The manifest is a YAML file named
2323
`rofl.yaml` which defines the versions of all components, upgrade policies, etc.
2424
needed to manage, build and deploy the ROFL app.
2525

2626
![code shell](../examples/rofl/init.in.static)
2727

2828
![code](../examples/rofl/init.out.static)
2929

30-
Note that by default the manifest will not contain any deployments. In order to
31-
create deployments, use `rofl create`.
30+
You can create a new ROFL manifest file based on the existing one by passing
31+
`--reset` flag. This is useful if you want to make your own deployment of
32+
the existing ROFL project. It will remove information on previous user-specific
33+
deployments but keep information such as the minimum CPU, memory and storage
34+
requirements.
3235

3336
## Create a new ROFL app on the network {#create}
3437

0 commit comments

Comments
 (0)