Skip to content

Commit 0bd5508

Browse files
committed
CNV- 10120: dynamic SSH keys
Signed-off-by: Avital Pinnick <[email protected]>
1 parent a2a938d commit 0bd5508

15 files changed

+339
-131
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * virt/virtual_machines/virt-accessing-vm-ssh.adoc
4+
5+
:_content-type: REFERENCE
6+
[id="virt-about-static-and-dynamic-ssh-keys_{context}"]
7+
= About static and dynamic SSH key management
8+
9+
You can add public SSH keys to virtual machines (VMs) statically at first boot or dynamically at runtime.
10+
11+
[NOTE]
12+
====
13+
Only {op-system-base-full} 9 supports dynamic key injection.
14+
====
15+
16+
[discrete]
17+
[id="static-key-management_{context}"]
18+
== Static SSH key management
19+
20+
You can add a statically managed SSH key to a VM with a guest operating system that supports configuration by using a cloud-init data source. The key is added to the virtual machine (VM) at first boot.
21+
22+
You can add the key by using one of the following methods:
23+
24+
* Add a key to a single VM when you create it by using the web console or the command line.
25+
* Add a key to a project by using the web console. Afterwards, the key is automatically added to the VMs that you create in this project.
26+
27+
.Use cases
28+
29+
* As a VM owner, you can provision all your newly created VMs with a single key.
30+
31+
[discrete]
32+
[id="dynamic-key-management_{context}"]
33+
== Dynamic SSH key management
34+
35+
You can enable dynamic SSH key management for a VM with {op-system-base-full} 9 installed. Afterwards, you can update the key during runtime. The key is added by the QEMU guest agent, which is installed with Red Hat boot sources.
36+
37+
You can disable dynamic key management for security reasons. Then, the VM inherits the key management setting of the image from which it was created.
38+
39+
.Use cases
40+
41+
* Granting or revoking access to VMs: As a cluster administrator, you can grant or revoke remote VM access by adding or removing the keys of individual users from a `Secret` object that is applied to all VMs in a namespace.
42+
* User access: You can add your access credentials to all VMs that you create and manage.
43+
44+
* Ansible provisioning:
45+
46+
** As an operations team member, you can create a single secret that contains all the keys used for Ansible provisioning.
47+
** As a VM owner, you can create a VM and attach the keys used for Ansible provisioning.
48+
49+
* Key rotation:
50+
51+
** As a cluster administrator, you can rotate the Ansible provisioner keys used by VMs in a namespace.
52+
** As a workload owner, you can rotate the key for the VMs that you manage.

modules/virt-access-configuration-considerations.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ If the internal cluster network cannot handle the traffic load, you can configur
1616
* Simple to configure.
1717
* Recommended for troubleshooting VMs.
1818
* `virtctl port-forwarding` recommended for automated configuration of VMs with Ansible.
19+
* Dynamic public SSH keys can be used to provision VMs with Ansible.
1920
* Not recommended for high-traffic applications like Rsync or Remote Desktop Protocol because of the burden on the API server.
2021
* The API server must be able to handle the traffic load.
2122
* The clients must be able to access the API server.
@@ -38,4 +39,3 @@ Secondary network::
3839
* Allows a flexible approach to network topology.
3940
* Guest operating system must be configured with appropriate security because the VM is exposed directly to the secondary network. If a VM is compromised, an intruder could gain access to the secondary network.
4041

41-
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * virt/virtual_machines/virt-accessing-vm-ssh.adoc
4+
5+
ifeval::["{context}" == "static-key"]
6+
:static-key:
7+
:title: Adding a key
8+
endif::[]
9+
ifeval::["{context}" == "dynamic-key"]
10+
:dynamic-key:
11+
:title: Enabling dynamic key injection
12+
endif::[]
13+
14+
:_content-type: PROCEDURE
15+
[id="virt-adding-key-creating-vm-template_{context}"]
16+
= {title} when creating a VM from a template
17+
18+
ifdef::static-key[]
19+
You can add a statically managed public SSH key when you create a virtual machine (VM) by using the {product-title} web console. The key is added to the VM as a cloud-init data source at first boot. This method does not affect cloud-init user data.
20+
21+
Optional: You can add a key to a project. Afterwards, this key is added automatically to VMs that you create in the project.
22+
endif::[]
23+
ifdef::dynamic-key[]
24+
You can enable dynamic public SSH key injection when you create a virtual machine (VM) from a template by using the {product-title} web console. Then, you can update the key at runtime.
25+
26+
[NOTE]
27+
====
28+
Only {op-system-base-full} 9 supports dynamic key injection.
29+
====
30+
31+
The key is added to the VM by the QEMU guest agent, which is installed with {op-system-base} 9.
32+
endif::[]
33+
34+
.Prerequisites
35+
36+
* You generated an SSH key pair by running the `ssh-keygen` command.
37+
38+
.Procedure
39+
40+
. Navigate to *Virtualization* -> *Catalog* in the web console.
41+
ifdef::dynamic-key[]
42+
. Click the *Red Hat Enterprise Linux 9 VM* tile.
43+
endif::[]
44+
ifdef::static-key[]
45+
. Click a template tile.
46+
+
47+
The guest operating system must support configuration from a cloud-init data source.
48+
endif::[]
49+
. Click *Customize VirtualMachine*.
50+
. Click *Next*.
51+
. Click the *Scripts* tab.
52+
. If you have not already added a public SSH key to your project, click the edit icon beside *Authorized SSH key* and select one of the following options:
53+
54+
* *Use existing*: Select a secret from the secrets list.
55+
* *Add new*:
56+
.. Browse to the SSH key file or paste the file in the key field.
57+
.. Enter the secret name.
58+
.. Optional: Select *Automatically apply this key to any new VirtualMachine you create in this project*.
59+
ifdef::dynamic-key[]
60+
. Set *Dynamic SSH key injection* to on.
61+
endif::[]
62+
. Click *Save*.
63+
. Click *Create VirtualMachine*.
64+
+
65+
The *VirtualMachine details* page displays the progress of the VM creation.
66+
67+
.Verification
68+
. Click the *Scripts* tab on the *Configuration* tab.
69+
+
70+
The secret name is displayed in the *Authorized SSH key* section.
71+
72+
ifeval::["{context}" == "static-key"]
73+
:!static-key:
74+
endif::[]
75+
ifeval::["{context}" == "dynamic-key"]
76+
:!dynamic-key:
77+
endif::[]

modules/virt-adding-static-public-key-cli.adoc renamed to modules/virt-adding-public-key-cli.adoc

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,34 @@
22
//
33
// * virt/virtual_machines/virt-accessing-vm-ssh.adoc
44

5+
ifeval::["{context}" == "static-key"]
6+
:static-key:
7+
:header: Adding a key when creating a VM
8+
endif::[]
9+
ifeval::["{context}" == "dynamic-key"]
10+
:dynamic-key:
11+
:header: Enabling dynamic key injection
12+
endif::[]
13+
514
:_content-type: PROCEDURE
6-
[id="virt-adding-static-public-key-cli_{context}"]
7-
= Adding an SSH key when creating a virtual machine by using the command line
15+
[id="virt-adding-public-key-cli_{context}"]
16+
= {header} by using the command line
17+
18+
ifdef::static-key[]
19+
You can add a statically managed public SSH key when you create a virtual machine (VM) by using the command line. The key is added to the VM at first boot.
20+
21+
The key is added to the VM as a cloud-init data source. This method separates the access credentials from the application data in the cloud-init user data. This method does not affect cloud-init user data.
22+
endif::[]
23+
ifdef::dynamic-key[]
24+
You can enable dynamic key injection for a virtual machine (VM) by using the command line. Then, you can update the public SSH key at runtime.
825

9-
You can add a _static_ public SSH key when you create a virtual machine (VM) by using the command line. The key is added to the VM at startup.
26+
[NOTE]
27+
====
28+
Only {op-system-base-full} 9 supports dynamic key injection.
29+
====
1030

11-
The SSH key is added to the VM as generated cloud-init metadata, by using a cloud-init configuration disk. This method separates the access credentials from the application data in the cloud-init user data. This method does not affect cloud-init user data.
31+
The key is added to the VM by the QEMU guest agent, which is installed automatically with {op-system-base} 9.
32+
endif::[]
1233

1334
.Prerequisites
1435

@@ -80,32 +101,45 @@ spec:
80101
- dataVolume:
81102
name: example-volume
82103
name: example-vm-disk
83-
- cloudInitConfigDrive: <1>
104+
- cloudInitConfigDrive: <.>
84105
userData: |-
85106
#cloud-config
86107
user: cloud-user
87108
password: <password>
88109
chpasswd: { expire: False }
110+
ifdef::dynamic-key[]
111+
runcmd:
112+
- [ setsebool, -P, virt_qemu_ga_manage_ssh, on ]
113+
endif::[]
89114
name: cloudinitdisk
90115
accessCredentials:
91116
- sshPublicKey:
92117
propagationMethod:
118+
ifdef::static-key[]
93119
configDrive: {}
120+
endif::[]
121+
ifdef::dynamic-key[]
122+
qemuGuestAgent:
123+
users: ["user1","user2","fedora"] <.>
124+
endif::[]
94125
source:
95126
secret:
96-
secretName: authorized-keys <2>
127+
secretName: authorized-keys <.>
97128
---
98129
apiVersion: v1
99130
kind: Secret
100131
metadata:
101132
name: authorized-keys
102133
data:
103134
key: |
104-
MIIEpQIBAAKCAQEAulqb/Y... <3>
135+
MIIEpQIBAAKCAQEAulqb/Y... <.>
105136
----
106-
<1> Specify `cloudInitConfigDrive` to create a configuration drive.
107-
<2> Specify the `Secret` object name.
108-
<3> Paste the public SSH key.
137+
<.> Specify `cloudInitConfigDrive` to create a configuration drive.
138+
ifdef::dynamic-key[]
139+
<.> Specify the user names.
140+
endif::[]
141+
<.> Specify the `Secret` object name.
142+
<.> Paste the public SSH key.
109143

110144
. Create the `VirtualMachine` and `Secret` objects:
111145
+
@@ -143,9 +177,21 @@ spec:
143177
accessCredentials:
144178
- sshPublicKey:
145179
propagationMethod:
180+
ifdef::static-key[]
146181
configDrive: {}
182+
endif::[]
183+
ifdef::dynamic-key[]
184+
qemuGuestAgent:
185+
users: ["user1","user2","fedora"]
186+
endif::[]
147187
source:
148188
secret:
149189
secretName: authorized-keys
150190
----
151191

192+
ifeval::["{context}" == "static-key"]
193+
:!static-key:
194+
endif::[]
195+
ifeval::["{context}" == "dynamic-key"]
196+
:!dynamic-key:
197+
endif::[]

modules/virt-adding-static-public-key-project-web.adoc

Lines changed: 0 additions & 37 deletions
This file was deleted.

modules/virt-adding-static-public-key-vm-web.adoc

Lines changed: 0 additions & 40 deletions
This file was deleted.

modules/virt-connecting-secondary-network-ssh.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
:_content-type: PROCEDURE
66
[id="virt-connecting-secondary-network-ssh_{context}"]
7-
= Connecting to a virtual machine attached to a secondary network by using SSH
7+
= Connecting to a VM attached to a secondary network by using SSH
88

99
You can connect to a virtual machine (VM) attached to a secondary network by using SSH.
1010

modules/virt-connecting-service-ssh.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
:_content-type: PROCEDURE
77
[id="virt-connecting-service-ssh_{context}"]
8-
= Connecting to a virtual machine by using SSH and a service
8+
= Connecting to a VM exposed by a service by using SSH
99

10-
You can connect to a virtual machine (VM) by using SSH and a service.
10+
You can connect to a virtual machine (VM) that is exposed by a service by using SSH.
1111

1212
.Prerequisites
1313

14-
* You created a service to expose a VM.
14+
* You created a service to expose the VM.
1515
* You have an SSH client installed.
1616
* You are logged in to the cluster.
1717

modules/virt-creating-service-web.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
:_content-type: PROCEDURE
66
[id="virt-creating-service-web_{context}"]
7-
= Creating a node port or load balancer service by using the web console
7+
= Creating a service by using the web console
88

99
You can create a node port or load balancer service for a virtual machine (VM) by using the {product-title} web console.
1010

0 commit comments

Comments
 (0)