Skip to content

Commit 5c02432

Browse files
committed
Default CSCS identity and suffix helpers
1 parent f463357 commit 5c02432

4 files changed

Lines changed: 97 additions & 43 deletions

File tree

‎docs/cscs.md‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ student checkout without running stale infrastructure from it.
9090
From the workstation, start and connect with one command:
9191

9292
```bash
93-
curl -fsSL https://raw.githubusercontent.com/NVIDIA/accelerated-computing-hub/event/2026-07-cscs-summer-school/tutorials/pyhpc/brev/cscs-run-tutorial |
94-
bash -s -- --user YOUR_CSCS_USERNAME --account YOUR_CSCS_ACCOUNT
93+
curl -fsSL https://raw.githubusercontent.com/NVIDIA/accelerated-computing-hub/event/2026-07-cscs-summer-school/tutorials/pyhpc/brev/cscs-run-tutorial.bash | bash
9594
```
9695

9796
On its first run, the helper checks out the event branch in
98-
`${HOME}/accelerated-computing-hub`. It reuses one Daint SSH connection for the
99-
launch and compute-node tunnel; if the certificate expired, it runs
100-
`cscs-key sign` and retries once.
97+
`${HOME}/accelerated-computing-hub`. It reads the CSCS username from the signed
98+
SSH certificate and uses the user's default Slurm account. It reuses one Daint
99+
SSH connection for the launch and compute-node tunnel; if the certificate
100+
expired, it runs `cscs-key sign` and retries once.
101101
The Daint-side launcher:
102102

103103
- clones the event branch when `$SCRATCH/accelerated-computing-hub` is absent;
@@ -120,17 +120,17 @@ self-signed certificate, so the browser asks for confirmation once per URL.
120120
### Run the launch and connection separately
121121

122122
To launch on a Daint login node without the end-to-end helper, copy or download
123-
`cscs-launch-tutorial` there and run:
123+
`cscs-launch-tutorial.bash` there and run:
124124

125125
```bash
126-
./cscs-launch-tutorial --account YOUR_CSCS_ACCOUNT
126+
./cscs-launch-tutorial.bash
127127
```
128128

129129
After it reports a node, run the workstation-side connection helper:
130130

131131
```bash
132132
cd "${HOME}/accelerated-computing-hub/tutorials/pyhpc/brev"
133-
./cscs-connect-tutorial --user YOUR_CSCS_USERNAME nidXXXXXX
133+
./cscs-connect-tutorial.bash nidXXXXXX
134134
```
135135

136136
This second script prints the three URLs, opens the five forwards, and leaves

tutorials/pyhpc/brev/cscs-connect-tutorial renamed to tutorials/pyhpc/brev/cscs-connect-tutorial.bash

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,36 @@ set -euo pipefail
55

66
usage() {
77
cat <<'EOF'
8-
Usage: cscs-connect-tutorial --user USER [OPTIONS] NODE
8+
Usage: cscs-connect-tutorial.bash [OPTIONS] NODE
99
1010
Run this script on the workstation with the web browser. It opens the five
1111
required SSH forwards and, by default, leaves you in a shell on NODE. Exiting
1212
that shell closes the forwards but does not cancel the Slurm job.
1313
1414
Options:
15-
--user USER CSCS username (or set CSCS_USER)
15+
--user USER Override the username read from the SSH certificate
1616
--key PATH CSCS private key (default: ~/.ssh/cscs-key)
1717
EOF
1818
}
1919

20+
discover_cscs_user() {
21+
local certificate="${1}-cert.pub"
22+
[ -f "${certificate}" ] || return 1
23+
local details
24+
details=$(ssh-keygen -L -f "${certificate}" 2>/dev/null) || return 1
25+
awk '
26+
$1 == "Principals:" { principals = 1; next }
27+
principals && $1 == "Critical" && $2 == "Options:" { exit }
28+
principals {
29+
line = $0
30+
sub(/^[[:space:]]+/, "", line)
31+
sub(/[[:space:]]+$/, "", line)
32+
if (line != "") { count++; value = line }
33+
}
34+
END { if (count == 1) print value; else exit 1 }
35+
' <<< "${details}"
36+
}
37+
2038
user=${CSCS_USER:-}
2139
ssh_key=${CSCS_SSH_KEY:-${HOME:?HOME is not set}/.ssh/cscs-key}
2240
ela_host=${CSCS_ELA_HOST:-ela.cscs.ch}
@@ -68,19 +86,23 @@ case "${jupyter_local_port}" in
6886
;;
6987
esac
7088

71-
case "${user}" in
72-
''|-*|*[!A-Za-z0-9._-]*)
73-
echo "Error: provide --user or set CSCS_USER." >&2
74-
exit 2
75-
;;
76-
esac
7789
case "${ssh_key}" in
7890
*$'\n'*|*$'\r'*|*'"'*) echo "Error: invalid CSCS key path." >&2; exit 2 ;;
7991
esac
8092
if [ ! -f "${ssh_key}" ]; then
8193
echo "Error: CSCS private key not found: ${ssh_key}" >&2
8294
exit 2
8395
fi
96+
if [ -z "${user}" ]; then
97+
user=$(discover_cscs_user "${ssh_key}" || true)
98+
fi
99+
case "${user}" in
100+
''|-*|*[!A-Za-z0-9._-]*)
101+
echo "Error: could not read one CSCS username from ${ssh_key}-cert.pub." >&2
102+
echo "Run 'cscs-key sign --file ${ssh_key}' or use --user." >&2
103+
exit 2
104+
;;
105+
esac
84106

85107
config_dir=
86108
ssh_config=${ACH_CSCS_SSH_CONFIG:-}

tutorials/pyhpc/brev/cscs-launch-tutorial renamed to tutorials/pyhpc/brev/cscs-launch-tutorial.bash

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ umask 077
66

77
usage() {
88
cat <<'EOF'
9-
Usage: cscs-launch-tutorial --account ACCOUNT [OPTIONS]
9+
Usage: cscs-launch-tutorial.bash [OPTIONS]
1010
1111
Run this script on a Daint login node. It prepares the checkout, submits the
1212
web-service job, waits until all three services are ready, prints the job and
1313
node IDs, and exits.
1414
1515
Options:
16-
--account ACCOUNT CSCS Slurm account (or set CSCS_ACCOUNT)
16+
--account ACCOUNT Override the user's default Slurm account
1717
--repo PATH Checkout path (default: $SCRATCH/accelerated-computing-hub)
1818
--branch BRANCH Release and new-checkout branch
1919
(default: event/2026-07-cscs-summer-school)
@@ -262,10 +262,6 @@ login_main() {
262262
echo "Error: run the launcher on a Daint login node, not inside a Slurm job." >&2
263263
return 1
264264
fi
265-
if [ -z "${account}" ]; then
266-
echo "Error: provide --account or set CSCS_ACCOUNT." >&2
267-
return 2
268-
fi
269265
case "${start_timeout}" in
270266
''|*[!0-9]*) echo "Error: --start-timeout must be an integer." >&2; return 2 ;;
271267
esac
@@ -291,14 +287,25 @@ login_main() {
291287
return 1
292288
fi
293289

290+
local -a sbatch_args=(
291+
--parsable
292+
"--partition=${partition}"
293+
"--time=${duration}"
294+
--nodes=1
295+
--ntasks=1
296+
--gpus=1
297+
--signal=B:TERM@60
298+
--job-name=ach-pyhpc-web
299+
"--chdir=${repo}"
300+
"--output=${state_dir}/slurm-%j.log"
301+
"--export=ALL,ACH_REPO=${repo},ACH_RUNTIME_REPO=${runtime_repo},ACH_STATE=${state_dir},ACH_RELEASE_BRANCH=${branch}"
302+
)
303+
if [ -n "${account}" ]; then
304+
sbatch_args+=(--account="${account}")
305+
fi
306+
294307
local job_id
295-
job_id=$(sbatch --parsable \
296-
--account="${account}" --partition="${partition}" --time="${duration}" \
297-
--nodes=1 --ntasks=1 --gpus=1 --signal=B:TERM@60 \
298-
--job-name=ach-pyhpc-web \
299-
--chdir="${repo}" --output="${state_dir}/slurm-%j.log" \
300-
--export=ALL,ACH_REPO="${repo}",ACH_RUNTIME_REPO="${runtime_repo}",ACH_STATE="${state_dir}",ACH_RELEASE_BRANCH="${branch}" \
301-
"${batch_script}" --batch)
308+
job_id=$(sbatch "${sbatch_args[@]}" "${batch_script}" --batch)
302309
job_id=${job_id%%;*}
303310
case "${job_id}" in
304311
''|*[!0-9]*) echo "Error: sbatch returned an invalid job ID: ${job_id}" >&2; return 1 ;;

tutorials/pyhpc/brev/cscs-run-tutorial renamed to tutorials/pyhpc/brev/cscs-run-tutorial.bash

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,39 @@ umask 077
66

77
usage() {
88
cat <<'EOF'
9-
Usage: cscs-run-tutorial --user USER --account ACCOUNT [OPTIONS]
9+
Usage: cscs-run-tutorial.bash [OPTIONS]
1010
1111
Run this script on the workstation with the web browser. It opens one
12-
authenticated SSH control connection to Daint, invokes cscs-launch-tutorial
13-
there, waits for the services, and then invokes cscs-connect-tutorial locally.
12+
authenticated SSH control connection to Daint, invokes cscs-launch-tutorial.bash
13+
there, waits for the services, and then invokes cscs-connect-tutorial.bash locally.
1414
1515
Workstation options:
16-
--user USER CSCS username (or set CSCS_USER)
16+
--user USER Override the username read from the SSH certificate
1717
--key PATH CSCS private key (default: ~/.ssh/cscs-key)
1818
19-
Other options are passed to cscs-launch-tutorial, including --repo, --branch,
20-
--state, --partition, --time, and --start-timeout.
19+
Other options are passed to cscs-launch-tutorial.bash, including --repo, --branch,
20+
--account, --state, --partition, --time, and --start-timeout.
2121
EOF
2222
}
2323

24+
discover_cscs_user() {
25+
local certificate="${1}-cert.pub"
26+
[ -f "${certificate}" ] || return 1
27+
local details
28+
details=$(ssh-keygen -L -f "${certificate}" 2>/dev/null) || return 1
29+
awk '
30+
$1 == "Principals:" { principals = 1; next }
31+
principals && $1 == "Critical" && $2 == "Options:" { exit }
32+
principals {
33+
line = $0
34+
sub(/^[[:space:]]+/, "", line)
35+
sub(/[[:space:]]+$/, "", line)
36+
if (line != "") { count++; value = line }
37+
}
38+
END { if (count == 1) print value; else exit 1 }
39+
' <<< "${details}"
40+
}
41+
2442
if [ "${1:-}" = -h ] || [ "${1:-}" = --help ]; then
2543
usage
2644
exit 0
@@ -48,7 +66,7 @@ bootstrap_workstation_checkout() {
4866
git -C "${checkout}" pull --ff-only origin "${branch}"
4967
fi
5068

51-
local runner="${checkout}/tutorials/pyhpc/brev/cscs-run-tutorial"
69+
local runner="${checkout}/tutorials/pyhpc/brev/cscs-run-tutorial.bash"
5270
if [ ! -x "${runner}" ]; then
5371
echo "Error: ${checkout} does not contain the ${branch} web helper." >&2
5472
exit 1
@@ -65,8 +83,8 @@ if [ -z "${BASH_SOURCE[0]:-}" ]; then
6583
fi
6684

6785
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd -P)
68-
launch_script="${script_dir}/cscs-launch-tutorial"
69-
connect_script="${script_dir}/cscs-connect-tutorial"
86+
launch_script="${script_dir}/cscs-launch-tutorial.bash"
87+
connect_script="${script_dir}/cscs-connect-tutorial.bash"
7088
for script in "${launch_script}" "${connect_script}"; do
7189
if [ ! -x "${script}" ]; then
7290
echo "Error: missing executable sibling script: ${script}" >&2
@@ -86,9 +104,6 @@ while [ "$#" -gt 0 ]; do
86104
*) launch_args+=("$1"); shift ;;
87105
esac
88106
done
89-
case "${user}" in
90-
''|-*|*[!A-Za-z0-9._-]*) echo "Error: provide --user or set CSCS_USER." >&2; exit 2 ;;
91-
esac
92107
for host in "${ela_host}" "${daint_host}"; do
93108
case "${host}" in
94109
''|-*|*[!A-Za-z0-9._-]*) echo "Error: invalid CSCS hostname: ${host}" >&2; exit 2 ;;
@@ -101,6 +116,16 @@ if [ ! -f "${ssh_key}" ]; then
101116
echo "Error: CSCS private key not found: ${ssh_key}" >&2
102117
exit 2
103118
fi
119+
if [ -z "${user}" ]; then
120+
user=$(discover_cscs_user "${ssh_key}" || true)
121+
fi
122+
case "${user}" in
123+
''|-*|*[!A-Za-z0-9._-]*)
124+
echo "Error: could not read one CSCS username from ${ssh_key}-cert.pub." >&2
125+
echo "Run 'cscs-key sign --file ${ssh_key}' or use --user." >&2
126+
exit 2
127+
;;
128+
esac
104129

105130
control_dir=$(mktemp -d "${TMPDIR:-/tmp}/ach-cscs-ssh.XXXXXX")
106131
control_path="${control_dir}/master"
@@ -163,10 +188,10 @@ if ! open_master; then
163188
fi
164189
fi
165190

166-
upload_command="umask 077; mkdir -p \"\$HOME/.local/share/accelerated-computing-hub\"; cat > \"\$HOME/.local/share/accelerated-computing-hub/cscs-launch-tutorial\"; chmod 700 \"\$HOME/.local/share/accelerated-computing-hub/cscs-launch-tutorial\""
191+
upload_command="umask 077; mkdir -p \"\$HOME/.local/share/accelerated-computing-hub\"; cat > \"\$HOME/.local/share/accelerated-computing-hub/cscs-launch-tutorial.bash\"; chmod 700 \"\$HOME/.local/share/accelerated-computing-hub/cscs-launch-tutorial.bash\""
167192
ssh -F "${ssh_config}" -S "${control_path}" ach-daint "${upload_command}" < "${launch_script}"
168193

169-
remote_command="\"\$HOME/.local/share/accelerated-computing-hub/cscs-launch-tutorial\""
194+
remote_command="\"\$HOME/.local/share/accelerated-computing-hub/cscs-launch-tutorial.bash\""
170195
for arg in "${launch_args[@]}"; do
171196
printf -v quoted_arg '%q' "${arg}"
172197
remote_command+=" ${quoted_arg}"

0 commit comments

Comments
 (0)