From 2e4a1acd03ab1653cda0d7b648806c0d94b7e4bb Mon Sep 17 00:00:00 2001 From: Victor Santos Date: Mon, 8 Dec 2025 14:28:05 -0300 Subject: [PATCH] fix: enhance error messaging and improve resource selection in PAM components - Updated error message in AWS IAM resource factory to include the PAM role ARN for better debugging. - Added functionality to clear the search input when a value is selected in the ResourceSelect component, improving user experience. - Refactored AwsIamAccountForm to fetch PAM resource details based on account or provided resourceId and resourceType, ensuring accurate role ARN usage in trust policy. --- .../aws-iam/aws-iam-resource-factory.ts | 3 +- .../PamAccountForm/AwsIamAccountForm.tsx | 36 ++++++++++++------- .../components/ResourceSelect.tsx | 2 ++ 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/backend/src/ee/services/pam-resource/aws-iam/aws-iam-resource-factory.ts b/backend/src/ee/services/pam-resource/aws-iam/aws-iam-resource-factory.ts index 01f593b4f..844908671 100644 --- a/backend/src/ee/services/pam-resource/aws-iam/aws-iam-resource-factory.ts +++ b/backend/src/ee/services/pam-resource/aws-iam/aws-iam-resource-factory.ts @@ -62,8 +62,7 @@ export const awsIamResourceFactory: TPamResourceFactory; -export const AwsIamAccountForm = ({ account, onSubmit }: Props) => { +export const AwsIamAccountForm = ({ account, resourceId, resourceType, onSubmit }: Props) => { const isUpdate = Boolean(account); const { projectId } = useProject(); + const resourceIdToFetch = account?.resourceId || resourceId; + const resourceTypeToFetch = account?.resource?.resourceType || resourceType; + const { data: resource } = useGetPamResourceById(resourceTypeToFetch, resourceIdToFetch, { + enabled: !!resourceIdToFetch && !!resourceTypeToFetch + }); + + const pamRoleArn = + (resource?.resourceType === PamResourceType.AwsIam && + (resource as TAwsIamResource).connectionDetails?.roleArn) || + "arn:aws:iam:::role/"; + const targetRoleTrustPolicy = `{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Principal": { - "AWS": "arn:aws:iam:::role/" + "AWS": "${pamRoleArn}" }, "Action": "sts:AssumeRole", "Condition": { @@ -166,16 +182,12 @@ export const AwsIamAccountForm = ({ account, onSubmit }: Props) => {

- Note: Replace{" "} - <YOUR_ACCOUNT_ID> with - your AWS account ID and{" "} - <YOUR_PAM_ROLE_NAME>{" "} - with the name of the PAM role you created in the "Resources" tab. The - External ID{" "} + Note: The Principal role ARN shown above is from the PAM Resource + selected for this account. The External ID{" "} {projectId} is your - current project ID. If this target role name doesn't match the wildcard pattern - in your PAM role's permissions policy, you'll need to update that policy - to include this role's ARN. + current project ID. If your target role name doesn't match the wildcard pattern + in your PAM Resource's role's permissions policy, you'll need to + update that policy to include this role's ARN.

diff --git a/frontend/src/pages/pam/PamAccountsPage/components/ResourceSelect.tsx b/frontend/src/pages/pam/PamAccountsPage/components/ResourceSelect.tsx index 879167195..d9667ddbf 100644 --- a/frontend/src/pages/pam/PamAccountsPage/components/ResourceSelect.tsx +++ b/frontend/src/pages/pam/PamAccountsPage/components/ResourceSelect.tsx @@ -80,6 +80,8 @@ export const ResourceSelect = ({ onSubmit, projectId }: Props) => { return; } + // Clear search when a value is selected so the selected label is shown + setSearch(""); onChange(newValue); }} isLoading={isPending}