Skip to content

[cli] export org not working? #21

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

Open
cocoon opened this issue Mar 20, 2025 · 8 comments
Open

[cli] export org not working? #21

cocoon opened this issue Mar 20, 2025 · 8 comments

Comments

@cocoon
Copy link
Contributor

cocoon commented Mar 20, 2025

Is anybody able to export an org vault with the cli?
With web ui with the same user (no admin) it is working at least partially, not the full org vault is exported, credentials in folders got not exported.

I would expect it to be the same.
So either I need to be admin or not.

src:
https://bitwarden.com/help/export-your-data/#tab-cli-2er90bORbbPnqOiFdfz6vW

Using the current one (Windows 11):
bw-windows-2025.2.0.zip

Login with cli is possible, but ONLY if I set "sso_auth_only_not_session" to TRUE.

If set to false I get:

message: 'Unable to refresh login credentials: Impossible to read refresh_token: Error decoding JWT'

Unlocking and listing orgs is also working fine.

But as soon as I try to export, the session seems to get invalidated.

Steps:

bw login --sso
(login in browser)

bw unlock
(enter master password, get session)

bw list items --session <SESSION>
bw list items --session <SESSION>
(working multiple times OK)

bw export --organizationid <ORG ID> --session <SESSION>
(tried with and without masterwassword, with and without format)

ERROR:
{"response":{"error":{"code":401,"reason":"Unauthorized","description":"The request requires user authentication."}},"captchaRequired":false,"statusCode":401}

after this no more calls are possible, session is not valid anymore.

and the same error in oidcwarden trace:

[2025-03-20 12:23:57.151][request][INFO] GET /api/organizations/<org_id>/export
[2025-03-20 12:23:57.152][auth][ERROR] Unauthorized Error: You need to be Admin or Owner to call this endpoint
[2025-03-20 12:23:57.152][oidcwarden::api::core::organizations::_][WARN] Request guard `AdminHeaders` failed: "You need to be Admin or Owner to call this endpoint".
[2025-03-20 12:23:57.152][rocket::server::_][WARN] No 401 catcher registered. Using Rocket default.
[2025-03-20 12:23:57.152][response][INFO] (get_org_export) GET /api/organizations/<org_id>/export => 401 Unauthorized

Your environment (Generated via diagnostics page)

  • Vaultwarden version: vv2025.2.2-1
  • Web-vault version: voidc_override-v2025.2.2-1
  • OS/Arch: windows/x86_64
  • Running within a container: false (Base: Not applicable)
  • Database type: SQLite
  • Database version: 3.48.0
  • Environment settings overridden!: false
  • Uses a reverse proxy: false
  • Internet access: true
  • Internet access via a proxy: false
  • DNS Check: true
  • Browser/Server Time Check: true
  • Server/NTP Time Check: true
  • Domain Configuration Check: true
  • HTTPS Check: true
  • Websocket Check: true
  • HTTP Response Checks: true

Config & Details (Generated via diagnostics page)

Show Config & Details

Config:

{
  "_duo_akey": null,
  "_enable_duo": true,
  "_enable_email_2fa": true,
  "_enable_smtp": true,
  "_enable_yubico": true,
  "_icon_service_csp": "",
  "_icon_service_url": "",
  "_ip_header_enabled": true,
  "_max_note_size": 10000,
  "_smtp_img_src": "***:",
  "admin_ratelimit_max_burst": 3,
  "admin_ratelimit_seconds": 300,
  "admin_session_lifetime": 20,
  "admin_token": "***",
  "allowed_connect_src": "",
  "allowed_iframe_ancestors": "",
  "attachments_folder": "data/attachments",
  "auth_request_purge_schedule": "30 * * * * *",
  "authenticator_disable_time_drift": false,
  "data_folder": "data",
  "database_conn_init": "",
  "database_max_conns": 10,
  "database_timeout": 30,
  "database_url": "***************",
  "db_connection_retries": 15,
  "disable_2fa_remember": false,
  "disable_admin_token": false,
  "disable_icon_download": false,
  "domain": "*****://*****************",
  "domain_origin": "*****://*****************",
  "domain_path": "",
  "domain_set": true,
  "duo_context_purge_schedule": "30 * * * * *",
  "duo_host": null,
  "duo_ikey": null,
  "duo_skey": null,
  "duo_use_iframe": false,
  "email_2fa_auto_fallback": false,
  "email_2fa_enforce_on_verified_invite": false,
  "email_attempts_limit": 3,
  "email_change_allowed": false,
  "email_expiration_time": 600,
  "email_token_size": 6,
  "emergency_access_allowed": true,
  "emergency_notification_reminder_schedule": "0 3 * * * *",
  "emergency_request_timeout_schedule": "0 7 * * * *",
  "enable_db_wal": true,
  "enable_websocket": true,
  "enforce_single_org_with_reset_pw_policy": false,
  "event_cleanup_schedule": "0 10 0 * * *",
  "events_days_retain": null,
  "experimental_client_feature_flags": "fido2-vault-credentials,autofill-overlay,autofill-v2,browser-fileless-import",
  "extended_logging": true,
  "helo_name": null,
  "hibp_api_key": null,
  "http_request_block_non_global_ips": false,
  "http_request_block_regex": null,
  "icon_blacklist_non_global_ips": true,
  "icon_blacklist_regex": null,
  "icon_cache_folder": "data/icon_cache",
  "icon_cache_negttl": 259200,
  "icon_cache_ttl": 2592000,
  "icon_download_timeout": 10,
  "icon_redirect_code": 302,
  "icon_service": "internal",
  "incomplete_2fa_schedule": "30 * * * * *",
  "incomplete_2fa_time_limit": 3,
  "increase_note_size_limit": false,
  "invitation_expiration_hours": 120,
  "invitation_org_name": "Vaultwarden",
  "invitations_allowed": true,
  "ip_header": "X-Real-IP",
  "job_poll_interval_ms": 30000,
  "log_file": "log.txt",
  "log_level": "trace",
  "log_timestamp_format": "%Y-%m-%d %H:%M:%S.%3f",
  "login_ratelimit_max_burst": 10,
  "login_ratelimit_seconds": 60,
  "org_attachment_limit": null,
  "org_creation_users": "",
  "org_events_enabled": false,
  "org_groups_enabled": true,
  "organization_invite_auto_accept": false,
  "password_hints_allowed": true,
  "password_iterations": 600000,
  "purge_incomplete_sso_nonce": "0 20 0 * * *",
  "push_enabled": false,
  "push_identity_uri": "https://identity.bitwarden.com",
  "push_installation_id": "***",
  "push_installation_key": "***",
  "push_relay_uri": "https://push.bitwarden.com",
  "reload_templates": false,
  "require_device_email": false,
  "rsa_key_filename": "data/rsa_key",
  "send_purge_schedule": "0 5 * * * *",
  "sendmail_command": null,
  "sends_allowed": true,
  "sends_folder": "data/sends",
  "show_password_hint": true,
  "signups_allowed": true,
  "signups_domains_whitelist": "",
  "signups_verify": false,
  "signups_verify_resend_limit": 6,
  "signups_verify_resend_time": 3600,
  "smtp_accept_invalid_certs": false,
  "smtp_accept_invalid_hostnames": false,
  "smtp_auth_mechanism": null,
  "smtp_debug": false,
  "smtp_embed_images": true,
  "smtp_explicit_tls": null,
  "smtp_from": "************************",
  "smtp_from_name": "Vaultwarden",
  "smtp_host": "************",
  "smtp_password": null,
  "smtp_port": 25,
  "smtp_security": "off",
  "smtp_ssl": null,
  "smtp_timeout": 15,
  "smtp_username": null,
  "sso_allow_unknown_email_verification": false,
  "sso_audience_trusted": null,
  "sso_auth_only_not_session": true,
  "sso_authority": "https://win10pro.lab:8443/auth/v1",
  "sso_authorize_extra_params": "",
  "sso_callback_path": "https://win10pro.lab:8000/identity/connect/oidc-signin",
  "sso_client_cache_expiration": 0,
  "sso_client_id": "11111222222",
  "sso_client_secret": "***",
  "sso_debug_force_fail_auth_code": false,
  "sso_debug_tokens": false,
  "sso_enabled": true,
  "sso_master_password_policy": null,
  "sso_only": true,
  "sso_organizations_all_collections": true,
  "sso_organizations_id_mapping": "",
  "sso_organizations_invite": false,
  "sso_organizations_revocation": false,
  "sso_organizations_token_path": "/groups",
  "sso_pkce": true,
  "sso_roles_default_to_user": true,
  "sso_roles_enabled": false,
  "sso_roles_token_path": "/resource_access/11111222222/roles",
  "sso_scopes": "email profile offline_access",
  "sso_signups_match_email": true,
  "templates_folder": "data/templates",
  "tmp_folder": "data/tmp",
  "trash_auto_delete_days": null,
  "trash_purge_schedule": "0 5 0 * * *",
  "use_sendmail": false,
  "use_syslog": false,
  "user_attachment_limit": null,
  "user_send_limit": null,
  "web_vault_enabled": true,
  "web_vault_folder": "web-vault/",
  "yubico_client_id": null,
  "yubico_secret_key": null,
  "yubico_server": null
}
@Timshel
Copy link
Owner

Timshel commented Mar 20, 2025

Hey,

For a standard user the Export vault available in Tools does not export Organization secrets.

The Organization export (In the Admin console) in the web client is calling the same endpoint as the CLI, so the same restriction will apply.

But as soon as I try to export, the session seems to get invalidated.

Never used the CLI, but I'm guessing the Unauthorized Error: You need to be Admin or Owner to call this endpoint is responsible for the session invalidation.

Login with cli is possible, but ONLY if I set "sso_auth_only_not_session" to TRUE.

Is this the case for the web client too ? Which provider are you using ?

@cocoon
Copy link
Contributor Author

cocoon commented Mar 21, 2025

For a standard user the Export vault available in Tools does not export Organization secrets.

And this is not what I see. I can export with Web Tools menu from normal users, BUT it seems only the items where the user has "Manage Collection" permission, if the user has only "Edit items" it is not exported. So this is at least what I see.

Is this the case for the web client too ? Which provider are you using ?

No this is only with the cli, the web ui is working OK as far as I can see. I am testing with local rauthy 0.28.1 currently.

@cocoon
Copy link
Contributor Author

cocoon commented Mar 21, 2025

Is this the case for the web client too ?

Oh I have to correct myself, it is failing for the web ui, too.
Will try to find out more.

The refresh token that oidcwarden is complaining about is beeing decoded OK with:
https://github.com/salcode/jwt

grant_type=refresh_token&client_id=undefined&refresh_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJuYmYiOjE3NDI1NDQ3NDEsImV4cCI6MTc0MjcxNTgwMSwiaXNzIjoiaHR0cHM6Ly93aW4xMHByby5sYWI6ODAwMHxsb2dpbiIsInN1YiI6InNzbyIsImRldmljZV90b2tlbiI6Im01aGs0ZHgyNldnVUk5bnpJT0hDbzBGcjZIckstR2ZVQTc1eFFjanV5bkxrbzJjaHJid0JxRURBS0RSQkQzdl9DZ2NPczE3M05LNUJIQ1FZTXJmWkJ3PT0iLCJ0b2tlbiI6eyJSZWZyZXNoIjoiZXlKaGJHY2lPaUpGWkVSVFFTSXNJbXRwWkNJNklrVlljbGxNTmtabVFtRmpaVEpCU1RGVFNrNU1jVE5YTUNJc0luUjVjQ0k2SWtwWFZDSjkuZXlKcFlYUWlPakUzTkRJMU5ETXdNREVzSW1WNGNDSTZNVGMwTWpjeE5UZ3dNU3dpYm1KbUlqb3hOelF5TlRRME56UXhMQ0pwYzNNaU9pSm9kSFJ3Y3pvdkwzZHBiakV3Y0hKdkxteGhZam80TkRRekwyRjFkR2d2ZGpFaUxDSmhkV1FpT2lJeE1URXhNVEl5TWpJeU1pSXNJbUY2Y0NJNklqRXhNVEV4TWpJeU1qSXlJaXdpZEhsd0lqb2lVbVZtY21WemFDSXNJblZwWkNJNklrczJUR3QwYTNjd1JVSlBSbUZwWTI1VlIyMDFRMmhKVXlJc0ltRjFkR2hmZEdsdFpTSTZNVGMwTWpVME16QXdNSDAuMmlHb0ZOUEQtbGNFbG1KeFFhNkZHbERuTkJvM1k5b2RoMG42ZTV1WWwxb1hQVFZXcGxYankxaUxEQ3VmeExkb0QzbmJKbGFUT2ZXU0ZVT0lLM2ZuQ0EifX0.Q9STk4S7F2-Bu2wBAngIOEDSqWd0Z8cqw5KjPDZxD5ngl43QN3Nlgp4ian0UaWdJebP-W_GAIO-y8JkbVkz5asfhkqUILxAZu844YqDkpPPUnI31VbxdqpNle9fRCC7C2tM2HIubZPchANqQ7nfjr15x8aE938pi_9YhOMdsizXsGLknLc01Wy0BLF4oc43AIiPKBr4vpplVzia4njQBsX-TlGBW6tPAsdRr2Fbv_C-xTKUOnvH6SUeBaqzAQ300wmk4YVyjxMse7s-_qqfKoXzFpn3Sz0mG9mWL_Y1tOcYwXvEUgn-QASq69_z30HmNe5kdS6LHbIcM93WN7Li-UA

Image
Image

@cocoon
Copy link
Contributor Author

cocoon commented Mar 21, 2025

Update:
If I disable "refresh_token" support for the oidcwarden client in rauthy, it works.

For some reason oidcwarden has a problem with the refresh token.

maybe it doesn't support EdDSA.

UPDATE:
looks like it is fixed to RSA:

const JWT_ALGORITHM: Algorithm = Algorithm::RS256;

let mut validation = jsonwebtoken::Validation::new(JWT_ALGORITHM);

There is also this hint, so I just disable it:

If the client supports EdDSA / ed25519 alrotihms, it should always be the preferred choice. RSA algorithms exist for compatibility only.

The algorithm for refresh tokens cannot be changed, since these are used by Rauthy only.

But maybe it would be better to handle the error instead of failing to login or support all algorithms?

@Timshel
Copy link
Owner

Timshel commented Mar 21, 2025

Thanks for the investigation :).

I'll have to check it because there is something strange, the JWT with the device_token is generated by the server not your provider, so it should only fail to decode when it's expired.

Additionally, I do try to decode the refresh_token returned by your provider in case it's a JWT to try to read the exp, but failure to decode should not block login since not all refresh_token are JWT.

@Timshel
Copy link
Owner

Timshel commented Apr 2, 2025

Hey

Sorry should have had a closer look earlier :(.

As I expected the issue is not around the use of RS256 since as I mentioned it's signed by the app.
But discovered a new way for the decoding to fail 😅, the refresh_token sent by Rauthy has a nbf (not before date) set after the expiration of the access_token. When building the wrapping refresh_token I reuse the same nbf, and since Bitwarden aggressively call the refresh token endpoint (I expect as a way to confirm the session validity) it ends up failing since it's not yet valid :(.

I don't think it's a good idea to try to change the refresh_token handling (could truly refresh the token only if the access_token is expired, and call another endpoint to check the session validity).

Luckily the issue was raised and an env setting allow bypassing the issue: DISABLE_REFRESH_TOKEN_NBF=true.

@cocoon
Copy link
Contributor Author

cocoon commented Apr 2, 2025

Oh great you identified it already, many thanks!

No problem, I am fighting with so many stuff around the whole topic and other stuff at the same time that I did not find the time to check it myself, so I am more than happy that you found how to get it working.

Will try it 👍

@cocoon
Copy link
Contributor Author

cocoon commented Apr 3, 2025

Seems to work! :)
So feel free to close this if you don't plan to support nbf claim calculation and this is not a problem:

For a standard user the Export vault available in Tools does not export Organization secrets.

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

2 participants