aws-cloudformation / aws-cloudformation/cloudformation-coverage-roadmap
Creation of organization CloudTrail from delegated admin account fails
- Dominant language
- No language data
- Stars
- 1.1k
- Forks
- 62
- PR merge metrics
- No merged PRs in 30d
Description
### Name of the resource
AWS::CloudTrail::Trail
### Resource Name
_No response_
### Issue Description
I am trying to create an organization CloudTrail from a CloudTrail delegated administrator account, but it fails during deployment.
My setup contains a management account with id `111111111111` and another account `222222222222` that is registered as a delegated CloudTrail administrator account. CloudFormation template is being deployed in account `222222222222` and trail is named `org-cloudtrail`.
During deployment Cfn calls `CreateTrail` and receives a successful response. Trail is created in the management account, as expected, with Arn: `arn:aws:cloudtrail:us-east-1:111111111111:trail/org-cloudtrail`. Cfn then invokes `StartLogging`, using the trail name value `org-cloudtrail` as the `name` parameter instead of an Arn for CloudTrail. This call fails with `TrailNotFoundException` and Cfn then proceeds to roll-back the deployment.
```json
{
"eventVersion": "1.10",
"userIdentity": {
"type": "AssumedRole",
"accountId": "222222222222",
"accessKeyId": "ASIAXYKJWD7HLQEHAAAA",
"invokedBy": "cloudformation.amazonaws.com"
},
"eventTime": "2024-02-24T23:18:13Z",
"eventSource": "cloudtrail.amazonaws.com",
"eventName": "StartLogging",
"awsRegion": "us-east-1",
"sourceIPAddress": "cloudformation.amazonaws.com",
"userAgent": "cloudformation.amazonaws.com",
"errorCode": "TrailNotFoundException",
"errorMessage": "Unknown trail: arn:aws:cloudtrail:us-east-1:222222222222:trail/org-cloudtrail for the user: 222222222222",
"requestParameters": {
"name": "org-cloudtrail"
},
"responseElements": null,
"requestID": "-",
"eventID": "-",
"readOnly": false,
"eventType": "AwsApiCall",
"managementEvent": true,
"recipientAccountId": "222222222222",
"eventCategory": "Management"
}
```
Cfn resource:
```YAML
rOrgTrail:
Type: AWS::CloudTrail::Trail
Properties:
TrailName: 'org-cloudtrail'
IsLogging: true
IncludeGlobalServiceEvents: true
IsMultiRegionTrail: true
IsOrganizationTrail: true
EnableLogFileValidation: true
EventSelectors:
- IncludeManagementEvents: true
ReadWriteType: All
S3BucketName: 'bucket-name'
S3KeyPrefix: ''
```
### Expected Behavior
Deploying Cfn template in the CloudTrail delegated administrator account should successfully create CloudTrail in the management account.
When invoking `StartLogging` Cfn needs to pass Arn instead of name of the trail as the `name` parameter.
CLI commands executed as `222222222222`:
```bash
$ aws cloudtrail start-logging --name org-cloudtrail
An error occurred (TrailNotFoundException) when calling the StartLogging operation: Unknown trail: arn:aws:cloudtrail:us-east-1:222222222222:trail/org-cloudtrail for the user: 222222222222
$ aws cloudtrail start-logging --name arn:aws:cloudtrail:us-east-1:111111111111:trail/org-cloudtrail
```
### Observed Behavior
Organization trail is successfully created, but CloudFormation encounters an error when calling `StartLogging` and rolls back the deployment.
### Test Cases
- Enabled Trusted Access for AWS CloudTrail
- Register delegated administrator for AWS CloudTrail
- Try to deploy organization CloudTrail from the delegated administrator account.
### Other Details
This is also reported as CDK issue: https://github.com/aws/aws-cdk/issues/26840
Contributor guide
Research direction
Start with the AWS::CloudTrail::Trail behavior described in the deployment trace and reproduce it with the documented CLI commands from a delegated administrator account. Done means an organization trail deployed through CloudFormation starts logging successfully without rollback, including when the trail exists in the management account.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws
- Domain
- cloud
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100