mirror of
https://github.com/Infisical/infisical.git
synced 2026-01-09 07:28:09 -05:00
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.
This commit is contained in:
@@ -62,8 +62,7 @@ export const awsIamResourceFactory: TPamResourceFactory<TAwsIamResourceConnectio
|
||||
|
||||
if (!isValid) {
|
||||
throw new BadRequestError({
|
||||
message:
|
||||
"Unable to assume the target role. Verify the target role ARN and ensure the PAM role has permission to assume it."
|
||||
message: `Unable to assume the target role. Verify the target role ARN and ensure the PAM role (ARN: ${connectionDetails.roleArn}) has permission to assume it.`
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,12 @@ import {
|
||||
} from "@app/components/v2";
|
||||
import { CopyButton } from "@app/components/v2/CopyButton";
|
||||
import { useProject } from "@app/context";
|
||||
import { PamResourceType, TAwsIamAccount } from "@app/hooks/api/pam";
|
||||
import {
|
||||
PamResourceType,
|
||||
TAwsIamAccount,
|
||||
TAwsIamResource,
|
||||
useGetPamResourceById
|
||||
} from "@app/hooks/api/pam";
|
||||
|
||||
import { GenericAccountFields, genericAccountFieldsSchema } from "./GenericAccountFields";
|
||||
|
||||
@@ -51,16 +56,27 @@ const formSchema = genericAccountFieldsSchema.extend({
|
||||
|
||||
type FormData = z.infer<typeof formSchema>;
|
||||
|
||||
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::<YOUR_ACCOUNT_ID>:role/<YOUR_PAM_ROLE_NAME>";
|
||||
|
||||
const targetRoleTrustPolicy = `{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [{
|
||||
"Effect": "Allow",
|
||||
"Principal": {
|
||||
"AWS": "arn:aws:iam::<YOUR_ACCOUNT_ID>:role/<YOUR_PAM_ROLE_NAME>"
|
||||
"AWS": "${pamRoleArn}"
|
||||
},
|
||||
"Action": "sts:AssumeRole",
|
||||
"Condition": {
|
||||
@@ -166,16 +182,12 @@ export const AwsIamAccountForm = ({ account, onSubmit }: Props) => {
|
||||
</pre>
|
||||
</div>
|
||||
<p className="text-xs text-mineshaft-400">
|
||||
<strong>Note:</strong> Replace{" "}
|
||||
<code className="rounded bg-mineshaft-700 px-1"><YOUR_ACCOUNT_ID></code> with
|
||||
your AWS account ID and{" "}
|
||||
<code className="rounded bg-mineshaft-700 px-1"><YOUR_PAM_ROLE_NAME></code>{" "}
|
||||
with the name of the PAM role you created in the "Resources" tab. The
|
||||
External ID{" "}
|
||||
<strong>Note:</strong> The Principal role ARN shown above is from the PAM Resource
|
||||
selected for this account. The External ID{" "}
|
||||
<code className="rounded bg-mineshaft-700 px-1 font-bold">{projectId}</code> 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.
|
||||
</p>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user