Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit 59572ef

Browse files
[HOUSEKEEPING] Remove/Comment Out resources related to key vault for … (#458)
* [HOUSEKEEPING] Remove/Comment Out resources related to key vault for introspection * remove commented out code * Update onboard.test.ts Co-authored-by: Andre Briggs <[email protected]>
1 parent 8a6a84d commit 59572ef

File tree

4 files changed

+7
-106
lines changed

4 files changed

+7
-106
lines changed

guides/service-introspection.md

+3-14
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,11 @@ introspection:
4444
table_name: "table-name"
4545
partition_key: "partition-key"
4646
key: "storage-access-key"
47-
service_principal_id: "service-principal-id"
48-
service_principal_secret: "service-principal-secret"
49-
subscription_id: "subscription-id"
50-
tenant_id: "tenant-id"
51-
resource-group: "resource-group-name"
5247
```
5348

54-
## Prerequisites
55-
56-
1. Service principal with owner access.
57-
[Create a service principal with owner access.](#service-principal)
58-
2. Optionally, Azure Key Vault can be used to securely store and tightly control
59-
access to tokens, passwords, API keys, and other secrets
60-
[How to create key vault](https://docs.microsoft.com/en-us/azure/key-vault/quick-create-cli).
61-
3. Give the service principal get and list access. Follow step 2 from
62-
[these instructions](https://docs.microsoft.com/en-us/azure/devops/pipelines/library/variable-groups?view=azure-devops&tabs=yaml#link-secrets-from-an-azure-key-vault).
49+
To create storage-account and table, use the `spk deployment onboard` command to
50+
create them where subscription Id, resource group name, service principal Id,
51+
password and tenant Id are required.
6352

6453
### Service Principal
6554

src/commands/deployment/onboard.decorator.json

-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
"description": "Name of the resource group to create new storage account when it does not exist",
2323
"required": true
2424
},
25-
{
26-
"arg": "-k, --key-vault-name <key-vault-name>",
27-
"description": "Name of the Azure key vault"
28-
},
2925
{
3026
"arg": "--service-principal-id <service-principal-id>",
3127
"description": "Azure service principal id with `contributor` role in Azure Resource Group",

src/commands/deployment/onboard.test.ts

+2-43
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import yaml from "js-yaml";
44
import * as path from "path";
55
import { Config, loadConfiguration } from "../../config";
66
import * as config from "../../config";
7-
import * as keyvault from "../../lib/azure/keyvault";
87
import * as storage from "../../lib/azure/storage";
98
import { createTempDir } from "../../lib/ioUtil";
109
import { deepClone } from "../../lib/util";
@@ -15,7 +14,6 @@ import {
1514
} from "../../logger";
1615
import { AzureAccessOpts, ConfigYaml } from "../../types";
1716
import {
18-
createKeyVault,
1917
execute,
2018
getStorageAccessKey,
2119
CommandOptions,
@@ -37,7 +35,6 @@ afterAll(() => {
3735
});
3836

3937
const MOCKED_VALUES: CommandOptions = {
40-
keyVaultName: "testKeyVault",
4138
servicePrincipalId: "servicePrincipalId",
4239
servicePrincipalPassword: "servicePrincipalPassword",
4340
storageAccountName: "testaccount",
@@ -49,7 +46,6 @@ const MOCKED_VALUES: CommandOptions = {
4946
};
5047

5148
const MOCKED_CONFIG: OnBoardConfig = {
52-
keyVaultName: "testKeyVault",
5349
servicePrincipalId: "servicePrincipalId",
5450
servicePrincipalPassword: "servicePrincipalPassword",
5551
storageAccountName: "testaccount",
@@ -108,7 +104,6 @@ const testPopulatedVal = (
108104
describe("test populateValues", () => {
109105
it("all values are set", () => {
110106
const values = populateValues(getMockedValues());
111-
expect(values.keyVaultName).toBe(MOCKED_VALUES.keyVaultName);
112107
expect(values.servicePrincipalId).toBe(MOCKED_VALUES.servicePrincipalId);
113108
expect(values.servicePrincipalPassword).toBe(
114109
MOCKED_VALUES.servicePrincipalPassword
@@ -152,19 +147,6 @@ describe("test populateValues", () => {
152147
}
153148
);
154149
});
155-
it("keyVaultName default to config.introspection.azure.key_vault_name", () => {
156-
testPopulatedVal(
157-
(configYaml: ConfigYaml) => {
158-
configYaml.key_vault_name = "KeyVaultName";
159-
},
160-
(values: CommandOptions) => {
161-
values.keyVaultName = undefined;
162-
},
163-
(values) => {
164-
expect(values.keyVaultName).toBe("KeyVaultName");
165-
}
166-
);
167-
});
168150
it("servicePrincipalId default to config.introspection.azure.service_principal_id", () => {
169151
testPopulatedVal(
170152
(configYaml: ConfigYaml) => {
@@ -316,37 +298,17 @@ describe("test validateAndCreateStorageAccount function", () => {
316298

317299
describe("test getStorageAccessKey function", () => {
318300
it("already exist", async () => {
319-
jest
320-
.spyOn(storage, "getStorageAccountKey")
321-
.mockReturnValueOnce(Promise.resolve("key"));
301+
jest.spyOn(storage, "getStorageAccountKey").mockResolvedValueOnce("key");
322302
const values = getMockedConfig();
323303
const accessOpts = getMockedAccessOpts(values);
324304
const storageKey = await getStorageAccessKey(values, accessOpts);
325305
expect(storageKey).toBe("key");
326306
});
327307
});
328308

329-
describe("test createKeyVault function", () => {
330-
it("[+ve] not key vault value", async () => {
331-
const values = getMockedConfig();
332-
values.keyVaultName = undefined;
333-
const accessOpts = getMockedAccessOpts(values);
334-
// nothing is done
335-
await createKeyVault(values, accessOpts, "accessString");
336-
});
337-
it("[+ve] with key vault value", async () => {
338-
jest.spyOn(keyvault, "setSecret").mockReturnValueOnce(Promise.resolve());
339-
const values = getMockedConfig();
340-
const accessOpts = getMockedAccessOpts(values);
341-
await createKeyVault(values, accessOpts, "accessString");
342-
});
343-
});
344-
345309
describe("onboard", () => {
346310
test("empty location", async () => {
347-
jest
348-
.spyOn(storage, "isStorageAccountExist")
349-
.mockReturnValueOnce(Promise.resolve(false));
311+
jest.spyOn(storage, "isStorageAccountExist").mockResolvedValueOnce(false);
350312

351313
try {
352314
const values = getMockedConfig();
@@ -392,9 +354,6 @@ describe("onboard", () => {
392354
jest
393355
.spyOn(storage, "createStorageAccount")
394356
.mockReturnValueOnce(Promise.resolve({ location: "test" }));
395-
jest
396-
.spyOn(onboardImpl, "createKeyVault")
397-
.mockReturnValueOnce(Promise.resolve());
398357
jest.spyOn(onboardImpl, "setConfiguration").mockReturnValueOnce(true);
399358

400359
const data = {

src/commands/deployment/onboard.ts

+2-45
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import commander from "commander";
44
import fs from "fs";
55
import yaml from "js-yaml";
66
import { Config, defaultConfigFile, readYaml } from "../../config";
7-
import { setSecret } from "../../lib/azure/keyvault";
87
import {
98
createStorageAccount,
109
createTableIfNotExists,
@@ -29,7 +28,6 @@ export interface CommandOptions {
2928
storageTableName: string | undefined;
3029
storageLocation: string | undefined;
3130
storageResourceGroupName: string | undefined;
32-
keyVaultName: string | undefined;
3331
servicePrincipalId: string | undefined;
3432
servicePrincipalPassword: string | undefined;
3533
tenantId: string | undefined;
@@ -44,7 +42,6 @@ export interface OnBoardConfig {
4442
servicePrincipalPassword: string;
4543
subscriptionId: string;
4644
tenantId: string;
47-
keyVaultName?: string;
4845
storageLocation?: string;
4946
}
5047

@@ -61,7 +58,6 @@ export const populateValues = (opts: CommandOptions): CommandOptions => {
6158
opts.storageAccountName || azure?.account_name || undefined;
6259
opts.storageTableName =
6360
opts.storageTableName || azure?.table_name || undefined;
64-
opts.keyVaultName = opts.keyVaultName || config.key_vault_name || undefined;
6561
opts.servicePrincipalId =
6662
opts.servicePrincipalId || azure?.service_principal_id || undefined;
6763
opts.servicePrincipalPassword =
@@ -111,7 +107,6 @@ export const validateValues = (opts: CommandOptions): OnBoardConfig => {
111107
servicePrincipalPassword: opts.servicePrincipalPassword || "",
112108
subscriptionId: opts.subscriptionId || "",
113109
tenantId: opts.tenantId || "",
114-
keyVaultName: opts.keyVaultName,
115110
storageLocation: opts.storageLocation,
116111
};
117112
};
@@ -207,45 +202,9 @@ export const getStorageAccessKey = async (
207202
return accessKey;
208203
};
209204

210-
/**
211-
* Creates Key Vault if value from commander has value for `keyVaultName`
212-
*
213-
* @param values values from commander
214-
* @param accessOpts Azure Access Opts
215-
* @param accessKey Access Key
216-
*/
217-
export const createKeyVault = async (
218-
values: OnBoardConfig,
219-
accessOpts: AzureAccessOpts,
220-
accessKey: string
221-
): Promise<void> => {
222-
// if key vault is not specified, exit without reading storage account
223-
// key and setting it in the key vault
224-
if (values.keyVaultName) {
225-
logger.debug(
226-
`Calling setSecret with storage account primary key ***
227-
and ${values.keyVaultName}`
228-
);
229-
await setSecret(
230-
values.keyVaultName,
231-
`${values.storageAccountName}Key`,
232-
accessKey,
233-
accessOpts
234-
);
235-
} else {
236-
// notify the user to set the environment variable with storage access key
237-
logger.info(
238-
`Please set the storage account access key in environment variable
239-
INTROSPECTION_STORAGE_ACCESS_KEY before issuing any deployment commands.`
240-
);
241-
logger.info(`Storage account ${values.storageAccountName} access key: ***`);
242-
}
243-
};
244-
245205
/**
246206
* Creates the Storage account `accountName` in resource group `resourceGroup`,
247-
* sets storage account access key in keyvalut, and updates pipelines
248-
* (acr-hld, hld->manifests)
207+
* and updates pipelines (acr-hld, hld->manifests)
249208
*
250209
* @param values Values from commander.
251210
*/
@@ -254,7 +213,7 @@ export const onboard = async (
254213
): Promise<StorageAccount | undefined> => {
255214
logger.debug(
256215
`onboard called with ${values.storageAccountName}, ${values.storageTableName},
257-
${values.storageResourceGroupName}, ${values.storageLocation}, and ${values.keyVaultName}`
216+
${values.storageResourceGroupName} and ${values.storageLocation}`
258217
);
259218

260219
const accessOpts: AzureAccessOpts = {
@@ -288,8 +247,6 @@ export const onboard = async (
288247
table ${values.storageTableName} exist.`);
289248
}
290249

291-
await createKeyVault(values, accessOpts, accessKey);
292-
293250
// save storage account and table names in configuration
294251
setConfiguration(values.storageAccountName, values.storageTableName);
295252
return storageAccount;

0 commit comments

Comments
 (0)