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

def: support secret encryption + decryption #155

Merged
merged 1 commit into from
Nov 2, 2023
Merged

Conversation

pgavlin
Copy link
Member

@pgavlin pgavlin commented Oct 30, 2023

These changes add support for encrypting and decrypting static secrets in environment definitions. Encryprtion and decryption is handled as a pre-evaluation pass. The parser expects secrets to be decrypted prior to parsing, and will issue errors if it detects encrypted secrets.

Encrypted secrets are represented in the document by calls to fn::secret of the form

fn::secret:
  ciphertext: <base64-encoded value>

In order to support this representation, fn::secret now requires that its argument is a string literal.

@pgavlin pgavlin force-pushed the pgavlin/ciphertext branch 3 times, most recently from f0f044f to 2aeb566 Compare November 1, 2023 18:52
@pgavlin pgavlin marked this pull request as ready for review November 1, 2023 18:52
@pgavlin pgavlin force-pushed the pgavlin/ciphertext branch from 2aeb566 to 0239480 Compare November 1, 2023 20:29
@pgavlin
Copy link
Member Author

pgavlin commented Nov 1, 2023

This is ready for review. PTAL.

eval/crypt.go Outdated
// decryptSecret decrypts a single ciphertext string into its plaintext value.
func decryptSecret(ctx context.Context, decrypter Decrypter, base64Ciphertext string) (string, error) {
// Decode and decrypt the ciphertext.
ciphertext, err := base64.StdEncoding.DecodeString(base64Ciphertext)
Copy link
Member

Choose a reason for hiding this comment

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

Does the encrypter also handle b64 encoding?

`

_, err := EncryptSecrets(context.Background(), "doc", []byte(doc), broken{})
assert.NoError(t, err)
Copy link
Member

Choose a reason for hiding this comment

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

Why is this NoError rather than Error? Same for the matching decrypt test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah--malformed secrets are ignored by the encrypt/decrypt paths. Error reporting will happen if/when the environment is parsed.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add a comment to that effect

@pgavlin pgavlin force-pushed the pgavlin/ciphertext branch 3 times, most recently from 7f83b69 to c9ca96e Compare November 2, 2023 18:05
These changes add support for encrypting and decrypting static secrets
in environment definitions. Encryprtion and decryption is handled as a
pre-evaluation pass. The parser expects secrets to be decrypted prior
to parsing, and will issue errors if it detects encrypted secrets.

Encrypted secrets are represented in the document by calls to `fn::secret`
of the form

```yaml
fn::secret:
  ciphertext: <base64-encoded value>
```

In order to support this representation, `fn::secret` now requires that
its argument is a boolean, number, or string literal.
@pgavlin pgavlin force-pushed the pgavlin/ciphertext branch from c9ca96e to 2fa5852 Compare November 2, 2023 18:07
@pgavlin pgavlin merged commit 68e1653 into main Nov 2, 2023
@pgavlin pgavlin deleted the pgavlin/ciphertext branch November 2, 2023 18:20
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

Successfully merging this pull request may close these issues.

3 participants