diff --git a/doc/connections/AWS.md b/doc/connections/AWS.md index c499166951b..4acd94acec4 100644 --- a/doc/connections/AWS.md +++ b/doc/connections/AWS.md @@ -6,7 +6,8 @@ AWS key for the role method. For each connection, the control plane mints a one-hour bearer token at call time. Agents see the AWS tools like any other connector's tools and never receive AWS credentials. -It is behind the `enableAwsConnector` experimental setting (off by default). +It is available on every instance. The former `enableAwsConnector` experimental +setting is a compatibility key whose value is ignored. The design and the spike that proved it are in [the AWS connector plan](../plans/2026-11-17-aws-connector-and-minted-credentials.md) and [the workload identity issuer](../plans/2026-11-17-workload-identity-issuer.md). @@ -90,11 +91,10 @@ sequenceDiagram The role method takes two steps, because the role must trust a connection that already exists. The setup screen walks through them: -1. Turn on **AWS connector** in Instance Settings, Experimental. -2. In Connectors, open AWS. Choose the endpoint region and the access level, +1. In Connectors, open AWS. Choose the endpoint region and the access level, then click **Connect**. There is no role ARN to enter yet: the role does not exist until the next step creates it. -3. Paperclip saves a draft without contacting AWS and publishes the company's +2. Paperclip saves a draft without contacting AWS and publishes the company's issuer. The role is named after the connection (`paperclip-`), and CloudFormation fills in the account, so nothing is typed by hand. The screen shows one thing by default: @@ -110,25 +110,30 @@ already exists. The setup screen walks through them: - While the agent works, the step shows its live checklist (it sets and ticks off its steps with the URLs and token in the prompt; see `docs/api/agent-setup-progress.md`), and its finish summary carries the - role ARN. - - Paste that role ARN into the Role ARN field. + role ARN. When the agent finishes, the screen fills in that ARN itself. It + accepts only an ARN naming this connection's own role, and keeps any ARN + you typed yourself. - **Or do it by hand** shows the same setup without an agent: + **Or do it by hand** shows the same setup without an agent, and holds the + Role ARN field. It opens on its own when a test fails or the agent finished + without a usable ARN: - **With CloudFormation.** Download the template, create a stack from it in the AWS account, set `CreateIdentityProvider` to `false` if the account already has an identity provider for this issuer, choose `AccessPolicyArn` for full access, and acknowledge that the stack creates IAM resources - (`CAPABILITY_NAMED_IAM`). Copy `RoleArn` from the stack's outputs. + (`CAPABILITY_NAMED_IAM`). Copy `RoleArn` from the stack's outputs into the + Role ARN field. - **In the IAM console or AWS CLI.** Add an OpenID Connect provider with the shown provider URL and audience, then create the role with the shown trust policy (replace `ACCOUNT_ID`), which trusts only `connection:`. Attach `AWSMCPSignInOAuthAccessPolicy` and the agents' permissions. The CLI - commands read the account ID themselves and print the role ARN. + commands read the account ID themselves and print the role ARN to paste + into the Role ARN field. If the instance's address changed after the draft was saved, the screen shows no steps and asks you to go back and click **Connect** again, which saves the draft with the current address. -4. Click **Test connection**. Paperclip saves the role ARN, mints a token, lists the tools and +3. Click **Test connection**. Paperclip saves the role ARN, mints a token, lists the tools and finishes setup. If AWS refuses, the screen shows why, in place. The screen reads `GET /api/tool-connections/{connectionId}/aws-setup`, which diff --git a/packages/shared/src/app-definitions.test.ts b/packages/shared/src/app-definitions.test.ts index 269e1c82f37..591727cee24 100644 --- a/packages/shared/src/app-definitions.test.ts +++ b/packages/shared/src/app-definitions.test.ts @@ -1492,7 +1492,7 @@ describe("AppDefinition catalog", () => { }); it("mints AWS credentials instead of placing stored keys in headers", () => { const aws = APP_DEFINITIONS.find((app) => app.slug === "aws")!; - expect(aws.experimentalFeatureKey).toBe("enableAwsConnector"); + expect(aws.experimentalFeatureKey).toBeUndefined(); for (const method of aws.methods) { expect(method).toMatchObject({ transport: "mcp_remote", auth: "api_key", credentialMinter: "aws_mcp" }); expect(method.keyPlacement).toBeUndefined(); diff --git a/packages/shared/src/app-definitions/aws.json b/packages/shared/src/app-definitions/aws.json index f6413552f37..33762ad62b4 100644 --- a/packages/shared/src/app-definitions/aws.json +++ b/packages/shared/src/app-definitions/aws.json @@ -1,5 +1,4 @@ { - "experimentalFeatureKey": "enableAwsConnector", "schemaVersion": 1, "slug": "aws", "name": "AWS", diff --git a/packages/shared/src/feature-catalog.ts b/packages/shared/src/feature-catalog.ts index f30fed662ad..468dbae9dba 100644 --- a/packages/shared/src/feature-catalog.ts +++ b/packages/shared/src/feature-catalog.ts @@ -184,11 +184,11 @@ export const INSTANCE_FEATURE_CATALOG: Record { await request(app).get(`/api/tool-connections/${keyDraft.body.connectionId}/aws-setup`).expect(422); }); - it("stays unavailable until the experimental setting is on", async () => { + it("is available even where an old setting turned the former experimental flag off", async () => { const { org } = await company(); const { service } = harness(); await instanceSettingsService(db).updateExperimental({ enableAwsConnector: false }); + expect((await instanceSettingsService(db).getExperimental()).enableAwsConnector).toBe(true); await expect(service.connectGalleryApp(org.id, { galleryKey: "aws", connectionMethodKey: "aws-access-key", configValues: { endpointRegion: "us-east-1", accessLevel: "read_only" }, credentialValues: { "credentials.accessKeyId": ACCESS_KEY_ID, "credentials.secretAccessKey": SECRET_ACCESS_KEY }, - }, actor)).rejects.toThrow(); + }, actor)).resolves.toBeTruthy(); }); it("access key: lists and calls tools with a minted token, never sending the stored key", async () => { diff --git a/server/src/__tests__/instance-settings-managed-overlay.test.ts b/server/src/__tests__/instance-settings-managed-overlay.test.ts index 3b3930a2916..a0a285a88ee 100644 --- a/server/src/__tests__/instance-settings-managed-overlay.test.ts +++ b/server/src/__tests__/instance-settings-managed-overlay.test.ts @@ -142,10 +142,10 @@ describe("instanceSettingsService managed overlay", () => { expect((await service.get()).experimental).toMatchObject(features); expect((await service.getExperimental()).managedKeys).toMatchObject( Object.fromEntries(Object.keys(features) - .filter((key) => key !== "enableApps" && key !== "enableMcpAggregators" && key !== "enablePublicMcp") + .filter((key) => key !== "enableApps" && key !== "enableMcpAggregators" && key !== "enablePublicMcp" && key !== "enableAwsConnector") .map((key) => [key, { managed: true, managedBy: "paperclip-cloud" }])), ); - for (const key of Object.keys(features).filter((key) => key !== "enablePublicMcp")) { + for (const key of Object.keys(features).filter((key) => key !== "enablePublicMcp" && key !== "enableAwsConnector")) { await expect(service.updateExperimental({ [key]: false })).rejects.toMatchObject({ status: 403, details: { code: "settings_operator_managed" }, @@ -273,6 +273,25 @@ describe("instanceSettingsService managed overlay", () => { expect(await service.updateExperimental({ enableMcpAggregators: false })).toMatchObject({ experimental: { enableMcpAggregators: true, enableChatConnectors: true } }); }); + it.each([{}, { enableAwsConnector: false }])("keeps the AWS connector on with legacy stored and managed values: %j", async (stored) => { + const { db } = stubDb(settingsRow(stored)); + const service = instanceSettingsService(db, { runtimeEnv: managedEnv(JSON.stringify({ + v: 1, mode: "cloud", catalogVersion: "legacy", features: { enableAwsConnector: false }, plugins: { autoInstall: [] }, + })) }); + const experimental = await service.getExperimental(); + expect(experimental.enableAwsConnector).toBe(true); + expect(experimental.managedKeys).not.toHaveProperty("enableAwsConnector"); + expect(await service.updateExperimental({ enableAwsConnector: false })).toMatchObject({ experimental: { enableAwsConnector: true } }); + }); + + it("accepts an old client's write of the retired AWS connector key while Cloud lists it as on", async () => { + const { db } = stubDb(settingsRow({})); + const service = instanceSettingsService(db, { runtimeEnv: managedEnv(JSON.stringify({ + v: 1, mode: "cloud", catalogVersion: "test", features: { enableAwsConnector: true }, plugins: { autoInstall: [] }, + })) }); + expect(await service.updateExperimental({ enableAwsConnector: false })).toMatchObject({ experimental: { enableAwsConnector: true } }); + }); + it("persists chat connector opt-in and reads it back after service reconstruction", async () => { const row = settingsRow({}); const { db, persistedSets } = stubDb(row); diff --git a/server/src/__tests__/instance-settings-service.test.ts b/server/src/__tests__/instance-settings-service.test.ts index d1328dd3895..f13a39c643f 100644 --- a/server/src/__tests__/instance-settings-service.test.ts +++ b/server/src/__tests__/instance-settings-service.test.ts @@ -140,7 +140,7 @@ describe("instance settings service", () => { enableMemoryConnectors: false, enablePaperclipNotebook: false, enableGoogleWorkspaceConnector: false, - enableAwsConnector: false, + enableAwsConnector: true, enableConferenceRoomChat: false, enableClassicTaskInterface: false, enableLegacyComposerSubmit: false, diff --git a/server/src/services/instance-settings.ts b/server/src/services/instance-settings.ts index 3a981d64ae3..699dd307416 100644 --- a/server/src/services/instance-settings.ts +++ b/server/src/services/instance-settings.ts @@ -261,6 +261,8 @@ export function normalizeExperimentalSettings(raw: unknown): InstanceExperimenta enableMcpAggregators: true, // Assistant connections (MCP) graduated from Experimental; ignore historical off values. enablePublicMcp: true, + // The AWS connector graduated from Experimental; ignore historical off values. + enableAwsConnector: true, enableOpenAiDot: parsed.data.enableOpenAiDot ?? false, enableMuse: parsed.data.enableMuse ?? false, enableGrokBot: parsed.data.enableGrokBot ?? false, @@ -269,7 +271,6 @@ export function normalizeExperimentalSettings(raw: unknown): InstanceExperimenta enableMemoryConnectors: parsed.data.enableMemoryConnectors ?? false, enablePaperclipNotebook: parsed.data.enablePaperclipNotebook ?? false, enableGoogleWorkspaceConnector: parsed.data.enableGoogleWorkspaceConnector ?? false, - enableAwsConnector: parsed.data.enableAwsConnector ?? false, enableCases: parsed.data.enableCases ?? false, enableAgentChat: true, enableCombinedInboxTasks: parsed.data.enableCombinedInboxTasks ?? false, @@ -333,7 +334,7 @@ export function normalizeExperimentalSettings(raw: unknown): InstanceExperimenta enableMemoryConnectors: false, enablePaperclipNotebook: false, enableGoogleWorkspaceConnector: false, - enableAwsConnector: false, + enableAwsConnector: true, enableCases: false, enableAgentChat: true, enableCombinedInboxTasks: false, @@ -397,9 +398,10 @@ export function applyManagedExperimentalOverlay( [ManagedExperimentalFeatureKey, boolean] >) { // Existing Cloud stack configs may still carry retired flags. Accept the - // document during rollout, but never let retired flags disable Apps, Agent Chat, MCP aggregators - // or Assistant connections (MCP). - if (key === "enableApps" || key === "enableAgentChat" || key === "enableMcpAggregators" || key === "enablePublicMcp") continue; + // document during rollout, but never let retired flags disable Apps, Agent Chat, MCP aggregators, + // Assistant connections (MCP) or the AWS connector. + if (key === "enableApps" || key === "enableAgentChat" || key === "enableMcpAggregators" || key === "enablePublicMcp" + || key === "enableAwsConnector") continue; next[key] = value; managedKeys[key] = { managed: true, managedBy: PAPERCLIP_CLOUD_MANAGED_BY }; } @@ -643,7 +645,7 @@ export function instanceSettingsService(db: Db, options: InstanceSettingsService updateExperimental: async (patch: PatchInstanceExperimentalSettings): Promise => { for (const [key, enabled] of Object.entries(managedConfig?.features ?? {})) { // Retired always-on keys are ignored on read, so an old client's write must not be rejected. - if (key === "enablePublicMcp") continue; + if (key === "enablePublicMcp" || key === "enableAwsConnector") continue; if (enabled && patch[key as ManagedExperimentalFeatureKey] === false) { throw forbidden(`${key} is enabled by Paperclip Cloud and cannot be disabled on this instance`, { code: "settings_operator_managed", diff --git a/tests/runner-e2e/source-sdk-public-inputs.json b/tests/runner-e2e/source-sdk-public-inputs.json index 350fd9c1ddd..091ba7d3694 100644 --- a/tests/runner-e2e/source-sdk-public-inputs.json +++ b/tests/runner-e2e/source-sdk-public-inputs.json @@ -78,7 +78,7 @@ "packages/shared/src/app-definitions-url.test.ts": "56792d6745a5bc7eafc36e7403f4c9bbd671ae99", "packages/shared/src/app-definitions.generated.ts": "b162e9621fab029951d77a6b4605ab7893904a3a", "packages/shared/src/app-definitions.ingestion-report.json": "a7b60c7c16a484a411989315e9f08d48258fa647", - "packages/shared/src/app-definitions.test.ts": "269e1c82f377bab004c00765ba51543922315172", + "packages/shared/src/app-definitions.test.ts": "591727cee240c7b1f9a2e2c726d8656d539129e2", "packages/shared/src/app-definitions.ts": "f8c9c3aa66ea3bbe38c3a2eff7abca9a25911c83", "packages/shared/src/app-definitions/1password.json": "c11a4777de2c78805b2d391da5eb075a9511e0f8", "packages/shared/src/app-definitions/agentmail.json": "edd0799b1980d0f5f43b89c8f7a1173dc623f7fa", @@ -87,7 +87,7 @@ "packages/shared/src/app-definitions/api-key-generic.json": "09e6d4295513ac9f1002eaf37c34e7c2d00a3c05", "packages/shared/src/app-definitions/arcade.json": "c8379450055d4ea226d229b1cbf99c7ed2e52beb", "packages/shared/src/app-definitions/asana.json": "42d051d84a576509d75a73fe49b23443d34759f8", - "packages/shared/src/app-definitions/aws.json": "f6413552f37f06e3b003486324c7d892d8f3e5f3", + "packages/shared/src/app-definitions/aws.json": "33762ad62b4e45b6c04cce52a0fab67c83a30caa", "packages/shared/src/app-definitions/bedrock.json": "962d8a722ac6e2e4db00abc34f71947a3fdb733a", "packages/shared/src/app-definitions/beehiiv.json": "47aec8fdfbf5aed0919b6ac9bddb435de4988db3", "packages/shared/src/app-definitions/bitly.json": "81f4937e92f2971f2011acb50929adf5287315e4", @@ -261,7 +261,7 @@ "packages/shared/src/external-objects.ts": "a9953c4e3f77f2bad03cb7832914ffc0b1a1266a", "packages/shared/src/fast-response.ts": "a81332a2b46b59c1f6953cfc4da659eae2326beb", "packages/shared/src/feature-catalog.test.ts": "d3e000c039492daad1fe0b7302b34e7c3816a8ce", - "packages/shared/src/feature-catalog.ts": "f30fed662ad1a7dec4c3012b7653af2f777f0a0d", + "packages/shared/src/feature-catalog.ts": "468dbae9dba45b45f1a993de9307c5b6409f513c", "packages/shared/src/frontmatter-runner-contract.test.ts": "cd121330e10aaa9da36c16293bcd9760561b6b41", "packages/shared/src/frontmatter.test.ts": "56635e331c8abca8868da76f23a08e98f20ff07f", "packages/shared/src/frontmatter.ts": "a86e046ce588d2f92d4996122cc2068ec275e89c", @@ -519,7 +519,7 @@ "packages/shared/src/validators/inbox-agent-policy.ts": "29cef157f4d9b564fd813868038aa8c813df4a7b", "packages/shared/src/validators/index.ts": "25a142aeffc3b395993347c2d7bb0538738fefc3", "packages/shared/src/validators/instance.test.ts": "3faa9593a9a05f74429d9b1d2251906a03e9a903", - "packages/shared/src/validators/instance.ts": "edde733b1d1b91023321c6c59b17b65aadf5dfa1", + "packages/shared/src/validators/instance.ts": "1c151c58a13a8aedc8ed04b9c07d31f23fd41d40", "packages/shared/src/validators/issue-chat-bootstrap.test.ts": "e1ebb9aa94da22c825bc3ddd32ce2cfc98bfe645", "packages/shared/src/validators/issue-tree-control.ts": "7144ef86a83e008ac0626e1d62a1d6164c46f438", "packages/shared/src/validators/issue.test.ts": "7584bcce33a933ebcb02695b439767163e5ef61a", diff --git a/ui/src/features/connections/AwsRoleSetup.tsx b/ui/src/features/connections/AwsRoleSetup.tsx index 1a9c789af21..cc902f7a1cb 100644 --- a/ui/src/features/connections/AwsRoleSetup.tsx +++ b/ui/src/features/connections/AwsRoleSetup.tsx @@ -1,6 +1,7 @@ import { useEffect, useState } from "react"; import { ArrowUpRight, ChevronRight, Download, Loader2 } from "lucide-react"; -import { getAppStoreDefinition, type AwsConnectionSetup } from "@paperclipai/shared"; +import type { AwsConnectionSetup } from "@paperclipai/shared"; +import { ROLE_ARN_PATTERN, roleArnFromAgentSummary } from "./aws-role-arn"; import { ApiError } from "@/api/client"; import { toolsApi } from "@/api/tools"; import { describeError } from "@/api/errors"; @@ -78,20 +79,12 @@ export const AWS_AGENT_SETUP_STEPS: AgentSetupStep[] = [ { key: "report-role", title: "Report the role ARN" }, ]; -/** - * The app definition's role ARN rule (a server test keeps it equal to the server's), so this - * check matches what the server accepts. Without a definition the server alone decides. - */ -const ROLE_ARN_PATTERN = new RegExp( - getAppStoreDefinition("aws")?.methods.find((method) => method.key === "aws-role") - ?.tenantFields?.find((field) => field.key === "roleArn")?.validation?.pattern ?? "^arn:", -); - /** * The middle of AWS role setup: the connection is saved as a draft, so AWS can * now trust exactly this connection. By default the customer hands a prompt to - * their own agent, which creates the role, then pastes back the role ARN; the - * CloudFormation and by-hand steps are there for anyone who prefers them. + * their own agent, which creates the role and reports its ARN back through the + * live checklist; the CloudFormation and by-hand steps, and the Role ARN field, + * are there for anyone who prefers them. */ export function AwsRoleSetup({ connectionId, @@ -118,6 +111,9 @@ export function AwsRoleSetup({ const promptReady = !companyId || Boolean(agentProgress.handoff) || Boolean(agentProgress.error); const [loadError, setLoadError] = useState(null); const [roleArn, setRoleArn] = useState(""); + // Set once the person types in the field: the agent's ARN then never replaces their value. + const [roleArnEdited, setRoleArnEdited] = useState(false); + const [byHandOpen, setByHandOpen] = useState(false); useEffect(() => { let cancelled = false; @@ -137,6 +133,16 @@ export function AwsRoleSetup({ const ready = setup?.available === true ? setup : null; const trimmedArn = roleArn.trim(); const arnInvalid = trimmedArn.length > 0 && !ROLE_ARN_PATTERN.test(trimmedArn); + const agentFinished = agentProgress.progress?.status === "done"; + const reportedArn = ready && agentFinished ? roleArnFromAgentSummary(agentProgress.progress?.summary, ready.roleName) : null; + useEffect(() => { + if (reportedArn && !roleArnEdited) setRoleArn(reportedArn); + }, [reportedArn, roleArnEdited]); + // The field is under "Or do it by hand"; open it whenever the person has to see or fix the ARN. + const needsArnByHand = Boolean(error) || arnInvalid || (agentFinished && !reportedArn); + useEffect(() => { + if (needsArnByHand) setByHandOpen(true); + }, [needsArnByHand]); return (
@@ -171,7 +177,9 @@ export function AwsRoleSetup({

Give this prompt to an agent on a computer signed in to your AWS account.{" "} {ready.savedRoleArn ? "It updates the existing role" : "It creates the role"} with the AWS CLI - {agentProgress.handoff ? ", shows its progress here," : ""} and tells you the role ARN to paste below. + {agentProgress.handoff + ? ", shows its progress here, and hands back the role when it finishes." + : " and tells you the role ARN to paste under Or do it by hand."}

{agentProgress.error ? ( @@ -202,25 +210,17 @@ export function AwsRoleSetup({ onRetryRefresh={agentProgress.retryRefresh} /> ) : null} -
- - setRoleArn(event.target.value)} - placeholder={`arn:aws:iam:::role/${ready.roleName}`} - aria-invalid={arnInvalid || undefined} - className="font-mono text-base md:text-xs" - autoComplete="off" - spellCheck={false} - /> - {arnInvalid ? ( -

Use the full role ARN, like arn:aws:iam::123456789012:role/{ready.roleName}.

- ) : null} -
- + {reportedArn && trimmedArn === reportedArn ? ( +

Your agent’s role is ready. Test the connection to finish.

+ ) : agentFinished && !reportedArn ? ( +

+ Your agent finished without a role ARN Paperclip could use. Paste it under Or do it by hand. +

+ ) : null} + + Or do it by hand @@ -260,7 +260,7 @@ export function AwsRoleSetup({ resources.
  • - When the stack finishes, copy RoleArn from its Outputs tab into the field above. If this role came from + When the stack finishes, copy RoleArn from its Outputs tab into the Role ARN field below. If this role came from this template before, update that stack ({ready.roleName}) with the new template instead of creating another.
  • @@ -277,7 +277,7 @@ export function AwsRoleSetup({ {ready.savedRoleArn ? "so its trust policy is the one below" : "with the trust policy below"}, replacing ACCOUNT_ID with your AWS account ID. The CLI commands do either. -
  • Attach AWSMCPSignInOAuthAccessPolicy and the permissions agents should have, then paste the role ARN above.
  • +
  • Attach AWSMCPSignInOAuthAccessPolicy and the permissions agents should have, then paste the role ARN below.
  • @@ -286,6 +286,23 @@ export function AwsRoleSetup({ + +
    + + { setRoleArnEdited(true); setRoleArn(event.target.value); }} + placeholder={`arn:aws:iam:::role/${ready.roleName}`} + aria-invalid={arnInvalid || undefined} + className="font-mono text-base md:text-xs" + autoComplete="off" + spellCheck={false} + /> + {arnInvalid ? ( +

    Use the full role ARN, like arn:aws:iam::123456789012:role/{ready.roleName}.

    + ) : null} +
    @@ -359,7 +376,9 @@ export function awsAgentSetupPrompt(setup: Extract --capabilities CAPABILITY_NAMED_IAM --parameter-overrides CreateIdentityProvider=${setup.accessLevel === "full" ? " AccessPolicyArn=" : ""}`, ` If it fails because the role ${setup.roleName} already exists outside this stack, do not delete it. Instead update its trust policy with \`aws iam update-assume-role-policy\` to the trust policy in the template (with this account's ID and the identity provider's ARN), make sure AWSMCPSignInOAuthAccessPolicy and the access policy are attached, and use that role's ARN in step 5.`, - `5. Give me the role's ARN (the stack's RoleArn output, or \`aws iam get-role --role-name ${setup.roleName} --query Role.Arn --output text\`), so I can paste it into Paperclip and press Test connection.${progressInstructions ? " Also put it in your finish summary, as \"Role ARN: \"." : ""}`, + progressInstructions + ? `5. Put the role's ARN (the stack's RoleArn output, or \`aws iam get-role --role-name ${setup.roleName} --query Role.Arn --output text\`) in your finish summary, as "Role ARN: ". Paperclip fills it in from there; then I press Test connection.` + : `5. Give me the role's ARN (the stack's RoleArn output, or \`aws iam get-role --role-name ${setup.roleName} --query Role.Arn --output text\`), so I can paste it into Paperclip under Or do it by hand and press Test connection.`, "", "The role trusts only this one Paperclip connection, and no AWS keys are created or shared:", `- Identity provider: ${setup.issuer} (audience ${setup.audience})`, diff --git a/ui/src/features/connections/aws-role-arn.test.ts b/ui/src/features/connections/aws-role-arn.test.ts new file mode 100644 index 00000000000..34da0e391b5 --- /dev/null +++ b/ui/src/features/connections/aws-role-arn.test.ts @@ -0,0 +1,30 @@ +import { describe, expect, it } from "vitest"; +import { ROLE_ARN_PATTERN, roleArnFromAgentSummary } from "./aws-role-arn"; + +const roleName = "paperclip-c41a8e57-0f3b-4b6e-9d22-7a1e5c3f8b90"; +const arn = `arn:aws:iam::123456789012:role/${roleName}`; + +describe("roleArnFromAgentSummary", () => { + it("reads this connection's role ARN from the agent's finish summary", () => { + expect(roleArnFromAgentSummary(`Role ARN: ${arn}`, roleName)).toBe(arn); + expect(roleArnFromAgentSummary(`Done. The role is ${arn}.`, roleName)).toBe(arn); + expect(roleArnFromAgentSummary(`Role ARN: arn:aws:iam::123456789012:role/team/${roleName}`, roleName)) + .toBe(`arn:aws:iam::123456789012:role/team/${roleName}`); + }); + + it("never accepts another role, a longer name, or a malformed account", () => { + expect(roleArnFromAgentSummary("Role ARN: arn:aws:iam::123456789012:role/admin", roleName)).toBeNull(); + expect(roleArnFromAgentSummary(`Role ARN: ${arn}-copy`, roleName)).toBeNull(); + expect(roleArnFromAgentSummary(`Role ARN: ${arn}/other`, roleName)).toBeNull(); + expect(roleArnFromAgentSummary(`Role ARN: ${arn}./other`, roleName)).toBeNull(); + expect(roleArnFromAgentSummary(`Role ARN: arn:aws:iam::12345:role/${roleName}`, roleName)).toBeNull(); + expect(roleArnFromAgentSummary("Stopped: no permission to create the role.", roleName)).toBeNull(); + expect(roleArnFromAgentSummary(null, roleName)).toBeNull(); + }); + + it("only returns ARNs the connection's own validation accepts", () => { + expect(ROLE_ARN_PATTERN.test(roleArnFromAgentSummary(`Role ARN: ${arn}`, roleName)!)).toBe(true); + expect(ROLE_ARN_PATTERN.test("arn:aws:s3:::some-bucket")).toBe(false); + expect(ROLE_ARN_PATTERN.test(`arn:aws:iam::123456789012:user/${roleName}`)).toBe(false); + }); +}); diff --git a/ui/src/features/connections/aws-role-arn.ts b/ui/src/features/connections/aws-role-arn.ts new file mode 100644 index 00000000000..47983b5f41f --- /dev/null +++ b/ui/src/features/connections/aws-role-arn.ts @@ -0,0 +1,24 @@ +import { getAppStoreDefinition } from "@paperclipai/shared"; + +/** An IAM role ARN, the same shape the AWS app definition requires. */ +const IAM_ROLE_ARN_SHAPE = "^arn:aws[a-z-]*:iam::[0-9]{12}:role/(?:[A-Za-z0-9+=,.@_-]+/)*[A-Za-z0-9+=,.@_-]{1,64}$"; + +/** + * The app definition's role ARN rule (a server test keeps it equal to the server's), so this + * check matches what the server accepts. Without a definition it still requires an IAM role ARN. + */ +export const ROLE_ARN_PATTERN = new RegExp( + getAppStoreDefinition("aws")?.methods.find((method) => method.key === "aws-role") + ?.tenantFields?.find((field) => field.key === "roleArn")?.validation?.pattern ?? IAM_ROLE_ARN_SHAPE, +); + +/** + * The role ARN an agent reported in its finish summary, accepted only when it names this + * connection's own role, so a summary can never point the connection at another role. An ARN + * that continues past the role name (`…//other`) names a different role and is rejected. + */ +export function roleArnFromAgentSummary(summary: string | null | undefined, roleName: string): string | null { + const escaped = roleName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); + const match = summary?.match(new RegExp(`arn:aws[a-z-]*:iam::\\d{12}:role/(?:[\\w+=,.@-]+/)*${escaped}(?![\\w+=,@/-]|\\.[\\w+=,@/-])`)); + return match && ROLE_ARN_PATTERN.test(match[0]) ? match[0] : null; +} diff --git a/ui/src/pages/InstanceExperimentalSettings.tsx b/ui/src/pages/InstanceExperimentalSettings.tsx index b661433bb63..d8fca725871 100644 --- a/ui/src/pages/InstanceExperimentalSettings.tsx +++ b/ui/src/pages/InstanceExperimentalSettings.tsx @@ -322,18 +322,6 @@ export function InstanceExperimentalSettings() { ariaLabel="Toggle Areas & Responsibilities dashboard experimental setting" /> - toggleMutation.mutate({ enableAwsConnector: checked })} - disabled={toggleMutation.isPending} - settingKey="enableAwsConnector" - managed={managedKeys.enableAwsConnector} - ariaLabel="Toggle AWS connector experimental setting" - /> -