balena login fails after new server setup, getting BalenaRequestError

When I try to do ‘balena login’ I get:

$ balena login --credentials --email xx@xxxx.org --password xxxxx --debug                                                                                                                                                           (10-18 14:10)
[debug] new argv=[/home/khoran/programs/balena-cli/balena,/snapshot/balena-cli/bin/balena,login,--credentials,--email,xx@xxxx.org,--password,xxxx] length=8
[debug] Deprecation check: Cache miss for the balena CLI next major version release date.
[debug] Will query https://registry.npmjs.org/balena-cli/18.0.0
 _            _
| |__   __ _ | |  ____  _ __    __ _
| '_ \ / _` || | / __ \| '_ \  / _` |
| |_) | (_) || ||  ___/| | | || (_) |
|_.__/ \__,_||_| \____/|_| |_| \__,_|


Logging in to ob.galcom.org
[debug] Event tracking error: Timeout awaiting 'response' for 0ms
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

I have followed the openbalena getting started guide. I ran the quickstart and generated the certificates OK. I’ve set the NODE_EXTRA_CA_CERTS environment variable.

Running

curl -k https://api.ob.galcom.org/ping 

results in “OK”.

I logged into the api container and ran tcpdump -A so I could see the HTTP traffic. It seem that the “/login_” endpoint succeeds and returns a token. But then every other url fails:

POST /login_ HTTP/1.1                                                                                                                                                                                                                                                               
X-Balena-Client: balena-sdk/18.0.2                                                                                                                                                                                                                                                               
Content-Type: application/json                                                                                                                                                                                                                                                                   
Accept-Encoding: compress, gzip                                                                                                                                                                                                                                                                  
Accept: */*                                                                                                                                                                                                                                                                                      
Content-Length: 56                                                                                                                                                                                                                                                                               
User-Agent: node-fetch/1.0 (+https://github.com/bitinn/node-fetch)                                                                                                                                                                                                                               
Connection: close                                                                                                                                                                                                                                                                                
Host: api.ob.galcom.org                                                                                                                                                                                                                                                                          
X-Forwarded-Proto: https                                                                                                                                                                                                                                                                         
X-Forwarded-For: 192.168.0.1                                                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                                                                 
{"username":"xx@xxxx.org","password":"xxx"}     
HTTP/1.1 200 OK
...

GET /actor/v1/whoami HTTP/1.1
Authorization: Bearer  XXXXXX<confirmed this is token returned by login_>
X-Balena-Client: balena-sdk/18.0.2
Accept-Encoding: compress, gzip
Accept: */*
User-Agent: node-fetch/1.0 (+https://github.com/bitinn/node-fetch)
Connection: close
Host: api.ob.galcom.org
X-Forwarded-Proto: https
X-Forwarded-For: 192.168.0.1

HTTP/1.1 404 Not Found
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, PUT, POST, PATCH, DELETE, OPTIONS, HEAD
Access-Control-Allow-Headers: Content-Type, Authorization, Application-Record-Count, MaxDataServiceVersion, X-Requested-With, X-Balena-Client
Access-Control-Allow-Credentials: true
Access-Control-Max-Age: 86400
Content-Security-Policy: default-src 'none'
Content-Type: text/html; charset=utf-8
Content-Length: 154
Vary: Accept-Encoding
Date: Wed, 18 Oct 2023 18:30:22 GMT
Connection: close

Been fighting with this one for a whole day. The API container never logs anything beyond the initial message that systemd started. PRODUCTION_MODE is false.

Any ideas? Thanks.

Just found this article after posting: Login not working with balena-cli.

Downgrading balena-cli to 16.7.6 also fixed my problem.

1 Like