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

aws.vpc | set-flow-log | DeliverLogsPermissionArn not required with DestinationType as s3 #4666

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions c7n/resources/vpc.py
Expand Up @@ -1992,9 +1992,10 @@ class CreateFlowLogs(BaseAction):
def validate(self):
self.state = self.data.get('state', True)
if self.state:
if not self.data.get('DeliverLogsPermissionArn'):
if (self.data.get('LogDestinationType') == 's3' and
self.data.get('DeliverLogsPermissionArn')):
PratMis marked this conversation as resolved.
Show resolved Hide resolved
raise PolicyValidationError(
'DeliverLogsPermissionArn required when '
'DeliverLogsPermissionArn not required with destination as s3 when'
'creating flow-logs on %s' % (self.manager.data,))
if (not self.data.get('LogGroupName') and not self.data.get('LogDestination')):
raise PolicyValidationError(
Expand Down
@@ -1,22 +1,22 @@
{
"status_code": 200,
"status_code": 200,
"data": {
"Unsuccessful": [],
"ClientToken": "rPg75zxg3CoD0FIsjmETO7i3vlDfujvJ4fXvhnYuvBc=",
"FlowLogIds": [
"fl-0fe58629b419a1230"
],
"Unsuccessful": [],
"ResponseMetadata": {
"RetryAttempts": 0,
"HTTPStatusCode": 200,
"RequestId": "33afe06e-de8e-4e07-803c-7435f5cbd000",
"RequestId": "2b3d0572-c082-4e4f-9d1c-0a836dedfa44",
"HTTPStatusCode": 200,
"HTTPHeaders": {
"transfer-encoding": "chunked",
"content-type": "text/xml;charset=UTF-8",
"vary": "Accept-Encoding",
"date": "Fri, 02 Nov 2018 21:48:21 GMT",
"content-type": "text/xml;charset=UTF-8",
"transfer-encoding": "chunked",
"vary": "accept-encoding",
"date": "Fri, 23 Aug 2019 17:51:32 GMT",
"server": "AmazonEC2"
}
},
"FlowLogIds": [
"fl-061d3f3b816da485e"
],
"ClientToken": "LeufVjrP/fkZbjxFlNUErFlijDZf1A89z4aCjHIqCxM="
},
"RetryAttempts": 0
}
}
}
@@ -1,18 +1,18 @@
{
"status_code": 200,
"status_code": 200,
"data": {
"FlowLogs": [],
"FlowLogs": [],
"ResponseMetadata": {
"RetryAttempts": 0,
"HTTPStatusCode": 200,
"RequestId": "bad4f4f1-afa6-48d1-ac78-2970a939d998",
"RequestId": "4cb232af-722b-4960-a7eb-0d42ee265f79",
"HTTPStatusCode": 200,
"HTTPHeaders": {
"transfer-encoding": "chunked",
"content-type": "text/xml;charset=UTF-8",
"vary": "Accept-Encoding",
"date": "Fri, 02 Nov 2018 21:48:21 GMT",
"content-type": "text/xml;charset=UTF-8",
"transfer-encoding": "chunked",
"vary": "accept-encoding",
"date": "Fri, 23 Aug 2019 17:51:32 GMT",
"server": "AmazonEC2"
}
},
"RetryAttempts": 0
}
}
}
@@ -1,39 +1,38 @@
{
"status_code": 200,
"status_code": 200,
"data": {
"FlowLogs": [
{
"LogDestinationType": "s3",
"ResourceId": "vpc-d2d616b5",
"CreationTime": {
"hour": 21,
"__class__": "datetime",
"month": 11,
"second": 21,
"microsecond": 961000,
"year": 2018,
"day": 2,
"minute": 48
},
"TrafficType": "ALL",
"FlowLogStatus": "ACTIVE",
"FlowLogId": "fl-061d3f3b816da485e",
"DeliverLogsPermissionArn": "arn:aws:iam::644160558196:role/testing-vpc-flow-log-role",
"LogDestination": "arn:aws:s3:::c7n-vpc-flow-logs/test.log.gz",
"DeliverLogsStatus": "SUCCESS"
"__class__": "datetime",
"year": 2019,
"month": 8,
"day": 23,
"hour": 17,
"minute": 51,
"second": 33,
"microsecond": 145000
},
"DeliverLogsStatus": "SUCCESS",
"FlowLogId": "fl-0fe58629b419a1230",
"FlowLogStatus": "ACTIVE",
"ResourceId": "vpc-d2d616b5",
"TrafficType": "ALL",
"LogDestinationType": "s3",
"LogDestination": "arn:aws:s3:::c7n-vpc-flow-logs/test.log.gz"
}
],
],
"ResponseMetadata": {
"RetryAttempts": 0,
"HTTPStatusCode": 200,
"RequestId": "8b3a9439-620d-440b-8b4a-3634460f9684",
"RequestId": "f4cec796-2342-4fa3-a2b2-07230145f0cb",
"HTTPStatusCode": 200,
"HTTPHeaders": {
"transfer-encoding": "chunked",
"content-type": "text/xml;charset=UTF-8",
"vary": "Accept-Encoding",
"date": "Fri, 02 Nov 2018 21:48:21 GMT",
"content-type": "text/xml;charset=UTF-8",
"transfer-encoding": "chunked",
"vary": "accept-encoding",
"date": "Fri, 23 Aug 2019 17:51:33 GMT",
"server": "AmazonEC2"
}
},
"RetryAttempts": 0
}
}
}
133 changes: 40 additions & 93 deletions tests/data/placebo/test_vpc_set_flow_logs_s3/ec2.DescribeVpcs_1.json
@@ -1,124 +1,71 @@
{
"status_code": 200,
"status_code": 200,
"data": {
"Vpcs": [
{
"VpcId": "vpc-f1516b97",
"InstanceTenancy": "default",
"Tags": [
{
"Value": "FancyTestVPC",
"Key": "Name"
},
{
"Value": "tagfanncyvalue",
"Key": "tagfancykey"
}
],
"CidrBlock": "10.205.0.0/18",
"DhcpOptionsId": "dopt-24ff1940",
"State": "available",
"VpcId": "vpc-03005fb9b8740263d",
"OwnerId": "644160558196",
"InstanceTenancy": "default",
"CidrBlockAssociationSet": [
{
"AssociationId": "vpc-cidr-assoc-98ba93f0",
"CidrBlock": "10.0.42.0/24",
"AssociationId": "vpc-cidr-assoc-0f6765530d80dc044",
"CidrBlock": "10.205.0.0/18",
"CidrBlockState": {
"State": "associated"
}
}
],
"State": "available",
"DhcpOptionsId": "dopt-24ff1940",
"CidrBlock": "10.0.42.0/24",
"IsDefault": false
},
{
"VpcId": "vpc-f8c6d983",
"InstanceTenancy": "default",
],
"IsDefault": false,
"Tags": [
{
"Value": "IpV6",
"Key": "Name"
}
],
"CidrBlockAssociationSet": [
"Key": "Owner",
"Value": "faizan.ahmed@capitalone.com"
},
{
"AssociationId": "vpc-cidr-assoc-c9ff12a5",
"CidrBlock": "10.0.0.0/16",
"CidrBlockState": {
"State": "associated"
}
"Key": "Name",
"Value": "testing-vpc"
}
],
"Ipv6CidrBlockAssociationSet": [
{
"Ipv6CidrBlock": "2600:1f18:2466:4b00::/56",
"AssociationId": "vpc-cidr-assoc-caff12a6",
"Ipv6CidrBlockState": {
"State": "associated"
}
}
],
"State": "available",
"DhcpOptionsId": "dopt-24ff1940",
"CidrBlock": "10.0.0.0/16",
"IsDefault": false
},
]
},
{
"VpcId": "vpc-03005fb9b8740263d",
"InstanceTenancy": "default",
"Tags": [
{
"Value": "testing-vpc",
"Key": "Name"
}
],
"CidrBlock": "172.31.0.0/16",
"DhcpOptionsId": "dopt-24ff1940",
"State": "available",
"VpcId": "vpc-d2d616b5",
"OwnerId": "644160558196",
"InstanceTenancy": "default",
"CidrBlockAssociationSet": [
{
"AssociationId": "vpc-cidr-assoc-0f6765530d80dc044",
"CidrBlock": "10.205.0.0/18",
"AssociationId": "vpc-cidr-assoc-33669f5a",
"CidrBlock": "172.31.0.0/16",
"CidrBlockState": {
"State": "associated"
}
}
],
"State": "available",
"DhcpOptionsId": "dopt-24ff1940",
"CidrBlock": "10.205.0.0/18",
"IsDefault": false
},
{
"VpcId": "vpc-d2d616b5",
"InstanceTenancy": "default",
],
"IsDefault": true,
"Tags": [
{
"Value": "FlowLogTest",
"Key": "Name"
}
],
"CidrBlockAssociationSet": [
{
"AssociationId": "vpc-cidr-assoc-33669f5a",
"CidrBlock": "172.31.0.0/16",
"CidrBlockState": {
"State": "associated"
}
"Key": "Name",
"Value": "FlowLogTest"
}
],
"State": "available",
"DhcpOptionsId": "dopt-24ff1940",
"CidrBlock": "172.31.0.0/16",
"IsDefault": true
]
}
],
],
"ResponseMetadata": {
"RetryAttempts": 0,
"HTTPStatusCode": 200,
"RequestId": "94ac021a-47d5-440d-8c38-4096ad2b4868",
"RequestId": "83f10946-4a3a-41c7-a0f1-4e89deab2dcc",
"HTTPStatusCode": 200,
"HTTPHeaders": {
"date": "Fri, 02 Nov 2018 21:48:20 GMT",
"content-type": "text/xml;charset=UTF-8",
"content-length": "4418",
"vary": "Accept-Encoding",
"content-type": "text/xml;charset=UTF-8",
"content-length": "2205",
"vary": "accept-encoding",
"date": "Fri, 23 Aug 2019 17:51:32 GMT",
"server": "AmazonEC2"
}
},
"RetryAttempts": 0
}
}
}
2 changes: 0 additions & 2 deletions tests/test_vpc.py
Expand Up @@ -2604,8 +2604,6 @@ def test_vpc_set_flow_logs_s3(self):
"type": "set-flow-log",
"LogDestinationType": "s3",
"LogDestination": "arn:aws:s3:::c7n-vpc-flow-logs/test.log.gz",
"DeliverLogsPermissionArn":
"arn:aws:iam::644160558196:role/testing-vpc-flow-log-role",
}
],
},
Expand Down