Skip to content

Commit 46ab215

Browse files
feat: add oasis rofl set-admin
1 parent 6a30efd commit 46ab215

5 files changed

Lines changed: 131 additions & 3 deletions

File tree

cmd/rofl/machine/mgmt.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@ var (
113113
}
114114

115115
changeAdminCmd = &cobra.Command{
116-
Use: "change-admin [<machine-name> | <provider-address>:<machine-id>] <new-admin>",
117-
Short: "Change the machine administrator",
118-
Args: cobra.RangeArgs(1, 2),
116+
Use: "change-admin [<machine-name> | <provider-address>:<machine-id>] <new-admin>",
117+
Short: "Change the machine administrator",
118+
Aliases: []string{"set-admin"},
119+
Args: cobra.RangeArgs(1, 2),
119120
Run: func(_ *cobra.Command, args []string) {
120121
txCfg := common.GetTransactionConfig()
121122
mCfg, err := resolveMachineCfg(args, &roflCommon.ManifestOptions{

cmd/rofl/rofl.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func init() {
2929
Cmd.AddCommand(identityCmd)
3030
Cmd.AddCommand(secretCmd)
3131
Cmd.AddCommand(upgradeCmd)
32+
Cmd.AddCommand(setAdminCmd)
3233
Cmd.AddCommand(provider.Cmd)
3334
Cmd.AddCommand(machine.Cmd)
3435
}

cmd/rofl/set_admin.go

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package rofl
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/spf13/cobra"
8+
9+
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/connection"
10+
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/rofl"
11+
12+
buildRofl "github.com/oasisprotocol/cli/build/rofl"
13+
"github.com/oasisprotocol/cli/cmd/common"
14+
roflCommon "github.com/oasisprotocol/cli/cmd/rofl/common"
15+
cliConfig "github.com/oasisprotocol/cli/config"
16+
)
17+
18+
var setAdminCmd = &cobra.Command{
19+
Use: "set-admin <new-admin>",
20+
Short: "Change the administrator of the application in ROFL",
21+
Aliases: []string{"change-admin"},
22+
Args: cobra.ExactArgs(1),
23+
Run: func(_ *cobra.Command, args []string) {
24+
txCfg := common.GetTransactionConfig()
25+
26+
manifest, deployment, npa := roflCommon.LoadManifestAndSetNPA(&roflCommon.ManifestOptions{
27+
NeedAppID: true,
28+
NeedAdmin: true,
29+
})
30+
31+
var appID rofl.AppID
32+
if err := appID.UnmarshalText([]byte(deployment.AppID)); err != nil {
33+
cobra.CheckErr(fmt.Errorf("malformed ROFL app ID: %w", err))
34+
}
35+
36+
npa.MustHaveAccount()
37+
npa.MustHaveParaTime()
38+
39+
if deployment.Policy == nil {
40+
cobra.CheckErr("no policy configured in the manifest")
41+
}
42+
43+
oldAdminAddr, _, err := common.ResolveLocalAccountOrAddress(npa.Network, deployment.Admin)
44+
if err != nil {
45+
cobra.CheckErr(fmt.Errorf("bad current administrator address: %w", err))
46+
}
47+
48+
newAdminAddr, newAdminEthAddr, err := common.ResolveLocalAccountOrAddress(npa.Network, args[0])
49+
if err != nil {
50+
cobra.CheckErr(fmt.Errorf("invalid new admin address: %w", err))
51+
}
52+
53+
if *oldAdminAddr == *newAdminAddr {
54+
fmt.Println("New admin is the same as the current admin, nothing to do.")
55+
return
56+
}
57+
58+
// When not in offline mode, connect to the given network endpoint.
59+
ctx := context.Background()
60+
var conn connection.Connection
61+
if !txCfg.Offline {
62+
conn, err = connection.Connect(ctx, npa.Network)
63+
cobra.CheckErr(err)
64+
}
65+
66+
newAdminStr := newAdminAddr.String()
67+
if newAdminEthAddr != nil {
68+
newAdminStr = newAdminEthAddr.Hex()
69+
}
70+
71+
fmt.Printf("App ID: %s\n", deployment.AppID)
72+
fmt.Printf("Old admin: %s\n", common.PrettyAddress(oldAdminAddr.String()))
73+
fmt.Printf("New admin: %s\n", common.PrettyAddress(newAdminStr))
74+
75+
secrets := buildRofl.PrepareSecrets(deployment.Secrets)
76+
77+
tx := rofl.NewUpdateTx(nil, &rofl.Update{
78+
ID: appID,
79+
Policy: *deployment.Policy.AsDescriptor(),
80+
Admin: newAdminAddr,
81+
Metadata: manifest.GetMetadata(roflCommon.DeploymentName),
82+
Secrets: secrets,
83+
})
84+
85+
acc := common.LoadAccount(cliConfig.Global(), npa.AccountName)
86+
sigTx, meta, err := common.SignParaTimeTransaction(ctx, npa, acc, conn, tx, nil)
87+
cobra.CheckErr(err)
88+
89+
if !common.BroadcastOrExportTransaction(ctx, npa, conn, sigTx, meta, nil) {
90+
return
91+
}
92+
93+
// Transaction succeeded — update the manifest with the new admin.
94+
deployment.Admin = args[0]
95+
if err = manifest.Save(); err != nil {
96+
cobra.CheckErr(fmt.Errorf("failed to update manifest: %w", err))
97+
}
98+
99+
fmt.Printf("ROFL app admin changed to %s.\n", common.PrettyAddress(newAdminStr))
100+
},
101+
}
102+
103+
func init() {
104+
common.AddAccountFlag(setAdminCmd)
105+
setAdminCmd.Flags().AddFlagSet(common.RuntimeTxFlags)
106+
setAdminCmd.Flags().AddFlagSet(roflCommon.DeploymentFlags)
107+
}

docs/rofl.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,24 @@ The current on-chain policy, metadata and secrets will be replaced with the ones
198198
in the manifest file. Keep in mind that ROFL replicas need to be restarted in
199199
order for changes to take effect.
200200

201+
## Change ROFL app administrator {#set-admin}
202+
203+
Run `rofl set-admin` to transfer ownership of a ROFL app to a new
204+
administrator. The transaction is signed by the current admin and, on success,
205+
the manifest is updated with the new admin.
206+
207+
![code shell](../examples/rofl/set-admin.in.static)
208+
209+
:::info ROFL admin vs machine admin
210+
211+
The **ROFL app admin** (changed via `oasis rofl set-admin`) owns the
212+
application — transfer ownership, upgrades, policy changes, removal.
213+
The **machine admin** (changed via `oasis rofl machine change-admin`) manages
214+
an individual machine instance — execution, restarts, stops.
215+
These are independent roles.
216+
217+
:::
218+
201219
## Show ROFL information {#show}
202220

203221
Run `rofl show` to obtain the information from the network on the ROFL admin

examples/rofl/set-admin.in.static

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oasis rofl set-admin <new-admin>

0 commit comments

Comments
 (0)