From c4804b7f3c4337f355bfb3aba42ce196265d40f9 Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Mon, 2 Nov 2026 23:43:37 +0000 Subject: [PATCH] fix(console): default the New Role trust policy to the account root The New Role form filled its trust policy box with the principal arn:aws:iam::*:user/*, and create_role refuses a principal ARN that holds a wildcard, so submitting the form unchanged answered "Invalid trust policy: wildcard is not allowed in a principal ARN: arn:aws:iam::*:user/*". The default principal is now arn:aws:iam:::root, which every principal of the account matches. The account ID is encoded as a JSON string and then HTML-escaped before it goes into the form. A console test reads the form's default trust policy, checks that its principal is the account root, submits it with a role name, and checks that the role is created. With the old default it fails with the wildcard error. Fixes #730. --- crates/server/src/console/pages/role_pages.rs | 8 +++++- tests/test_console_integration.py | 26 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/crates/server/src/console/pages/role_pages.rs b/crates/server/src/console/pages/role_pages.rs index f2ffe4697..b56f65ca7 100755 --- a/crates/server/src/console/pages/role_pages.rs +++ b/crates/server/src/console/pages/role_pages.rs @@ -39,6 +39,12 @@ pub async fn new_role_form( (&account_id, Some(&format!("/console/accounts/{eid}"))), ("New Role", None), ]); + // The default principal is the account's root, which every principal of + // the account matches. `create_role` refuses a principal ARN that holds a + // wildcard, so the default must not carry one. + let root_principal = html::escape( + &serde_json::Value::String(format!("arn:aws:iam::{account_id}:root")).to_string(), + ); let content = format!( r#"{crumbs}

Create Role

@@ -51,7 +57,7 @@ pub async fn new_role_form( "Version": "2012-10-17", "Statement": [{{ "Effect": "Allow", - "Principal": {{"AWS": "arn:aws:iam::*:user/*"}}, + "Principal": {{"AWS": {root_principal}}}, "Action": "sts:AssumeRole" }}] }} diff --git a/tests/test_console_integration.py b/tests/test_console_integration.py index 402d9b2d4..0f23a0d0a 100755 --- a/tests/test_console_integration.py +++ b/tests/test_console_integration.py @@ -23,6 +23,7 @@ from __future__ import annotations +import html import json import os import re @@ -418,6 +419,31 @@ def test_create_and_view_role(self): self.console.post(f"/accounts/{self.account_id}/roles/{role}/delete") + def test_create_role_with_the_form_default_trust_policy(self): + resp = self.console.get(f"/accounts/{self.account_id}/roles/new") + assert resp.status_code == 200 + m = re.search( + r'', resp.text, re.S + ) + assert m, "the New Role form has a trust policy box" + default_policy = html.unescape(m.group(1)) + assert json.loads(default_policy)["Statement"][0]["Principal"] == { + "AWS": f"arn:aws:iam::{self.account_id}:root" + } + + role = f"df-{uuid.uuid4().hex[:8]}" + resp = self.console.post(f"/accounts/{self.account_id}/roles/new", { + "role_name": role, + "trust_policy": default_policy, + }) + assert resp.status_code == 303, resp.text + + resp = self.console.get(f"/accounts/{self.account_id}/roles/{role}") + assert resp.status_code == 200 + assert role in resp.text + + self.console.post(f"/accounts/{self.account_id}/roles/{role}/delete") + def test_delete_role(self): role = f"dr-{uuid.uuid4().hex[:8]}" self.console.post(f"/accounts/{self.account_id}/roles/new", {