Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Support for Hashicorp Vault #198

Merged
merged 15 commits into from
Nov 8, 2019
Merged

Support for Hashicorp Vault #198

merged 15 commits into from
Nov 8, 2019

Conversation

Pluies
Copy link
Contributor

@Pluies Pluies commented Nov 5, 2019

Hello all!

I've been building on @bboerst 's work from his fork to add support for Hashicorp Vault as a backend for external-secrets. 🎉

I've currently got this working through the bundled Helm Chart, which I've had to tweak a little to add the necessary bits and pieces.

I've also added a first draft of documentation, please let me know what you think / what could be improved!

Fixes #62

@Pluies
Copy link
Contributor Author

Pluies commented Nov 5, 2019

cc @silasbw @JacopoDaeli @jeffpearce from the linked issue 👍

Copy link
Contributor

@silasbw silasbw left a comment

Choose a reason for hiding this comment

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

Awesome 🔥 🌶️ ! I'm excited to get this merged in.

Can you add some basic unit testing?

README.md Outdated
# This role will need to be bound to kubernetes-external-secret's ServiceAccount; see Vault's documentation:
# https://www.vaultproject.io/docs/auth/kubernetes.html
vaultRole: my-vault-role
properties:
Copy link
Contributor

Choose a reason for hiding this comment

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

rename to data. we renamed this to data a while ago (but are still backwards compatible with properties).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good! Fixing...

backendType: vault
vaultMountPoint: my-kubernetes-vault-mount-point
vaultRole: my-vault-role
properties:
Copy link
Contributor

Choose a reason for hiding this comment

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

rename to data

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixing here too 👍

*/
async getSecretManifestData ({ secretDescriptor }) {
const data = {}
// Use secretDescriptor.properties to be backwards compatible.
Copy link
Contributor

Choose a reason for hiding this comment

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

misplaced comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yes, punted it a few lines down

lib/backends/vault-backend.js Show resolved Hide resolved
@silasbw silasbw requested review from Flydiverny and keweilu November 5, 2019 21:26
Comment on lines 78 to 94
async getSecretManifestData ({ secretDescriptor }) {
const data = {}
// Use secretDescriptor.properties to be backwards compatible.
const vaultMountPoint = secretDescriptor.vaultMountPoint
const vaultRole = secretDescriptor.vaultRole

const externalData = secretDescriptor.data || secretDescriptor.properties
const secretPropertyValues = await this._fetchSecretPropertyValues({
vaultMountPoint,
vaultRole,
externalData
})
externalData.forEach((secret, index) => {
data[secret.name] = (Buffer.from(secretPropertyValues[index], 'utf8')).toString('base64')
})
return data
}
Copy link
Member

@Flydiverny Flydiverny Nov 5, 2019

Choose a reason for hiding this comment

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

Think it would be good if we didn't have to maintain duplicates of getSecretManifestData and _fetchSecretPropertyValues now theres an additional dataFrom support in kv-backend as well :)

Perhaps we could pass along extras from secretDescriptor

ie changing
https://github.com/godaddy/kubernetes-external-secrets/blob/25e2f7426ee9bedeffe02e7d8e8befd07fedad30/lib/backends/kv-backend.js#L87-L95

to something like

async getSecretManifestData ({ 
   secretDescriptor: { 
     // Use secretDescriptor.properties to be backwards compatible. 
     properties = [], 
     data = properties, 
     dataFrom = [], 
     ...secretDescriptorOptions
   } 
 }) { 

and pass along secretDescriptorConfig to the fetch functions which can send it down to abstract get ie

    const [dataFromValues, dataValues] = await Promise.all([
      this._fetchDataFromValues({ dataFrom, secretDescriptorOptions}),
      this._fetchDataValues({ data, secretDescriptorOptions})
    ])

then signature of _get could become

 _get ({ secretKey, secretDescriptorOptions }) {

@silasbw forgot to press post 😅

@@ -46,4 +46,22 @@ subjects:
- name: {{ template "kubernetes-external-secrets.serviceAccountName" . }}
namespace: {{ .Release.Namespace | quote }}
kind: ServiceAccount
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding!

@@ -16,6 +16,7 @@ if (environment === 'development') {
require('dotenv').config()
}

const vaultEndpoint = process.env.VAULT_ADDR || 'http://127.0.0.1:8200'
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, adding this!

@Pluies
Copy link
Contributor Author

Pluies commented Nov 6, 2019

Alright, I've addressed all code comments; now adding unit tests as well as per @silasbw comment 👍

silasbw
silasbw previously approved these changes Nov 6, 2019
Copy link
Contributor

@silasbw silasbw left a comment

Choose a reason for hiding this comment

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

i think this is awesome. i think kubernetes-external-secrets has an issue with our kv-backend.js/KVBackend implementation being too specific to AWS, but i think that's outside the scope of this PR (i'll let @Flydiverny confirm :))

@@ -217,7 +218,7 @@ data:

## Backends

kubernetes-external-secrets supports both AWS Secrets Manager and AWS System Manager.
kubernetes-external-secrets supports AWS Secrets Manager, AWS System Manager, and Hashicorp Vault.
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉 !

@Flydiverny
Copy link
Member

Think we can merge this as is once tests are in, and do a separate PR to improve kv-backend! :)

@silasbw silasbw dismissed their stale review November 6, 2019 23:11

doh, forgot about the tests :)

@Pluies
Copy link
Contributor Author

Pluies commented Nov 7, 2019

The tests are here! 🎉

@Pluies
Copy link
Contributor Author

Pluies commented Nov 7, 2019

Uh oh, wait a bit before merging please – I just realised that this version (post-reviews) now creates undefined keys in the Secret:

apiVersion: v1
kind: Secret
metadata:
  name: hello-service
  namespace: default
type: Opaque
data:
  undefined: b3Blbiwgc2VzYW1l

I have to leave for the day but will review this and fix it asap tomorrow.

@Pluies
Copy link
Contributor Author

Pluies commented Nov 8, 2019

Found & fixed the issue & rebased on top of master. This is ready to merge if approved :)

Copy link
Member

@Flydiverny Flydiverny left a comment

Choose a reason for hiding this comment

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

name is currently disregarded when generating the secret, ie name field should control what name is set in the generated secret.

README.md Show resolved Hide resolved
externalData
})
externalData.forEach((secret, index) => {
data[secret.property] = (Buffer.from(secretPropertyValues[index], 'utf8')).toString('base64')
Copy link
Member

Choose a reason for hiding this comment

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

this should be set by secret.name instead of property

@Flydiverny
Copy link
Member

I was also perhaps a bit fast on merging #204 (meanwhile you rebased) but I can fix that part after this is merged

@Pluies
Copy link
Contributor Author

Pluies commented Nov 8, 2019

@Flydiverny thanks for the feedback! I've amended this PR by adding name where needed, and changing secretDescriptor to spec to align with #204.

Copy link
Member

@Flydiverny Flydiverny left a comment

Choose a reason for hiding this comment

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

Whoop think this is good to go! 🎉
@silasbw wanna take a last look?

@silasbw silasbw merged commit d61312c into external-secrets:master Nov 8, 2019
@silasbw
Copy link
Contributor

silasbw commented Nov 8, 2019

We just released 2.1.0 which includes vault support. thank you for contributing this 🥂 !

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

Successfully merging this pull request may close these issues.

hashicorp vault
4 participants