Signing in with the metalcloud-cli
Available since: version 8.0
From MetalSoft 8.0, metalcloud-cli can sign in as you through your browser, the same way you sign in to the MetalSoft web interface. You no longer need to create, copy or store an API token to use the CLI.
Before you start
Section titled “Before you start”You need three things:
- **metalcloud-cli with the **
logincommand, release 8.0 or later. Runmetalcloud-cli login --helpto check. Install or update it from the metalcloud-cli releases page. - Your MetalSoft address, which the CLI calls the endpoint, for example
<https://metalsoft.example.com.> Pass it with-eon each command, or set it once withexport METALCLOUD_ENDPOINT=<https://metalsoft.example.com> or inmetalcloud.yaml. - API access for your account. Your role needs the same API access that API tokens need (the
api_key_usepermission). Ask your MetalSoft administrator if you’re not sure.
Sign in
Section titled “Sign in”- Run
metalcloud-cli login. The CLI prints a link and a code, and opens the link in your browser. - Sign in to MetalSoft in the browser if you aren’t already. You land on the sign-in request.
- Check that the page shows the same code as your terminal, and that you started this request yourself.
- Click Approve, then confirm it’s you with your password, plus your authenticator code if you use one. If you sign in through your company’s identity provider (single sign-on), you’re sent there and back; click Approve again, and enter your authenticator code if asked.
- The terminal prints “Signed in as” with your email address, and the date and time the sign-in ends. For LDAP users without email address, this will show your username. Service accounts will show “Signed in as a service account”.
The code is valid for 10 minutes. If it expires, run metalcloud-cli login again.
On a machine without a browser, such as a server you reach over SSH, run metalcloud-cli login --no-browser. The CLI only prints the link and the code. Open the link on your laptop or phone, check the code and approve there; the CLI on the server finishes signing in on its own.
Use the CLI
Section titled “Use the CLI”Once you’re signed in, run commands as usual, for example metalcloud-cli user list. They act as you, with your role’s access. The sign-in is saved on your computer in ~/.metalcloud/sessions.json, readable only by you, with one sign-in per MetalSoft address.
Your CLI sign-in ends:
- under the same rules as a sign-in to the web interface, for example after a period without use set by your administrator, or when your password changes;
- when you sign in to the CLI again, on this or any other computer, because each person keeps one CLI sign-in at a time;
- when you run
metalcloud-cli logout.
Signing in to the CLI never signs you out of the web interface.
If an API token is also set, with --api_key, METALCLOUD_API_KEY or in metalcloud.yaml, the CLI uses the token instead of your sign-in. Remove it to use your sign-in.
Sign out
Section titled “Sign out”Run metalcloud-cli logout. It prints “Signed out.”, ends the sign-in in MetalSoft and removes it from your computer. If MetalSoft can’t be reached, the sign-in is still removed from your computer.
What needs the web interface or an API token
Section titled “What needs the web interface or an API token”To protect your account if a sign-in is ever approved by mistake, a CLI sign-in can’t:
- create, change or delete API tokens;
- change your password, email address or two-factor authentication.
Those commands answer “This route does not accept a CLI session; use the UI or an API token.” Do them in the web interface, or with an API token. Your CLI sign-in stays active.
For scripts, CI pipelines and scheduled jobs, keep using an API token. A CLI sign-in is meant for a person at a keyboard: it ends after a period without use, and each person has only one at a time.
Keep your account safe
Section titled “Keep your account safe”Approving a sign-in gives the CLI that asked for it access to your account. Before you click Approve:
- approve only a request you started yourself, a moment ago;
- check that the code on the page matches the one in your terminal;
- check where the request came from: the page shows the computer’s name and its IP address.
If you didn’t start it, click Deny. Never approve a code that someone sends you by email, chat or phone.
Troubleshooting
Section titled “Troubleshooting”| You see | What it means | What to do |
|---|---|---|
| ”Your session has ended; run metalcloud-cli login” | You signed in on another computer, signed out, or the sign-in ended after a period without use | Run metalcloud-cli login |
| ”Sign in with metalcloud-cli login, or set an API token with —api_key or METALCLOUD_API_KEY.” | You aren’t signed in to this MetalSoft address | Run metalcloud-cli login |
| ”The sign-in request has expired; run metalcloud-cli login again.” | Nobody approved the request within 10 minutes | Run metalcloud-cli login again |
| ”The sign-in was denied.” | Someone clicked Deny on the page | If it was you by mistake, run metalcloud-cli login again |
| On the page: “This code isn’t valid any more. Run metalcloud-cli login again.” | The code is mistyped, expired or already used | Check the code, or start again. After several wrong codes, the page refuses lookups for up to 10 minutes |
| On the page: “Signing in from the CLI needs the api_key_use permission.” | Your role doesn’t include API access | Ask your MetalSoft administrator |
| ”This route does not accept a CLI session; use the UI or an API token.” | The command manages API tokens or your account’s security | Use the web interface, or an API token |
| ”This MetalCloud doesn’t support signing in from the CLI; use an API token.” | Your MetalSoft is older than 8.0 | Use an API token |
| ”API endpoint is required.…” | The CLI doesn’t know your MetalSoft address | Pass -e <https://metalsoft.example.com> or set METALCLOUD_ENDPOINT |