Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

feat: Azure Key Vault YAML setup support #285

Merged
merged 6 commits into from
Sep 4, 2019
Merged

Conversation

PIC123
Copy link
Contributor

@PIC123 PIC123 commented Aug 29, 2019

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

@codecov
Copy link

codecov bot commented Aug 29, 2019

Codecov Report

Merging #285 into dev will increase coverage by 0.29%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/armTemplates/resources/functionApp.ts 100% <ø> (ø) ⬆️
src/index.ts 100% <100%> (ø) ⬆️
src/plugins/identity/azureKeyVaultPlugin.ts 100% <100%> (ø)
src/services/azureKeyVaultService.ts 100% <100%> (ø)
src/test/mockFactory.ts 91.52% <100%> (+0.09%) ⬆️
src/services/azureBlobStorageService.ts 100% <0%> (ø) ⬆️
src/plugins/login/azureLoginPlugin.ts 100% <0%> (ø) ⬆️
src/services/loginService.ts 100% <0%> (ø) ⬆️
src/services/rollbackService.ts 100% <0%> (ø) ⬆️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bb2c661...5fca3b8. Read the comment docs.

Copy link
Contributor

@wbreza wbreza left a 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.

@PIC123 PIC123 force-pushed the phcherne/managed-identity-arm branch from 49443fc to 115e255 Compare August 30, 2019 04:55
@PIC123 PIC123 requested a review from wbreza September 3, 2019 19:59
Copy link
Contributor

@wbreza wbreza left a 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 () => {
Copy link
Contributor

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 = {
Copy link
Contributor

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 () => {
Copy link
Contributor

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented code.

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")});
Copy link
Contributor

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.

Copy link
Contributor

@tbarlow12 tbarlow12 left a 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": {
Copy link
Contributor

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?

Copy link
Contributor Author

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

@PIC123 PIC123 merged commit 0ee7167 into dev Sep 4, 2019
tbarlow12 pushed a commit that referenced this pull request Sep 13, 2019
* Add key vault linking

* Add keyvault service

* Update tests

* Fix test

* Add tests for coverage and address more pr feedback

* Address final pr comments
@tbarlow12 tbarlow12 deleted the phcherne/managed-identity-arm branch September 16, 2019 16:50
@turkoglusaffet
Copy link

How can we use it in a serverless.yml file? Is there any example for the topic?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants