Login not working with balena-cli

I am receiving an unexpected error when trying to log in to our openbalena instance via balena-cli (shown below with --debug output). Tried updating to v17.1.5 (latest available as of this writing) and experiencing the same error. Tried deleting my ~/.balena folder with no luck either. Login is confirmed working as it authenticates fine via other channels, and all devices are communicating with the API just fine as well. For some reason this problem is limited to balena-cli.

[debug] new argv=[/opt/balena-cli/balena,/snapshot/balena-cli/bin/balena,login] length=3
[debug] Deprecation check: 0.00232 days since last npm registry query for next major version release date.
[debug] Will not query the registry again until at least 7 days have passed.
 _            _
| |__   __ _ | |  ____  _ __    __ _
| '_ \ / _` || | / __ \| '_ \  / _` |
| |_) | (_) || ||  ___/| | | || (_) |
|_.__/ \__,_||_| \____/|_| |_| \__,_|


Logging in to xxx
? How would you like to login? (Use arrow keys)
? How would you like to login? Credentials
? Email: xxxx@xxxx.com
? Password: [hidden]
BalenaRequestError: Request error: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /actor/v1/whoami</pre>
</body>
</html>


BalenaRequestError: Request error: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /actor/v1/whoami</pre>
</body>
</html>

    at Object.<anonymous> (/snapshot/balena-cli/node_modules/balena-request/build/request.js:193:27)
    at Generator.next (<anonymous>)
    at fulfilled (/snapshot/balena-cli/node_modules/tslib/tslib.js)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

For further help or support, visit:
https://www.balena.io/docs/reference/balena-cli/#support-faq-and-troubleshooting

Well, looks like I found the culprit, see below. For anyone who stumbles on this page with the same error, it appears that you can’t use balena-cli past v16.7.6 without upgrading your openbalena instance. Confirmed v16.7.6 is working fine.

<summary> Update balena-sdk to v18 [Otávio Jacobi] </summary>

> ### balena-sdk-18.0.0 - 2023-08-17
> 
> * **BREAKING**: Remove the device-type.json state & name normalization [Thodoris Greasidis]
> * **BREAKING**: Drop auth.getUserActorId in favor of auth.getActorId [Otávio Jacobi]
> * auth: Add getActorId [Otávio Jacobi]
> * **BREAKING**: Drop auth.getUserId in favor of auth.getUserInfo [Otávio Jacobi]
> * **BREAKING**: Drop auth.getEmail in favor of auth.getUserInfo [Otávio Jacobi]
> * auth: Add getUserInfo [Otávio Jacobi]
> * **BREAKING**: Drop pre-Resin OS v1 device.os_version normalization [Thodoris Greasidis]
> * **BREAKING**: Support non-user API keys in auth.isLoggedIn() & whoami() [Otávio Jacobi]
> * **BREAKING**: Drop support to node < 16 [Otávio Jacobi]
3 Likes

Thanks, I had the same issue and thanks to your post I am able to login. One question though: What do you mean with “upgrading your openbalena instance”? I just installed it today, this is the latest version, right?

1 Like

@Cybex take a look in the file compose/versions within the open-balena repo, as of today you will see:

export OPENBALENA_API_VERSION_TAG=v0.209.2
export OPENBALENA_DB_VERSION_TAG=v5.1.2
export OPENBALENA_MDNS_PUBLISHER_VERSION_TAG=v1.9.2
export OPENBALENA_REGISTRY_VERSION_TAG=v2.25.3
export OPENBALENA_S3_VERSION_TAG=v2.13.10
export OPENBALENA_VPN_VERSION_TAG=v11.4.6

And if you then check out the v0.209.2 tag within the open-balena-api repo, you’ll see that it is about 16 months old. So the “latest” open-balena is a bit of a misnomer when it comes to the underlying application.

We run more current versions of the open-balena apps using custom helm scripts (examples can be found here) - just note that you’ll need a k8s environment to use them.

Thanks, that is very helpful!

Hello,
I would like to reopen this ticket because I have the same problem with the balena cli 18.0.0 version
When I try to log in with the credentials previously used for the quickstart script I get the following error

 Logging in to balena.xxx.io
? How would you like to login? Credentials
? Email: test@xxx.io
? Password: [hidden]
BalenaRequestError: Request error: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /actor/v1/whoami</pre>
</body>
</html>


Additional information may be available with the `--debug` flag.

For further help or support, visit:
https://www.balena.io/docs/reference/balena-cli/#support-faq-and-troubleshooting I use the same 

version of the open balena API as @drcnyc

export OPENBALENA_API_VERSION_TAG=v0.209.2
export OPENBALENA_DB_VERSION_TAG=v5.1.2
export OPENBALENA_MDNS_PUBLISHER_VERSION_TAG=v1.9.2
export OPENBALENA_REGISTRY_VERSION_TAG=v2.25.3
export OPENBALENA_S3_VERSION_TAG=v2.13.10
export OPENBALENA_VPN_VERSION_TAG=v11.4.6

At the debug level, when I curl my api

 âžś  curl -k https://api.xxx.io/ping
OK% 

It work.
I can also connect to the admin page: GitHub - dcaputo-harmoni/open-balena-admin: Open Balena Admin with my credentials but it is impossible to connect with balena cli

ok, I misread the answer…
I confirm that with version 16.7.6 authentication works.
It’s a shame that there was a regression on version 18.
It will be interesting to fix this problem on new versions of balena-cli

@Firat it looks like you are using an old version of open-balena-api:

You will need to upgrade this to be able to use newer versions of balena-cli. Unfortunately, upgrading is not as simple as just changing the version number in that file though - you’ll have to either use one of the solutions developed by members of the community as it requires changes to the various environment variables. I believe there are branches of the open-balena-api repo which do this (using the docker compose deployment methodology) or alternatively you can use one of the helm scripts that are out there if you use k8s.

1 Like

Given the number of branches on the git repository, the best solution would be to fix the main branch rather than basing it on a dev branch which can be merged over time

@Firat I agree that merging the updates into the main branch would make it easier for new users to get up and running with openbalena. I believe community members have submitted PR’s for some of the branches with these updates, but it would be up to the Balena team to accept them as they control the repository.