Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/rofl/machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func init() {
Cmd.AddCommand(stopCmd)
Cmd.AddCommand(removeCmd)
Cmd.AddCommand(changeAdminCmd)
Cmd.AddCommand(acceptAdminCmd)
Cmd.AddCommand(topUpCmd)
Cmd.AddCommand(logsCmd)
}
82 changes: 80 additions & 2 deletions cmd/rofl/machine/mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@

changeAdminCmd = &cobra.Command{
Use: "set-admin [<machine-name> | <provider-address>:<machine-id>] <new-admin>",
Short: "Change the machine administrator",
Short: "Propose a new machine administrator",
Long: "Propose a new machine administrator. The change only takes effect once the new administrator accepts it using `rofl machine accept-admin`. Proposing the current administrator cancels any pending change.",
Aliases: []string{"change-admin"},
Args: cobra.RangeArgs(1, 2),
Run: func(_ *cobra.Command, args []string) {
Expand Down Expand Up @@ -153,10 +154,12 @@
fmt.Printf("Machine: %s [%s]\n", mCfg.MachineName, mCfg.Machine.ID)

// Resolve old admin in online mode.
var oldAdminAddr *types.Address
if !txCfg.Offline {
insDsc, err := conn.Runtime(mCfg.NPA.ParaTime).ROFLMarket.Instance(ctx, client.RoundLatest, *mCfg.ProviderAddr, mCfg.MachineID)
cobra.CheckErr(err)

oldAdminAddr = &insDsc.Admin
fmt.Printf("Old admin: %s\n", common.PrettyAddress(insDsc.Admin.String()))
}

Expand All @@ -181,7 +184,78 @@
return
}

fmt.Printf("Machine admin address changed.\n")
if oldAdminAddr != nil && oldAdminAddr.Equal(*newAdminAddr) {
fmt.Printf("Pending machine admin change cancelled.\n")
return
}

fmt.Printf("Machine admin change proposed.\n")
fmt.Printf("The new admin must accept it for the change to take effect by running:\n")
fmt.Println()
fmt.Printf(" oasis rofl machine accept-admin %s:%s\n", mCfg.ProviderAddr, mCfg.Machine.ID)
},
}

acceptAdminCmd = &cobra.Command{
Use: "accept-admin [<machine-name> | <provider-address>:<machine-id>]",
Short: "Accept a pending machine administrator change",
Long: "Accept a pending machine administrator change (by the new admin).",
Args: cobra.MaximumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
txCfg := common.GetTransactionConfig()
mCfg, err := resolveMachineCfg(args, &roflCommon.ManifestOptions{
NeedAppID: true,
NeedAdmin: false,
})
cobra.CheckErr(err)

// When not in offline mode, connect to the given network endpoint.
ctx := context.Background()
var conn connection.Connection
if !txCfg.Offline {
conn, err = connection.Connect(ctx, mCfg.NPA.Network)
cobra.CheckErr(err)
}

fmt.Printf("Provider: %s\n", common.PrettyAddress(mCfg.ProviderAddr.String()))
fmt.Printf("Machine: %s [%s]\n", mCfg.MachineName, mCfg.Machine.ID)

// Resolve old and pending admin in online mode.
var pendingAdminAddr *types.Address
if !txCfg.Offline {
insDsc, err := conn.Runtime(mCfg.NPA.ParaTime).ROFLMarket.Instance(ctx, client.RoundLatest, *mCfg.ProviderAddr, mCfg.MachineID)
cobra.CheckErr(err)

if insDsc.PendingAdmin == nil {

Check failure on line 229 in cmd/rofl/machine/mgmt.go

View workflow job for this annotation

GitHub Actions / tests-ubuntu-latest

insDsc.PendingAdmin undefined (type *roflmarket.Instance has no field or method PendingAdmin)

Check failure on line 229 in cmd/rofl/machine/mgmt.go

View workflow job for this annotation

GitHub Actions / lint

insDsc.PendingAdmin undefined (type *roflmarket.Instance has no field or method PendingAdmin)
cobra.CheckErr("machine has no pending admin change")
}
pendingAdminAddr = insDsc.PendingAdmin

Check failure on line 232 in cmd/rofl/machine/mgmt.go

View workflow job for this annotation

GitHub Actions / tests-ubuntu-latest

insDsc.PendingAdmin undefined (type *roflmarket.Instance has no field or method PendingAdmin)

Check failure on line 232 in cmd/rofl/machine/mgmt.go

View workflow job for this annotation

GitHub Actions / lint

insDsc.PendingAdmin undefined (type *roflmarket.Instance has no field or method PendingAdmin)

fmt.Printf("Old admin: %s\n", common.PrettyAddress(insDsc.Admin.String()))
fmt.Printf("New admin: %s\n", common.PrettyAddress(insDsc.PendingAdmin.String()))

Check failure on line 235 in cmd/rofl/machine/mgmt.go

View workflow job for this annotation

GitHub Actions / tests-ubuntu-latest

insDsc.PendingAdmin undefined (type *roflmarket.Instance has no field or method PendingAdmin)

Check failure on line 235 in cmd/rofl/machine/mgmt.go

View workflow job for this annotation

GitHub Actions / lint

insDsc.PendingAdmin undefined (type *roflmarket.Instance has no field or method PendingAdmin)
}

common.Warn("WARNING: Accepting the change will clear the current machine deployment and any queued commands!")

acc := common.LoadAccount(cliConfig.Global(), mCfg.NPA.AccountName)
if pendingAdminAddr != nil && !pendingAdminAddr.Equal(acc.Address()) {
cobra.CheckErr(fmt.Errorf("account '%s' is not the pending machine admin", mCfg.NPA.AccountName))
}

// Prepare transaction.
tx := roflmarket.NewInstanceAcceptAdminTx(nil, &roflmarket.InstanceAcceptAdmin{

Check failure on line 246 in cmd/rofl/machine/mgmt.go

View workflow job for this annotation

GitHub Actions / tests-ubuntu-latest

undefined: roflmarket.InstanceAcceptAdmin

Check failure on line 246 in cmd/rofl/machine/mgmt.go

View workflow job for this annotation

GitHub Actions / tests-ubuntu-latest

undefined: roflmarket.NewInstanceAcceptAdminTx

Check failure on line 246 in cmd/rofl/machine/mgmt.go

View workflow job for this annotation

GitHub Actions / lint

undefined: roflmarket.InstanceAcceptAdmin

Check failure on line 246 in cmd/rofl/machine/mgmt.go

View workflow job for this annotation

GitHub Actions / lint

undefined: roflmarket.NewInstanceAcceptAdminTx
Provider: *mCfg.ProviderAddr,
ID: mCfg.MachineID,
})

sigTx, meta, err := common.SignParaTimeTransaction(ctx, mCfg.NPA, acc, conn, tx, nil)
cobra.CheckErr(err)

if !common.BroadcastOrExportTransaction(ctx, mCfg.NPA, conn, sigTx, meta, nil) {
return
}

fmt.Printf("Machine admin change accepted.\n")
},
}

Expand Down Expand Up @@ -467,6 +541,10 @@
changeAdminCmd.Flags().AddFlagSet(common.RuntimeTxFlags)
changeAdminCmd.Flags().AddFlagSet(roflCommon.DeploymentFlags)

common.AddSelectorFlags(acceptAdminCmd)
acceptAdminCmd.Flags().AddFlagSet(common.RuntimeTxFlags)
acceptAdminCmd.Flags().AddFlagSet(roflCommon.DeploymentFlags)

common.AddSelectorFlags(topUpCmd)
topUpCmd.Flags().AddFlagSet(common.RuntimeTxFlags)
topUpCmd.Flags().AddFlagSet(roflCommon.DeploymentFlags)
Expand Down
3 changes: 3 additions & 0 deletions cmd/rofl/machine/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
fmt.Println()
fmt.Printf("Creator: %s\n", common.PrettyAddress(out.Machine.Creator.String()))
fmt.Printf("Admin: %s\n", common.PrettyAddress(out.Machine.Admin.String()))
if out.Machine.PendingAdmin != nil {

Check failure on line 112 in cmd/rofl/machine/show.go

View workflow job for this annotation

GitHub Actions / tests-ubuntu-latest

out.Machine.PendingAdmin undefined (type *roflmarket.Instance has no field or method PendingAdmin)

Check failure on line 112 in cmd/rofl/machine/show.go

View workflow job for this annotation

GitHub Actions / lint

out.Machine.PendingAdmin undefined (type *roflmarket.Instance has no field or method PendingAdmin)
fmt.Printf(" Pending: %s\n", common.PrettyAddress(out.Machine.PendingAdmin.String()))

Check failure on line 113 in cmd/rofl/machine/show.go

View workflow job for this annotation

GitHub Actions / tests-ubuntu-latest

out.Machine.PendingAdmin undefined (type *roflmarket.Instance has no field or method PendingAdmin)

Check failure on line 113 in cmd/rofl/machine/show.go

View workflow job for this annotation

GitHub Actions / lint

out.Machine.PendingAdmin undefined (type *roflmarket.Instance has no field or method PendingAdmin) (typecheck)
}
switch out.Machine.NodeID {
case nil:
fmt.Printf("Node ID: <none>\n")
Expand Down
24 changes: 23 additions & 1 deletion docs/rofl.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,34 @@ Run `rofl machine set-admin` to change the administrator of an individual
machine instance. This is independent of the ROFL app administrator and only
affects management of the specific machine instance.

Changing the machine administrator is a two-step process. First, the current
administrator proposes the new administrator:

![code shell](../examples/rofl/machine-set-admin.in.static)

To change the administrator of the machine without a local manifest, run:
To propose the new administrator of the machine without a local manifest, run:

![code shell](../examples/rofl/machine-set-admin-address.in.static)

The current administrator remains in control of the machine until the proposed
administrator accepts the change by running `rofl machine accept-admin` using
their account:

![code shell](../examples/rofl/machine-accept-admin-address.in.static)

Accepting the change clears the current machine deployment and any queued
commands, so the new administrator needs to deploy the app again. Until the
change is accepted, the current administrator can cancel it by proposing
themselves as the new administrator.

:::info

The proposed administrator can also be a smart contract. In that case, the
contract accepts the change by calling `roflmarket.InstanceAcceptAdmin` via the
subcall precompile.

:::

### Remove ROFL app from the network {#remove}

Run `rofl remove` to deregister your ROFL app:
Expand Down
1 change: 1 addition & 0 deletions examples/rofl/machine-accept-admin-address.in.static
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oasis rofl machine accept-admin oasis1qp2ens0hsp7gh23wajxa4hpetkdek3swyyulyrmz:000000000000055c --account bob
Loading