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

GCP Secret Manager Backend Enhancements #347

Merged
merged 35 commits into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a0f7387
change for adding support for GCP Secret Manager
karan-kap Feb 23, 2020
ed7e736
Changes for supporting GCP Secret Manager
karan-kap Feb 24, 2020
dd236e4
Code formatting
karan-kap Feb 24, 2020
bd99782
Code formatting
karan-kap Feb 24, 2020
d1d5d53
Create GCP Secret Manager Client using env variable GOOGLE_APPLICATIO…
karan-kap Mar 2, 2020
d4298da
added the test case
karan-kap Mar 13, 2020
922fa17
minor code formatting
karan-kap Mar 13, 2020
2913421
resolved indentation issues
karan-kap Mar 13, 2020
dda9f4c
Corrected test cases for GCP Secret Manager
karan-kap Mar 13, 2020
834d067
updated the readme file
karan-kap Mar 17, 2020
d140c06
added more content into readme
karan-kap Mar 17, 2020
f460596
added more content into readme
karan-kap Mar 17, 2020
0f6661e
corrected the repo and version
karan-kap Mar 17, 2020
c7c6710
Resolve merge conflicts
karan-kap Apr 3, 2020
4971836
Merge pull request #2 from aeristhings/godaddy-master
karan-kap Apr 3, 2020
9495734
Enhanced the GCP Secret Manager support
karan-kap Apr 3, 2020
0668c00
Corrected the test case
karan-kap Apr 3, 2020
bc96782
Removed gcpsecretsmanager-example copy.yaml
karan-kap Apr 3, 2020
459c193
dummy project id
karan-kap Apr 6, 2020
0b53ee1
Changed projectId to gcpProjectId
karan-kap Apr 9, 2020
02c69d4
Removed .project and .settings
karan-kap Apr 9, 2020
6dd3595
Corrected typo in mountPath & GOOGLE_APPLICATION_CREDENTIALS
karan-kap Apr 9, 2020
1ab786c
Corrected the image name
karan-kap Apr 9, 2020
a26062b
reverted the version back to 3.2.0
karan-kap Apr 25, 2020
2cfc16a
Merge branch 'master' of https://github.com/godaddy/kubernetes-extern…
karan-kap Apr 25, 2020
b39d6c1
Merge conflict resolved
karan-kap Apr 25, 2020
215c337
Enhanced the GCP Secret Manager support
karan-kap Apr 3, 2020
7a9de5e
chore: workflow to run for PRs (#350)
Flydiverny Apr 16, 2020
13b8cb5
chore(docs): fix link to kubernetes auth method (#342)
dj80hd Apr 18, 2020
28bcdff
feat: add last_state metric (#357)
cep21 Apr 23, 2020
6f7d2a4
Resolved merge conflict
karan-kap Apr 25, 2020
0b7e1e2
Merge branch 'master' of https://github.com/aeristhings/kubernetes-ex…
karan-kap Apr 25, 2020
54a4688
Merge https://github.com/godaddy/kubernetes-external-secrets
karan-kap Apr 26, 2020
63db1b2
Corrected the repo URL of log-symbols
karan-kap Apr 26, 2020
987cd14
Corrected the repo URL of chai
karan-kap Apr 26, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,4 +476,4 @@ Add secrets using the AWS cli (example)

```sh
AWS_ACCESS_KEY_ID=foobar AWS_SECRET_ACCESS_KEY=foobar aws --region=us-west-2 --endpoint-url=http://localhost:4584 secretsmanager create-secret --name hello-service/password --secret-string "1234"
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ spec:
secret:
secretName: {{ $value.secret }}
{{- end }}
{{- end }}
{{- end }}
6 changes: 3 additions & 3 deletions charts/kubernetes-external-secrets/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env:
LOG_LEVEL: info
METRICS_PORT: 3001
VAULT_ADDR: http://127.0.0.1:8200
# GOOGLE_APPLICATION_CREDENTIALS: /app/gcp-creds.json
GOOGLE_APPLICATION_CREDENTIALS: /app/gcp-creds/gcp-creds.json

# Create environment variables from existing k8s secrets
# envVarsFromSecret:
Expand All @@ -33,7 +33,7 @@ env:
# filesFromSecret:
# gcp-creds:
# secret: gcp-creds
# mountPath: /app/gcp-creds.json
# mountPath: /app/gcp-creds

rbac:
# Specifies whether RBAC resources should be created
Expand Down Expand Up @@ -86,4 +86,4 @@ affinity: {}
serviceMonitor:
enabled: false
interval: "30s"
namespace:
namespace:
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ metadata:
name: gcp-secrets-manager-example
spec:
backendType: gcpSecretsManager
gcpProjectId: hello-service-project-id
data:
- key: projects/111122223333/secrets/my-secret/versions/latest
- key: hello-service-password
name: password
property: value
version: 1
32 changes: 27 additions & 5 deletions lib/backends/gcp-secrets-manager-backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,38 @@ class GCPSecretsManagerBackend extends KVBackend {
this._client = client
}

/**
* Gets the project id from auth object from the GCP Secret Manager Client
*/
_getProjectId () {
return this._client.auth._cachedProjectId
}

/**
* Get secret property value from GCP Secrets Manager.
* @param {string} key - Key used to store secret property value in GCP Secrets Manager.
* @param {boolean} keyOptions.isBinary - Is the secret base64 encoded? Set to true to handle as binary.
* @param {string} key - Key used to store secret property value in Azure Key Vault.
* @param {string} specOptions.projectId - Id of the gcp project, if not passed, this will be fetched from the client auth
* @param {string} keyOptions.version - If version is passed then fetch that version, else fetch the latest version
* @returns {Promise} Promise object representing secret property value.
*/
async _get ({ key, keyOptions }) {
this._logger.info(`fetching secret ${key} from GCP Secret Manager`)
async _get ({ key, keyOptions, specOptions: { projectId } }) {
if (!projectId) {
// get the project id from client
projectId = this._getProjectId()
}

let secretVersion
if (!keyOptions || !keyOptions.version) {
// get the latest version
secretVersion = 'latest'
} else {
secretVersion = keyOptions.version
}

this._logger.info(`fetching secret ${key} from GCP Secret for project ${projectId} with version ${secretVersion}`)

const version = await this._client.accessSecretVersion({
name: key
name: 'projects/' + projectId + '/secrets/' + key + '/versions/' + secretVersion
})
const secret = { value: version[0].payload.data.toString('utf8') }
// Handle binary files - this is useful when you've stored a base64 encoded string
Expand Down
8 changes: 7 additions & 1 deletion lib/backends/gcp-secrets-manager-backend.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ describe('GCPSecretsManagerBackend', () => {
logger: loggerMock,
client: clientMock
})

gcpSecretsManagerBackend._getProjectId = sinon.stub().returns('111122223333')
})

describe('_get', () => {
it('returns secret property value', async () => {
const secretPropertyValue = await gcpSecretsManagerBackend._get({
key: key
key: key,
keyOptions: { version: 1 },
specOptions: {
projectId: '111122223333'
}
})
expect(secretPropertyValue).equals(secret)
})
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.