
Q-Bits: Configuring Cross-Account Access with Amazon Q Developer
Implement secure multi-account strategies with cross-account access. Amazon Q Developer generates IAM role trust relationships, explains assume role operations, demonstrates integration with AWS Organizations, and provides CLI examples for managing cross-account permissions.
Welcome to another installment of Q-Bits, our regular series showcasing cool ways Amazon employees are leveraging Amazon Q Developer. Today, we're diving into how Q Developer can assist with Configuring Cross-Account Access.
Help Partners to access Diagnostic Tools across Linked accounts in AWS Organization
AWS Diagnostic Tools is a specialized service exclusively available to AWS Partners participating in the Partner-Led Support program, providing support engineers with a suite of over 50 context-aware tools to diagnose issues across 22 different AWS services. The service enables partners to perform read-only diagnostic operations on their customers' AWS accounts without requiring direct console access, offering a secure and streamlined approach to troubleshooting. Through these tools, support engineers can access necessary service metadata, view cross-region information, and link diagnostic activities to specific support cases using robust tagging features. The service covers various AWS service categories including compute, databases, networking, security, and application integration, while maintaining security through role-based access control and integration with AWS Organization for efficient multi-account management.
AWSPartnerLedSupportReadOnlyAccess is an AWS managed policy designed to provide partners in the AWS Partner-Led Support Program with read-only access to service metadata across numerous AWS services in their customers' accounts. This policy grants essential permissions for troubleshooting technical support cases while maintaining security by limiting access to read-only operations. The policy is specifically crafted to enable support engineers to diagnose issues and provide technical assistance while ensuring they cannot make changes to the customer's infrastructure or configurations.
I wanted to test Diagnostic Tools and AWSPartnerLedSupportReadOnlyAccess so I asked Amazon Q Developer to implament a secure multi-account strategy across my Organization.
Asking Q Developer to generate a Role in an AWS Account that use AWSPartnerLedSupportReadOnlyAccess
I started by asking Amazon Q Developer Chat in my IDE to following prompt:
plaintext
Create a CloudFormation template that allows a specific AWS account (Partner account) to assume a cross-account IAM role.The template should include:- An IAM role with the AWSPartnerLedSupportReadOnlyAccess managed policy- The role can be assumed by the Partner account if belongs to the same AWS Organization. Ask for the ARN of the AWS Organizations root- The role can be assumed also by the AWS Trusted Service (ts.amazonaws.com)- Grant role with PassRole permissions for Diagnostic Tools- Allowing all operations on the Diagnostic Tools service- Parameters to make the Partner account ID configurable- Appropriate resource naming and tagging for better identification- A trust policy to delegate access to Diagnostic Tools Service "ts.amazonaws.com"- Grant role with PassRole permissions for Diagnostic Tools- Allowing all operations on the Diagnostic Tools service- Parameters to make the Partner account ID configurable- Appropriate resource naming and tagging for better identification
Q Developer provided the following response:
plaintext
Based on your requirements, I can help you with a CloudFormation template that creates an IAM role for cross-account access with the specified permissions. The template includes all the requested features and follows AWS security best practices. [1]Here's the complete CloudFormation template: [2]AWSTemplateFormatVersion: '2010-09-09'Description: 'Creates an IAM role for Partner-Led Support with cross-account access and Diagnostic Tools permissions'Parameters:PartnerAccountId:Type: StringDescription: 'AWS Account ID of the partner that will assume this role'AllowedPattern: '^[0-9]{12}$'ConstraintDescription: 'Must be a valid 12-digit AWS account ID'RootArn:Type: StringDescription: 'ARN of the AWS Organizations root (format: arn:aws:organizations::account-id:root/o-id/r-id)'AllowedPattern: '^arn:aws:organizations::[0-9]{12}:root/o-[a-z0-9]{10,32}/r-[a-z0-9]{4,32}$'ConstraintDescription: 'Must be a valid AWS Organizations root ARN'Resources:PartnerSupportRole:Type: 'AWS::IAM::Role'Properties:RoleName: 'PartnerLedSupportRole'Description: 'Role for Partner-Led Support with read-only access and diagnostic tools permissions'MaxSessionDuration: 3600AssumeRolePolicyDocument:Version: '2012-10-17'Statement:- Effect: AllowPrincipal:AWS: !Sub 'arn:aws:iam::${PartnerAccountId}:root'Service: 'ts.amazonaws.com'Action: 'sts:AssumeRole'Condition:StringEquals:'aws:PrincipalOrgID': !Select [1, !Split ['/', !Ref RootArn]]- Effect: AllowPrincipal:Service: 'ts.amazonaws.com'Action: 'sts:AssumeRole'ManagedPolicyArns:- 'arn:aws:iam::aws:policy/AWSPartnerLedSupportReadOnlyAccess'Policies:- PolicyName: DiagnosticToolsAccessPolicyDocument:Version: '2012-10-17'Statement:- Effect: AllowAction:- 'ts:GetExecution'- 'ts:GetExecutionOutput'- 'ts:GetTool'- 'ts:ListExecutions'- 'ts:ListTools'- 'ts:StartExecution'- 'ts:TagResource'- 'ts:UntagResource'- 'ts:ListTagsForResource'- 'iam:PassRole'Resource: '*'Tags:- Key: PurposeValue: PartnerLedSupport- Key: EnvironmentValue: Production- Key: CreatedByValue: CloudFormationOutputs:RoleARN:Description: 'ARN of the created IAM role'Value: !GetAtt PartnerSupportRole.ArnRoleName:Description: 'Name of the created IAM role'Value: !Ref PartnerSupportRoleThis template includes:1. Two parameters:- PartnerAccountId: For the AWS account ID that will assume the role- RootArn: For the AWS Organizations root ARN to enforce organization membership2. An IAM role with:- Trust policy allowing assumption by both the partner account and ts.amazonaws.com- Organization membership verification using aws:PrincipalOrgID condition- AWSPartnerLedSupportReadOnlyAccess managed policy- Custom inline policy for Diagnostic Tools permissions- Maximum session duration of 1 hour- Appropriate tags for resource identification3. Outputs section providing:- The ARN of the created role- The name of the created role [3]To deploy this template, you'll need:1. The 12-digit AWS account ID of the partner2. The AWS Organizations root ARN (format: arn:aws:organizations::account-id:root/o-id/r-id)3. The CAPABILITY_NAMED_IAM capability when deploying the stack since we're creating an IAM role with a specific nameThe template enforces security best practices by:- Limiting the role to specific AWS accounts within the organization [4]- Using specific permissions instead of wildcard permissions where possible- Including proper resource tagging for tracking and management- Setting a reasonable session duration limitSources[1] Create IAM Roles Anywhere resources with AWS CloudFormation - IAM Roles Anywheredocs.aws.amazon.comrolesanywherelatestcreating-resources-with-cloudformation.html[2] Setting up AWS CloudFormation StackSets - Application Migration Servicedocs.aws.amazon.commgnlatestsetting-up-stacksets.html[3] AWS::IAM::Role - AWS CloudFormationdocs.aws.amazon.comAWSCloudFormationlatestaws-resource-iam-role.html[4] Create an SSO and Identity Store using Cloudformation | AWS re:Post
Now I want to deploy this CloudFormation Stack with StackSets in every linked account of my Organization.
I asked Q:
plaintext
Now I want to implement it in every linked account of my Organization with StackSets
Q Developer provided the following response:
plaintext
I'll help you create a CloudFormation StackSet template to deploy the previous IAM role across all accounts in your AWS Organization. Here's how to implement it: [1]AWSTemplateFormatVersion: '2010-09-09'Description: 'StackSet to deploy Partner-Led Support Role across Organization accounts'Parameters:PartnerAccountId:Type: StringDescription: 'AWS Account ID of the partner that will assume this role'AllowedPattern: '^[0-9]{12}$'ConstraintDescription: 'Must be a valid 12-digit AWS account ID'RootArn:Type: StringDescription: 'ARN of the AWS Organizations root (format: arn:aws:organizations::account-id:root/o-id/r-id)'AllowedPattern: '^arn:aws:organizations::[0-9]{12}:root/o-[a-z0-9]{10,32}/r-[a-z0-9]{4,32}$'ConstraintDescription: 'Must be a valid AWS Organizations root ARN'Resources:PartnerSupportRole:Type: 'AWS::IAM::Role'Properties:RoleName: 'PartnerLedSupportRole'Description: 'Role for Partner-Led Support with read-only access and diagnostic tools permissions'MaxSessionDuration: 3600AssumeRolePolicyDocument:Version: '2012-10-17'Statement:- Effect: AllowPrincipal:AWS: !Sub 'arn:aws:iam::${PartnerAccountId}:root'Service: 'ts.amazonaws.com'Action: 'sts:AssumeRole'Condition:StringEquals:'aws:PrincipalOrgID': !Select [1, !Split ['/', !Ref RootArn]]- Effect: AllowPrincipal:Service: 'ts.amazonaws.com'Action: 'sts:AssumeRole'ManagedPolicyArns:- 'arn:aws:iam::aws:policy/AWSPartnerLedSupportReadOnlyAccess'Policies:- PolicyName: DiagnosticToolsAccessPolicyDocument:Version: '2012-10-17'Statement:- Effect: AllowAction:- 'ts:GetExecution'- 'ts:GetExecutionOutput'- 'ts:GetTool'- 'ts:ListExecutions'- 'ts:ListTools'- 'ts:StartExecution'- 'ts:TagResource'- 'ts:UntagResource'- 'ts:ListTagsForResource'- 'iam:PassRole'Resource: '*'Tags:- Key: PurposeValue: PartnerLedSupport- Key: EnvironmentValue: Production- Key: CreatedByValue: CloudFormation- Key: StackSetValue: TrueOutputs:RoleARN:Description: 'ARN of the created IAM role'Value: !GetAtt PartnerSupportRole.ArnRoleName:Description: 'Name of the created IAM role'Value: !Ref PartnerSupportRoleTo deploy this as a StackSet, follow these steps: [2]1. First, ensure you have trusted access enabled between CloudFormation StackSets and AWS Organizations: [3]aws organizations enable-aws-service-access --service-principal cloudformation.amazonaws.com2. Create the StackSet using AWS CLI (from your management account or delegated administrator account): [4]aws cloudformation create-stack-set \--stack-set-name partner-support-role \--template-body file://stackset-template.yaml \--parameters ParameterKey=PartnerAccountId,ParameterValue=123456789012 \ParameterKey=RootArn,ParameterValue=arn:aws:organizations::123456789012:root/o-abcd1234/r-ab12 \--capabilities CAPABILITY_NAMED_IAM \--permission-model SERVICE_MANAGED \--auto-deployment Enabled=true,RetainStacksOnAccountRemoval=false3. Deploy the StackSet instances to your organization or specific OUs:aws cloudformation create-stack-instances \--stack-set-name partner-support-role \--deployment-targets OrganizationalUnitIds='["ou-xxxx-xxxxxxxx"]' \--regions '["us-east-1"]' \--operation-preferences RegionConcurrencyType=PARALLEL,MaxConcurrentPercentage=100Key features of this implementation:1. Uses service-managed permissions model, which automatically handles the necessary IAM roles2. Enables auto-deployment to automatically deploy to new accounts added to the organization3. Allows parallel deployment across regions for faster rollout4. Maintains consistent role configuration across all accounts5. Added a StackSet tag to identify resources deployed via StackSetImportant considerations:1. Deploy from either the organization's management account or a delegated administrator account2. Ensure you have the necessary permissions to create StackSets3. The role name will be consistent across all accounts4. Consider the region(s) where you want to deploy the role5. You can target specific organizational units (OUs) or the entire organization6. The template maintains idempotency, so it can be safely redeployedThe StackSet will automatically:1. Deploy to all existing accounts in the specified OUs2. Deploy to new accounts as they're added to the organization/OUs3. Remove the stack when accounts are removed from the organization4. Maintain consistency across all accounts during updatesSources[1] AWS CloudFormation StackSets and AWS Organizations - AWS Organizationsdocs.aws.amazon.comorganizationslatestservices-that-can-integrate-cloudformation.html[2] Deploy multiple OUs in one stack set update | AWS re:Postrepost.awsknowledge-centercfn-deploy-multiple-ous[3] Deploying Resource Explorer to the accounts in an organization - AWS Resource Explorerdocs.aws.amazon.comresource-explorerlatestmanage-service-all-org-with-stacksets.html[4] Deploy CloudFormation Hooks to an Organization with service-managed StackSets | AWS DevOps Blog
Following the above instructions I have been able implement cross-account access to Diagnostic Tools in all AWS Organization Accounts.
Conclusion
In this Q-Bits article, we've explored how Amazon Q Developer can significantly streamline the implementation of cross-account access patterns within AWS Organizations. Through practical examples, we demonstrated how Q Developer can generate comprehensive CloudFormation templates that establish secure IAM roles with appropriate permissions, trust relationships, and necessary policies for Partner-Led Support access. The combination of CloudFormation StackSets and AWS Organizations enabled efficient deployment across multiple accounts while maintaining consistent security controls. This showcase illustrates how Amazon Q Developer serves as a powerful ally in implementing complex multi-account strategies, reducing the time and effort required to set up secure cross-account access patterns while ensuring adherence to AWS best practices.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article