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

Commit

Permalink
fix(azure-registry): handle binary files (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaspj authored Mar 27, 2020
1 parent 5b41ad0 commit 9727d48
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,24 @@ spec:
property: value
```
Due to the way Azure handles binary files, you need to explicitly let the ExternalSecret know that the secret is binary.
You can do that with the `isBinary` field on the key. This is necessary for certificates and other secret binary files.

```yml
apiVersion: kubernetes-client.io/v1
kind: ExternalSecret
metadata:
name: hello-keyvault-service
spec:
backendType: azureKeyVault
keyVaultName: hello-world
data:
- key: hello-service/credentials
name: password
isBinary: true
```


## Metrics

kubernetes-external-secrets exposes the following metrics over a prometheus endpoint:
Expand Down
6 changes: 6 additions & 0 deletions crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ spec:
type: string
property:
description: Property to extract if secret in backend is a JSON object
isBinary:
description: >-
You must set this to true if configuring an item for a binary file stored in Azure KeyVault.
Azure automatically base64 encodes binary files and setting this to true ensures External Secrets
does not base64 encode the base64 encoded binary files.
type: boolean
required:
- name
- key
Expand Down
7 changes: 6 additions & 1 deletion lib/backends/azure-keyvault-backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ class AzureKeyVaultBackend extends KVBackend {
* Get secret property value from Azure Key Vault.
* @param {string} key - Key used to store secret property value in Azure Key Vault.
* @param {string} specOptions.keyVaultName - Name of the azure key vault
* @param {string} keyOptions.isBinary - Does the secret contain a binary? Set to "true" to handle as binary. Does not work with "property"
* @returns {Promise} Promise object representing secret property value.
*/

async _get ({ key, specOptions: { keyVaultName } }) {
async _get ({ key, keyOptions, specOptions: { keyVaultName } }) {
const client = this._keyvaultClient({ keyVaultName })
this._logger.info(`fetching secret ${key} from Azure KeyVault ${keyVaultName}`)
const secret = await client.getSecret(key)
// Handle binary files, since the Azure client does not
if (keyOptions && keyOptions.isBinary) {
return Buffer.from(secret.value, 'base64')
}
return JSON.stringify(secret)
}
}
Expand Down

0 comments on commit 9727d48

Please sign in to comment.