Code Monkey home page Code Monkey logo

bitwarden-configuration-provider's Introduction

This is a custom configuration provider for .NET Core applications already utilizing Microsoft.Configuration. It utilizes the Bitwarden CLI to retrieve secure notes and insert them as configuration keys in the running application. It is primarily meant to be used as a means of holding secrets during development, and it is it therefore not currently recommended to use in a production setting.

Installing Bitwarden CLI

The details can be found here: https://bitwarden.com/help/article/cli/#download-and-install

Quick install instructions for the most common package distributors:

  • NPM: npm install -g @bitwarden/cli
  • Homebrew: brew install bitwarden-cli
  • Chocolatey: choco install bitwarden-cli
  • Snap: sudo snap install bw
  • AUR: yay -S bitwarden-cli

Unlocking Bitwarden via the CLI

Before the configuration provider can be taken into use, it is necessary to sign in:

bw login

The first time an application with the configuration provider is run, it will prompt for a password in order to start a session. The configuration provider will save the session key in ~/.bw-session-key.tmp (/home/USER on Unix and C:/Users/USER on Windows).

Unlocking outside the running application

In order to avoid getting prompted, the configuration provider can be unlocked by updating ~/.bw-session-key.tmp with a session key - acquired by the command:

bw unlock

This can be also be done semi-automatically via:

bw unlock --raw >> ~/.bw-session-key.tmp

Locking

This can be done by throwing away the session key, i. e. deleting ~/.bw-session-key.tmp. Alternativaly, all session keys can be invalidated via:

bw lock

Usage

Bitwarden is not primarily meant for secret management, like for instance HashiCorp's Vault. However, besides credentials types (Login/Card/Identity), Bitwarden also has a type 'Secure note'. A secure note consists of a name, some fields, and a 'notes' property. If fields are omitted, a secure note is basically a key-value-pair.

Installation

The nuget package can be installed via dotnet add package MikaelElkiaer.Extensions.Configuration.Bitwarden. Then it can be added via an extension method on IConfigurationBuilder:

c.AddBitwardenConfiguration();

Default usage

By default, the configuration provider will replace key-values which refer to a secret found in Bitwarden. If the configuration provider is enabled without any configuration, it will only alter already defined configuration keys, set by other configuration providers such as JsonFile or EnvironmentVariables. It will update any keys, which has a certain value - in the following format:

{PREFIX}{NAME}[.{FIELDNAME}]

The prefix is by default bw:, the name refers to the name of a Bitwarden secret, and the field name is optionally set to get the value of a specific field. If there is no field name, or it is set to notes, it will refer to the notes property of the secret. Note the use of . as a field selector which prohibits the use of . in secret names.

More complex configurations

The configuration provider supports the following types of secrets:

  • Env file secret
  • Single value secret
  • Fields secret

The single value secret is simply transformed into a single key-value-pair, with the name as key, and the note itself as a value.

The .env file secret is treated as a standard .env file, expecting a key-value-pair per line of the note, each line in the format KEY=VALUE.

A fields secret takes all fields and turn them into a key in the format {NAME}{FieldSeperator}{FIELDNAME}, where notes is reserved and will refer to the note property.

bitwarden-configuration-provider's People

Contributors

mikaelelkiaer avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

mapspeople

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.