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

Enable encrypted config parameters #8562

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Enable encrypted config parameters #8562

wants to merge 1 commit into from

Conversation

jefferai
Copy link
Member

@jefferai jefferai commented Mar 13, 2020

This provides a new command, vault operator config encrypt/decrypt that can use a defined KMS within the configuration marked for config purpose to encrypt or decrypt values. These values can be decrypted with a corresponding seal/kms block at runtime, so in practice, an operator that has access to the secrets can run the encrypt command, but the resulting file is then safe to pass through e.g. CI/CD or store in Git for deployment.

(Internal RFC link: https://docs.google.com/document/d/1zupY4OTTpwSgBqDAClywyyy_JpNXiY_sqFly0b3z0aY/edit#heading=h.7sk1hglz1ywl)

An example (you'd not want to actually use an AEAD KMS in real life, but this works well for demo/test):

listener "tcp" {
        address = "127.0.0.1:8205"
        tls_disable = true
}
telemetry {
        prometheus_retention_time = "{{encrypt(24h)}}"
        disable_hostname = true
}
storage "inmem" {
}

kms "aead" {
        purpose = "autoseal"
        key = "{{encrypt(kcI2Pyo6jZBRE9Nr7sdniVAYCRwEmOE93tw7qS0Hjq4=)}}"
        aead_type = "aes-gcm"
}

kms "aead" {
        purpose = "config"
        key = "kcI2Pyo6jZBRE9Nr7sdniVAYCRwEmOE93tw7qS0Hjq4="
        aead_type = "aes-gcm"
}

This becomes encrypted via the command to:

listener "tcp" {
        address = "127.0.0.1:8205"
        tls_disable = true
}
telemetry {
        prometheus_retention_time = "{{decrypt(Ch-feItbSZwpND15ovFKly_nFxfEnjlpz3g-f-4RVIon)}}"
        disable_hostname = true
}
storage "inmem" {
}

kms "aead" {
        purpose = "autoseal"
        key = "{{decrypt(Ckg1MovuQwkMyK4m2VKNG0WLnOjsqFxU0WDPu2KIL8_dbQWf4xAOxdG9U8suhu9zargZOo4X50IvxHeyfbT6mHgvQfaZEarnSWk)}}"
        aead_type = "aes-gcm"
}

kms "aead" {
        purpose = "config"
        key = "kcI2Pyo6jZBRE9Nr7sdniVAYCRwEmOE93tw7qS0Hjq4="
        aead_type = "aes-gcm"
}

At runtime Vault will pass config files, before decoding, to a function that decrypts with the given KMS.

As is apparent from the example, a nice feature of this is the ability to encrypt the other seal/KMS block parameters.

This can use a defined KMS within the configuration marked for `config`
purpose to encrypt or decrypt values. These values can be decrypted with
a corresponding seal/kms block at runtime, so in practice, an operator
that has access to the secrets can run the encrypt command, but the
resulting file is then safe to pass through e.g. CI/CD or store in Git
for deployment.

An example (you'd not want to actually use an AEAD KMS in real life, but
this works well for demo/test):

```
listener "tcp" {
        address = "127.0.0.1:8205"
        tls_disable = true
}
telemetry {
        prometheus_retention_time = "{{encrypt(24h)}}"
        disable_hostname = true
}
storage "inmem" {
}

kms "aead" {
        purpose = "autoseal"
        key = "{{encrypt(kcI2Pyo6jZBRE9Nr7sdniVAYCRwEmOE93tw7qS0Hjq4=)}}"
        aead_type = "aes-gcm"
}

kms "aead" {
        purpose = "config"
        key = "kcI2Pyo6jZBRE9Nr7sdniVAYCRwEmOE93tw7qS0Hjq4="
        aead_type = "aes-gcm"
}
```
This becomes encrypted via the command to:
```
listener "tcp" {
        address = "127.0.0.1:8205"
        tls_disable = true
}
telemetry {
        prometheus_retention_time = "{{decrypt(Ch-feItbSZwpND15ovFKly_nFxfEnjlpz3g-f-4RVIon)}}"
        disable_hostname = true
}
storage "inmem" {
}

kms "aead" {
        purpose = "autoseal"
        key = "{{decrypt(Ckg1MovuQwkMyK4m2VKNG0WLnOjsqFxU0WDPu2KIL8_dbQWf4xAOxdG9U8suhu9zargZOo4X50IvxHeyfbT6mHgvQfaZEarnSWk)}}"
        aead_type = "aes-gcm"
}

kms "aead" {
        purpose = "config"
        key = "kcI2Pyo6jZBRE9Nr7sdniVAYCRwEmOE93tw7qS0Hjq4="
        aead_type = "aes-gcm"
}
```
At runtime Vault will pass config files, before decoding, to a function
that decrypts with the given KMS.

As is apparent from the example, a nice feature of this is the ability
to encrypt the other seal/KMS block parameters.
@mladlow mladlow added this to the 1.6 milestone Jul 20, 2020
return 0
}

file, err := os.Create(path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be handy to have an --output flag (optional) so one could transform into a target file without overwrite. Or is the intent merely redirecting stdout to said file.

c.configKMS = kms
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Could refactor for code reuse w/ the operator encrypt/decrypt, but nbd.

@@ -508,7 +506,7 @@ func testLoadConfigDir(t *testing.T) {
}

func testConfig_Sanitized(t *testing.T) {
config, err := LoadConfigFile("./test-fixtures/config3.hcl")
config, err := LoadConfigFile("./test-fixtures/config3.hcl", nil)
if err != nil {
t.Fatalf("err: %s", err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to unit test the encrypt/decrypt functionality?

@vishalnayak vishalnayak modified the milestones: 1.6, 1.7 Oct 26, 2020
@mladlow mladlow removed this from the 1.7 milestone Mar 17, 2021
@aphorise
Copy link
Contributor

@sgmiller @jefferai - is this still an applicable request and which Vault release is it likely to be a candidate in?

@VioletHynes VioletHynes added the hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed label Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core/config hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants