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

Commit 9727d48

Browse files
authored
fix(azure-registry): handle binary files (#311)
1 parent 5b41ad0 commit 9727d48

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,24 @@ spec:
410410
property: value
411411
```
412412
413+
Due to the way Azure handles binary files, you need to explicitly let the ExternalSecret know that the secret is binary.
414+
You can do that with the `isBinary` field on the key. This is necessary for certificates and other secret binary files.
415+
416+
```yml
417+
apiVersion: kubernetes-client.io/v1
418+
kind: ExternalSecret
419+
metadata:
420+
name: hello-keyvault-service
421+
spec:
422+
backendType: azureKeyVault
423+
keyVaultName: hello-world
424+
data:
425+
- key: hello-service/credentials
426+
name: password
427+
isBinary: true
428+
```
429+
430+
413431
## Metrics
414432

415433
kubernetes-external-secrets exposes the following metrics over a prometheus endpoint:

crd.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ spec:
6969
type: string
7070
property:
7171
description: Property to extract if secret in backend is a JSON object
72+
isBinary:
73+
description: >-
74+
You must set this to true if configuring an item for a binary file stored in Azure KeyVault.
75+
Azure automatically base64 encodes binary files and setting this to true ensures External Secrets
76+
does not base64 encode the base64 encoded binary files.
77+
type: boolean
7278
required:
7379
- name
7480
- key

lib/backends/azure-keyvault-backend.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,18 @@ class AzureKeyVaultBackend extends KVBackend {
2626
* Get secret property value from Azure Key Vault.
2727
* @param {string} key - Key used to store secret property value in Azure Key Vault.
2828
* @param {string} specOptions.keyVaultName - Name of the azure key vault
29+
* @param {string} keyOptions.isBinary - Does the secret contain a binary? Set to "true" to handle as binary. Does not work with "property"
2930
* @returns {Promise} Promise object representing secret property value.
3031
*/
3132

32-
async _get ({ key, specOptions: { keyVaultName } }) {
33+
async _get ({ key, keyOptions, specOptions: { keyVaultName } }) {
3334
const client = this._keyvaultClient({ keyVaultName })
3435
this._logger.info(`fetching secret ${key} from Azure KeyVault ${keyVaultName}`)
3536
const secret = await client.getSecret(key)
37+
// Handle binary files, since the Azure client does not
38+
if (keyOptions && keyOptions.isBinary) {
39+
return Buffer.from(secret.value, 'base64')
40+
}
3641
return JSON.stringify(secret)
3742
}
3843
}

0 commit comments

Comments
 (0)