Bitwarden

Siehe auch

Web-GUI

Bitwarden-Filter, um nur private Einträge anzuzeigen:

>-organizationid:*

Kommandozeilen-Tool bw

Siehe auch https://bitwarden.com/help/article/cli/.

Installation auf RHEL - entweder Download des CLI-Tools direkt von Bitwarden, oder Installation per NPM:

# direct download
wget 'https://vault.bitwarden.com/download/?app=cli&platform=linux' -O bw.zip
unzip bw.zip
chmod +x bw
rm -f bw.zip

# or install via NPM
dnf -y install npm
npm install -g @bitwarden/cli

Automatisierter Login. Dazu die Details zum API-Key (client_id und client_secret) unter dem persönlichen/eigenen Benutzer-Account einsehen, und das Master-Passwort für dieses Beispiel in ~/.bwpwd ablegen. Der automatisierte Login funktioniert nicht mit dem API-Key der Organisation.

# Use the API key of your named account (begins with client.xxxxxx).
# If the client_id begins with organization.xxxxxx, the bw operation will fail.
export BW_CLIENTID='client_id'
export BW_CLIENTSECRET='client_secret'
bw login --apikey
export BW_SESSION=$(bw unlock --passwordfile ~/.bwpwd --raw)

Verwaltbare Objekte auflisten:

# organizations
bw list organizations --pretty

# collections
bw list collections --pretty

# password items
bw list items --pretty

Ein spezifisches Passwort auslesen:

bw get password www.example.com

Passwort erzeugen:

# Include uppercase, lowercase, numeric and special characters, 30 chars long
bw generate -ulns --length 30

Anlegen eines Passwort-Items (erfordert jq; wiederholtes Ausführen legt das Item mehrfach an):

BW_ORGANIZATION_ID='org_id'
BW_COLLECTION_IDS='"collection_id1","collection_id2"'
BW_ITEM_TITLE='item title'
BW_ITEM_USERNAME='username'

# ---

BW_ITEM_PASSWORD=$(bw generate --length 30)
BW_LOGIN=$(bw get template item.login | \
    jq ".username = \"$BW_ITEM_USERNAME\" | .password = \"$BW_ITEM_PASSWORD\" | .totp = \"\"")

bw get template item | \
    jq ".collectionIds = [$BW_COLLECTION_IDS] | .login = $BW_LOGIN | .name = \"$BW_ITEM_TITLE\" | .notes = \"\" | .organizationId = \"$BW_ORGANIZATION_ID\"" | \
    bw encode | \
    bw create item

Logout:

bw logout unset BW_SESSION

Bemerkung

Nur das API löscht ein Item sofort und nachhaltig. Wird im GUI der Trash geleert, bleiben die Einträge noch einige Stunden per API abrufbar, enthalten aber keine brauchbaren Daten mehr.

Eine Beispiel-Session - Login, Anlegen eines Items, Abfrage des Items und Logout - mit bw:

export BW_CLIENTID='user.55482c68-0d6e-4747-a9df-9a560b826e5d'
export BW_CLIENTSECRET='7283516a37df47a09c8616c2fa988xx0'

bw login --apikey
export BW_SESSION=$(bw unlock --passwordfile ~/.bwpwd --raw)

BW_ITEM_TITLE='appsrv4711'
BW_ITEM_USERNAME='username'
BW_ITEM_URI='https://www.example.com'

BW_ORGANIZATION_ID='c93ca15f-79f7-4e04-9ed4-8c739bd366d5'
BW_COLLECTION_ID='a2ad36b6-008f-4e43-a96d-644c7108b0f7'

BW_ITEM_PASSWORD=$(bw generate --length 30)
BW_URI=$(bw get template item.login.uri | jq ".uri = \"$BW_ITEM_URI\"")
BW_LOGIN=$(bw get template item.login | jq ".username = \"$BW_ITEM_USERNAME\" | .password = \"$BW_ITEM_PASSWORD\" | .totp = \"\" | .uris = [$BW_URI]")

bw get template item | jq ".collectionIds = [\"$BW_COLLECTION_ID\"] | .login = $BW_LOGIN | .name = \"$BW_ITEM_TITLE\" | .notes = \"Created by Linuxfabrik\" | .organizationId = \"$BW_ORGANIZATION_ID\"" | bw encode | bw create item

bw get password appsrv4711
bw get password 2cfb6cc5-abad-4340-bff0-5a9722a65c92

bw logout
unset BW_CLIENTID
unset BW_CLIENTSECRET
unset BW_SESSION

Troubleshooting

TypeError: Cannot read properties of null (reading ‚keyB64‘)

Korrupte rm -f  ~/.config/Bitwarden\ CLI/data.json löschen, anschliessend neu einloggen und unlocken.

Built on 2024-04-18