Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functional aws_cloudtrail_trail resource #186

Merged
merged 8 commits into from
Jan 23, 2018

Conversation

rx294
Copy link
Contributor

@rx294 rx294 commented Jan 17, 2018

Fixes #146

rx294 added 6 commits January 17, 2018 13:14
Fixes chef-boneyard#146

Signed-off-by: Rony Xavier <rx294@nyu.edu>
Fixes chef-boneyard#146

Signed-off-by: Rony Xavier <rx294@nyu.edu>
Signed-off-by: Rony Xavier <rx294@nyu.edu>
Signed-off-by: Rony Xavier <rx294@nyu.edu>
Signed-off-by: Rony Xavier <rx294@nyu.edu>
Signed-off-by: Rony Xavier <rx294@nyu.edu>
Copy link
Collaborator

@clintoncwolfe clintoncwolfe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few tiny doc edits, and a question about an IAM policy. Very good work, and a very good contribution - thank you!


### be_encrypted

The test will pass if the logs delivered by identified trail is encrypted.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delivered by the identified trail

The ARN identifier of the specified trail. An ARN uniquely identifies the trail within AWS.

describe aws_cloudtrail_trail('trail-name') do
its('trail_arn') { should cmp "trail-arn" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer that we had a real-looking ARN URI as the comparison value


### be_log_file_validation_enabled

The test will pass if the identified trail log file integrity validation is enabled.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test will pass if the identified trail has log file integrity validation is enabled.

@@ -0,0 +1,74 @@
class AwsCloudTrailTrail < Inspec.resource(1)
name 'aws_cloudtrail_trail'
desc 'Verifies settings for individual AWS CloudTrail Trail'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verifies settings for an individual AWS CloudTrail Trail


output "aws_region" {
value = "${data.aws_region.region.name}"
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 to this, I've almost added it myself several times.

}
},
{
"Sid": "Enable cross account log decryption",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we require this ability?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary...i was going with the default Key Policy Created in CloudTrail Console.
I have removed it.

describe aws_cloudtrail_trail(fixtures['cloudtrail_trail_2_name']) do
it { should_not be_log_file_validation_enabled }
end
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 The fixtures and integration tests are very good here.

Signed-off-by: Rony Xavier <rx294@nyu.edu>
@rx294
Copy link
Contributor Author

rx294 commented Jan 18, 2018

Thank you @clintoncwolfe i have made the updates.

@clintoncwolfe
Copy link
Collaborator

I'm happy with the code, and unit tests pass cleanly. However, the integration tests fail for me, with an IAM Role error:

aws_cloudtrail.trail_1: Still creating... (10s elapsed)
Error applying plan:

1 error(s) occurred:

* aws_cloudtrail.trail_1: 1 error(s) occurred:

* aws_cloudtrail.trail_1: InvalidCloudWatchLogsLogGroupArnException: Access denied. Check the permissions for your role.
	status code: 400, request id: 6263e786-d490-4a99-9ae9-90ae11da9df8

Offhand, that looks like this now-fixed terraform-aws bug, but that had a workaround of re-running terraform, which doesn't work here; that makes me think the policy is actually bad, rather than being a timing issue.

I'll continue making my "rounds"; and then circle back to this later, if you haven't gotten to it yet. IAM policies are always pretty subtle, and I'm no expert on what CloudTrail needs.

@rx294
Copy link
Contributor Author

rx294 commented Jan 19, 2018

@clintoncwolfe thats weird the integration tests are working fine on my side.

I just had @samcornwell try the same and its working for him too.

"logs:CreateLogStream"
],
"Resource": [
"arn:aws:logs:us-east-1:${data.aws_caller_identity.creds.account_id}:log-group:${aws_cloudwatch_log_group.trail_1_log_group.name}:log-stream:${data.aws_caller_identity.creds.account_id}_CloudTrail_${data.aws_region.region.name}*"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the location triggering the IAM role permission issue - the us-east-1 here needs to be parameterized, that is, replaced with ${data.aws_region.region.name}.

I test in us-east-2, and this grants permission to work in us-east-1; thus the conflict.

"logs:PutLogEvents"
],
"Resource": [
"arn:aws:logs:us-east-1:${data.aws_caller_identity.creds.account_id}:log-group:${aws_cloudwatch_log_group.trail_1_log_group.name}:log-stream:${data.aws_caller_identity.creds.account_id}_CloudTrail_${data.aws_region.region.name}*"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue here, parameterize the region.

@clintoncwolfe
Copy link
Collaborator

Ok, I found where it was happening - a hardcoded region in the policy. The integration tests pass once that's in place. Once you make the change, we'll get it merged!

Signed-off-by: Rony Xavier <rx294@nyu.edu>
@rx294
Copy link
Contributor Author

rx294 commented Jan 23, 2018

Ah! my bad...I have made the corrections...thanks again @clintoncwolfe.

@clintoncwolfe
Copy link
Collaborator

Thanks for this excellent contribution!

@clintoncwolfe clintoncwolfe merged commit 0af7105 into chef-boneyard:master Jan 23, 2018
@rx294 rx294 deleted the aws_cloudtrail_trail_pr branch January 23, 2018 18:59
HackerShark pushed a commit to HackerShark/inspec-aws that referenced this pull request Feb 7, 2018
Signed-off-by: Rony Xavier <rx294@nyu.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants