Skip to content

Commit bf04768

Browse files
Merge pull request #265705 from dramasamy/ssh
[NotReleaseSpecific] SSH key doc for NAKS
2 parents 097bed7 + a696460 commit bf04768

8 files changed

+437
-46
lines changed

articles/operator-nexus/TOC.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,10 @@
204204
href: howto-kubernetes-cluster-action-restart.md
205205
- name: Customize cluster DNS
206206
href: how-to-customize-kubernetes-cluster-dns.md
207-
- name: Customize Worker Nodes
207+
- name: Customize worker nodes
208208
href: howto-kubernetes-cluster-customize-workers.md
209+
- name: Manage SSH keys
210+
href: howto-kubernetes-cluster-manage-ssh-key.md
209211
- name: Nexus Virtual Machine
210212
expanded: false
211213
items:
Lines changed: 306 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,306 @@
1+
---
2+
title: Configure and manage SSH keys on Azure Operator Nexus Kubernetes cluster nodes #Required; page title is displayed in search results. Include the brand.
3+
description: Learn how to configure and manage SSH keys on Azure Operator Nexus Kubernetes cluster nodes. #Required; article description that is displayed in search results.
4+
author: dramasamy #Required; your GitHub user alias, with correct capitalization.
5+
ms.author: dramasamy #Required; microsoft alias of author; optional team alias.
6+
ms.service: azure-operator-nexus #Required; service per approved list. slug assigned by ACOM.
7+
ms.topic: how-to #Required; leave this attribute/value as-is.
8+
ms.date: 02/06/2024 #Required; mm/dd/yyyy format.
9+
ms.custom: template-how-to-pattern #Required; leave this attribute/value as-is.
10+
---
11+
12+
# Configure and manage SSH keys on Azure Operator Nexus Kubernetes cluster nodes
13+
14+
This article describes how to configure and manage the SSH key on your Nexus Kubernetes agent pool and control plane nodes. SSH keys provide a secure method of accessing these nodes in your cluster.
15+
16+
## Prerequisites
17+
18+
Before proceeding with this how-to guide, it's recommended that you:
19+
20+
* Refer to the Operator Nexus Kubernetes cluster [QuickStart guide](./quickstarts-kubernetes-cluster-deployment-bicep.md) for a comprehensive overview and steps involved.
21+
* Ensure that you meet the outlined prerequisites in the quickstart to ensure smooth implementation of the guide.
22+
23+
> [!NOTE]
24+
> This guide assumes that you already have an existing Operator Nexus Kubernetes cluster that was created using the quickstart guide, and that you have access to either the CLI, ARM template, or Bicep used in the quickstart to update the SSH keys.
25+
26+
## Configure Operator Nexus Kubernetes cluster node SSH keys
27+
28+
When configuring an Operator Nexus Kubernetes cluster, you need to provide SSH keys for the nodes in the cluster. SSH keys provide a secure method of accessing these nodes in your cluster.
29+
30+
There are a few different ways that you can provide SSH keys for your cluster nodes.
31+
32+
* If you want to use the same SSH key for all nodes in your cluster, you can provide an array of public keys when you create the cluster. These keys are inserted into all agent pool nodes and control plane nodes.
33+
* If you want to use different SSH keys for different agent pools or control plane nodes, you can provide a unique public key for each pool, allows you to manage SSH access more granularly, this overrides the cluster wide keys. Any new agent pool gets added to the cluster later without keys use the cluster wide keys, if it has key then it uses the provided key.
34+
* If you don't provide any SSH keys when creating your cluster, no SSH keys are inserted into the nodes. This means that users can't SSH into the nodes. You can add SSH keys later by updating the cluster configuration, but can't remove those keys once added.
35+
36+
### [Azure CLI](#tab/azure-cli)
37+
38+
Following are the variables you need to set, along with the [QuickStart guide](./quickstarts-kubernetes-cluster-deployment-cli.md#create-an-azure-nexus-kubernetes-cluster) default values you can use for certain variables.
39+
40+
* `SSH_PUBLIC_KEY` - For the cluster wide keys. Using cluster wide key with agent pool and control plane keys doesn't have any effect as the control plane and agent pool keys are used instead of the cluster wide keys.
41+
* `CONTROL_PLANE_SSH_PUBLIC_KEY` - For the control plane, you can provide public keys that are inserted into the control plane nodes.
42+
* `INITIAL_AGENT_POOL_SSH_PUBLIC_KEY` - For each agent pool, you can provide public keys that are inserted into the nodes in that pool.
43+
44+
```azurecli
45+
az networkcloud kubernetescluster create \
46+
--name "${CLUSTER_NAME}" \
47+
--resource-group "${RESOURCE_GROUP}" \
48+
--subscription "${SUBSCRIPTION_ID}" \
49+
--extended-location name="${CUSTOM_LOCATION}" type=CustomLocation \
50+
--location "${LOCATION}" \
51+
--kubernetes-version "${K8S_VERSION}" \
52+
--aad-configuration admin-group-object-ids="[${AAD_ADMIN_GROUP_OBJECT_ID}]" \
53+
--admin-username "${ADMIN_USERNAME}" \
54+
--ssh-key-values "${SSH_PUBLIC_KEY}" \
55+
--control-plane-node-configuration \
56+
count="${CONTROL_PLANE_COUNT}" \
57+
vm-sku-name="${CONTROL_PLANE_VM_SIZE}" \
58+
ssh-key-values='["${CONTROL_PLANE_SSH_PUBLIC_KEY}"]' \
59+
--initial-agent-pool-configurations "[{count:${INITIAL_AGENT_POOL_COUNT},mode:System,name:${INITIAL_AGENT_POOL_NAME},vm-sku-name:${INITIAL_AGENT_POOL_VM_SIZE},ssh-key-values:['${INITIAL_AGENT_POOL_SSH_PUBLIC_KEY}']}]"\
60+
--network-configuration \
61+
cloud-services-network-id="${CSN_ARM_ID}" \
62+
cni-network-id="${CNI_ARM_ID}" \
63+
pod-cidrs="[${POD_CIDR}]" \
64+
service-cidrs="[${SERVICE_CIDR}]" \
65+
dns-service-ip="${DNS_SERVICE_IP}"
66+
```
67+
68+
### [ARM template](#tab/other)
69+
70+
The `administratorConfiguration` can be inserted into the `properties` object for the cluster wide keys, and into the `initialAgentPoolConfigurations[].administratorConfiguration` object for each agent pool. The `controlPlaneNodeConfiguration.administratorConfiguration` object is used for the control plane.
71+
72+
Update the quickstart ARM template or Bicep parameter file with the required keys so that the keys are inserted into the nodes when the cluster is created.
73+
74+
#### To provide cluster wide keys
75+
76+
```json
77+
"sshPublicKeys": {
78+
"value": [
79+
{
80+
"keyData": "ssh-rsa AAAAA...."
81+
},
82+
{
83+
"keyData": "ssh-rsa BBBBB...."
84+
}
85+
]
86+
}
87+
```
88+
89+
#### To provide keys for the control plane
90+
91+
```json
92+
"controlPlaneSshKeys": {
93+
"value": [
94+
{
95+
"keyData": "ssh-rsa CCCCC...."
96+
},
97+
{
98+
"keyData": "ssh-rsa DDDDD...."
99+
}
100+
]
101+
}
102+
```
103+
104+
#### To provide keys for the agent pool
105+
106+
```json
107+
"agentPoolSshKeys": {
108+
"value": [
109+
{
110+
"keyData": "ssh-rsa EEEEE...."
111+
},
112+
{
113+
"keyData": "ssh-rsa FFFFF...."
114+
}
115+
]
116+
}
117+
```
118+
119+
Apply the ARM template or Bicep to create the cluster.
120+
121+
---
122+
123+
## Manage Operator Nexus Kubernetes cluster node SSH keys
124+
125+
You can manage the SSH keys for the nodes in your Operator Nexus Kubernetes cluster after the cluster has been created. Updating the SSH keys is possible, but removing all SSH keys from the cluster node isn't an option. Instead, any new keys provided will replace all existing keys.
126+
127+
To update the SSH keys, you can apply the same Bicep/ARM configuration used during the initial deployment with new keys or use the CLI.
128+
129+
### Limitations
130+
131+
- You can't remove SSH keys from the cluster nodes. You can only update them with new keys.
132+
- If you try to update the cluster wide key with an empty array, the operation succeeds, but the existing keys remain unchanged.
133+
- If you try to update the agent pool keys or control plane with an empty array, the operation succeeds, and the cluster wide keys are used instead.
134+
- If you try to update the keys for a cluster that was created without any keys, the new key is added, but you can't remove it.
135+
136+
### Before you begin
137+
138+
- Ensure that you have the required permissions to update the cluster configuration.
139+
- You have the new SSH keys that you want to use for the cluster nodes.
140+
- You have the parameters file used during the initial deployment or the variables used in the CLI command.
141+
- To use this guide, you must have an existing Operator Nexus Kubernetes cluster that was created using the quickstart guide.
142+
143+
### Update cluster wide SSH keys
144+
145+
Use the following command to update the cluster wide SSH keys, which are used for all nodes in the cluster. The existing keys are replaced with the new keys.
146+
147+
> [!NOTE]
148+
> This works only if the cluster was created with cluster wide keys. If the cluster was created with agent pool or control plane keys, this operation has no effect. Refer the next sections to update agent pool or control plane keys.
149+
150+
#### Azure CLI to update cluster wide SSH keys
151+
152+
1. Set the `SSH_PUBLIC_KEY` variable with the new SSH key.
153+
154+
```bash
155+
SSH_PUBLIC_KEY="ssh-rsa CCCCC...."
156+
```
157+
158+
2. Use the following command to update the cluster wide SSH keys.
159+
160+
```azurecli
161+
az networkcloud kubernetescluster update --name "$CLUSTER_NAME" --resource-group "$RESOURCE_GROUP" --subscription "$SUBSCRIPTION_ID" --ssh-key-values "$SSH_PUBLIC_KEY"
162+
```
163+
164+
#### Azure Resource Manager (ARM) and Bicep to update cluster wide SSH keys
165+
166+
1. Update the `sshPublicKeys` parameter in `kubernetes-deploy-parameters.json` with the new SSH key.
167+
168+
```json
169+
"sshPublicKeys": {
170+
"value": [
171+
{
172+
"keyData": "ssh-rsa CCCCC...."
173+
}
174+
]
175+
}
176+
```
177+
178+
2. Redeploy the template.
179+
180+
For ARM template:
181+
182+
```azurecli
183+
az deployment group create --resource-group myResourceGroup --template-file kubernetes-deploy.json --parameters @kubernetes-deploy-parameters.json
184+
```
185+
186+
For Bicep:
187+
188+
```azurecli
189+
az deployment group create --resource-group myResourceGroup --template-file kubernetes-deploy.bicep --parameters @kubernetes-deploy-parameters.json
190+
```
191+
192+
### Update agent pool SSH keys
193+
194+
Use the following command to update the SSH keys for a specific agent pool.
195+
196+
* All the nodes in the agent pool will be updated with the new keys.
197+
* If the agent pool was created with keys, the new keys replace the existing keys.
198+
* If the agent pool was created without keys, the new keys are added.
199+
* If the agent pool was created with cluster wide keys, the new keys replace the existing keys.
200+
* If you try to update the keys for a cluster that was created without any keys, the new key is added, but you can't remove it.
201+
* If you try to update the agent pool keys with an empty array, the operation succeeds, and the cluster wide keys are used instead.
202+
203+
#### Azure CLI to update agent pool SSH keys
204+
205+
1. Set the `AGENT_POOL_KEY` variable with the new SSH key.
206+
207+
```bash
208+
AGENT_POOL_KEY="ssh-rsa DDDDD...."
209+
```
210+
211+
2. Use the following command to update the agent pool SSH keys.
212+
213+
```azurecli
214+
az networkcloud kubernetescluster agentpool update --agent-pool-name "${CLUSTER_NAME}-nodepool-2" --kubernetes-cluster-name "$CLUSTER_NAME" --resource-group "$RESOURCE_GROUP" --subscription "$SUBSCRIPTION_ID" --ssh-key-values "$AGENT_POOL_KEY"
215+
```
216+
217+
#### Azure ARM template and Bicep to update agent pool SSH keys
218+
219+
> [!NOTE]
220+
> Updating node pools created through initial agent pool configuration is not possible with this method, as there is no separate agent pool template and parameter file. Only the agent pool keys for pools created after cluster creation can be updated using this method. To update the keys for the initial agent pool, refer to the CLI command provided in the previous section. If the initial agent pool was created with cluster wide keys, and if you want to update the keys for the initial agent pool, you can update the cluster wide keys.
221+
222+
1. Update the `agentPoolSshKeys` parameter in `kubernetes-nodepool-parameters.json` with the new SSH key.
223+
224+
```json
225+
"agentPoolSshKeys": {
226+
"value": [
227+
{
228+
"keyData": "ssh-rsa DDDDD...."
229+
}
230+
]
231+
}
232+
```
233+
234+
2. Redeploy the template.
235+
236+
For ARM template:
237+
238+
```azurecli
239+
az deployment group create --resource-group myResourceGroup --template-file kubernetes-add-agentpool.json --parameters @kubernetes-nodepool-parameters.json
240+
```
241+
242+
For Bicep:
243+
244+
```azurecli
245+
az deployment group create --resource-group myResourceGroup --template-file kubernetes-add-agentpool.bicep --parameters @kubernetes-nodepool-parameters.json
246+
```
247+
248+
### Update control plane SSH keys
249+
250+
Use the following command to update the SSH keys for the control plane.
251+
252+
* All the nodes in the control plane will be updated with the new keys.
253+
* If the control plane was created with keys, the new keys replace the existing keys.
254+
* If the control plane was created without keys, the new keys are added.
255+
* If the control plane was created with cluster wide keys, the new keys replace the existing keys.
256+
* If you try to update the keys for a cluster that was created without any keys, the new key is added, but you can't remove it.
257+
* If you try to update the control plane keys with an empty array, the operation succeeds, and the cluster wide keys are used instead.
258+
259+
> [!NOTE]
260+
> The control plane keys can be updated using the initial deployment template and parameter file, as the control plane is a part of the cluster. However, agent pool keys cannot be updated in the same way, as the agent pool is a sub-resource, unless the agent pool uses cluster wide keys.
261+
262+
#### Azure CLI to update control plane SSH keys
263+
264+
1. Set the `CONTROL_PLANE_SSH_PUBLIC_KEY` variable with the new SSH key.
265+
266+
```bash
267+
CONTROL_PLANE_SSH_PUBLIC_KEY="ssh-rsa EEEEE...."
268+
```
269+
270+
2. Use the following command to update the control plane SSH keys.
271+
272+
```azurecli
273+
az networkcloud kubernetescluster update --name "$CLUSTER_NAME" --resource-group "$RESOURCE_GROUP" --subscription "$SUBSCRIPTION_ID" --control-plane-node-configuration ssh-key-values="['$CONTROL_PLANE_SSH_PUBLIC_KEY']"
274+
```
275+
276+
#### Azure ARM template and Bicep to update control plane SSH keys
277+
278+
1. Update the `controlPlaneSshKeys` parameter in `kubernetes-deploy-parameters.json` with the new SSH key.
279+
280+
```json
281+
"controlPlaneSshKeys": {
282+
"value": [
283+
{
284+
"keyData": "ssh-rsa EEEEE...."
285+
}
286+
]
287+
}
288+
```
289+
290+
2. Redeploy the template.
291+
292+
For ARM template:
293+
294+
```azurecli
295+
az deployment group create --resource-group myResourceGroup --template-file kubernetes-deploy.json --parameters @kubernetes-deploy-parameters.json
296+
```
297+
298+
For Bicep:
299+
300+
```azurecli
301+
az deployment group create --resource-group myResourceGroup --template-file kubernetes-deploy.bicep --parameters @kubernetes-deploy-parameters.json
302+
```
303+
304+
## Next steps
305+
306+
By understanding how to configure and manage SSH keys on your Operator Nexus Kubernetes cluster nodes, you can ensure that your cluster is secure and that you can access the nodes when you need to troubleshoot issues.

articles/operator-nexus/includes/kubernetes-cluster/quickstart-arm-add-node-pool.json

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,27 @@
2121
"description": "The custom location of the Nexus instance"
2222
}
2323
},
24-
"tags": {
25-
"type": "object",
26-
"defaultValue": {},
27-
"metadata": {
28-
"description": "Tags to be associated with the resource"
29-
}
30-
},
3124
"adminUsername": {
3225
"type": "string",
3326
"defaultValue": "azureuser",
3427
"metadata": {
3528
"description": "The username for the administrative account on the cluster"
3629
}
3730
},
38-
"sshPublicKey": {
39-
"type": "string",
40-
"defaultValue": "",
31+
"agentPoolSshKeys": {
32+
"type": "array",
4133
"metadata": {
42-
"description": "The SSH public key that will be associated with the 'azureuser' user for secure remote login"
43-
}
34+
"description": "The agent pool SSH public key that will be associated with the given user for secure remote login"
35+
},
36+
"defaultValue": []
37+
/*
38+
{
39+
"keyData": "ssh-rsa AAAAA...."
40+
},
41+
{
42+
"keyData": "ssh-rsa BBBBB...."
43+
}
44+
*/
4445
},
4546
"agentPoolNodeCount": {
4647
"type": "int",
@@ -167,7 +168,10 @@
167168
"type": "CustomLocation"
168169
},
169170
"properties": {
170-
"administratorConfiguration": {},
171+
"administratorConfiguration": {
172+
"adminUsername": "[parameters('adminUsername')]",
173+
"sshPublicKeys": "[if(empty(parameters('agentPoolSshKeys')), json('null'), parameters('agentPoolSshKeys'))]"
174+
},
171175
"count": "[parameters('agentPoolNodeCount')]",
172176
"mode": "[parameters('agentPoolMode')]",
173177
"vmSkuName": "[parameters('agentVmSku')]",

0 commit comments

Comments
 (0)