This repository has been archived by the owner on Jul 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added AkeylessBackend * fix missing spaces * Update akeyless-backend.js * removed key name from akyeless res * Update package-lock.json * fixed secretValue extra stringify * Update package-lock.json * Update package-lock.json * Update package-lock.json * Update package-lock.json * fix: update package-lock.json Signed-off-by: Markus Maga <[email protected]> Co-authored-by: renanaAkeyless <[email protected]>
- Loading branch information
1 parent
96c5f2a
commit dad820a
Showing
11 changed files
with
3,423 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict' | ||
const akeyless = require('akeyless') | ||
const AkeylessClient = new akeyless.ApiClient() | ||
AkeylessClient.basePath = process.env.AKEYLESS_API_ENDPOINT || 'https://api.akeyless.io' | ||
|
||
// Akeyless expects the following four environment variables: | ||
// - AKEYLESS_API_ENDPOINT: api-gw endpoint URL http(s)://api.akeyless.io | ||
// - AKEYLESS_ACCESS_ID: The access ID | ||
// - AKEYLESS_ACCESS_TYPE: The access type | ||
// - AKEYLESS_ACCESS_TYPE_PARAM: AZURE_OBJ_ID OR GCP_AUDIENCE OR ACCESS_KEY | ||
|
||
const client = new akeyless.V2Api(AkeylessClient) | ||
module.exports = { | ||
credential: { | ||
accessTypeParam: process.env.AKEYLESS_ACCESS_TYPE_PARAM, | ||
accessId: process.env.AKEYLESS_ACCESS_ID, | ||
accessType: process.env.AKEYLESS_ACCESS_TYPE, | ||
client: client | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
apiVersion: 'kubernetes-client.io/v1' | ||
kind: ExternalSecret | ||
metadata: | ||
name: hello-secret | ||
spec: | ||
backendType: akeyless | ||
data: | ||
- key: secret-name | ||
name: creds | ||
|
||
--- | ||
|
||
apiVersion: 'kubernetes-client.io/v1' | ||
kind: ExternalSecret | ||
metadata: | ||
name: hello-dynamic-secret | ||
spec: | ||
backendType: akeyless | ||
data: | ||
- key: dynamic-secret-name | ||
name: creds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
'use strict' | ||
const akeyless = require('akeyless') | ||
const akeylessCloud = require('akeyless-cloud-id') | ||
const KVBackend = require('./kv-backend') | ||
|
||
/** Akeyless Secrets Manager backend class. */ | ||
class AkeylessBackend extends KVBackend { | ||
/** | ||
* Create Akeyless backend. | ||
* @param {Object} credential - Credentials for authenticating with Akeyless Vault. | ||
* @param {Object} logger - Logger for logging stuff. | ||
*/ | ||
constructor ({ credential, logger }) { | ||
super({ logger }) | ||
this._credential = credential | ||
} | ||
|
||
_getCloudId () { | ||
return new Promise((resolve, reject) => { | ||
akeylessCloud.getCloudId(this._credential.accessType, this._credential.accessTypeParam, (err, res) => { | ||
if (err) { | ||
reject(err) | ||
} else { | ||
resolve(res) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
async _getSecret (key) { | ||
const api = this._credential.client | ||
const cloudId = await this._getCloudId() | ||
const opts = { 'access-id': this._credential.accessId, 'access-type': this._credential.accessType, 'access-key': this._credential.accessTypeParam, 'cloud-id': cloudId } | ||
|
||
const authResult = await api.auth(akeyless.Auth.constructFromObject(opts)) | ||
const token = authResult.token | ||
|
||
const dataType = await api.describeItem(akeyless.DescribeItem.constructFromObject({ | ||
name: key, | ||
token: token | ||
})) | ||
if (dataType.item_type === 'DYNAMIC_SECRET') { | ||
const data = await api.getDynamicSecretValue(akeyless.GetDynamicSecretValue.constructFromObject({ | ||
name: key, | ||
token: token | ||
})) | ||
return JSON.stringify(data) | ||
} | ||
if (dataType.item_type === 'STATIC_SECRET') { | ||
const staticSecretParams = akeyless.GetSecretValue.constructFromObject({ | ||
names: [key], | ||
token: token | ||
}) | ||
const data = await api.getSecretValue(staticSecretParams) | ||
const secretValue = JSON.stringify(data[key]) | ||
return JSON.parse(secretValue) | ||
} else { | ||
throw new Error('Invalid secret type' + dataType.item_type) | ||
} | ||
} | ||
|
||
/** | ||
* Get secret value from Akeyless Vault. | ||
* @param {string} key - Key the full name (path/name) of the stored secret at Akeyless. | ||
* @returns {Promise} Promise object representing secret property value. | ||
*/ | ||
async _get ({ key }) { | ||
this._logger.info(`fetching secret ${key} from akeyless`) | ||
const secret = await this._getSecret(key) | ||
return secret | ||
} | ||
} | ||
|
||
module.exports = AkeylessBackend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const { expect } = require('chai') | ||
const sinon = require('sinon') | ||
|
||
const AkeylessBackend = require('./akeyless-backend') | ||
|
||
describe('AkeylessBackend', () => { | ||
let loggerMock | ||
let clientMock | ||
let akeylessBackend | ||
|
||
const secret = 'fakeSecretValue' | ||
const key = 'secret_name' | ||
|
||
beforeEach(() => { | ||
loggerMock = sinon.mock() | ||
loggerMock.info = sinon.stub() | ||
clientMock = sinon.mock() | ||
clientMock.getSecretValue = sinon.stub().returns({ [key]: secret }) | ||
clientMock.getDynamicSecretValue = sinon.stub().returns(secret) | ||
clientMock.auth = sinon.stub().returns('token') | ||
clientMock.describeItem = sinon.stub().returns({ item_type: 'STATIC_SECRET' }) | ||
|
||
akeylessBackend = new AkeylessBackend({ | ||
credential: { endpoint: 'https//sampleendpoint', accessType: 'access_key', client: clientMock }, | ||
logger: loggerMock | ||
}) | ||
}) | ||
|
||
describe('_get', () => { | ||
it('returns secret property value', async () => { | ||
const specOptions = {} | ||
const keyOptions = {} | ||
const secretPropertyValue = await akeylessBackend._get({ | ||
key: key, | ||
specOptions, | ||
keyOptions | ||
}) | ||
expect(secretPropertyValue).equals(secret) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.