Skip to content

Commit c08f413

Browse files
committed
solidify things; update readme
1 parent 5f7f551 commit c08f413

4 files changed

Lines changed: 97 additions & 26 deletions

File tree

ssh-container/Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ ARG USER_GID=1234
88
ENV USER_UID=${USER_UID}
99
ENV USER_GID=${USER_GID}
1010

11-
# ENV USER="mpiuser"
1211
ENV SESSION_DIR="/home/mpiuser/ssh-session"
1312
ENV KEYS_DIR="/home/mpiuser/ssh-session/keys"
1413

@@ -38,8 +37,7 @@ RUN cat ${KEYS_DIR}mpiuser_key.pub > ${KEYS_DIR}/authorized_keys
3837
# Override any entrypoint from base image and set our own
3938
COPY entrypoint.sh /entrypoint.sh
4039
RUN chmod a+x /entrypoint.sh
41-
42-
# USER mpiuser
40+
4341
WORKDIR /home/mpiuser
4442

4543
# Configure SSH - port is set at runtime so we don't hardcode it here

ssh-container/Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ CONTAINER_TOOL ?= docker
2727
# Container name for easier management
2828
CONTAINER_NAME = ssh-container-$(UID)-$(GID)
2929

30-
.PHONY: all docker-build clean ssh-keys client-keys run stop connect status help
30+
.PHONY: all docker-build clean ssh-keys client-keys keys run stop connect status help
3131

3232
all: docker-build
3333

@@ -59,8 +59,14 @@ client-keys: ## Generate SSH client keys for authentication
5959
echo ""; \
6060
fi
6161

62+
# Generate both SSH host and client keys
63+
keys: ssh-keys client-keys ## Generate both SSH host and client keys
64+
@echo "SSH keys generated successfully"
65+
@echo "Host keys in: $(SSH_HOST_KEY_DIR)"
66+
@echo "Client keys in: $(SSH_CLIENT_KEY_DIR)"
67+
6268
# Build the container image
63-
docker-build: ssh-keys client-keys ## Build the container image with specified UID/GID
69+
docker-build:
6470
@echo "Building $(CONTAINER_TOOL) image with UID=$(UID), GID=$(GID)..."
6571
$(CONTAINER_TOOL) build \
6672
--platform linux/amd64 \

ssh-container/README.md

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,86 @@ This container provides SSH access to launcher containers running on Rabbit node
44

55
## Overview
66

7-
The SSH container enables remote access to Rabbit User Container workflows. It requires predetermined UID/GID and generated SSH keys baked into the image for secure authentication.
7+
The SSH container enables remote access to Rabbit User Container workflows. It requires predetermined UID/GID and
8+
generated SSH keys baked into the image for secure authentication. This means users will need to build their own image
9+
and publish it somewhere.
810

9-
⚠️ **Security Note**: Images are user-specific and the generated keys must be kept secure - loss of keys means loss of access to the container.
11+
⚠️ **Security Note**: Images are user-specific and the generated keys must be kept secure - loss of keys means loss of
12+
access to the container.
1013

11-
## Quick Start
14+
## Building and Publishing Your Image
15+
16+
In this example, I use ghcr.io to publish the image publicly. Change this to an internal registry. This is using docker, but podman can be used.
1217

1318
```bash
1419
# 1. Generate SSH keys
15-
make ssh-keys client-keys
20+
make keys
1621

1722
# 2. Build with your UID/GID
18-
make build UID=1060 GID=100
23+
make build UID=1060 GID=100 # you can also change this in the Makefile
1924

2025
# 3. Test locally
2126
make run
2227
make connect
2328

2429
# 4. Publish to your registry
25-
docker tag ssh-container:latest your-registry.com/ssh-container:latest
26-
docker push your-registry.com/ssh-container:latest
30+
docker tag ssh-container:latest ghcr.io/bdevcich/ssh-container:latest
31+
docker push ghcr.io/bdevcich/ssh-container:latest
2732
```
2833

34+
The keys will be created and kept in `ssh_client_keys/`. The private key `mpiuser_key` is required to SSH into the
35+
container — **keep this file safe and secure; if you lose it, you will lose access to the container.**
36+
37+
Only the private key (`mpiuser_key`) is needed on the compute node where you SSH from. The corresponding public key is
38+
already included in the container image.
39+
2940
## NNF Container Profile
3041

31-
Create a profile referencing your published image:
32-
33-
```yaml
34-
apiVersion: nnf.cray.hpe.com/v1alpha7
35-
kind: NnfContainerProfile
36-
metadata:
37-
name: ssh-container-profile
38-
spec:
39-
containers:
40-
- name: ssh-launcher
41-
image: your-registry.com/ssh-container:latest
42-
ports:
43-
- name: ssh
44-
port: 22
42+
Edit the `NnfContainerProfile` to point to your image. An example is provided in this repo in `ssh-container.yaml`. Have
43+
an admin create a profile referencing your published image:
44+
45+
```shell
46+
kubectl apply -f ssh-container.yaml
47+
```
48+
## Run
49+
50+
Once you have an image published and available to you via an `NnfContainerProfile`, you can use a flux allocation to
51+
start the containers and then jump to a compute node. As noted previously, you will need your private ssh key to get in.
52+
53+
Start the allocation and use a `container` directive:
54+
55+
```shell
56+
flux alloc -N4 --setattr=dw="#DW container name=ssh-container profile=ssh-container"
4557
```
4658

59+
Then, ssh into the container using the private key:
60+
61+
```shell
62+
[blake@rabbit-compute-2 ~]$ ssh -i ./mpiuser_key -p $NNF_CONTAINER_PORTS mpiuser@$NNF_CONTAINER_LAUNCHER
63+
64+
The programs included with the Debian GNU/Linux system are free software;
65+
the exact distribution terms for each program are described in the
66+
individual files in /usr/share/doc/*/copyright.
67+
68+
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
69+
permitted by applicable law.
70+
71+
$ hostname
72+
fluxjob-321103304048246784-launcher
73+
$ whoami
74+
mpiuser$
75+
```
76+
77+
Once inside the container, you can then run mpirun commands:
78+
79+
```
80+
$ mpirun hostname
81+
fluxjob-321103304048246784-worker-0
82+
fluxjob-321103304048246784-worker-1
83+
```
84+
85+
In this case, we have 2 workers on 2 rabbit nodes.
86+
4787
## Customization
4888
4989
Add tools by modifying the Dockerfile:

ssh-container/ssh-container.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: nnf.cray.hpe.com/v1alpha7
2+
kind: NnfContainerProfile
3+
metadata:
4+
name: ssh-container
5+
namespace: nnf-system
6+
data:
7+
mpiSpec:
8+
launcher:
9+
containers:
10+
- image: ghcr.io/bdevcich/ssh-container:latest
11+
imagePullPolicy: IfNotPresent
12+
name: ssh-svr
13+
worker:
14+
containers:
15+
- image: ghcr.io/bdevcich/ssh-container:latest
16+
imagePullPolicy: IfNotPresent
17+
name: ssh-worker
18+
numPorts: 1
19+
pinned: false
20+
postRunTimeoutSeconds: 0
21+
preRunTimeoutSeconds: 300
22+
retryLimit: 2
23+
storages:
24+
- name: DW_JOB_my_storage
25+
optional: true
26+
- name: DW_GLOBAL_lus
27+
optional: true

0 commit comments

Comments
 (0)