How to regain control of a canister?

This sounds ridiculous, but I accidentally removed my dfx principal as a controller of one of my canisters.

I meant to run:

dfx canister --network=ic update-settings --add-controller <principal-id>

but instead ran:

dfx canister --network=ic update-settings --controller <principal-id>

Is there any hope of retrieving my canister?

2 Likes

@Severin

—add-controller and —controller are just so close that it’s easy to make this mistake.

Sounds like we need a dfx warning built in for the —controller flag. That plus or a redesign of this flag, or even maybe a —force flag for certain irrecoverable actions.

@jzxchiang Do you own the principal you gave access to in any way? If so you can re-add the controller on the canister you lost through that principal using the ic management canister’s update_settings method.

1 Like

Unless you somehow have access to the accidentally-set principal, no. As @icme described, you’d have to proxy the update_settings command through that principal.

Agreed, this is easy to confuse. I added a note to our backlog. Don’t expect any instant fixes, but it’ll happen sometime in the near-ish future.

I do have access to that principal but only through Internet Identity.

Is there a way to add controllers using a principal you own via II?

Should be possible, just connect II to whatever site through agent js, and then add controllers by calling the management canister.

I suppose it depends on how exactly you have access through II. Since II generates a new pseudonymous principal for every separate url that requests login through II, it may be more or less difficult to do. If you’re in a random page, you should be able to do the calls through agent-js as Max describes. If you added the NNS principal, you should be able to manually add the canister to the canister list and add your normal principal through there.