Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
5 changes: 5 additions & 0 deletions architectures/aws-pcs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion architectures/aws-pcs/assets/cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 21 additions & 0 deletions architectures/aws-pcs/assets/scripts/ldap-add-user.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new duplicate guard checks LDAP only — a local/NSS name like ubuntu still passes, with a destructive follow-on (should fix)

The guard is a real improvement (and B5a locks it in — nice). One gap: it searches only ldap://localhost, so ldap-add-user.sh ubuntu 10001 3000 "<key>" passes both checks (the username regex admits ubuntu; UID 1000's owner isn't in LDAP), creates a shadowing LDAP ubuntu, appends the key to the real /home/ubuntu/.ssh/authorized_keys, and then chown -R 10001:3000 /home/ubuntu — breaking the DLAMI default account's home. Same for UIDs of local users. Since the shared /home is exactly where the damage lands, I'd check the full NSS view and the documented range before touching LDAP or the filesystem:

if getent passwd "${USERNAME}" >/dev/null; then echo "…exists (local or LDAP)…" >&2; exit 1; fi
if getent passwd "${USER_UID}" >/dev/null; then echo "…uid in use…" >&2; exit 1; fi
if [ "${USER_UID}" -lt 10001 ] || [ "${USER_UID}" -gt 59999 ]; then echo "…outside LDAP range 10001-59999…" >&2; exit 1; fi

(getent goes through SSSD, so it also sees LDAP — the two ldapsearch probes could then become the fallback for the SSSD-cold-cache window, keeping your documented fail-open behavior.)

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 <<EOF
dn: uid=${USERNAME},ou=People,${LDAP_DOMAIN_SUFFIX}
Expand Down
192 changes: 32 additions & 160 deletions architectures/aws-pcs/docs/IAM.md
Original file line number Diff line number Diff line change
@@ -1,88 +1,23 @@
# IAM Permissions Guide

The cluster distinguishes **two human roles** with very different
responsibilities, and ships a ready-to-deploy IAM policy stack for each:

| Role | Who | What they can do | Template |
|---|---|---|---|
| **Cluster admin** | The person who deploys/updates/deletes the cluster | Full CRUD on the infrastructure: CloudFormation, PCS, EC2 (VPC/SG/launch templates/placement groups/NAT/EIP), FSx, scoped IAM, SSM Parameter Store, KMS, Secrets Manager, and (optionally) Image Builder | [`cluster-admin-iam.yaml`](../assets/cluster-admin-iam.yaml) |
| **Cluster user** | Engineers who just run jobs on an existing cluster | SSM session **to the login node only**, port-forward Grafana, read the Grafana password, read PCS cluster/queue status. **Cannot create, modify, or delete anything**, and cannot open shells on compute nodes | [`cluster-user-iam.yaml`](../assets/cluster-user-iam.yaml) |

Splitting the roles means the deployer's broad permissions never have to be
handed to every engineer who just wants to `srun`, and the user role can be
given out widely — it can't accidentally delete the cluster or get a shell on a
compute node.

---

## Deploying the policies

Each template creates the customer-managed IAM policies, an IAM group with them
attached, and (optionally) adds existing IAM users to that group. Deploy both
as CloudFormation stacks:

| Stack | Creates | Deploy |
|---|---|---|
| **Cluster admin** | `<stack>-PCSClusterAdmin-core` (always) + `<stack>-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** | `<stack>-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. Cannot create, modify, or delete anything, and cannot shell into compute nodes. **Safe to hand out widely.** | [![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) |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Cannot create, modify, or delete anything … Safe to hand out widely" overstates what the user policy enforces (should fix)

The stock cluster-user-iam.yaml grants ssm:StartSession on the SSM-SessionManagerRunShell document, and a plain Session Manager shell lands as ssm-user, which has passwordless sudo by default (https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-getting-started-ssm-user-permissions.html). Root on the login node reaches the instance role's ssm:GetParameter on /pcs/<id>/ldap/* — i.e. the LDAP admin password — plus shared /home and Slurm accounting. The policy itself is untouched by this PR (worth a follow-up: drop RunShell from the user policy, or configure Session Manager Run As), but this rewrite is where the claim gets its strongest wording, so I'd soften the row to what the policy actually enforces: no AWS-API mutations and no compute-node sessions — the login-node shell it grants is root-equivalent on the shared directory until RunShell is removed.


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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one-cluster scoping claim lost its "Name tag is operator-mutable" caveat (should fix)

The deleted IAM.md section carried an explicit warning that the ssm:resourceTag/Name = <ClusterStackName>-login condition keys on the operator-mutable Name tag (re-tag ⇒ the scoping silently changes). This rewrite keeps the "scopes SSM session access to that one cluster's login node" claim but drops the caveat, leaving the claim unqualified. One sentence restores it: "Scoping keys on the EC2 Name tag, which is operator-mutable — re-tagging a login node changes who can reach it (fails closed for this cluster, but a matching tag elsewhere in the account would satisfy the condition).


---

Expand All @@ -95,84 +30,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**
`<ClusterStackName>-login` (exact match, no wildcards). PCS does not emit a
dedicated "is this a login node" tag, so the templates set
`Name=<ClusterName>-<cng-name>` on every instance — the deploy-all template
passes `${AWS::StackName}` as ClusterName, so the login CNG's default
`CngName=login` yields `Name=<StackName>-login`, and compute CNGs get
`<StackName>-cpu1`, `<StackName>-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.
Loading