Skip to content

Commit 2209bae

Browse files
authored
[Identity] - Add instructions for running Identity test in Azure Arc (Azure#15006)
This commit adds instructions on how to setup and run an identity smoke test in Azure Arc using managed identity to our collection of manual-integration tests. Tested manually using a Linux VM Resolves Azure#11724
1 parent 7adcb70 commit 2209bae

File tree

4 files changed

+131
-0
lines changed

4 files changed

+131
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Testing Identity in Azure Arc
2+
3+
## Prerequisites
4+
5+
- A non-Azure Windows or Linux virtual machine with NodeJS, NPM, and git installed.
6+
- Administrator privileges on the VM.
7+
- An Azure Key Vault.
8+
9+
### Install Azure Arc on the VM
10+
11+
> **Note:** You must be in your VM to install Azure Arc.
12+
13+
1. Create an Azure Arc server resource on the [Azure Portal](https://portal.azure.com) (at the time of writing, the
14+
resource is named "Azure Arc").
15+
2. Choose to add an existing server using an interactive script.
16+
3. When creating the resource, fill in your desired subscription, resource group, and region for the VM. Choose the
17+
operating system of your existing VM.
18+
4. No other configuration is necessary. You can go to the "Download and run script" tab and download the script shown.
19+
5. Once the script has been downloaded, run the script on your machine with administrator privileges.
20+
6. If using a Linux VM, run the following commands (using your user name for `<user>`) to gain necessary privileges:
21+
22+
```
23+
sudo usermod -a -G himds <user>
24+
sudo setfacl -m "g:himds:r-x" /var/opt/azcmagent/tokens/
25+
sudo setfacl -m "g::r-x" /var/opt/azcmagent/tokens/
26+
```
27+
28+
7. The Azure Arc setup should now be complete. Restart your VM to finalize your environment setup.
29+
8. After restarting, check your environment by searching for environment variables named `IDENTITY_ENDPOINT` and
30+
`IMDS_ENDPOINT`. If they are not present, or don't resemble `http://localhost:40342/metadata/identity/oauth2/token` and
31+
`http://localhost:40342` respectively, you may need to wait a short while or try restarting the VM again.
32+
33+
## Give the Azure Arc VM access to the key vault
34+
35+
For the tests to pass, the VM will need secret management permissions in your key vault.
36+
37+
1. Go to your key vault resource in the [Azure Portal](https://portal.azure.com).
38+
2. Go to the vault's "Access policies" page, and click "Add Access Policy".
39+
3. Using the secret management template, select your Arc VM resource as the principal.
40+
4. Click "Add".
41+
5. Don't forget to click "Save" at the top of the access policies page after the policy is added.
42+
43+
## Run the azure-identity Tests on the Azure Arc VM
44+
45+
> **Note:** The following steps are specific to JavaScript.
46+
47+
In a terminal window, run:
48+
49+
```bash
50+
git clone https://github.com/Azure/azure-sdk-for-js --single-branch --depth 1
51+
cd azure-sdk-for-js/sdk/identity/identity/test/manual-integration/AzureArc
52+
```
53+
54+
Set the environment variable `KEYVAULT_URI` to the vault URI of your key vault.
55+
56+
Install dependencies:
57+
58+
```bash
59+
npm install
60+
```
61+
62+
Compile the test file using TypeScript:
63+
64+
```bash
65+
npm run build
66+
```
67+
68+
Run the test file:
69+
70+
```bash
71+
node dist/index.js
72+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
import { SecretClient } from "@azure/keyvault-secrets";
5+
import { ManagedIdentityCredential } from "@azure/identity";
6+
7+
async function main(): Promise<void> {
8+
// This will use the system managed identity
9+
const credential = new ManagedIdentityCredential();
10+
11+
const vaultUri = process.env.KEYVAULT_URI;
12+
13+
if (!vaultUri) {
14+
throw new Error("Missing KEYVAULT_URI environment variable.");
15+
}
16+
const client = new SecretClient(vaultUri, credential);
17+
18+
await client.setSecret("secret-name-system", "secret-value-system");
19+
20+
console.log("Successfully authenticated with Key Vault!");
21+
}
22+
23+
main().catch((err) => {
24+
console.log("error code: ", err.code);
25+
console.log("error message: ", err.message);
26+
console.log("error stack: ", err.stack);
27+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "azurearctest",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "dist/index.js",
6+
"scripts": {
7+
"build": "tsc"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"@azure/identity": "^1.3.0",
13+
"@azure/keyvault-secrets": "^4.1.0",
14+
"typescript": "^4.2.4"
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"alwaysStrict": true,
4+
"esModuleInterop": true,
5+
"lib": ["DOM"],
6+
"module": "commonjs",
7+
"moduleResolution": "node",
8+
"noImplicitReturns": true,
9+
"noUnusedLocals": true,
10+
"noUnusedParameters": true,
11+
"strict": true,
12+
"outDir": "dist",
13+
"target": "es6"
14+
},
15+
"include": ["*.ts"]
16+
}

0 commit comments

Comments
 (0)