Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General guidelines, SSH setup options, tips, and examples for setting up the OpenStack environment. #544

Merged
merged 56 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
8d4d9f5
An introduction of connecting a local computer to a cloud host via SS…
giannidallatorre Nov 11, 2022
6fb24b3
Document SSH connection with a VM in OpenStack #543
giannidallatorre Nov 11, 2022
3698712
Markdown linter fix
giannidallatorre Nov 11, 2022
e1d6f76
Remove draft mode
giannidallatorre Nov 11, 2022
8ec126f
Improve compliance with Super Lint style
giannidallatorre Nov 11, 2022
09dd719
Change code block style fenced -> indented; Actual
giannidallatorre Nov 11, 2022
1fb2f7f
Fix links
giannidallatorre Nov 11, 2022
24a8345
Pagination & fixes
giannidallatorre Nov 11, 2022
c0363ed
Cosmetics
gwarf Nov 15, 2022
3780f8a
Try to fix error with mixing indented and fenced code blocks
gwarf Nov 15, 2022
550712e
Try to fix pattern
gwarf Nov 15, 2022
04aa95a
Fix link check, tested locally
gwarf Nov 15, 2022
6ade4ce
Prevent errors regarding bare urls
gwarf Nov 15, 2022
ad7df4a
Merge branch 'main' into accessing_vm_with_ssh
gwarf Nov 15, 2022
e586e7e
Move ssh username + password after SSH key
gwarf Nov 15, 2022
9b2166b
Insist on the risks of using password authentication
gwarf Nov 15, 2022
6676b93
Align name of tutorials, group the entries
gwarf Nov 15, 2022
eed2e2a
Merge branch 'main' into accessing_vm_with_ssh
gwarf Nov 25, 2022
c3a764c
Merge branch 'main' into accessing_vm_with_ssh
gwarf Dec 16, 2022
aaaab5b
Merge branch 'main' into accessing_vm_with_ssh
gwarf Jan 6, 2023
d52e380
Fix deprecated link
gwarf Jan 9, 2023
4939408
Fix deprecated links
gwarf Jan 9, 2023
09c195b
Fix deprecated links
gwarf Jan 9, 2023
2dd6b71
Fix deprecated link
gwarf Jan 9, 2023
7707672
Ignore all LTOS links.
gwarf Jan 9, 2023
1800ab0
Ignore RFC links that are often doing timeouts
gwarf Jan 9, 2023
92aed32
Fix deprecated link
gwarf Jan 9, 2023
3cbffa7
Use an http link for EC3
gwarf Jan 9, 2023
6244d42
Use an https link for oneclient installation
gwarf Jan 9, 2023
a6b73c5
Use https links
gwarf Jan 9, 2023
13dfe88
Replace more http links by https
gwarf Jan 9, 2023
0cd28d1
Use https links
gwarf Jan 9, 2023
7167e80
Replace more http links by https
gwarf Jan 9, 2023
eb1e7e1
Fix link to renamed page
gwarf Jan 9, 2023
48b81bd
Ops Portal VO page is protected
gwarf Jan 9, 2023
007bf64
Fix some obsolete links
gwarf Jan 9, 2023
1d02659
Fix some obsolete links
gwarf Jan 9, 2023
77834a8
Address issue with check github.com links, see https://github.com/tco…
gwarf Jan 9, 2023
52765e9
Fix some obsolete links
gwarf Jan 9, 2023
11fb8de
Fix broken link
gwarf Jan 9, 2023
7a53234
Address issue with check github.com links, see https://github.com/tco…
gwarf Jan 9, 2023
0dfaa4c
Fix broken link, including left over char
gwarf Jan 9, 2023
bee38ee
Drop link pointing to a dead page.
gwarf Jan 9, 2023
66cf654
Fix link to NBIS stuff
gwarf Jan 9, 2023
302f05c
Merge branch 'main' into accessing_vm_with_ssh
gwarf Mar 7, 2023
8937027
Update content/en/users/tutorials/accessing-vm-with-ssh/_index.md
gwarf Mar 7, 2023
4d8e095
Document retrieving user name from AppDB image description.
gwarf Mar 8, 2023
71e840b
Update content/en/users/tutorials/accessing-vm-with-ssh/_index.md
gwarf Mar 10, 2023
960ff79
Update content/en/users/tutorials/accessing-vm-with-ssh/_index.md
gwarf Mar 10, 2023
3f91f55
Update content/en/users/tutorials/accessing-vm-with-ssh/_index.md
gwarf Mar 10, 2023
26640eb
Update content/en/users/tutorials/accessing-vm-with-ssh/_index.md
gwarf Mar 10, 2023
c213cd1
Update content/en/users/tutorials/accessing-vm-with-ssh/_index.md
gwarf Mar 10, 2023
449b28e
Update content/en/users/tutorials/accessing-vm-with-ssh/_index.md
gwarf Mar 10, 2023
c9380fc
Merge branch 'main' into accessing_vm_with_ssh
gwarf Mar 10, 2023
4d679a6
Add mytoken to expected words
gwarf Mar 10, 2023
278e56c
ecas: add missing new line character at end of file.
gwarf Mar 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/linters/mlc_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
},
{
"pattern": "^https://operations-portal.egi.eu/downtimes/subscription"
},
{
"pattern": "^https://github.com/.*.keys"
}
]
}
215 changes: 215 additions & 0 deletions content/en/users/tutorials/accessing-vm-with-ssh/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
---
title: "Accessing virtual machines with SSH"
linkTitle: "Access a VM with SSH"
type: docs
weight: 20
description: "Accessing virtual machines with SSH"
---

## Overview

This page provides an introduction of connecting from a local computer to a
cloud host via SSH. It provides general guidelines, SSH options, tips, and
examples for setting up the OpenStack environment.

## SSH Keys

The recommended method to access a cloud virtual machine is via ssh using **SSH
keys**, you may inject your **public key** into the virtual machine, at
gwarf marked this conversation as resolved.
Show resolved Hide resolved
deployment time, and use your **private key** to connect via ssh without any
password.

{{% alert title="Tip" color="info" %}} If you are using ssh keys in GitHub your
public keys are available at: `https://github.com/${github_username}.keys`.
i.e.: `wget https://github.com/github_username.keys` {{% /alert %}}

### SSH username

The username to use to connect to a virtual machine is dependent on the virtual
machine image and is generally different in each operative system image.
gwarf marked this conversation as resolved.
Show resolved Hide resolved

For `official OS virtual machine images` you can use the general reference
enolfc marked this conversation as resolved.
Show resolved Hide resolved
documentation on
[obtaining images](https://docs.openstack.org/image-guide/obtain-images.html).

For custom virtual machine images you need to refer to your virtual machine
image provider (i.e. it could be something specific like `cloudadm`).

It is also possible to change the username using cloud-init with a user-data
configuration (i.e. see the
[cloud config examples](https://cloudinit.readthedocs.io/en/latest/topics/examples.html))
or inject some code to add additional users (i.e. with Ansible).

### Local ssh key configuration

The `private ssh-key` stored on your local computer is required to have
restrictive file permissions. Depending on your local operative system you may
need to run:

```shell
$ chmod 600 ~/.ssh/id_rsa
```

(with `id_rsa` being the name of the private key associated with the public key
in use).

## Username and password

{{% alert title="Warning" color="warning" %}} `Username` and `password` access
to cloud virtual machine images is usually **disabled** for security reasons and
it is **strongly suggested not to be used**. {{% /alert %}}

In case you have **no other option**, and are conscious of the risks, in order
to enable SSH password authentication, the destination virtual machine needs to
have `/etc/ssh/sshd_config` configuration changed from
`PasswordAuthentication no` to `PasswordAuthentication yes`.

If really needed, a custom image with `PasswordAuthentication` enabled can be
used or that can be injected when the virtual machine is deployed.

Depending on your deployment method it could be done with Ansible, Terraform,
Salt, Puppet, Chef, cloud-init, or your own deployment tool if supported (i.e.
the Infrastructure Manager and a custom TOSCA template).

{{% alert title="Warning" color="warning" %}} If you enable
`PasswordAuthentication`, be sure to
[generate a strong and unique password or passphrase](https://bitwarden.com/password-generator/)
for your account, otherwise you virtual machines **will be** compromised, and
you access may be suspended.{{% /alert %}}
gwarf marked this conversation as resolved.
Show resolved Hide resolved

## OpenStack networking
gwarf marked this conversation as resolved.
Show resolved Hide resolved

The OpenStack environment needs to be populated with the necessary
configurations and virtual hardware. To access the virtual machine from outside
the OpenStack project you have to associate a `floating IP` to the virtual
machine (which will provide a `public IP` to the virtual machine), you also have
to open the necessary ports and add or edit the security groups, (more details
on that in the specific section).
gwarf marked this conversation as resolved.
Show resolved Hide resolved

Depending on the default configuration of the OpenStack project in order to
associate a floating IP to a virtual machine in a private network it may be
necessary to set up a virtual `router` in OpenStack and `attach` it with an
`interface` to the private network. This step is usually not required as the
OpenStack router is usually pre-configured by the cloud provider.

### Security Groups Rules

The Virtual Machine that you want to connect needs to have the SSH port (22)
reachable by your local machine. For that, it is necessary that a specific
`Rule` is set up in one of the `Security Groups` associated with the virtual
machine. The rule has to open `port 22` either to any IPs (with
`CIDR 0.0.0.0/0`) or to a specific IP (or subnet) matching the IP of the local
machine used to connect with the virtual machine.

> Sites are often providing a `default` security group, that may already contain
> this rule. You can check this using
> `openstack security group rule list default`.

### Private IP vs public IP

Virtual machines in OpenStack are configured in a private network (like in the
subnet 192.168.0.0/24) but you can directly SSH-connect with them from the
internet only using a `Public IP`, which has to be associated with a virtual
machine in the private network.

### Accessing virtual machines in the private network

In general, to reach all the virtual machines in a private network, only a
single public IP is needed.

The virtual machine associated with a public IP is often referred to as a
`Bastion` host, once you connect with the bastion host, you can connect with the
other virtual machine in the same private network using the private IPs.
Alternatively, it is also possible to set up a `JumpHost` configuration in your
local ssh configuration to do that with a single command.

#### Example: ssh configuration for Jump host

```shell
$ cat ~/.ssh/config
# Bastion
Host bastion 193.1.1.2
User ubuntu
Hostname 193.168.1.2
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes

# with ProxyJump
Host private_vm
HostName 192.168.1.2
ProxyJump bastion

# old-style with ProxyCommand and additional settings
Host private_vm 192.168.1.2
Hostname 192.168.1.2
ProxyCommand ssh -q -A bastion nc %h %p
User ubuntu
ServerAliveInterval 60
TCPKeepAlive yes
ControlMaster auto
ControlPath ~/.ssh/mux-%r@%h:%p
ControlPersist 8h
IdentityFile ~/.ssh/dev
CheckHostIP=no
StrictHostKeyChecking=no
```

General considerations related to setting up the ssh configuration are valid
also for the connection between hosts in the private network (i.e. the ssh
destination host needs to have a `public key` in the `~/.ssh/known_hosts` file
of the destination user, matching the `private key` used for the connection).

## SSH connection practical example

Network configuration of two virtual machines `A` and `B` :

- `A` private IP 192.168.1.2, public IP 193.168.1.2
- `B` private IP 192.168.1.3

### Connecting from a local machine to `A`

```shell
# ssh VM_OS_username@PUBLIC_IP
$ ssh [email protected]
```

If the ssh local key is not the default `~/.ssh/id_rsa` it needs to be specified
with:

```shell
# ssh -i /path_of_your_private_ssh_key VM_OS_username@PUBLIC_IP
$ ssh -i ~/private_key [email protected]
```

### Connecting from a local machine to `B`

```shell
# from your computer
# connect to A
$ ssh [email protected]

# from the shell opened in 193.1.1.2
# connect from A to B
$ ssh [email protected]
```

## Infrastructure Manager (IM)

The Infrastructure Manager (IM) provides the SSH key that can be used to connect
gwarf marked this conversation as resolved.
Show resolved Hide resolved
to the virtual machine in the VM
[info page of the IM-Dashboard (see Fig 14)](https://imdocs.readthedocs.io/en/latest/dashboard.html#infrastructures).
gwarf marked this conversation as resolved.
Show resolved Hide resolved

The page shows the information related with the virtual machine: the IP, the
username (usually `cloudadm`), and the SSH key.

## Token-based authentication

If supported by your virtual machine, you can also use
[ssh-oidc](https://github.com/EOSC-synergy/ssh-oidc) which implements the
authentication consuming under-the-hood tokens from a local demon installed on
your local machine.

More details on that soon.

The Infrastructure Manager (IM) can `Enable SSH OIDC access to the VM` in
virtual machines by selecting the related `Optional Features`.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Create your first Virtual Machine"
title: "Create your first Virtual Machine (VM)"
type: docs
weight: 10
description: >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "Data transfer with grid storage"
linkTitle: "Data transfer with grid storage"
type: docs
weight: 50
weight: 160
description: >
Use EGI Data transfer to handle data in grid storage
---
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Data transfer with object storage"
type: docs
weight: 60
weight: 170
description: >
Use EGI Data transfer to handle data in object storage
---
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Create a Virtual Machine with Jupyter and DataHub"
title: "Create a VM with Jupyter and DataHub"
type: docs
weight: 100
description: >
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Automating with oidc-agent, fedcloudclient, terraform and Ansible"
title: "Automate with oidc-agent, fedcloudclient, terraform and Ansible"
type: docs
weight: 150
description: >
Expand Down
2 changes: 1 addition & 1 deletion content/en/users/tutorials/vm-datahub/_index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Access DataHub from a Virtual machine"
title: "Access DataHub from a VM"
type: docs
weight: 40
description: >
Expand Down