-
Notifications
You must be signed in to change notification settings - Fork 161
feat: Azure Key Vault YAML setup support #285
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #285 +/- ##
==========================================
+ Coverage 93.89% 94.18% +0.29%
==========================================
Files 46 48 +2
Lines 1589 1634 +45
Branches 215 222 +7
==========================================
+ Hits 1492 1539 +47
+ Misses 97 95 -2
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Added a few suggestions to wrap up in addition to the missing tests.
49443fc
to
115e255
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. Added a few other comments to address before merging.
expect(sls.cli.log).lastCalledWith("Finished KeyVault service setup") | ||
}); | ||
|
||
it("does not call deploy API or deploy functions when \"keyVault\" not included in config", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is test name correct? I would imagine it not calling setPolicy
or similar, right?
let serverless: Serverless = MockFactory.createTestServerless(); | ||
|
||
beforeEach(() => { | ||
// KeyVaultManagementClient.prototype.vaults = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed commented code.
expect(service).not.toBeNull(); | ||
}); | ||
|
||
it("Throws an error if correct keyvault name is not specified", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test name seems off. The test shows that the vault doesn't exist - not that it was not specified.
properties: knownVaults["testVault"].properties | ||
} | ||
); | ||
// fail(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove commented code.
src/services/azureKeyVaultService.ts
Outdated
const identity = func.identity; | ||
|
||
const keyVaultClient = new KeyVaultManagementClient(this.credentials, subscriptionID); | ||
const vault = await keyVaultClient.vaults.get(keyVaultConfig.resourceGroup, keyVaultConfig.name).catch((e) => {throw new Error("Error: Specified vault not found")}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the .catch()
required here? If you are using async/await it should throw an exception that you can catch with normal catch
block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with Wallace's comments, and had one more question, but looks good
@@ -58,6 +58,9 @@ export class FunctionAppResource implements ArmResourceTemplateGenerator { | |||
"apiVersion": "2016-03-01", | |||
"name": "[parameters('functionAppName')]", | |||
"location": "[parameters('location')]", | |||
"identity": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this always going to be the case? Is there any situation where someone would not want system assigned identity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure, I don't know if there is any issue with always assigning the identity
* Add key vault linking * Add keyvault service * Update tests * Fix test * Add tests for coverage and address more pr feedback * Address final pr comments
How can we use it in a serverless.yml file? Is there any example for the topic? |
It is bad practice to push code with secrets hard coded. Services such as keyvault allow users to securely store their keys and just reference them from their code. This change adds sets up a managed identity for the function app and sets permissions to allow the serverless app to get secrets.
AB#535