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.

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.0.2.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

tg_bw_helper-1.0.2-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file tg-bw-helper-1.0.2.tar.gz.

File metadata

  • Download URL: tg-bw-helper-1.0.2.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.10 Linux/5.4.109+

File hashes

Hashes for tg-bw-helper-1.0.2.tar.gz
Algorithm Hash digest
SHA256 55d514af00a27f50b1b7b3aff924cd17e2e5f0bb254cd20dd72e374a6c887e3e
MD5 1d89369d7b219719d6cc6cfa99ace788
BLAKE2b-256 6ff0df0a384244eae77eadfd61d5b08fa3e0e23a0dc98d5ce0204a160963c641

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tg_bw_helper-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.10 Linux/5.4.109+

File hashes

Hashes for tg_bw_helper-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0e531c779fcc1cc55b9c5116968433bf955e216025d852aea828d5563568b22b
MD5 20ef400a345486a3a66d7e2dd87f428c
BLAKE2b-256 c6ad41db377076bb1761fbc349d5dae2c729f651060262af2254b4e3402de1eb

See more details on using hashes here.

Supported by

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