Code Monkey home page Code Monkey logo

amber's Introduction

amber

Rust

Manage secret values in-repo via public key cryptography. See the announcement blog post for more motivation.

Amber provides the ability to securely store secret data in a plain-text file. Secrets can be encrypted by anyone with access to the file, without the ability to read those files without a secret key. The file format is a plain text YAML file which minimizes diffs on value changes, making it amenable to tracking changes in version control.

The primary use case for Amber is storing secret values for Continuous Integration systems. In most CI secrets management systems, there is no way to track the changes in values over time. With Amber, the public key and encrypted values live inside the repo, ensuring future runs of the same commit will either fail (if you've misplaced/changed the key) or have identical inputs.

Install

See below for OS specific packages. Alternatively, you can install from source by installing Rust and running cargo install --git https://github.com/fpco/amber. Binaries are available on the release page. Place the executable on your PATH and ensure that the executable bit is set (for non-Windows platforms).

Arch Linux

There is a AUR package available for Amber. Install with makepkg or your preferred helper:

git clone https://aur.archlinux.org/amber-secrets.git
cd amber-secrets
makepkg -si

Nix/NixOS

Currently, amber is available as part of nixpkgs unstable. It should be available in the stable set in the next nixpkgs stable release. On NixOS distribution, you can install it through:

$ nix-env -iA nixos.amber-secret

On non NixOS distribution, you can install it through:

$ nix-env -iA nixpkgs.amber-secret

GitHub actions

For installing and caching amber, in GitHub actions workflow you can use psibi/setup-amber.

Example usage:

- uses: psibi/[email protected]
  with:
    amber-version: 'v0.1.3' # Optional version, otherwise latest
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

The GITHUB_TOKEN secret is optional, but is recommended to avoid rate limiting. You don't have to set up anything specific for it since for each workflow run, GitHub automatically populates that token for you.

The amber-demo repository has an example workflow showcasing the usage of this GitHub action.

Usage

Running amber --help will give you full, up to date set of instructions. The --amber-yaml option, or the AMBER_YAML environment variable, can be used to specify the location of the file containing your secret values. If unspecified, it will default to amber.yaml. The typical workflow is:

  • amber init to create a new secret key and amber.yaml file.
  • Securely store that secret key, such as in a password manager. Additionally, if desired, put that secret key in your CI system's secrets.
  • Add additional secrets with amber encrypt.
    • Use the "read from stdin" feature to encrypt whole files amber encrypt SECRET_SAUCE < my-secret-sauce.txt
  • Commit your amber.yaml file into your repository.
  • Within your CI scripts, or when using your secrets on your own system:
    • Set the AMBER_SECRET environment variable to your secret key.
    • Use amber print to see a list of your secrets.
    • Use amber exec ... to execute subcommands with the secrets available.
  • Over time, use amber encrypt to add new secrets or update existing secrets, and amber remove to remove a secret entirely.
  • By storing the secrets in Git, you'll always be able to recover old secret values.

Here's a sample shell session:

$ amber init
Your secret key is: 15aa07775395303732870cff2cc35c26f94af3344cf0f85d230aa004234d9764
Please save this key immediately! If you lose it, you will lose access to your secrets.
Recommendation: keep it in a password manager
If you're using this for CI, please update your CI configuration with a secret environment variable
export AMBER_SECRET=15aa07775395303732870cff2cc35c26f94af3344cf0f85d230aa004234d9764
$ amber encrypt PASSWORD deadbeef
$ amber print
Error: Error loading secret key from environment variable AMBER_SECRET

Caused by:
    environment variable not found
$ export AMBER_SECRET=15aa07775395303732870cff2cc35c26f94af3344cf0f85d230aa004234d9764
$ amber print
export PASSWORD="deadbeef"
$ amber exec -- sh -c 'echo $PASSWORD'
deadbeef
$ cat amber.yaml
---
file_format_version: 1
public_key: 9a4eb57571201fe413a5a9d583a070d180669928f0b98152ad93454cf5079860
secrets:
  - name: PASSWORD
    sha256: 2baf1f40105d9501fe319a8ec463fdf4325a2a5df445adf3f572f626253678c9
    cipher: c7f3d90e15b2d37801055d9773e6bd1e4b36120987bf31c6f111d5d69acb6d020a5f532ea035c272465f2a6e43c55fb009bf03a5c7a93581
$ amber encrypt PASSWORD deadbeef
[2021-08-13T10:45:13Z INFO  amber::config] New value matches old value, doing nothing
$ amber encrypt PASSWORD deadbeef2
[2021-08-13T10:45:16Z WARN  amber::config] Overwriting old secret value
$ amber print
export PASSWORD="deadbeef2"
$ amber remove PASSWORD
$ amber print
$ cat amber.yaml
---
file_format_version: 1
public_key: 9a4eb57571201fe413a5a9d583a070d180669928f0b98152ad93454cf5079860
secrets: []

Authors

This tool was written by the FP Complete engineering team. It was originally part of a deployment system for our Kube360 Kubernetes software collection. We decided to extract the generalizable parts to a standalone tool to improve Continuous Integration workflows.

If you have a use case outside of CI, or additional features you think would fit in well, please let us know in the issue tracker!

amber's People

Contributors

chrisjsimpson avatar matsubara0507 avatar psibi avatar sk3w avatar snoyberg avatar wezm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

amber's Issues

An installation script.

Since the tool is used in CI steps, the user would need to install amber into their building environment / container. A simple script that always pull the latest release (better if major version can be set and fixed) would be helpful.

Ability to copy secrets to system clipboard

Often while using amber locally, I want to copy certain secrets to the clipboard. I'm imagining a interface like this for this feature:

USAGE:
    amber clipboard <key> --amber-yaml <amber-yaml>

Additionally, I can volunteer to implement this if there is no objections.

encrypt: take secret value from stdin

Could the encrypt subcommand take the secret value from stdin? This would help prevent raw secrets from being saved in shell history, for example.

BTW, this is a very cool project! It hits a lot of sweet spots for in-repo secret storage.

AUR package

I created an AUR (Arch User Repository) package for amber: https://aur.archlinux.org/packages/amber-secrets/

I called it amber-secrets as there is already a package called amber (the Crystal web-framework). It also depends on the system libsodium instead of statically linking its own copy.

Anyway, just passing on the info to let you know it's out there. Not sure if it's worth mentioning in the install section of the README or not.

Proposal: Add ability to specify environment for secrets

For example user story: As a user I can specify an environment name of my choosing whilst storing a secret, perhaps with a default. When accesing a secret, the default environment is used.

e.g. Interface

(base) (environment)$ ./amber --verbose encrypt 
error: The following required arguments were not provided:
    <ENVIRONMENT>
    <KEY>

USAGE:
    amber encrypt [OPTIONS] <ENVIRONMENT> <KEY> [VALUE]

For more information try --help
(base) (environment)$ ./amber --verbose encrypt staging API_KEY secret
[2022-01-01T22:16:45Z DEBUG amber] Cmd { opt: Opt { verbose: true, amber_yaml: None, unmasked: false }, sub: Encrypt { environment: "staging", key: "API_KEY", value: Some("secret") } }
[2022-01-01T22:16:45Z DEBUG amber::cli] Checking if file "amber.yaml" exists
[2022-01-01T22:16:45Z INFO  amber::config] New value matches old value, doing nothing
(base) (environment)$ 

Possible structure: (Note the additon of "environment")

---
file_format_version: 2
public_key: 7801a1206e8e339c396a990bdd758dcccce9d1e8846b3a08b8329d3925adf801
secrets:
  - name: API_KEY
    environment: staging
    sha256: 2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a25fe97bf527a25b
    cipher: 104b00746ab5a029ee6c693e33d6cee116163b695d5ed685e1e8428984f5105012e3741ec89d4e944c4f02209762f11f69f6eed17be7
  - name: API_KEY
    environment: production
    sha256: 2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a25fe97bf527a25b
    cipher: 104b00746ab5a029ee6c693e33d6cee116163b695d5ed685e1e8428984f5105012e3741ec89d4e944c4f02209762f11f69f6eed17be7

Motivations

  • Secrets may change between environments (e.g. testing, staging etc )
  • Whilst it is possible to achieve managing different environment secrets with amber (potentially by managing amber.yaml in a different repo per environment, this undermines the goal to track the changes in values over time.

Considerations

  • To store envrionment name per secret not elsewhere
  • Provide a default environment name, or none
  • This would/could be a breaking change to the file format so may require a bump of FILE_FORMAT_VERSION

I've coded an intial attempt at this to demonstrate the idea and will push, though a complete implementation is missing since I'm new to Rust. I specifically got stuck at:

.map(|(key, value)| SecretRaw {

after altering SecretRaw structure to include environment.

I hope the code tempts someone or someone can point me in a better direction.

How do you think of this model for Terraform-alike?

  1. Having an IAM role only for CI/CD.
  2. At starting of the job, create some AWS secrets from Amber. Restrict them for CI/CD role.
  3. Running Terraform (using data to reference to the secrets).
  4. Succeeded or not, remove all secrets from AWS.

Hence we do not have AWS secrets for long term, and we do not have secret texts in Terraform artifacts.

Allow amber.yaml file to be searched in parent directory

Right now amber by default checks amber.yaml in the directory where
the command is being executed.

I think it might be convenient if it searches it's parent directory
too. I found that this could be convenient in one of the recent
projects I integrated amber with.

So I think for finding the amber.yaml, we can slightly change it to
accommodate something like this:

  • check if the passed location (either default or explicitly passed value) of file exists and use that if found.
  • If not, traverse your parent directory to see if it exists

I would be happy to implement it in the coming days, if you aren't
opposed to it.

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.