Repository navigation
docs(aws-pcs): improve JUPYTER + USER-MANAGEMENT + IAM walkthroughs (verbatim-verified) #1222
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
Changes from 9 commits
a778864
fc1bcd5
7134b76
390aac1
484d684
232f191
5aa8b65
deb0afa
6616029
491df97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | [](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 | [](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.** | [](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.** | [](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) | | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| 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. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| --- | ||
|
|
||
|
|
@@ -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. | ||
There was a problem hiding this comment.
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
ubuntustill 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, soldap-add-user.sh ubuntu 10001 3000 "<key>"passes both checks (the username regex admitsubuntu; UID 1000's owner isn't in LDAP), creates a shadowing LDAPubuntu, appends the key to the real/home/ubuntu/.ssh/authorized_keys, and thenchown -R 10001:3000 /home/ubuntu— breaking the DLAMI default account's home. Same for UIDs of local users. Since the shared/homeis exactly where the damage lands, I'd check the full NSS view and the documented range before touching LDAP or the filesystem:(
getentgoes through SSSD, so it also sees LDAP — the twoldapsearchprobes could then become the fallback for the SSSD-cold-cache window, keeping your documented fail-open behavior.)