From 19950b0f0632ec40295e1af4a243d4262805da08 Mon Sep 17 00:00:00 2001 From: Jernej Kos Date: Fri, 20 Nov 2026 10:02:05 +0100 Subject: [PATCH] cmd/rofl: Support the two-step admin change flow --- cmd/rofl/machine/machine.go | 1 + cmd/rofl/machine/mgmt.go | 82 ++++++++++++++++++- cmd/rofl/machine/show.go | 3 + docs/rofl.md | 24 +++++- .../machine-accept-admin-address.in.static | 1 + 5 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 examples/rofl/machine-accept-admin-address.in.static diff --git a/cmd/rofl/machine/machine.go b/cmd/rofl/machine/machine.go index 0d08fc47..c3e2f3fe 100644 --- a/cmd/rofl/machine/machine.go +++ b/cmd/rofl/machine/machine.go @@ -16,6 +16,7 @@ func init() { Cmd.AddCommand(stopCmd) Cmd.AddCommand(removeCmd) Cmd.AddCommand(changeAdminCmd) + Cmd.AddCommand(acceptAdminCmd) Cmd.AddCommand(topUpCmd) Cmd.AddCommand(logsCmd) } diff --git a/cmd/rofl/machine/mgmt.go b/cmd/rofl/machine/mgmt.go index d0ba58b0..93855b8b 100644 --- a/cmd/rofl/machine/mgmt.go +++ b/cmd/rofl/machine/mgmt.go @@ -114,7 +114,8 @@ var ( changeAdminCmd = &cobra.Command{ Use: "set-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) { @@ -153,10 +154,12 @@ var ( 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())) } @@ -181,7 +184,78 @@ var ( 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 [ | :]", + 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 { + cobra.CheckErr("machine has no pending admin change") + } + pendingAdminAddr = insDsc.PendingAdmin + + fmt.Printf("Old admin: %s\n", common.PrettyAddress(insDsc.Admin.String())) + fmt.Printf("New admin: %s\n", common.PrettyAddress(insDsc.PendingAdmin.String())) + } + + 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{ + 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") }, } @@ -467,6 +541,10 @@ func init() { 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) diff --git a/cmd/rofl/machine/show.go b/cmd/rofl/machine/show.go index 05e65566..06ed0ba1 100644 --- a/cmd/rofl/machine/show.go +++ b/cmd/rofl/machine/show.go @@ -109,6 +109,9 @@ func prettyPrintMachine(mCfg *machineCfg, out *machineShowOutput) { 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 { + fmt.Printf(" Pending: %s\n", common.PrettyAddress(out.Machine.PendingAdmin.String())) + } switch out.Machine.NodeID { case nil: fmt.Printf("Node ID: \n") diff --git a/docs/rofl.md b/docs/rofl.md index 7be5211a..f7433382 100644 --- a/docs/rofl.md +++ b/docs/rofl.md @@ -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: diff --git a/examples/rofl/machine-accept-admin-address.in.static b/examples/rofl/machine-accept-admin-address.in.static new file mode 100644 index 00000000..258c787b --- /dev/null +++ b/examples/rofl/machine-accept-admin-address.in.static @@ -0,0 +1 @@ +oasis rofl machine accept-admin oasis1qp2ens0hsp7gh23wajxa4hpetkdek3swyyulyrmz:000000000000055c --account bob