Skip to main content

Thorgate helper for ansible vault password

Project description

CLI command that connects two awesome tools together - Ansible Vault & Bitwarden Password Manager

https://gitlab.com/thorgate-public/tg-bw-helper/badges/master/pipeline.svg https://gitlab.com/thorgate-public/tg-bw-helper/badges/master/coverage.svg
https://asciinema.org/a/d8zWlTHhrtXYi8KhAvresaHK8.svg

Why?

At Thorgate, we deploy project using Ansible. Ansible comes with awesome encrypted storage, and every storage needs it’s own password to access it contents.

We also using Bitwarden to store company-wide passwords and sensitive information. And if we already are storing passwords to Ansible Vault’s in Bitwarden, we thought why not use Bitwarden CLI tool to pass these passwords directly to Ansible Vault?

And that’s how this project was born 😎

Getting Started

Prerequisites

We need these tools to be installed:

We strongly recommend installing Python packages in dedicated and isolated virtual environments. There are several tools that helps manage virtual environments:

Installation

We assume several things:

  • That you have existing or starting new Ansible project

  • That your Ansible installation lives in virtual environment

Based on these assumptions, for installation you need to add this package into your virtual environment. For example you might run $ poetry add tg-bw-helper

Setting Up With Ansible

  1. Create if not yet existing shell script with this example content (it can be named ask-vault-pass.sh) - note that you do not need to add poetry run before invoking bw_helper here, or activate virtualenv etc., since your ansible will be already running in correct environment

    #!/bin/sh
    bw_helper --vault-item "Ansible Vault" --vault-item-field "Password"
  2. Make sure that this script is executable! If not, run $ sudo chmod +x ask-vault-pass.sh

  3. Edit ansible.cfg to specify script that Ansible will be using to get Vault password

    [defaults]
    vault_password_file=./ask-vault-pass.sh

Usage

Now when all these steps completed:

  • tg-bw-helper is installed into virtual environment where Ansible is installed

  • Ansible project is configured to use special script

We are ready to use the tool:

  1. Run $ bw login (Needs to be run once per user session)

  2. Run your usual Ansible playbook that previously asked for Vault password

  3. Enter Bitwarden master password

CLI Options

--bw-executable

Optional, should point to bw executable, defaults to /usr/bin/bw, can also be set with TG_BW_AP_EXECUTABLE_PATH env variable

--fallback-prompt

optional, prompt to display if bw fails, defaults to “Vault password: “, can also be set with TG_BW_AP_FALLBACK_PROMPT env variable

--vault-item

vault item ID or name, should be specific since tool will fail if multiple items are found

  • Item name is what you see as it’s name in bitwarden UI

  • Item ID is useful if you have two items with same name, you can learn it by using bitwarden CLI (use bw login to login, follow the instructions for how to pass the session information over to the next command, and then use bw list items --search <item name>. You will get json array of matching objects, each object will have ID that you can use.)

--vault-item-field

optional, field to use on the item. If not specified, password is used. Examples:

  • You have an item “Awesome project ansible vault” with password “123”, and you want to use “123”. You do not specify --valut-item-field in this case.

  • You have an item “Ansible secrets” with password set to “abc”, that has additional fields “Test server ansible” set to “123” and “Live server ansible” set to “456”, and you want to use “123”. You specify --valut-item-field="Test server ansible" in this case.

Environment

If BW_SESSION is set in environment, it will be used instead of asking bitwarden master password to unlock bitwarden.

If using linux, you can opt to save the bitwarden session in linux kernel secret storage by setting TG_BW_SESSION_SECRET_NAME environment variable to to some string (preferably random) that will be used to store the secret on user’s session keyring.

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

Developing

For local development project repository contains pyproject.toml and poetry.lock. When using them with Poetry you will be able to recreate ready to use environment.

We also added Makefile that contains lots of useful commands to help setup the project, run tests and lint code. Do check it out by running make

Opening MR

  1. Clone the Project

  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)

  3. Commit your Changes (git commit -m 'Add some AmazingFeature')

  4. Push to the Branch (git push origin feature/AmazingFeature)

  5. Open a Merge Request

License

Distributed under the MIT License. See LICENSE for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tg_bw_helper-1.1.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tg_bw_helper-1.1.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file tg_bw_helper-1.1.0.tar.gz.

File metadata

  • Download URL: tg_bw_helper-1.1.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.0.dev0 CPython/3.13.11 Linux/6.18.5-arch1-1

File hashes

Hashes for tg_bw_helper-1.1.0.tar.gz
Algorithm Hash digest
SHA256 91e1786b09e4e1278d8af1702dfc46b7addd6acc1442219933f3f96ccca7f9c8
MD5 a8b856afc2f00420b7c46c3061f6a1f0
BLAKE2b-256 3944ef75d0cfa09c43b996531113e7c7b01eb821e600928528da7cde3af9f4bf

See more details on using hashes here.

File details

Details for the file tg_bw_helper-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: tg_bw_helper-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.0.dev0 CPython/3.13.11 Linux/6.18.5-arch1-1

File hashes

Hashes for tg_bw_helper-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7d35d36655d67a41ee8019b6436cd7b577c13db020c098ada621cf649d6d7696
MD5 e2cc056312dbbbba3f51010616de3b7f
BLAKE2b-256 fe3e8842b11c509878654d3a1aaa587f1b3055598d53bc4d36bd4bf3ece4301a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page