diff --git a/architectures/aws-pcs/README.md b/architectures/aws-pcs/README.md index 8a68dbb0a..3be4ef698 100644 --- a/architectures/aws-pcs/README.md +++ b/architectures/aws-pcs/README.md @@ -337,6 +337,10 @@ lines.) To submit it as a batch job instead: sbatch --partition=cpu1 --nodes=2 --wrap='srun bash -c "hostname"' ``` +> With `AccountingPolicyEnforcement` set, the submitter must be registered +> in Slurm accounting or the job is rejected — see +> [docs/USER-MANAGEMENT.md §4](./docs/USER-MANAGEMENT.md#4-slurm-accounting). + ### Example B — multi-node GPU NCCL test (needs a GPU queue) A 2-node `all_reduce_perf` is the quickest GPU end-to-end check (GPU queue + Pyxis @@ -778,6 +782,7 @@ In this repo: - [Jupyter on a compute node](./docs/JUPYTER.md) — run Jupyter as a Slurm job, browser access via SSM port forwarding - [IAM permissions guide](./docs/IAM.md) — cluster admin / cluster user roles, policy deploy, security considerations - [Deploy & testing procedures](./docs/DEPLOY-TESTING.md) — development deploy workflow with test S3 bucket +- [PCS-Ready DLAMI version history](./docs/PCS-READY-DLAMI.md) — PCS Agent / Slurm / driver / CUDA / EFA / DCGM per published build - [Test & Validation Guide](./tests/README.md) — reproducible matrix with measured numbers - [GPU Cluster Health Check](../../4.validation_and_observability/2.gpu-cluster-healthcheck) — comprehensive GPU/EFA/NVLink validation suite (lightweight + intensive modes, Slurm prolog integration) - [Roadmap / TODO](./docs/ROADMAP.md) diff --git a/architectures/aws-pcs/assets/cluster.yaml b/architectures/aws-pcs/assets/cluster.yaml index d784c64e9..3d6688da0 100644 --- a/architectures/aws-pcs/assets/cluster.yaml +++ b/architectures/aws-pcs/assets/cluster.yaml @@ -31,7 +31,7 @@ Parameters: ClusterName: Type: String Description: Name of the PCS cluster - Default: "ml-cluster" + Default: "pcs-ml-cluster" AllowedPattern: '^[a-zA-Z][a-zA-Z0-9-]{0,39}$' ConstraintDescription: Must start with a letter, contain only alphanumeric characters and hyphens, and be 1-40 characters long diff --git a/architectures/aws-pcs/assets/scripts/ldap-add-user.sh b/architectures/aws-pcs/assets/scripts/ldap-add-user.sh index 589e00a22..bfac15220 100755 --- a/architectures/aws-pcs/assets/scripts/ldap-add-user.sh +++ b/architectures/aws-pcs/assets/scripts/ldap-add-user.sh @@ -35,6 +35,32 @@ if [[ ! "${USER_GID}" =~ ^[0-9]+$ ]]; then exit 1 fi +# Refuse UIDs outside the range this cluster reserves for LDAP users +# (10001-59999). The DLAMI's local accounts sit at 1000 (ubuntu) and other +# system UIDs live below 10000; a shadowing LDAP entry at those UIDs would +# `chown -R "${USER_UID}:${USER_GID}" /home/` and destroy the +# local user's HOME on the shared /home (documented lower bound in +# USER-MANAGEMENT.md §3.1). +if [ "${USER_UID}" -lt 10001 ] || [ "${USER_UID}" -gt 59999 ]; then + echo "uid '${USER_UID}' is outside the LDAP-user range 10001-59999 (see USER-MANAGEMENT.md §3.1)." >&2 + exit 1 +fi + +# Reject any username/UID that already resolves via NSS (local /etc/passwd, +# SSSD/LDAP, or any other configured source). LDAP-only checks below miss +# local shadowing: e.g. `ubuntu` has UID 1000 in /etc/passwd, and adding an +# LDAP `ubuntu` would append the pubkey to /home/ubuntu/.ssh/authorized_keys +# and chown /home/ubuntu to the new numeric UID — breaking the DLAMI account. +if getent passwd "${USERNAME}" >/dev/null; then + echo "Username '${USERNAME}' already exists (local passwd or LDAP via NSS)." >&2 + exit 1 +fi +if getent passwd "${USER_UID}" >/dev/null; then + EXISTING=$(getent passwd "${USER_UID}" | cut -d: -f1) + echo "uid ${USER_UID} is already used by '${EXISTING}' (local passwd or LDAP via NSS)." >&2 + exit 1 +fi + # Auto-detect LDAP config from sssd.conf or environment LDAP_DOMAIN_SUFFIX="${LDAP_DOMAIN_SUFFIX:-$(sed -n 's/^ldap_search_base[[:space:]]*=[[:space:]]*//p' /etc/sssd/sssd.conf 2>/dev/null || echo 'dc=cluster,dc=internal')}" LDAP_DOMAIN_SUFFIX="${LDAP_DOMAIN_SUFFIX:-dc=cluster,dc=internal}" @@ -49,6 +75,27 @@ if [ -z "${LDAP_ADMIN_PASSWORD:-}" ]; then echo fi +# Refuse a uidNumber that another entry already owns. LDAP itself won't reject +# this — uidNumber is not part of the DN — so two users would silently share +# the same POSIX UID and, on the shared /home + /fsx, become the same principal. +# Same check for the username (its DN would be unique, but shadowing an +# existing account is still a mistake). ldapsearch here is unauthenticated +# and read-only; a lookup failure (LDAP down) still lets us continue and +# surface the real error at ldapadd time. +if command -v ldapsearch >/dev/null 2>&1; then + if OWNER=$(ldapsearch -x -LLL -H ldap://localhost -b "${LDAP_DOMAIN_SUFFIX}" \ + "(uidNumber=${USER_UID})" uid 2>/dev/null | sed -n 's/^uid: //p' | head -1) \ + && [ -n "${OWNER}" ]; then + echo "uidNumber ${USER_UID} is already used by '${OWNER}'. Pick a different uid." >&2 + exit 1 + fi + if ldapsearch -x -LLL -H ldap://localhost -b "${LDAP_DOMAIN_SUFFIX}" \ + "(uid=${USERNAME})" dn 2>/dev/null | grep -q .; then + echo "Username '${USERNAME}' already exists in the directory." >&2 + exit 1 + fi +fi + # Create user entry LDIF=$(cat <-PCSClusterAdmin-core` (always) + `-PCSClusterAdmin-imagebuilder` (if opted in) managed policies + an IAM group | [![Launch](../images/launch-stack.svg)](https://console.aws.amazon.com/cloudformation/home#/stacks/quickcreate?templateUrl=https://awsome-distributed-ai.s3.amazonaws.com/templates/aws-pcs/cluster-admin-iam.yaml&stackName=pcs-cluster-admins) | -| **Cluster user** | `-PCSClusterUser` managed policy + an IAM group | [![Launch](../images/launch-stack.svg)](https://console.aws.amazon.com/cloudformation/home#/stacks/quickcreate?templateUrl=https://awsome-distributed-ai.s3.amazonaws.com/templates/aws-pcs/cluster-user-iam.yaml&stackName=pcs-cluster-users) | - -Or from the CLI (use `--template-body` against a local checkout for a pre-merge -sandbox test): - -```bash -# Admin: create the policies + group, attach existing users, include Image Builder perms -aws cloudformation create-stack \ - --stack-name pcs-cluster-admins \ - --template-body file://architectures/aws-pcs/assets/cluster-admin-iam.yaml \ - --parameters ParameterKey=AttachUsers,ParameterValue=alice,bob \ - ParameterKey=AttachImageBuilderPolicy,ParameterValue=true \ - --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM - -# User: create the policy + group, attach existing users -# ClusterStackName scopes SSM session access to that one cluster's login node — -# deploy one stack of this template per cluster. -aws cloudformation create-stack \ - --stack-name pcs-cluster-users-pcs-ml-cluster \ - --template-body file://architectures/aws-pcs/assets/cluster-user-iam.yaml \ - --parameters ParameterKey=ClusterStackName,ParameterValue=pcs-ml-cluster \ - ParameterKey=AttachUsers,ParameterValue=carol,dave \ - --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM -``` - -Both templates take an `AttachUsers` parameter (comma-separated existing IAM -user names) so you can wire up group membership at deploy time, or leave it -empty and add users to the group later. The admin template's -`AttachImageBuilderPolicy` defaults to `false`; set it `true` only when the +responsibilities. Each ships a CloudFormation template that creates the +customer-managed IAM policy and an IAM group with it attached (optionally +adding existing IAM users at deploy time). + +| Role | Launch | +|---|---| +| **Cluster admin** — deploys/updates/deletes clusters. Full CRUD on CloudFormation, PCS, EC2 (VPC/SG/launch templates/placement groups/NAT/EIP), FSx, scoped IAM, SSM Parameter Store, KMS, Secrets Manager, and (optionally) Image Builder. **Broad — do not hand to every engineer.** | [![Launch](../images/launch-stack.svg)](https://console.aws.amazon.com/cloudformation/home#/stacks/quickcreate?templateUrl=https://awsome-distributed-ai.s3.amazonaws.com/templates/aws-pcs/cluster-admin-iam.yaml&stackName=pcs-cluster-admins) | +| **Cluster user** — engineers running jobs on an existing cluster. SSM session to the **login node only**, port-forward Grafana, read the Grafana password, read PCS cluster/queue status. **No AWS-API mutations** (cannot create, modify, or delete cluster resources) and **no compute-node sessions**. The login-node SSM shell it grants runs as `ssm-user` with passwordless sudo (SSM default), so on the login node it is effectively root — meaning read access to shared `/home`, Slurm accounting, and the instance role's `/pcs//ldap/*` SSM secret; treat it as trusted-operator-scope, not arbitrary-viewer-scope. | [![Launch](../images/launch-stack.svg)](https://console.aws.amazon.com/cloudformation/home#/stacks/quickcreate?templateUrl=https://awsome-distributed-ai.s3.amazonaws.com/templates/aws-pcs/cluster-user-iam.yaml&stackName=pcs-cluster-users) | + +Both templates take an optional `AttachUsers` parameter (comma-separated +existing IAM user names) so you can wire up group membership at deploy time, +or add users later via the IAM console. The cluster-admin template's +`AttachImageBuilderPolicy` defaults to `false`; set it `true` only if the admin will also deploy the standalone DLAMI builder -(`pcs-ready-dlami-with-enroot-pyxis.yaml`). - -### What the cluster user can do once attached - -```bash -STACK_NAME=pcs-ml-cluster # your CloudFormation stack name -AWS_REGION=us-east-1 # your region - -# Find the login node's instance ID via the PCS API — no dependency on tag naming -CLUSTER_ID=$(aws cloudformation describe-stacks --stack-name "$STACK_NAME" --region "$AWS_REGION" --query 'Stacks[0].Outputs[?OutputKey==`ClusterId`].OutputValue' --output text) -[ -n "$CLUSTER_ID" ] && [ "$CLUSTER_ID" != "None" ] || { echo "No ClusterId — check STACK_NAME/AWS_REGION"; return 1; } - -LOGIN_CNG_ID=$(aws pcs list-compute-node-groups --cluster-identifier "$CLUSTER_ID" --region "$AWS_REGION" --query 'computeNodeGroups[?name==`login`].id' --output text) -LOGIN_INSTANCE_ID=$(aws ec2 describe-instances --region "$AWS_REGION" --filters "Name=tag:aws:pcs:compute-node-group-id,Values=$LOGIN_CNG_ID" "Name=instance-state-name,Values=running" --query 'Reservations[0].Instances[0].InstanceId' --output text) - -# Open a session -aws ssm start-session --target "$LOGIN_INSTANCE_ID" --region "$AWS_REGION" - -# Port-forward Grafana (443 -> 8443), then open https://localhost:8443/grafana/ -aws ssm start-session --target "$LOGIN_INSTANCE_ID" --region "$AWS_REGION" \ - --document-name AWS-StartPortForwardingSession \ - --parameters '{"portNumber":["443"],"localPortNumber":["8443"]}' - -# Read the Grafana admin password (CLUSTER_ID is resolved by CFN Outputs above; look it up if needed) -CLUSTER_ID=$(aws cloudformation describe-stacks --stack-name "$STACK_NAME" --region "$AWS_REGION" \ - --query 'Stacks[0].Outputs[?OutputKey==`ClusterId`].OutputValue' --output text) -aws ssm get-parameter --name "/pcs/${CLUSTER_ID}/grafana/admin-password" --region "$AWS_REGION" \ - --with-decryption --query 'Parameter.Value' --output text -``` +(`pcs-ready-dlami-with-enroot-pyxis.yaml`). The cluster-user template +requires `ClusterStackName` and scopes SSM session access to that one +cluster's login node — deploy one stack of it per cluster. That scoping +keys on the EC2 `Name` tag (`ssm:resourceTag/Name = -login`), +which is operator-mutable: re-tagging a login node changes who can reach it, +and if another instance in the account happens to carry a matching `Name` +tag it would also satisfy the condition. Treat `Name` as part of this +policy's trust surface. --- @@ -95,84 +35,21 @@ plus the extra permissions the all-in-one template needs because it provisions VPC + FSx + IAM roles itself (the AWS reference policy assumes those already exist). Review and tighten before production use. -**Login-node access is scoped by the `Name` tag, to one stack.** The user -policy conditions `ssm:StartSession` on `ssm:resourceTag/Name` **equalling** -`-login` (exact match, no wildcards). PCS does not emit a -dedicated "is this a login node" tag, so the templates set -`Name=-` on every instance — the deploy-all template -passes `${AWS::StackName}` as ClusterName, so the login CNG's default -`CngName=login` yields `Name=-login`, and compute CNGs get -`-cpu1`, `-gpu-p5`, etc. That means one deploy of -`cluster-user-iam.yaml` grants access to **exactly one cluster**; deploy the -template again with a different `ClusterStackName` for each additional -cluster you want the group to reach. **The `Name` tag is operator-mutable**: -if you re-tag a login node, update the policy condition to match (or fork -the templates to add a dedicated `IsLoginNode=true` tag and key off that). - -**Combined CRUD is intentional, not a mistake.** The admin policy covers -create + update + delete in one policy because (1) CFN rollback on a failed -Create requires Delete actions, (2) UpdateStack is operationally a superset of -Create (it may replace resources), and (3) drift detection during Update calls -Describe across every service. If you want a read-only variant, reduce the same -actions to `*:Describe*` / `*:Get*` / `*:List*` for an auditor role. - -**The admin policy is split into core + Image Builder** because the combined -document (~7.4 KB) exceeds the IAM 6,144-character per-policy limit. The -~5.8 KB core covers a normal deploy; the ~1.7 KB Image Builder add-on is only -needed for the standalone DLAMI builder. The CFN template attaches both to the -group when `AttachImageBuilderPolicy=true`. - -**There is no `AmazonPCSFullAccess` managed policy** as of January 2026 — AWS -publishes only `AWSPCSComputeNodePolicy` (for compute instances) and -`AWSPCSServiceRolePolicy` (the service-linked role). The PCS portion of the -admin policy must therefore be customer-managed. - -**Pairing with AWS-managed policies.** For a smaller customer-managed surface -you can attach AWS-managed policies for parts of the stack and trim the matching -statements: `AWSCloudFormationFullAccess`, `AmazonFSxFullAccess`, -`AWSImageBuilderFullAccess` are reasonable fits. Avoid `AmazonEC2FullAccess` — -it is materially overprivileged (e.g. EBS public-share); prefer the -customer-managed EC2 statements in the template. - -### Not covered by these policies - -- **The compute instance role** (passed to EC2 by `cluster.yaml`) — provisioned - by the templates themselves; use the AWS-managed `AWSPCSComputeNodePolicy`. -- **The Image Builder build instance role** — use the AWS-managed +**Pairing with AWS-managed policies.** For a smaller customer-managed +surface, attach AWS-managed policies for parts of the stack and trim the +matching statements: `AWSCloudFormationFullAccess`, `AmazonFSxFullAccess`, +`AWSImageBuilderFullAccess` are reasonable fits. Avoid +`AmazonEC2FullAccess` — it is materially overprivileged (e.g. EBS +public-share); prefer the customer-managed EC2 statements in the template. +There is no `AmazonPCSFullAccess`, so the PCS portion has to stay +customer-managed. + +**Not covered by these policies:** +- The compute instance role (passed to EC2 by `cluster.yaml`) — use the + AWS-managed `AWSPCSComputeNodePolicy`. +- The Image Builder build instance role — use the AWS-managed `EC2InstanceProfileForImageBuilder` / `EC2InstanceProfileForImageBuilderECRContainerBuilds`. -- **Fine-grained per-cluster scoping** — both policies use `Resource: "*"` for - many EC2/VPC actions because resource-level scoping there is limited. This is - a deliberate sample-grade choice. - -### Refining to least-privilege via CloudTrail - -To generate a tighter policy from real usage: - -1. Deploy a representative cluster in a sandbox account with broad permissions on - the deploying principal (so nothing fails for spurious IAM reasons). -2. Let the full lifecycle run — deploy, then `delete-stack` — so CloudTrail - captures every API call. -3. Generate a policy from CloudTrail with IAM Access Analyzer - (`aws accessanalyzer start-policy-generation` → `get-generated-policy`), then - diff against the template's statements. Access Analyzer output is usually - *narrower* on actions but leaves `Resource: "*"`; the template's resource ARNs - are usually the keepers. - -The same approach works for the user policy — exercise the user workflows -(start a session, port-forward Grafana, terminate it) in a sandbox, then narrow. - ---- - -## Verifying the policies - -To confirm the admin policy can deploy a cluster end-to-end and the user policy is -correctly constrained (login-only SSM, no LDAP-password access), see the reproducible -procedure in [tests/iam-test.md](../tests/iam-test.md). - -> **Note on the template-source bucket.** The admin policy grants no `s3:GetObject`, -> because the production templates live in the public `awsome-distributed-ai` -> bucket (CFN fetches `--template-url` anonymously). If you host the templates in -> a **private** bucket, the deploying principal additionally needs `s3:GetObject` -> on that bucket — grant it separately; it is intentionally out of the -> cluster-admin policy. +- Fine-grained per-cluster scoping — both policies use `Resource: "*"` for + many EC2/VPC actions where resource-level scoping is limited. Sample-grade, + deliberate. diff --git a/architectures/aws-pcs/docs/JUPYTER.md b/architectures/aws-pcs/docs/JUPYTER.md index 8fe5de3fc..5a4d9d375 100644 --- a/architectures/aws-pcs/docs/JUPYTER.md +++ b/architectures/aws-pcs/docs/JUPYTER.md @@ -45,6 +45,9 @@ Compute node — Jupyter server, launched as an sbatch job - **Multi-user clusters:** your `$HOME` must exist before the first job — log in to the login node (SSH or SSM) once so `pam_mkhomedir` creates it. Slurm jobs do not create home directories. +- **Do not run Jupyter on the login node.** It has no GPUs and is shared with + the monitoring stack; always launch the server as a Slurm job on a compute + node, as Step 2 does. ## Step 1 — one-time: create a Jupyter environment on `/home` @@ -56,6 +59,16 @@ python3 -m venv $HOME/jupyter-env $HOME/jupyter-env/bin/pip install --upgrade pip jupyterlab ``` +**To run the GPU-visibility verify cell below**, also install PyTorch here so +the kernel can `import torch` without another install roundtrip. The +PCS-Ready DLAMI's NVIDIA driver (595.x) supports current CUDA wheels; the +`cu130` build matches the image's CUDA 13.2 stack (see +[PCS-READY-DLAMI.md](./PCS-READY-DLAMI.md)): + +```bash +$HOME/jupyter-env/bin/pip install torch --index-url https://download.pytorch.org/whl/cu130 +``` + > For ML work, also set `HF_HOME=/fsx/$USER/.hf-cache` in your notebooks/jobs — > the HuggingFace cache must not live on NFS `/home` (file-locking errors under > concurrent access), and a per-user path avoids ownership clashes on @@ -103,11 +116,17 @@ exec jupyter lab --no-browser --ip="$NODE_IP" --port="$PORT" \ --notebook-dir="$HOME" ``` -Then submit it with `sbatch`. **`-p ` is required** — Slurm has no -default partition, so a bare `sbatch jupyter.sbatch` is rejected with +Then submit it with `sbatch` **from `$HOME`** — Slurm's default working +directory for a job is the submitter's CWD, and the `--output=%u-jupyter-%j.log` +line above resolves relative to that. Submitting from anywhere else (e.g. an +SSM shell that lands in `/var/…`) drops the log there instead of `$HOME`, and +the connect step in Step 3 won't find it. **`-p ` is required** — Slurm +has no default partition, so a bare `sbatch jupyter.sbatch` is rejected with *"invalid partition specified"*. Run `sinfo` to list your queues, then: ```bash +cd $HOME + # CPU session — pick a CPU queue (e.g. cpu1) sbatch -p cpu1 jupyter.sbatch @@ -115,9 +134,7 @@ sbatch -p cpu1 jupyter.sbatch sbatch -p gpu-g6 --gres=gpu:1 jupyter.sbatch ``` -For GPU work, add the ML stack to the venv from Step 1 once -(`$HOME/jupyter-env/bin/pip install torch # + transformers, etc.`); the GPU -allocation behaviour is detailed in [Using GPUs](#using-gpus) below. +GPU allocation behaviour is detailed in [Using GPUs](#using-gpus) below. The first submission on an idle queue waits ~2–3 minutes for the node to scale up (8–12 minutes if the node is also running its first-boot @@ -128,16 +145,23 @@ Enroot/Pyxis install). The job log (`~/-jupyter-.log`, printed by the running job) gives you the compute node's `NODE_IP` and `PORT`. With those two values: -**1. On your workstation** — open the SSM tunnel (fill in your Region and the -`NODE_IP` / `PORT` from the log): +**1. On your workstation** — open the SSM tunnel (fill in the `NODE_IP` / +`PORT` from the job log). The login instance ID is resolved from the +CloudFormation stack via the PCS API — same recipe used in +[README §6](../README.md#6-accessing-the-cluster), so it works across +multi-cluster VPCs without accidentally targeting another cluster's login: ```bash -LOGIN_ID=$(aws ec2 describe-instances --region \ - --filters "Name=tag:Name,Values=*login" \ - "Name=instance-state-name,Values=running" \ - --query 'Reservations[0].Instances[0].InstanceId' --output text) +STACK_NAME=pcs-ml-cluster # your CloudFormation stack name +AWS_REGION=us-east-1 # your region -aws ssm start-session --region --target "$LOGIN_ID" \ +CLUSTER_ID=$(aws cloudformation describe-stacks --stack-name "$STACK_NAME" --region "$AWS_REGION" --query 'Stacks[0].Outputs[?OutputKey==`ClusterId`].OutputValue' --output text) +[ -n "$CLUSTER_ID" ] && [ "$CLUSTER_ID" != "None" ] || { echo "No ClusterId — check STACK_NAME/AWS_REGION"; return 1; } + +LOGIN_CNG_ID=$(aws pcs list-compute-node-groups --cluster-identifier "$CLUSTER_ID" --region "$AWS_REGION" --query 'computeNodeGroups[?name==`login`].id' --output text) +LOGIN_ID=$(aws ec2 describe-instances --region "$AWS_REGION" --filters "Name=tag:aws:pcs:compute-node-group-id,Values=$LOGIN_CNG_ID" "Name=instance-state-name,Values=running" --query 'Reservations[0].Instances[0].InstanceId' --output text) + +aws ssm start-session --region "$AWS_REGION" --target "$LOGIN_ID" \ --document-name AWS-StartPortForwardingSessionToRemoteHost \ --parameters "host=,portNumber=,localPortNumber=8888" ``` @@ -153,14 +177,50 @@ cat ~/.jupyter-token- **3. In your browser** — open `http://localhost:8888/?token=`. -> **Required IAM.** The two CLI calls above are already permitted by the stock +> **Required IAM.** The CLI calls above are already permitted by the stock > [`cluster-user-iam.yaml`](../assets/cluster-user-iam.yaml) policy (and by any > broader admin credentials). Under a restricted role, ensure it grants: +> `cloudformation:DescribeStacks`, `pcs:ListComputeNodeGroups`, > `ec2:DescribeInstances` (find the login node); `ssm:StartSession` on the -> login instance (`ssm:resourceTag/Name = PCS-login*`) and on the -> `AWS-StartPortForwardingSessionToRemoteHost` document; and +> login instance (`ssm:resourceTag/Name = -login`) and on +> the `AWS-StartPortForwardingSessionToRemoteHost` document; and > `ssm:TerminateSession` / `ssm:DescribeSessions` to end the tunnel. +### Running without a token (single-user clusters only) + +If you're the only user on the cluster and want to skip the token +copy-paste, swap the `--ServerApp.token=…` line in the sbatch script +with the disabled-auth form: + +```bash +exec jupyter lab --no-browser --ip="$NODE_IP" --port="$PORT" \ + --ServerApp.token='' --ServerApp.password='' \ + --notebook-dir="$HOME" +``` + +The token file (and the `openssl rand` line above it) are no longer +needed and can be dropped; you can also drop the `token = ...` line +from the sbatch banner heredoc. Steps 1 and 3 of Step 3 are unchanged — +skip sub-step 2 (there is no token to read). Connect to +`http://localhost:8888/lab` — no token required. + +Jupyter's default XSRF protection is left **enabled** (this recipe does +not set `--ServerApp.disable_check_xsrf`); the Lab UI's own cookie+header +flow works fine with it on, and it is the one browser-side guard that +still prevents a random webpage open in your browser from POSTing to +`http://localhost:8888` and executing code on the compute node. + +> **Do NOT do this on a multi-user cluster.** Jupyter binds to the compute +> node's private IP; any other cluster user's job on any other node in the +> same VPC subnet can reach that IP:port. The token is what separates one +> user's notebook (with your `$HOME` and credentials) from another user's. +> Removing it means anyone who can run a job on this cluster can attach to +> your kernel. Only use the token-less form when **every IAM principal who +> can reach the VPC or submit jobs is trusted as the same person** — the +> single-`ubuntu`-user default cluster is that case by construction; +> `DirectoryService=OpenLDAP-LoginNode` (or any shared multi-user setup) +> is not, so always keep the token there. + ## Stopping ```bash @@ -174,54 +234,55 @@ costs nothing. ## Using GPUs You launch a GPU session with the same script and the `sbatch -p ---gres=gpu:N` form shown in Step 2 — nothing else changes. How the GPU -allocation behaves: - -- **Slurm enforces the `--gres` count.** The job gets `CUDA_VISIBLE_DEVICES` - set to its allocated GPUs (e.g. `0,1` for `--gres=gpu:2` on a 4-GPU - g6.12xlarge), so frameworks like PyTorch see exactly the requested GPUs — - `torch.cuda.device_count()` matches the `--gres` count. GPU node groups - configure gres automatically (e.g. `Gres=gpu:L4:4`; check with - `scontrol show node `). -- **Multi-GPU works inside one notebook.** All allocated GPUs are visible to - the kernel, so `DataParallel` / FSDP / `accelerate` with - `num_processes=` run as usual. Leave GPUs you don't need - unrequested — on multi-GPU nodes Slurm can schedule other jobs (another - user's Jupyter, batch training) onto the remaining GPUs. -- **Sizing:** request only what you interactively need (`--gres=gpu:1` is - plenty for most exploration) and keep `--time` tight — an idle notebook - holds its GPUs until the job ends. For multi-hour *training*, prefer a - batch job over a notebook so the GPUs free up when the run finishes. - (Remember `HF_HOME=/fsx/$USER/.hf-cache` from Step 1 for model downloads.) -- **Multi-NIC GPU nodes (P5/P6) work as-is.** On these instances `hostname -I` - returns dozens of addresses (one per EFA NIC). The script binds Jupyter to - the first entry, which in practice is the primary interface's IP (verified - on p5.48xlarge, 32 NICs) — and any entry is same-VPC-reachable from the - login node, so the port-forward path works regardless. The kernel saw all - 8 H100s with `--gres=gpu:8`. -- **Containerized kernels (optional):** to use an NGC image as the notebook - environment instead of a venv, wrap the server in Pyxis: - `srun --container-image= --container-mounts=/fsx,$HOME …` around the - `jupyter lab` command inside the job. Import large images once to - `/fsx/*.sqsh` (see the [README §7](../README.md#7-running-a-job) enroot - note) and pass the `.sqsh` path as the image. - -## Notes - -- **Multi-user:** each user runs their own server job under their own UID; the - job-ID-derived port makes same-node collisions unlikely (see the comment in - the script). Keep tokens in `$HOME` (created mode 600 by the script) — treat - the token like a password to your account, since the SSM/IAM layer alone - does not distinguish cluster users. -- **Multiple clusters in one account:** the `Name=*login` tag filter in the - connect snippet matches the login node of *every* PCS cluster that follows - the naming convention — add a `"Name=tag:ClusterName,Values="` - filter to pin it when you run more than one. -- **Alternative when `SSHAccessCidr` is set:** a plain SSH tunnel also works — - `ssh -L 8888:: @` — useful for - users who cannot install the Session Manager plugin. -- **Do not run Jupyter on the login node.** It has no GPUs, and it is shared - by every user (and hosts the monitoring stack). -- **Scripts on `/fsx` can't be exec'd directly** (Lustre blocks `execve` on - some paths) — keep the sbatch file under `$HOME`, or invoke via - `bash /fsx/script.sh`. +--gres=gpu:N` form shown in Step 2 — nothing else changes. + +### How the GPU allocation behaves + +- **`--gres=gpu:N` is the only knob.** Slurm sets `CUDA_VISIBLE_DEVICES` + accordingly and PyTorch sees exactly those GPUs. Request only what you + need — the remaining GPUs on a multi-GPU node stay available for other + jobs. +- **Multi-GPU works inside one notebook.** All allocated GPUs are visible + to the kernel, so `DataParallel` / FSDP / `accelerate` run as usual. +- **Sizing.** `--gres=gpu:1` is plenty for most interactive exploration. + Keep `--time` tight — an idle notebook holds its GPUs until the job + ends; prefer a batch job for multi-hour training. +- **Multi-NIC GPU nodes (P5/P6) work as-is.** `hostname -I` returns one + address per EFA NIC; the script binds to the first, which is + same-VPC-reachable from the login node. +- **Containerized kernels (optional).** Wrap `jupyter lab` in + `srun --container-image= --container-mounts=/fsx,$HOME …` to run + the notebook inside a Pyxis-imported image (see [README §7](../README.md#7-running-a-job)). + +### Verify GPU visibility from the notebook + +Paste this into a new notebook cell after the kernel comes up. It confirms +Slurm's `--gres` count, that PyTorch sees the same set of GPUs, and that a +kernel actually runs on the allocated device: + +```python +import os, torch + +# 1. What Slurm handed us +print("CUDA_VISIBLE_DEVICES =", os.environ.get("CUDA_VISIBLE_DEVICES")) +print("SLURM_JOB_GPUS =", os.environ.get("SLURM_JOB_GPUS")) + +# 2. What PyTorch actually sees +print("torch.cuda.is_available:", torch.cuda.is_available()) +print("torch.cuda.device_count:", torch.cuda.device_count()) +for i in range(torch.cuda.device_count()): + p = torch.cuda.get_device_properties(i) + print(f" [{i}] {p.name} {p.total_memory/1024**3:.1f} GiB SM {p.major}.{p.minor}") + +# 3. Prove compute runs on the allocated GPU (raises if the kernel can't launch) +if torch.cuda.is_available(): + x = torch.randn(4096, 4096, device="cuda:0") + print("matmul on cuda:0 -> sum =", float((x @ x).sum())) +``` + +Expected: `torch.cuda.device_count()` **equals the `--gres=gpu:N` you +requested**. Note that `nvidia-smi` from inside the job may still show +all physical GPUs on the node — that's expected on these clusters; +allocation is enforced per-process via `CUDA_VISIBLE_DEVICES`, which +`torch.cuda.device_count()` respects. + diff --git a/architectures/aws-pcs/docs/PCS-READY-DLAMI.md b/architectures/aws-pcs/docs/PCS-READY-DLAMI.md new file mode 100644 index 000000000..4b7dd7f03 --- /dev/null +++ b/architectures/aws-pcs/docs/PCS-READY-DLAMI.md @@ -0,0 +1,58 @@ +# PCS-Ready DLAMI version history + +AWS publishes the **PCS-Ready DLAMI Base GPU AMI (Ubuntu 24.04)** as the default +compute-node image for AWS PCS. Every deploy-all / add-cng template in this repo +resolves it through the public SSM parameter +`/aws/service/pcs/ami/dlami-base-ubuntu2404/x86_64/latest/ami-id` when `AmiId` +is left empty. + +The image is a two-layer stack: + +1. **Base DLAMI** — Ubuntu 24.04, kernel, NVIDIA driver, CUDA stack, EFA, DCGM, + containerd, OFI-NCCL. Maintained on the DLAMI release cadence. +2. **PCS layer** — PCS Agent, one or more Slurm builds, EFS utils. Added on top + by the PCS team. + +The AMI `Description` embeds every PCS-layer version and the base DLAMI build +date, for example: + +``` +PCS-Ready DLAMI based on Deep Learning Base OSS Nvidia Driver GPU AMI (Ubuntu 24.04) 20260724. +PCS Agent: 1.5.0-1. Slurm: 24.11.7-2, 25.05.8-2, 25.11.6-2. EFS Utils: 2.4.2 +``` + +New builds are announced through the SNS topic +`arn:aws:sns:us-west-2:265886551188:pcs-ready-dlami-release-notifications` +(see the [PCS-Ready DLAMI user guide](https://docs.aws.amazon.com/pcs/latest/userguide/working-with_ami_pcs-ready-dlami.html)). + +## PCS-Ready DLAMI x86\_64 + +Snapshot (as of 2026-08-05) of the published x86\_64 PCS-Ready DLAMIs, newest +first. AMI IDs are region-scoped and shown for **us-east-2** — the SSM +parameter above resolves to the newest build in each region, so leaving +`AmiId` empty in the templates is the region-portable path; refer here only +when pinning to a specific build. + +Base-DLAMI component versions (kernel, NVIDIA driver, CUDA, DCGM, EFA, +OFI-NCCL, containerd) come from the DLAMI release notes for the build named in +the "Base DLAMI" column. Intermediate base builds without their own release +notes inherit values from the nearest previous published build. + +| PCS build | AMI ID (us-east-2) | Base DLAMI | PCS Agent | Slurm | EFS Utils | Kernel | NVIDIA driver | Default CUDA | CUDA stack | DCGM | EFA | OFI-NCCL | containerd | +| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | +| 2026-07-27 | `ami-0631f0a4211880f98` | 20260724 | 1.5.0-1 | 24.11.7-2, 25.05.8-2, 25.11.6-2 | 2.4.2 | 6.17.0-1019 | 595.71.05 | 13.2 | 12.8, 12.9, 13.0, 13.2 | 4.6.0 | 1.47.0 | 1.18.0 | v2.2.6 | +| 2026-07-22 | `ami-045669174d015d92c` | 20260721 | 1.5.0-1 | 24.11.7-2, 25.05.8-2, 25.11.6-2 | 2.4.2 | 6.17.0-1019 | 595.71.05 | 13.2 | 12.8, 12.9, 13.0, 13.2 | 4.6.0 | 1.47.0 | 1.18.0 | v2.2.6 | +| 2026-07-20 | `ami-0c91bfa1d3999dfea` | 20260717 | 1.5.0-1 | 24.11.7-2, 25.05.8-2, 25.11.6-2 | 2.4.2 | 6.17.0-1019 | 595.71.05 | 13.2 | 12.8, 12.9, 13.0, 13.2 | 4.6.0 | 1.47.0 | 1.18.0 | v2.2.6 | +| 2026-07-13 | `ami-0c1b2f4317de42125` | 20260710 | 1.4.0-1 | 24.11.7-1, 25.05.8-2, 25.11.6-2 | 2.4.2 | 6.17.0-1019 | 595.71.05 | 13.2 | 12.8, 12.9, 13.0, 13.2 | 4.6.0 | 1.47.0 | 1.18.0 | v2.2.5 | +| 2026-07-08 | `ami-01b64e972d350b317` | 20260707 | 1.4.0-1 | 24.11.7-1, 25.05.8-2, 25.11.6-2 | 2.4.2 | 6.17.0-1019 | 595.71.05 | 13.2 | 12.8, 12.9, 13.0, 13.2 | 4.6.0 | 1.47.0 | 1.18.0 | v2.2.5 | +| 2026-07-06 | `ami-04e4916942b70bf64` | 20260703 | 1.4.0-1 | 24.11.7-1, 25.05.8-2, 25.11.6-2 | 2.4.2 | 6.17.0-1019 | 595.71.05 | 13.2 | 12.8, 12.9, 13.0, 13.2 | 4.6.0 | 1.47.0 | 1.18.0 | v2.2.5 | +| 2026-06-29 | `ami-03ef51e588e1864db` | 20260626 | 1.4.0-1 | 24.11.7-1, 25.05.7-1, 25.11.2-1 | 2.4.2 | 6.17.0-1019 | 595.71.05 | 13.2 | 12.8, 12.9, 13.0, 13.2 | 4.6.0 | 1.47.0 | 1.18.0 | v2.2.5 | +| 2026-06-22 | `ami-039d4de58ea181e3d` | 20260619 | 1.4.0-1 | 24.11.7-1, 25.05.7-1, 25.11.2-1 | 2.4.2 | 6.17.0-1017 | 595.71.05 | 13.2 | 12.8, 12.9, 13.0, 13.2 | 4.5.3 | 1.47.0 | 1.18.0 | v2.2.4 | +| 2026-06-09 | `ami-08a86ee651999836e` | 20260609 | 1.4.0-1 | 24.11.7-1, 25.05.7-1, 25.11.2-1 | 2.4.2 | 6.17.0-1017 | 595.71.05 | 13.2 | 12.8, 12.9, 13.0, 13.2 | 4.5.3 | 1.47.0 | 1.18.0 | v2.2.4 | +| 2026-06-07 | `ami-08ab1cf913f168f31` | 20260605 | 1.4.0-1 | 24.11.7-1, 25.05.7-1, 25.11.2-1 | 2.4.2 | 6.17.0-1017 | 595.71.05 | 13.2 | 12.8, 12.9, 13.0, 13.2 | 4.5.3 | 1.47.0 | 1.18.0 | v2.2.4 | +| 2026-06-02 | `ami-0da9c0741ad44f950` | 20260602 | 1.4.0-1 | 24.11.7-1, 25.05.7-1, 25.11.2-1 | 2.4.2 | 6.17.0-1015 | 595.71.05 | 13.2 | 12.8, 12.9, 13.0, 13.2 | 4.5.3 | 1.47.0 | 1.18.0 | v2.2.4 | +| 2026-05-30 | `ami-0ddf60cecde4935de` | 20260529 | 1.4.0-1 | 24.11.7-1, 25.05.7-1, 25.11.2-1 | 2.4.2 | 6.17.0-1015 | 595.71.05 | 13.2 | 12.8, 12.9, 13.0, 13.2 | 4.5.3 | 1.47.0 | 1.18.0 | v2.2.4 | +| 2026-05-23 | `ami-0b0605bcf9ffffa63` | 20260522 | 1.4.0-1 | 24.11.7-1, 25.05.7-1, 25.11.2-1 | 2.4.2 | 6.17.0-1015 | 595.71.05 | 13.2 | 12.8, 12.9, 13.0, 13.2 | 4.5.3 | 1.47.0 | 1.18.0 | v2.2.4 | + +Full base DLAMI release notes: + diff --git a/architectures/aws-pcs/docs/USER-MANAGEMENT.md b/architectures/aws-pcs/docs/USER-MANAGEMENT.md index 9ce91000b..4ee53552d 100644 --- a/architectures/aws-pcs/docs/USER-MANAGEMENT.md +++ b/architectures/aws-pcs/docs/USER-MANAGEMENT.md @@ -1,363 +1,349 @@ # User Management Guide -This guide is written for **cluster administrators who may not be familiar with -LDAP**. It covers the day-to-day operations of managing users on a PCS -reference architecture cluster with `DirectoryService=OpenLDAP-LoginNode`. - -By default, the cluster runs as a single `ubuntu` user. When multi-user is -enabled, an OpenLDAP directory runs on the login node and provides centralized -POSIX user accounts visible on all nodes via SSSD. +**By default a cluster runs as a single `ubuntu` user** — the PCS-Ready +DLAMI default account, shared across the login and every compute node. +Nothing further is needed for single-operator workflows. + +**Read on only if you need multi-user access** (multiple engineers with +their own POSIX accounts, home directories, and Slurm job ownership). +This guide covers the day-to-day operations of a cluster deployed with +`DirectoryService=OpenLDAP-LoginNode`, in which an OpenLDAP directory +runs on the login node and provides centralized POSIX accounts visible +on every node via SSSD. Written for cluster admins who may not be +familiar with LDAP. --- -## Quick reference (common tasks) - -Run on the login node. `$ADMIN_PW` is the LDAP admin password from SSM (see -[Getting the admin password](#getting-the-admin-password)); the `LDAP_*` env -vars must be passed **inline to `sudo`** (`sudo VAR=... cmd`) — `sudo -E` alone -drops them under the default `env_reset`/`secure_path`. - -> **Slurm path matches `SlurmVersion`.** The `sacctmgr` / `sbatch` paths below use -> `slurm-25.11` (the default). If you deployed with `SlurmVersion=25.05`, replace -> `slurm-25.11` with `slurm-25.05` in every path (or just run `export -> PATH=/opt/aws/pcs/scheduler/slurm-$(ls /opt/aws/pcs/scheduler | sed 's/slurm-//')/bin:$PATH` -> once and drop the absolute path). - -| Task | Command (run on the login node) | -|---|---| -| Add a user | `sudo LDAP_ADMIN_PASSWORD="$ADMIN_PW" ldap-add-user.sh alice 10001 3000` | -| Add a user + SSH key | `sudo LDAP_ADMIN_PASSWORD="$ADMIN_PW" ldap-add-user.sh alice 10001 3000 "ssh-ed25519 AAAA..."` | -| List all users | `ldapsearch -x -H ldap://localhost -b ou=People,dc=cluster,dc=internal uid` | -| Delete a user | `ldapdelete -x -H ldap://localhost -D cn=admin,dc=cluster,dc=internal -w "$ADMIN_PW" uid=alice,ou=People,dc=cluster,dc=internal` then `sudo sss_cache -E` | -| Reset a user's password | `ldappasswd -x -H ldap://localhost -D cn=admin,dc=cluster,dc=internal -w "$ADMIN_PW" -s NEWPASS uid=alice,ou=People,dc=cluster,dc=internal` | -| Add user to Slurm accounting | `sudo /opt/aws/pcs/scheduler/slurm-25.11/bin/sacctmgr -i add user alice Account=ml-team` (root = accounting admin) | -| Verify user on compute node | `srun -N1 -n1 -p cpu1 id alice` | - -`ldap-add-user.sh` is a helper script installed on the login node at -`/usr/local/bin/` (it wraps `ldapadd`+`ldappasswd` so you don't need the LDAP -syntax). List/delete/reset use the raw `ldap*` tools directly — the full -commands are documented in each section below. - ---- +## 1. Enabling multi-user -## How it works (overview) - -``` -┌─────────────────────────────────────────────────────────┐ -│ Login Node │ -│ │ -│ ┌──────────┐ ┌──────────┐ ┌──────────────┐ │ -│ │ slapd │────►│ SSSD │────►│ NSS / PAM │ │ -│ │ (OpenLDAP│ │ (cache) │ │ (getent, │ │ -│ │ server) │ │ │ │ login, su) │ │ -│ └──────────┘ └──────────┘ └──────────────┘ │ -│ │ │ -│ DB: /home/ldap-db/ (shared OpenZFS) │ -└───────┼──────────────────────────────────────────────────┘ - │ ldap://login-ip:389 - ▼ -┌─────────────────────────────────────────────────────────┐ -│ Compute Node │ -│ │ -│ ┌──────────┐ ┌──────────────┐ │ -│ │ SSSD │────►│ NSS / PAM │ │ -│ │ (client)│ │ (getent, │ │ -│ │ │ │ srun user) │ │ -│ └──────────┘ └──────────────┘ │ -└─────────────────────────────────────────────────────────┘ -``` - -**Key points:** -- Users are stored in the LDAP database on the login node -- The database lives on shared `/home` (OpenZFS NFS) — it survives login node restart/replacement -- Every node (login + compute) runs SSSD which queries LDAP for user info -- When you add a user in LDAP, they become visible on all nodes within seconds -- Home directories are auto-created at first login (shared `/home` on OpenZFS) -- Slurm sees LDAP users transparently — no Slurm configuration needed for user resolution - -> ⚠️ **Single login node only.** `OpenLDAP-LoginNode` runs the directory server -> on **one** login node, so keep the login node group at `MinCount=MaxCount=1` -> while the directory is enabled. Compute clients discover the server by its -> `directory-role=server` tag and the slapd database is a single MDB on shared -> `/home`; running two login nodes would give clients an ambiguous server and -> have two `slapd` processes open the same database files concurrently -> (corruption risk). If you need multiple login nodes or a highly-available -> directory, use a managed backend (the planned `SimpleAD` / `ManagedAD` -> `DirectoryService` options) rather than the login-node OpenLDAP. - -### How a compute node finds the LDAP server (tag-based discovery) - -This part is **not obvious**, so it's worth spelling out. A compute node does -**not** receive the login node's IP as a parameter — PCS launches the login and -compute node groups independently, and the login node's private IP isn't known -at template-synthesis time (and it changes if the login node is replaced). -Instead, discovery happens **at compute-node boot**, by EC2 tag lookup: - -1. When the directory is enabled, the login node group tags its instance - `directory-role=server` (alongside `pcs-cluster-id=`). The - compute node groups tag themselves `directory-role=client`. This - `directory-role` tag is **dedicated to the directory feature** — it is - deliberately *separate* from the monitoring stack's `monitoring-role` tag, so - the two features don't depend on each other. -2. On first boot, each compute node runs `setup-directory.sh client`, which - calls `aws ec2 describe-instances` filtering for - `tag:pcs-cluster-id=` + `tag:directory-role=server` + - `instance-state-name=running`, and reads the matching instance's - `PrivateIpAddress`. The `pcs-cluster-id` filter scopes the lookup to **this - cluster only**, so multiple PCS clusters can share one VPC without their - compute nodes finding the wrong cluster's LDAP server. (`CLUSTER_ID` is - passed from `${ClusterId}` in UserData; the script aborts client setup if it - is empty, rather than risk matching another cluster's server.) -3. That IP becomes the SSSD `ldap_uri` (`ldap://`). SSSD on the - compute node then resolves users from the login node's slapd. - -Implications to be aware of: - -- **Compute nodes need `ec2:DescribeInstances`** in their instance role (the - cluster IAM role already grants it). Without it, discovery fails and the node - boots without LDAP (check `/var/log/directory-setup.log` for - `could not discover directory server IP`). -- **The login (server) node must be running before a compute node boots** for - discovery to succeed. In normal deploy order the login node group comes up - first; a compute node that scales up later simply queries the - already-running server. -- **If the login node is replaced**, its new instance re-tags itself - `directory-role=server` and re-attaches to the same `/home/ldap-db`, so newly - booting compute nodes discover the new IP automatically. The admin password is - **preserved** across replacement (the new login node reuses the existing - `/pcs//ldap/admin-password` from SSM rather than regenerating it), so cached - admin passwords keep working and the DB stays accessible. - **Already-running compute nodes, however, keep their cached `ldap_uri`** (the - old login node's private IP, which the replacement no longer has). Cached users - still resolve via SSSD, but **name resolution for uncached/new users and group - expansion degrades** on those nodes until you refresh them. (Jobs already - submitted by such users still *run* — Slurm uses numeric UIDs, so a name- - resolution gap is a degradation, not a hard job failure — but `id`/`getent`, - `pam_mkhomedir`, and anything that looks the user up by name can misbehave.) - After a login-node replacement, run on every running compute node: - ```bash - srun -N -n bash -c 'sudo sed -i "s#ldap_uri = .*#ldap_uri = ldap://#" /etc/sssd/sssd.conf && sudo sss_cache -E && sudo systemctl restart sssd' - ``` - or simply let PCS replace the compute nodes (terminate them; the replacements - discover the new IP on boot). A stable endpoint that removes this manual step is - tracked in [ROADMAP.md](./ROADMAP.md) ("Stable LDAP endpoint across login-node - replacement"). -- **An explicit override exists**: set `LDAP_SERVER_URI` (or `DIRECTORY_DNS_IPS`, - for the future managed-directory path) in the client's environment to skip the - tag lookup entirely — used by the SimpleAD/ManagedAD extension and handy for - debugging. +Multi-user is a **deploy-time parameter**, not something you can flip +on after the stack exists. Set it via either the AWS console or the +CLI — pick one. ---- +### deploy-all — from the CloudFormation console (Quick Create) -## Enabling multi-user +1. Open the deploy-all template's **Launch Stack** link in the + [README](../README.md#3-quick-start) (or navigate to CloudFormation + → *Create stack* → *Upload* `pcs-ml-cluster-deploy-all.yaml`). +2. On the *Specify stack details* page, set: + - **`DirectoryService`** → `OpenLDAP-LoginNode` (default is `none` + → single-user; **must be changed here** to get multi-user) + - **`SSHAccessCidr`** → your office CIDR (e.g. `203.0.113.10/32`), + because LDAP users log in over SSH — see + [§2.3 Log in as that user](#23-log-in-as-that-user). Leave empty + to disable direct SSH; users then log in only via SSH-over-SSM. +3. The other parameters (VPC/CIDR, instance types, monitoring, etc.) + have sensible defaults — see [PARAMETERS.md](./PARAMETERS.md). +4. Acknowledge the two IAM capabilities and *Create stack*. -### Option 1: deploy-all (recommended) +### deploy-all — from the CLI ```bash aws cloudformation create-stack \ - --stack-name my-cluster \ + --stack-name pcs-ml-cluster \ --template-url https://awsome-distributed-ai.s3.amazonaws.com/templates/aws-pcs/pcs-ml-cluster-deploy-all.yaml \ --parameters \ ParameterKey=PrimarySubnetAZ,ParameterValue=us-east-2b \ ParameterKey=DirectoryService,ParameterValue=OpenLDAP-LoginNode \ + ParameterKey=SSHAccessCidr,ParameterValue=/32 \ --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM ``` -That's it. The login node will have slapd running and compute nodes will be -configured as LDAP clients automatically at first boot. +Both paths produce the same stack — the console *Quick Create* form +just fills in the same `--parameters` for you. Use whichever fits +your workflow. -### Option 2: modular deployment +### modular deployment -Pass these to your `add-cng.yaml` stacks: -- Login CNG: `DirectoryRole=server`, `DirectoryDomainSuffix=dc=cluster,dc=internal` -- Compute CNG: `DirectoryRole=client`, `DirectoryDomainSuffix=dc=cluster,dc=internal` +Pass to your `add-cng.yaml` stacks: +- Login CNG: `DirectoryRole=server`, `IamProfileArn=` +- Compute CNG: `DirectoryRole=client`, `IamProfileArn=` -> **IAM profile — give the login CNG the login profile.** `cluster.yaml` outputs two -> instance profiles: `InstanceProfileArn` (compute) and `LoginInstanceProfileArn` (login, -> which additionally grants read+decrypt of the OpenLDAP admin secret). When deploying -> modularly with multi-user enabled, pass `IamProfileArn=` to the -> **login** CNG and `IamProfileArn=` to the **compute** CNGs. Giving -> the login node the plain compute profile makes its OpenLDAP setup fail (it can't write -> the admin password to SSM). `deploy-all` wires this automatically. +Both share `DirectoryDomainSuffix=dc=cluster,dc=internal` (default). -### Parameters +> **IAM profile matters.** `cluster.yaml` outputs `LoginInstanceProfileArn` +> (login-only, grants SSM write of the OpenLDAP admin secret) and +> `InstanceProfileArn` (compute). Give the login CNG the login profile; +> otherwise OpenLDAP setup fails silently. deploy-all wires this +> automatically. -| Parameter | Default | Description | +| Parameter | Default | Purpose | |---|---|---| -| `DirectoryService` | `none` | (deploy-all only) Set to `OpenLDAP-LoginNode` to enable multi-user; deploy-all derives each CNG's `DirectoryRole` from it | -| `DirectoryRole` | `none` | (add-cng) `server` for the login CNG, `client` for compute CNGs | -| `DirectoryDomainSuffix` | `dc=cluster,dc=internal` | LDAP base DN (change only if you need a different domain) | +| `DirectoryService` (deploy-all) | `none` | `OpenLDAP-LoginNode` enables the flow | +| `DirectoryRole` (add-cng) | `none` | `server` on the login CNG, `client` on compute CNGs | +| `DirectoryDomainSuffix` | `dc=cluster,dc=internal` | LDAP base DN | --- -## Day-to-day operations +## 2. Adding your first LDAP user -All commands below run on the **login node** as root (`sudo`). +Walkthrough for the first LDAP user on a fresh cluster — recover the +admin password, add the user with an SSH key, log them in, and prove +their Slurm jobs actually run on a compute node. Once you've done this +once, subsequent users go through the shorter recipes in +[§3 Detailed operations](#3-detailed-operations). -### Getting the admin password +§2.1–§2.2 run on the login node (SSM session or SSH as `ubuntu`); +§2.3–§2.4 are the LDAP user's own login and job submission from their +workstation. -The LDAP admin password is auto-generated at cluster creation and stored in -AWS Systems Manager Parameter Store: +### 2.1 Recover the LDAP admin password + +The source of truth is SSM Parameter Store, populated by the login node +at first boot. Print it once at the start of your session — every raw +`ldap*` command below uses `-W` and every `ldap-add-user.sh` call reads +an env var or prompts, so the value never has to land on the command +line or in shell history. + +The login node reads its own cluster ID and region from IMDS, and its +instance role is already granted `ssm:GetParameter` on +`/pcs//ldap/*`: ```bash -CLUSTER_ID= +TOKEN=$(curl -s -X PUT http://169.254.169.254/latest/api/token -H "X-aws-ec2-metadata-token-ttl-seconds: 60") +CLUSTER_ID=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/tags/instance/aws:pcs:cluster-id) +AWS_REGION=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/placement/region) -aws ssm get-parameter \ - --name "/pcs/${CLUSTER_ID}/ldap/admin-password" \ - --with-decryption \ - --query 'Parameter.Value' \ - --output text +aws ssm get-parameter --region "$AWS_REGION" --with-decryption --name "/pcs/$CLUSTER_ID/ldap/admin-password" --query 'Parameter.Value' --output text ``` -> **If SSM is empty** (instance role lacked the permission at first boot): +> **If SSM has no password** (rare — instance role lacked permission at +> first boot), fall back to the copy on shared storage: > ```bash > sudo cat /home/ldap-db/.admin-password > ``` +> +> If a later `ldap*` command replies *"Invalid credentials"*, the password +> was typed wrong at the `-W` prompt — re-run the command to re-prompt, +> and re-fetch from SSM here if you've lost it. -Store this password somewhere safe — you'll need it for all user management -operations. - ---- +### 2.2 Add your first user -### Adding a user +The `ldap-add-user.sh` helper takes ` +[ssh-public-key]`. For the very first user, `10001` is safe — that's the +bottom of the LDAP UID range. For subsequent users pick 10002, 10003, +etc.; the helper refuses a duplicate `uidNumber` or username, so a +collision fails loudly instead of silently sharing a POSIX principal on +the shared `/home` + `/fsx`. -**Using the helper script** (recommended): +Get the user's SSH public key. If they don't have one yet, they can +generate a keypair on their own workstation: ```bash -# Usage: ldap-add-user.sh [ssh-public-key] -sudo LDAP_ADMIN_PASSWORD="" ldap-add-user.sh alice 10001 3000 +# On the user's workstation +ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -C "alice@laptop" +# Then send you the *public* half (~/.ssh/id_ed25519.pub, one line). ``` -This creates the user with: -- Username: `alice` -- UID: `10001` (pick a unique number in range 10001–59999) -- GID: `3000` (= `clusterusers` group, the default) -- Home directory: `/home/alice` (auto-created on first login) -- Shell: `/bin/bash` -- A random initial password (printed to stdout) +Back on the login node, add the user. The helper prompts for the admin +password if it isn't already in the environment: + +```bash +sudo /usr/local/bin/ldap-add-user.sh alice 10001 3000 "ssh-ed25519 AAAA... alice@laptop" +# LDAP admin password: