Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Add ability to specify environment for secrets #24

Open
chrisjsimpson opened this issue Jan 1, 2022 · 5 comments
Open

Proposal: Add ability to specify environment for secrets #24

chrisjsimpson opened this issue Jan 1, 2022 · 5 comments

Comments

@chrisjsimpson
Copy link
Contributor

chrisjsimpson commented Jan 1, 2022

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.

@snoyberg
Copy link
Member

snoyberg commented Jan 2, 2022

This seems to break the current interface, which I'm not in favor of. Additionally, from a security perspective, I think it's a bad idea to use the same private key for different environments. I'd recommend separate files per env instead.

@chrisjsimpson
Copy link
Contributor Author

chrisjsimpson commented Jan 2, 2022

Separate files per env makes a lot of sense, how did I miss that!?

I hit the issue when working with GitHub CI environments and didn't have that obvious thought.

So potentially amber-testing.yaml , amber-staging.yaml etc would address this exactly.

If useful I'll PR some docs on this since it's possible I'm not the only one to miss this, and miss that amber does cater to ,this use case. Failing that, will just let this thread be evidence for anyone else having the same misunderstanding.

@snoyberg
Copy link
Member

snoyberg commented Jan 3, 2022

A doc PR would be great!

@chrisjsimpson
Copy link
Contributor Author

Here's a demo repo doc demonstrating amber in combination with GitHub actions with different envionrments:

https://github.com/chrisjsimpson/amber-secrets-ci-example (I'll proof read asap)
perhaps not all needed for docs

@snoyberg
Copy link
Member

I like the docs, they look great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants