BalenaRequestError: Request error: Unauthorized

Dear balena team,
first of all, thank you for working on openbalena. The approach of managing iot devices using docker is great.

Unfortunately I have some problems to login with the balena-cli:

I’ve installed openbalena on an Oracle Vm VirtualBox OS Ubuntu 18.04.1 LTS.
Created superuser: ./scripts/quickstart -U super@local -P mypassword -d openbalena.fritz.box
Installed balena-cli on Windows 10 Pro 64bit and copied the ca.crt file from the openbalena server to the client os.

When trying to login I get this error:
BalenaRequestError: Request error: Unauthorized

I scrupulously checked email address and password. I’m not able to find the reason for the error.

Hello @rossiman, how do you invoke the CLI command? You must point the CLI to the location of your server, i.e. invoke it like so:

$ export BALENARC_BALENA_URL=my-domain.com
$ export NODE_EXTRA_CA_CERTS=/path/to/ca.crt
$ balena login

The key is BALENARC_BALENA_URL, but I’ve also added NODE_EXTRA_CA_CERTS for completeness.

1 Like

Hello @dfunckt,

Thank you for the immediate response. I didn’t set BALENARC_BALENA_URL, but I changed the hosts file as described in How to setup CNAME .

Just for doing a double-check I set BALENARC_BALENA_URL to a wrong url. I got this error:
ENOTFOUND: request to https://api.wrongbalena.fritz.box/login_ failed, reason: getaddrinfo ENOTFOUND api.wrongbalena.fritz.box api.wrongbalena.fritz.box:443

I also tried to set a wrong link for NODE_EXTRA_CA_CERTS. I got this error:
SELF_SIGNED_CERT_IN_CHAIN: request to https://api.openbalena.fritz.box/login_ failed, reason: self signed certificate in certificate chain

Seems that I do have the right value for both settings. I do have access to the api and I use the correct certificate. Is there any restriction/rule for the email address and the password? I use a very simple unsecure combination of super@local password:nix for testing.

@rossiman, could you paste the whole output from the command? This will show the host being used, like so…

$ balena login
 _            _
| |__   __ _ | |  ____  _ __    __ _
| '_ \ / _` || | / __ \| '_ \  / _` |
| |_) | (_) || ||  ___/| | | || (_) |
|_.__/ \__,_||_| \____/|_| |_| \__,_|


Logging in to balena-cloud.com
? How would you like to login? (Use arrow keys)
❯ Web authorization (recommended)
  Credentials
  Authentication token
  I don't have a balena account!

As you can see in the output above, it is using balena-cloud.com. This is a good way to confirm that the requests are going to your OpenBalena install, and not to Balena Cloud.

C:\Users\Stefan>balena login
 _            _
| |__   __ _ | |  ____  _ __    __ _
| '_ \ / _` || | / __ \| '_ \  / _` |
| |_) | (_) || ||  ___/| | | || (_) |
|_.__/ \__,_||_| \____/|_| |_| \__,_|


Logging in to openbalena.fritz.box
? How would you like to login? Credentials
? Email: super@local
? Password: [hidden]
BalenaRequestError: Request error: Unauthorized

If you need help, don't hesitate in contacting us at:

  GitHub: https://github.com/balena-io/balena-cli/issues/new
  Forums: https://forums.balena.io

Hi @richbayliss, hi balena team
I’ve started with a comple new server installation from scratch. Now it’s working! I’m able to login.
I don’t know whats different. I didn’t changed the balena-cli installation on my windows computer.
Thank you for your support

Having the exact same issue on a brand new machine. I setup followed all the instructions in the Getting Started doc, and when I try and login from CLI I am getting BalenaRequestError: Request error: Unauthorized.

I setup user using the quickstart script. Also tried again using the create-superuser script to add a user and still getting same message.

EDIT: looks like the password was truncated due to a special character. re-ran quickstart after deleting the config folder and all is good.

I think I also found how I can solve my problem. After doing new configuration by deleting the config folder and start with quickstart again it did’nt work. I got the same error message when doing the balena login.
After linux reboot it works again.

Seems that I was wrong by telling I can solve my problem. I can not reproduce to fix the problem by reboot. I’ve tried it with a new setup, because I wanted to change to another domain. Again the same error:
BalenaRequestError: Request error: Unauthorized
I don’t know what I’ve done differently to the working setup. Would be great to know which part of the code is throwing the error.

I have the same problem.I have deleted the old openbalena server upgrade to latest version.
Now when using balena login :

SELF_SIGNED_CERT_IN_CHAIN: request to https://api.mydomain.com/login_ failed, reason: self signed certificate in certificate chain

If you need help, don’t hesitate in contacting us at:

GitHub: https://github.com/balena-io/balena-cli/issues/new
Forums: https://forums.balena.io

It would be really helpful if the error message can indicate if the problem is in the client or server side.

To all having the same problems with cli login.
Meanwhile I found a way to get the server running and being able to log in using balena-cli.

I’ve started with a new installation on Ubuntu 18.04.1 x64 server.
I’ve used www.goip.de to define the needed domains. -> How to setup CNAME
I’ve processed all the steps as described in https://www.balena.io/open/docs/getting-started/
I’ve copied the certificate ./open-balena/config/certs/root/ca.crt to the client.
I’ve installed balena-cli, set the env variable to link to the server and the certificate and logged.

Just by deleting the open-balena/config folder and starting by ./scripts/quickstart didn’t work in my case. I always got the Unauthorized error.

I’m getting Unauthorized as well. I have tried all of the suggestions here and reinstalled a few times. Are there any logs, etc. that I should be looking at? Any other debugging suggestions?

I have the exact same problem. Followed the instructions from the getting started page and getting “Unauthorized”
Earlier that day i got it running and then wanted to make a clean solution with the result, that even from a fresh build it always gives me the “Unauthorized” message.

Update: I managed to get this working and i guess that is the same problem that 99% have
When reinstalling the thing i.e. deleting containers, running ./scripts/quickstart again to add another user the files are still persited in the according docker volumes.
To do a real cleanup one must delete those volumes as well
What i did was: Cleaning Containers and running $ docker volume prune
That will get rid of all unused volumes and thus all previous set settings

1 Like

indeed - you should also be able to use the ./scripts/compose down -v (from memory here) to bring down the stack and prune the volumes in one fell swoop.

Sorry for reviving this topic again but I’m running into the same issue.

I tried all the above:

  • checked the domain I’m logging in to
  • triple checked my credentials
  • tried to configure the server again after doing sudo ./scripts/compose down -v and then removing the ./open-balena/config folder
  • checked DNS settings

The machine running open-balena is a VM on Azure exclusively accessible from my IP.

I just keep getting the Unauthorized exception…

Hey @sylvain, could you run the CLI while prepending DEBUG=1 to see all the errors, and see what’s happening? Also can you check the config/activate file that the values inside there are correct? Is there any special character in there, that might not be passed to the container correctly?

Hi,

This is the output of balena login with debug enable:

iMacRocket:~ sylvain$ balena login
Debug: original argv0="node" argv=[/usr/local/bin/node,/usr/local/bin/balena,login] length=3
 _            _
| |__   __ _ | |  ____  _ __    __ _
| '_ \ / _` || | / __ \| '_ \  / _` |
| |_) | (_) || ||  ___/| | | || (_) |
|_.__/ \__,_||_| \____/|_| |_| \__,_|


Logging in to curaelabs.eu
? How would you like to login? Credentials
? Email: sylvain@curaelabs.eu
? Password: [hidden]
BalenaRequestError: Request error: Unauthorized
    at /usr/local/lib/node_modules/balena-cli/node_modules/balena-request/build/request.js:197:17
    at tryCatcher (/usr/local/lib/node_modules/balena-cli/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/balena-cli/node_modules/bluebird/js/release/promise.js:517:31)
    at Promise._settlePromise (/usr/local/lib/node_modules/balena-cli/node_modules/bluebird/js/release/promise.js:574:18)
    at Promise._settlePromise0 (/usr/local/lib/node_modules/balena-cli/node_modules/bluebird/js/release/promise.js:619:10)
    at Promise._settlePromises (/usr/local/lib/node_modules/balena-cli/node_modules/bluebird/js/release/promise.js:699:18)
    at _drainQueueStep (/usr/local/lib/node_modules/balena-cli/node_modules/bluebird/js/release/async.js:138:12)
    at _drainQueue (/usr/local/lib/node_modules/balena-cli/node_modules/bluebird/js/release/async.js:131:9)
    at Async._drainQueues (/usr/local/lib/node_modules/balena-cli/node_modules/bluebird/js/release/async.js:147:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/usr/local/lib/node_modules/balena-cli/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)
    at process.topLevelDomainCallback (domain.js:120:23)

If you need help, don't hesitate in contacting our support forums at
https://forums.balena.io

For bug reports or feature requests, have a look at the GitHub issues or
create a new one at: https://github.com/balena-io/balena-cli/issues/

My configfile (.balenarc.yml) only has the domain speciefied:
balenaUrl: "curaelabs.eu"

I have no activate file or at least not that I know of.

I just tried the same from a Windows 10 system and that gives me the same error.

Just for clarity, have you already registered to this openBalena instance with that user?

Ok, I figured there is an activate file on the server in the config folder :man_facepalming:.

I noticed that my password is different because of a certain character, apparently. I entered the password that is in the activate file and that is working.

Thanks for that hint!

Hey, no worries, glad it got sorted! Cheers!