Skip to content

Commit e8e167c

Browse files
authored
feat(instance): add ssh utility commands (#3161)
1 parent a14ec77 commit e8e167c

25 files changed

+28110
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Key will be added to server's tags and added to root user on next restart.
4+
Key is expected in openssh format "(format) (key) (comment)".
5+
The comment will be used as key name or generated
6+
Lookup /root/.ssh/authorized_keys on your server for more information
7+
8+
USAGE:
9+
scw instance ssh add-key [arg=value ...]
10+
11+
ARGS:
12+
[server-id] Server to add your key to
13+
[public-key] Public key you want to add to your server
14+
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | fr-par-3 | nl-ams-1 | nl-ams-2 | pl-waw-1 | pl-waw-2)
15+
16+
FLAGS:
17+
-h, --help help for add-key
18+
19+
GLOBAL FLAGS:
20+
-c, --config string The path to the config file
21+
-D, --debug Enable debug mode
22+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
23+
-p, --profile string The config profile to use
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Path of the config will be $HOME/.ssh/scaleway.config
4+
5+
USAGE:
6+
scw instance ssh install-config [arg=value ...]
7+
8+
ARGS:
9+
[project-id] Project ID to use. If none is passed the default project ID will be used
10+
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | fr-par-3 | nl-ams-1 | nl-ams-2 | pl-waw-1 | pl-waw-2)
11+
12+
FLAGS:
13+
-h, --help help for install-config
14+
15+
GLOBAL FLAGS:
16+
-c, --config string The path to the config file
17+
-D, --debug Enable debug mode
18+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
19+
-p, --profile string The config profile to use
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
List only keys added manually to a server using tags.
4+
The key comment is used as key name or generated
5+
Lookup /root/.ssh/authorized_keys on your server for more information
6+
7+
USAGE:
8+
scw instance ssh list-keys <server-id ...> [arg=value ...]
9+
10+
ARGS:
11+
server-id Server to add your key to
12+
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | fr-par-3 | nl-ams-1 | nl-ams-2 | pl-waw-1 | pl-waw-2)
13+
14+
FLAGS:
15+
-h, --help help for list-keys
16+
17+
GLOBAL FLAGS:
18+
-c, --config string The path to the config file
19+
-D, --debug Enable debug mode
20+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
21+
-p, --profile string The config profile to use
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Key will be remove from server's tags and removed from root user on next restart.
4+
Keys are identified by their comment as in openssh format.
5+
Lookup /root/.ssh/authorized_keys on your server for more information
6+
7+
USAGE:
8+
scw instance ssh remove-key [arg=value ...]
9+
10+
ARGS:
11+
server-id Server to add your key to
12+
[name] Name of the key you want to remove, has to be the key comment or the index
13+
[public-key] Public key you want to remove
14+
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | fr-par-2 | fr-par-3 | nl-ams-1 | nl-ams-2 | pl-waw-1 | pl-waw-2)
15+
16+
FLAGS:
17+
-h, --help help for remove-key
18+
19+
GLOBAL FLAGS:
20+
-c, --config string The path to the config file
21+
-D, --debug Enable debug mode
22+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
23+
-p, --profile string The config profile to use
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Command utilities around server SSH
4+
- Manage keys per server
5+
- Generate ssh config
6+
7+
USAGE:
8+
scw instance ssh <command>
9+
10+
UTILITY COMMANDS:
11+
add-key Add a public key to a server
12+
list-keys List manually added public keys
13+
remove-key Remove a manually added public key from a server
14+
15+
WORKFLOW COMMANDS:
16+
install-config Install a ssh config with all your servers as host
17+
It generate hosts for instance servers, baremetal, apple-silicon and bastions
18+
19+
FLAGS:
20+
-h, --help help for ssh
21+
22+
GLOBAL FLAGS:
23+
-c, --config string The path to the config file
24+
-D, --debug Enable debug mode
25+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
26+
-p, --profile string The config profile to use
27+
28+
Use "scw instance ssh [command] --help" for more information about a command.

cmd/scw/testdata/test-all-usage-instance-usage.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ AVAILABLE COMMANDS:
1414
server Instance management commands
1515
server-type Instance type management commands
1616
snapshot Snapshot management commands
17+
ssh SSH Utilities
1718
user-data User data management commands
1819
volume Volume management commands
1920
volume-type Volume type management commands

docs/commands/instance.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ Instance API.
7878
- [List snapshots](#list-snapshots)
7979
- [Update a snapshot](#update-a-snapshot)
8080
- [Wait for snapshot to reach a stable state](#wait-for-snapshot-to-reach-a-stable-state)
81+
- [SSH Utilities](#ssh-utilities)
82+
- [Add a public key to a server](#add-a-public-key-to-a-server)
83+
- [Install a ssh config with all your servers as host
84+
It generate hosts for instance servers, baremetal, apple-silicon and bastions](#install-a-ssh-config-with-all-your-servers-as-host
85+
it-generate-hosts-for-instance-servers,-baremetal,-apple-silicon-and-bastions)
86+
- [List manually added public keys](#list-manually-added-public-keys)
87+
- [Remove a manually added public key from a server](#remove-a-manually-added-public-key-from-a-server)
8188
- [User data management commands](#user-data-management-commands)
8289
- [Delete user data](#delete-user-data)
8390
- [Get user data](#get-user-data)
@@ -2588,6 +2595,104 @@ scw instance snapshot wait 11111111-1111-1111-1111-111111111111
25882595

25892596

25902597

2598+
## SSH Utilities
2599+
2600+
Command utilities around server SSH
2601+
- Manage keys per server
2602+
- Generate ssh config
2603+
2604+
2605+
### Add a public key to a server
2606+
2607+
Key will be added to server's tags and added to root user on next restart.
2608+
Key is expected in openssh format "(format) (key) (comment)".
2609+
The comment will be used as key name or generated
2610+
Lookup /root/.ssh/authorized_keys on your server for more information
2611+
2612+
**Usage:**
2613+
2614+
```
2615+
scw instance ssh add-key [arg=value ...]
2616+
```
2617+
2618+
2619+
**Args:**
2620+
2621+
| Name | | Description |
2622+
|------|---|-------------|
2623+
| server-id | | Server to add your key to |
2624+
| public-key | | Public key you want to add to your server |
2625+
| zone | Default: `fr-par-1`<br />One of: `fr-par-1`, `fr-par-2`, `fr-par-3`, `nl-ams-1`, `nl-ams-2`, `pl-waw-1`, `pl-waw-2` | Zone to target. If none is passed will use default zone from the config |
2626+
2627+
2628+
2629+
### Install a ssh config with all your servers as host
2630+
It generate hosts for instance servers, baremetal, apple-silicon and bastions
2631+
2632+
Path of the config will be $HOME/.ssh/scaleway.config
2633+
2634+
**Usage:**
2635+
2636+
```
2637+
scw instance ssh install-config [arg=value ...]
2638+
```
2639+
2640+
2641+
**Args:**
2642+
2643+
| Name | | Description |
2644+
|------|---|-------------|
2645+
| project-id | | Project ID to use. If none is passed the default project ID will be used |
2646+
| zone | Default: `fr-par-1`<br />One of: `fr-par-1`, `fr-par-2`, `fr-par-3`, `nl-ams-1`, `nl-ams-2`, `pl-waw-1`, `pl-waw-2` | Zone to target. If none is passed will use default zone from the config |
2647+
2648+
2649+
2650+
### List manually added public keys
2651+
2652+
List only keys added manually to a server using tags.
2653+
The key comment is used as key name or generated
2654+
Lookup /root/.ssh/authorized_keys on your server for more information
2655+
2656+
**Usage:**
2657+
2658+
```
2659+
scw instance ssh list-keys <server-id ...> [arg=value ...]
2660+
```
2661+
2662+
2663+
**Args:**
2664+
2665+
| Name | | Description |
2666+
|------|---|-------------|
2667+
| server-id | Required | Server to add your key to |
2668+
| zone | Default: `fr-par-1`<br />One of: `fr-par-1`, `fr-par-2`, `fr-par-3`, `nl-ams-1`, `nl-ams-2`, `pl-waw-1`, `pl-waw-2` | Zone to target. If none is passed will use default zone from the config |
2669+
2670+
2671+
2672+
### Remove a manually added public key from a server
2673+
2674+
Key will be remove from server's tags and removed from root user on next restart.
2675+
Keys are identified by their comment as in openssh format.
2676+
Lookup /root/.ssh/authorized_keys on your server for more information
2677+
2678+
**Usage:**
2679+
2680+
```
2681+
scw instance ssh remove-key [arg=value ...]
2682+
```
2683+
2684+
2685+
**Args:**
2686+
2687+
| Name | | Description |
2688+
|------|---|-------------|
2689+
| server-id | Required | Server to add your key to |
2690+
| name | | Name of the key you want to remove, has to be the key comment or the index |
2691+
| public-key | | Public key you want to remove |
2692+
| zone | Default: `fr-par-1`<br />One of: `fr-par-1`, `fr-par-2`, `fr-par-3`, `nl-ams-1`, `nl-ams-2`, `pl-waw-1`, `pl-waw-2` | Zone to target. If none is passed will use default zone from the config |
2693+
2694+
2695+
25912696
## User data management commands
25922697

25932698
User data is a key value store API you can use to provide data to your Instance without authentication.

internal/namespaces/instance/v1/custom.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,18 @@ func GetCommands() *core.Commands {
180180

181181
cmds.MustFind("instance", "private-nic", "get").Override(privateNicGetBuilder)
182182

183+
// SSH Utilities
184+
185+
human.RegisterMarshalerFunc([]*SSHKeyFormat(nil), marshalSSHKeys)
186+
187+
cmds.Merge(core.NewCommands(
188+
instanceSSH(),
189+
sshAddKeyCommand(),
190+
sshConfigInstallCommand(),
191+
sshListKeysCommand(),
192+
sshRemoveKeyCommand(),
193+
))
194+
183195
return cmds
184196
}
185197

0 commit comments

Comments
 (0)