Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't authorize_account as user, must be root #415

Closed
ncoleman opened this issue Feb 28, 2018 · 7 comments
Closed

Can't authorize_account as user, must be root #415

ncoleman opened this issue Feb 28, 2018 · 7 comments

Comments

@ncoleman
Copy link

First time install, first as Debian Stretch apt install, then, when that did not authorize, I removed it and installed by pip install on the basis that the newest version should be the best (the versions were in fact the same).

Problem

b2 can authorize_account successfully only if run as root. When run as a normal user, it fails. This means nothing can be done as a user, since authorize_account is needed before doing anything else.

Example (note when using sudo it works):

➜  ~ b2 authorize_account <account key goes here>  <application key goes here>
Using https://api.backblazeb2.com
ERROR: unable to authorize account: Invalid authorization token. Server said: Invalid authorization token (bad_auth_token)

➜  ~ sudo b2 authorize_account <account key goes here>  <application key goes here>
[sudo] password for nick:
Using https://api.backblazeb2.com

➜  ~ b2 list-buckets
ERROR: Invalid authorization token. Server said: Invalid authorization token (bad_auth_token)

➜  ~ sudo b2 list-buckets
289b50ffbe4edb4f6f160b16  allPrivate  Backups-dell-laptop
e87b60efbeaedb9f6f160b16  allPrivate  Backups-dell-laptop-home
28cbb0bfbebedb9f6f160b16  allPrivate  Backups-dell-laptop-system

It is not a key problem. The third-party backup application restic works successfully with the keys.

I want to automate the process in a script, so sudo isn't really a solution.

@ppolewicz
Copy link
Collaborator

It seems that you authorized successfully on the root account, but did not on your user account.

Are you 100% sure the auth data was the same in both cases?

Perhaps you have a WAF, transparent proxy server or environment variables set, that affect http queries done from your user account?

@nilayp
Copy link
Contributor

nilayp commented Feb 28, 2018

Does the regular user have access to write to a home directory? The B2 command line tool persists it's credentials in a file called ~/.b2_account_info.

@ncoleman
Copy link
Author

ncoleman commented Feb 28, 2018

Same result in a new shell with fresh, standard environment variables.

The actual error is:

➜  ~ b2 authorize_account <ACCOUNT_ID>  <APPLICATION_KEY>
Using https://api.backblazeb2.com
ERROR: unable to authorize account: Invalid authorization token. Server said: Invalid authorization token (bad_auth_token)

So, if the error message is correct, it is the auth token that b2 is generating that is invalid.

Two things:

  • the .b2_account_info database wasn't being filled in with values (sqlite3 dump showed this) when I generated it nor when authorize_account failed (obviously), so I originally ran sudo b2 which did generate values and populated the db, then I copied root's .b2_account_info over to the user and changed it's ownership to the user. Does b2 use user credentials as well as ACCOUNT_ID and APP KEY to salt the account_auth_token? That might be why it doesn't work for the user, only for root.

  • The bucket itself contains some files owned by root. Could that affect the auth failure?

I had sort of assumed this was common and I did something wrong. If this is non-trivial, I think I'll delete the bucket and purge the install, then start again with a fresh blank setup. It's only bandwidth, the files themselves were uploaded while testing out B2 and are only backups.

@bwbeach
Copy link
Contributor

bwbeach commented Feb 28, 2018

Have you tried removing ~/.b2_account_info and then re-authorizing? It could be that sqlite is being weird about using a database owned by root.

You could also try adding the --verbose option to get debugging information. That might tell us what's happening. This is what it looks like when I run it:

$ b2 authorize_account --verbose $ACCOUNT_ID $APP_KEY
INFO:b2.console_tool:// ========================================  1.1.0   ======================================== \\
DEBUG:b2.console_tool:platform is Darwin-16.7.0-x86_64-i386-64bit
DEBUG:b2.console_tool:Python version is CPython 3.5.4 (default, Sep 22 2017, 08:33:07)  [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)]
DEBUG:b2.console_tool:locale is ('en_US', 'UTF-8')
DEBUG:b2.console_tool:filesystem encoding is utf-8
INFO:b2.console_tool:starting command [b2.console_tool.AuthorizeAccount] (arguments hidden)
Using https://api.backblazeb2.com
DEBUG:b2.api:calling B2Api.authorize_account(self=<b2.api.B2Api object at 0x1038c87b8>, realm='production') (hidden args: account_id, application_key)
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.backblazeb2.com
DEBUG:urllib3.connectionpool:https://api.backblazeb2.com:443 "POST /b2api/v1/b2_authorize_account HTTP/1.1" 200 354
DEBUG:b2.account_info.sqlite_account_info:calling SqliteAccountInfo.set_auth_data(self=<b2.account_info.sqlite_account_info.SqliteAccountInfo object at 0x102aa14e0>, api_url='https://api000.backblazeb2.com', download_url='https://f000.backblazeb2.com', minimum_part_size=100000000, realm='production') (hidden args: account_id, account_auth_token, application_key)
INFO:b2.console_tool:\\ ========================================  exit=0  ======================================== //

@bwbeach
Copy link
Contributor

bwbeach commented Mar 16, 2018

Closing. Please re-open if fixing the permissions on ~/.b2_account_info does not solve the problem.

@bwbeach bwbeach closed this as completed Mar 16, 2018
@ncoleman
Copy link
Author

ncoleman commented Dec 12, 2018 via email

@JohnRobson
Copy link

authorize_account is working.

$ b2 authorize_account xxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

if you read your files with sudo, you need to authorize with sudo too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants