Repository navigation
fix(console): default the New Role trust policy to the account root - #767
LeeroyHannigan wants to merge 1 commit into
Conversation
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::<account id>: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.
demohan
left a comment
There was a problem hiding this comment.
The New Role form proposes a trust policy its own create accepts at c4804b7, and no caller outside the account can assume a role made from it. The form shows {"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"AWS":"arn:aws:iam::<account>:root"},"Action":"sts:AssumeRole"}]} for the account the role is created in and stores it as shown, and submitting it unchanged lands on the new role's page, where main proposed arn:aws:iam::*:user/* and refused it with "wildcard is not allowed" (#730). Only the server admin gets the form; an IAM user is redirected on GET and POST. With ExtendDB's AssumeRole on SQLite and PostgreSQL, on this head and on main with #1325, twice each, every caller in the account gets 201 and a user, the root or a role session of another account, and *, get 403. The same principal is what the IAM console proposes for "This account". In headless Chromium the form works with this head and under #1325's Content-Security-Policy, with the CSRF field added and no violation. The new test passes on both backends and fails on main, restoring the old default or using the bare account ID fails it, fmt, clippy, the 1.88 check and the server tests are clean, CI is green, and it merges onto main at 222d80a and onto main with #1325, where the server tests and the 1.94.0 check pass and both builds succeed.
I will approve once a test holds the escape of the default principal.
| // 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( |
There was a problem hiding this comment.
No test holds this escape: with html::escape removed the new test still passes, and an admin who opens /console/accounts/x"</textarea><script>alert(1)</script>/roles/new then gets a raw <script> element in the page; at this head the same request stays inside the box and decodes to valid JSON. A test that requests a path with markup and checks the box would hold it. Separately, the body says the test with the old default "fails with the wildcard error"; it fails earlier, at the principal check at test_console_integration.py:430, and never submits the form.
navareamol
left a comment
There was a problem hiding this comment.
The default is right and the form works for me: on a SQLite build of this head, TestConsoleRoles passes 6 of 6, and the same test file against main fails only the new test, with the wildcard error from the description.
One gap. The new test builds the form for a 12 digit account id, so it cannot tell whether the principal is HTML escaped. I removed the html::escape around root_principal in role_pages.rs and ran TestConsoleRoles again: 6 passed. The page does take any id in the URL (GET /console/accounts//roles/new answers 200 for any text). With the escape removed, the id </textarea><script>alert(1)</script> closes the textarea and puts the script in the page, and the id a&b comes back as a&b. With the escape in place both are fine, and so are 15 other ids with quotes, angle brackets, backslashes and non-ASCII characters. Can you add a check that fetches the form for an id with a quote and a closing textarea tag, and asserts the textarea content is escaped? A Rust test of the helper that builds the default would do as well.
I will approve once a test fails when the escape is removed.
The console's New Role form filled its trust policy box with the principal
arn:aws:iam::*:user/*.create_rolechecks the trust policy withvalidate_trust_policy, which refuses a principal ARN that holds a wildcard, so submitting the form unchanged returned the form withInvalid trust policy: wildcard is not allowed in a principal ARN: arn:aws:iam::*:user/*.Change
arn:aws:iam::<account id>:root, which every principal of the account matches (principal_entry_matches). The account ID is encoded as a JSON string and then HTML-escaped before it goes into the textarea.test_create_role_with_the_form_default_trust_policyintests/test_console_integration.pyreads the default trust policy from the form, checks that its principal is the account root, submits it with a role name, and checks that the role page exists.Testing
cargo +1.97.0 fmt --all -- --checkandcargo +1.97.0 clippy -p extenddb-server --all-targets -- -D warnings: clean.cargo +1.88.0 test --locked -p extenddb-server: 250 passed.devtools/run-tests --extenddb --pytest --filter TestConsoleRolesagainst asqlite-memory,dev-modebuild: 6 passed. With the old default restored, the new test fails with the wildcard error above and the other 5 pass.Fixes #730.