dani-garcia / vaultwarden

Unofficial Bitwarden compatible server written in Rust, formerly known as bitwarden_rs
GNU Affero General Public License v3.0
35.04k stars 1.71k forks source link

Bitwarden CLI Client Token has expired #4695

Closed DonSYS91 closed 2 weeks ago

DonSYS91 commented 2 weeks ago

Subject of the issue

I just started having random auth issues on Bitwarden CLI that runs in a docker on Azure app service and serves an HTTP endpoint.

Deployment environment

Steps to reproduce

I can't seem to find a proper way to reproduce the issue but last thing I did when it started acting like that was upgrading Bitwarden CLI client from 2024.4.1 to 2024.6.0 I also increased KDF to the recommended size on Vaultwarden user settings.

Expected behaviour

Bitwarden CLI will lock the vault only.

Actual behaviour

Bitwarden CLI is losing the authentication.

Troubleshooting data

Bitwarden CLI becomes unauthenticated returning:

{
    "success": true,
    "data": {
        "object": "template",
        "template": {
            "serverUrl": "https://******",
            "lastSync": null,
            "userEmail": "",
            "userId": "aca0fca5-0944-4b6e-a873-2c7e259c5efc",
            "status": "unauthenticated"
        }
    }
}

On Vaultwarden Logs i have:

[2024-07-02 14:30:10.482][vaultwarden::auth][ERROR] Token has expired
[2024-07-02 14:30:10.577][auth][ERROR] Unauthorized Error: Invalid claim
[2024-07-02 14:30:10.644][vaultwarden::api::core::sends::_][WARN] Request guard `Headers` failed: "Invalid claim".

Bitwarden CLI Dockerfile:

FROM --platform=linux/amd64 debian:latest
ENV DEBIAN_FRONTEND=noninteractive

WORKDIR /usr/local/bin
RUN apt update && apt install -y curl unzip libsecret-1-0 jq
COPY entrypoint.sh .
RUN chmod +x /usr/local/bin/entrypoint.sh
RUN export VER=$(curl -H "Accept: application/vnd.github+json" https://api.github.com/repos/bitwarden/clients/releases | jq  -r 'sort_by(.published_at) | reverse | .[].name | select( index("CLI") )' | sed 's:.*CLI v::' | head -n 1) && \
  curl -LO "https://github.com/bitwarden/clients/releases/download/cli-v{$VER}/bw-linux-{$VER}.zip" \
  && unzip *.zip && chmod +x ./bw
ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ]

entrypoint.sh

#!/usr/bin/env bash

# to enable interactive CLI usage
if [[ $# -gt 0 ]]; then
  bw "$@"
  exit $?
fi

STATUS="$(bw status | jq -r '.status')"

if [[ -n "$MFA_CODE" ]]; then
  # shellcheck disable=SC2034
  export MFA_LOGIN="--method 0 --code $MFA_CODE"
fi

if [[ -n "$BW_CLIENTSECRET" ]]; then
  export API_LOGIN="--apikey"
fi

if [[ "$STATUS" == "unauthenticated" ]]; then
  bw config server "$SERVER_HOST_URL" && echo
  # shellcheck disable=SC2086
  bw login "$VAULT_EMAIL" "$VAULT_PASSWORD" $API_LOGIN $MFA_LOGIN && echo
fi

bw serve --hostname all --port "${SERVE_PORT:-8087}" &
BW_SERVE_PID=$!
echo "\`bw serve\` pid: $BW_SERVE_PID"

if [[ "$UNLOCK_VAULT" == "true" ]]; then
  while ! curl -sX POST -H "Content-Type: application/json" -d "{\"password\": \"$VAULT_PASSWORD\"}" "http://localhost:${SERVE_PORT:-8087}/unlock" >/dev/null; do
    sleep 1
  done
  echo "Vault unlocked!"
fi

echo "Server can be reached at: http://localhost:${SERVE_PORT:-8087}/status"
sleep infinity

I tried to remove the rsa* files and they regenerated but the issue still persists until i restarted the CLI docker.

Any hint?

Thank you!