Skip to content

fix(onboarding): auto-generate AWS External ID and make field readonly#36

Merged
cristim merged 1 commit into
feat/multicloud-web-frontendfrom
fix/aws-external-id-autogen
Apr 24, 2026
Merged

fix(onboarding): auto-generate AWS External ID and make field readonly#36
cristim merged 1 commit into
feat/multicloud-web-frontendfrom
fix/aws-external-id-autogen

Conversation

@cristim
Copy link
Copy Markdown
Member

@cristim cristim commented Apr 24, 2026

Summary

  • Auto-generates the AWS External ID on new accounts via crypto.randomUUID(); preserves the stored value for existing accounts
  • Marks the field readonly and wraps it in a new .input-with-copy layout with a copy-to-clipboard button
  • Replaces the "External ID (optional)" label + placeholder with a hint pointing operators at sts:ExternalId in their IAM trust policy
  • Extends copyToClipboard to work with form inputs (reads .value) and nested wrappers (finds the .copy-btn via parent); also replaces the innerHTML-based feedback swap with childNode save/restore so the helper is scanner-friendly

Why

The editable + blank External ID let operators set any value or leave it empty, defeating the cross-account role-assumption security model. CUDly must own this shared secret.

Closes #18.

Test plan

  • npx jest — 1238 tests pass (+2 new: auto-generation on modal open; readonly + copy button + trust-policy hint in HTML)
  • npx tsc --noEmit — clean
  • Pre-commit hooks all pass
  • Post-merge: verify in AWS-deployed Settings → Accounts → Add AWS Account → IAM Role ARN mode → confirm the External ID field is pre-filled with a UUID, is readonly, and the copy button works

Issue #18 reported the External ID input in the Add AWS Account modal
as blank and user-editable. An editable External ID lets operators
set any value (or leave it empty), defeating the cross-account
role-assumption security model — the sts:ExternalId is a shared
secret between CUDly and the customer, and CUDly must own the value.

- index.html: mark `account-aws-external-id` readonly, wrap it in a
  `.input-with-copy` flex container with a copy button that copies
  the value to the clipboard. Replace the "External ID (optional)"
  label with a hint pointing operators at sts:ExternalId in their
  trust policy.
- settings.ts: on modal open, populate the field with the stored
  `aws_external_id` for existing accounts or a fresh
  `crypto.randomUUID()` for new accounts. New helper
  `generateExternalID` falls back to a timestamp+random string if
  crypto.randomUUID is unavailable (test environments, odd webviews)
  so the user never sees an empty field.
- settings.ts: extend `copyToClipboard` to prefer `.value` on form
  controls (the new input-with-copy layout uses an <input>) and fall
  back to `.textContent` for code/span sources. Resolve the feedback
  button from the element's parent instead of only its
  nextElementSibling so nested-wrapper layouts work. Replace the
  innerHTML swap in the feedback path with childNode array save/
  restore — semantically identical, hook-friendly, and avoids
  re-proving XSS safety at every edit.
- components.css: new `.input-with-copy` rule so the input and copy
  button read as a single control.
- settings-accounts.test.ts + html.test.ts: regression tests for
  the auto-generation + readonly + hint text.

Closes #18.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 24, 2026

Warning

Rate limit exceeded

@cristim has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 25 minutes and 18 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 25 minutes and 18 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4cd761cc-ba5d-45fd-ac86-a43056ee8e15

📥 Commits

Reviewing files that changed from the base of the PR and between 0ff59e4 and b352e80.

📒 Files selected for processing (5)
  • frontend/src/__tests__/html.test.ts
  • frontend/src/__tests__/settings-accounts.test.ts
  • frontend/src/index.html
  • frontend/src/settings.ts
  • frontend/src/styles/components.css
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/aws-external-id-autogen

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cristim
Copy link
Copy Markdown
Member Author

cristim commented Apr 24, 2026

@coderabbitai review

@cristim cristim merged commit 544ae3e into feat/multicloud-web-frontend Apr 24, 2026
3 checks passed
@cristim cristim deleted the fix/aws-external-id-autogen branch April 24, 2026 16:03
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 24, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

cristim added a commit that referenced this pull request Apr 24, 2026
#37)

Issue #19 reported the AWS Add-Account modal asks for a Role ARN but
provides no trust-policy snippet for the operator to apply in their
AWS account. Getting the principal, action, or ExternalId wrong
silently breaks cross-account role assumption — this was the
highest-friction step in AWS onboarding.

- index.html: add a `.trust-policy-section` inside
  `#account-aws-role-fields` with a `<pre id="account-aws-trust-policy">`
  and a copy button. Includes a guidance `<small>` below for
  screen-reader context; the actual text is rendered dynamically.
- settings.ts: new `renderAwsTrustPolicy` fetches the CUDly host
  AWS account ID from `api.getConfig().source_identity.account_id`
  and writes a fully-qualified trust policy JSON into the `<pre>`,
  interpolating the per-account External ID alongside the CUDly
  Principal ARN. Called automatically whenever the AWS modal opens
  via `populateAwsAccountFields`.
- When the deployment can't determine its own AWS account ID
  (CUDly running on Azure / GCP, or missing sts:GetCallerIdentity),
  the `<pre>` stays empty and the hint is swapped for an
  operator-facing explanation of what to do manually, so operators
  don't paste a half-rendered policy.
- Wires a copy-to-clipboard button on the snippet.
- Adds `.code-block` + `.trust-policy-section` CSS for the
  JSON block styling.
- Regression test in html.test.ts locks in the new DOM hooks.

Depends on #18 (External ID auto-generation), which landed as
PR #36 / commit 544ae3e.

Closes #19.
@cristim cristim added type/feat New capability severity/medium Moderate harm urgency/this-sprint Within the current sprint impact/many Affects most users effort/s Hours priority/p2 Backlog-worthy triaged Item has been triaged labels Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/s Hours impact/many Affects most users priority/p2 Backlog-worthy severity/medium Moderate harm triaged Item has been triaged type/feat New capability urgency/this-sprint Within the current sprint

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant