Skip to content

Commit

Permalink
upd: update policy 369 to be supported by open source Cloud Custodian
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-shcherbak committed Sep 23, 2024
1 parent abfff80 commit a5b7b3c
Show file tree
Hide file tree
Showing 19 changed files with 196 additions and 80 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

39 changes: 39 additions & 0 deletions policies/ecc-aws-369-workspaces_cloudwatch_integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (c) 2023 EPAM Systems, Inc.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

policies:
- name: ecc-aws-369-workspaces_cloudwatch_integration
comment: '010019123100'
description: |
CloudWatch Events is not set up for successful logins to WorkSpaces
resource: account
filters:
- not:
- type: missing
policy:
resource: workspaces
- type: missing
policy:
resource: aws.event-rule
filters:
- type: value
key: EventPattern
value: not-null
- type: value
key: from_json(EventPattern)."source"
op: in
value_type: swap
value: "aws.workspaces"
- or:
- type: value
key: from_json(EventPattern)."detail-type"
op: in
value_type: swap
value: "WorkSpaces Access"
- type: value
key: from_json(EventPattern)."detail-type"
value: absent

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4"
version = "~> 5"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4"
version = "~> 5"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4"
version = "~> 5"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"status_code": 200,
"data": {
"Rules": [
{
"Name": "369_cloudwatch_rule_green",
"Arn": "arn:aws:events:us-east-1:111111111111:rule/369_cloudwatch_rule_green",
"EventPattern": "{\"detail-type\":[\"WorkSpaces Access\"],\"source\":[\"aws.workspaces\"]}",
"State": "ENABLED",
"EventBusName": "default"
}
],
"ResponseMetadata": {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"status_code": 200,
"data": {
"AccountAliases": [
"epmcsec-lab10"
"test"
],
"IsTruncated": false,
"ResponseMetadata": {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"status_code": 200,
"data": {
"PaginationToken": "",
"ResourceTagMappingList": [
{
"ResourceARN": "arn:aws:workspaces:us-east-1:111111111111:workspace/ws-3zwmywlx2",
"Tags": [
{
"Key": "ComplianceStatus",
"Value": "Green"
},
{
"Key": "CustodiaRule",
"Value": "ecc-aws-541-workspaces_cloudwatch_integration"
}
]
}
],
"ResponseMetadata": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"status_code": 200,
"data": {
"PaginationToken": "",
"ResourceTagMappingList": [
{
"ResourceARN": "arn:aws:events:us-east-1:111111111111:rule/369_cloudwatch_rule_green",
"Tags": [
{
"Key": "ComplianceStatus",
"Value": "Green"
},
{
"Key": "CustodiaRule",
"Value": "ecc-aws-541-workspaces_cloudwatch_integration"
}
]
}
],
"ResponseMetadata": {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
"data": {
"Workspaces": [
{
"WorkspaceId": "ws-2kl4hch4j",
"DirectoryId": "d-90674cc9a1",
"WorkspaceId": "ws-3zwmywlx2",
"DirectoryId": "d-9067d5a5a6",
"UserName": "Administrator",
"IpAddress": "10.0.1.215",
"State": "STOPPED",
"IpAddress": "10.0.1.117",
"State": "AVAILABLE",
"BundleId": "wsb-8pmj7b7pq",
"SubnetId": "subnet-014f50caf7d83d8f2",
"ComputerName": "A-346MMO8DR51LL",
"SubnetId": "subnet-066f3d1d03",
"ComputerName": "A-3IONU2C6Z2WZY",
"WorkspaceProperties": {
"RunningMode": "AUTO_STOP",
"RunningModeAutoStopTimeoutInMinutes": 60,
"RootVolumeSizeGib": 80,
"UserVolumeSizeGib": 10,
"ComputeTypeName": "STANDARD"
"ComputeTypeName": "STANDARD",
"Protocols": [
"PCOIP"
],
"OperatingSystemName": "AMAZON_LINUX_2"
},
"ModificationStates": []
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"status_code": 200,
"data": {
"Rules": [
{
"Name": "369_cloudwatch_rule_red",
"Arn": "arn:aws:events:us-east-1:111111111111:rule/369_cloudwatch_rule_red",
"EventPattern": "{\"source\":[\"aws.appflow\"],\"detail-type\":[\"AppFlow Start Flow Run Report\"]}",
"State": "ENABLED",
"EventBusName": "default"
}
],
"ResponseMetadata": {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"status_code": 200,
"data": {
"AccountAliases": [
"epmcsec-lab10"
"test"
],
"IsTruncated": false,
"ResponseMetadata": {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"status_code": 200,
"data": {
"PaginationToken": "",
"ResourceTagMappingList": [
{
"ResourceARN": "arn:aws:workspaces:us-east-1:111111111111:workspace/ws-3zwmywlx2",
"Tags": [
{
"Key": "ComplianceStatus",
"Value": "Red"
},
{
"Key": "CustodiaRule",
"Value": "ecc-aws-541-workspaces_cloudwatch_integration"
}
]
}
],
"ResponseMetadata": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"status_code": 200,
"data": {
"PaginationToken": "",
"ResourceTagMappingList": [
{
"ResourceARN": "arn:aws:events:us-east-1:111111111111:rule/369_cloudwatch_rule_red",
"Tags": [
{
"Key": "ComplianceStatus",
"Value": "Red"
},
{
"Key": "CustodiaRule",
"Value": "ecc-aws-541-workspaces_cloudwatch_integration"
}
]
}
],
"ResponseMetadata": {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
"data": {
"Workspaces": [
{
"WorkspaceId": "ws-2kl4hch4j",
"DirectoryId": "d-90674cc9a1",
"WorkspaceId": "ws-3zwmywlx2",
"DirectoryId": "d-9067d5a5a6",
"UserName": "Administrator",
"IpAddress": "10.0.1.215",
"State": "STOPPED",
"IpAddress": "10.0.1.117",
"State": "AVAILABLE",
"BundleId": "wsb-8pmj7b7pq",
"SubnetId": "subnet-014f50caf7d83d8f2",
"ComputerName": "A-346MMO8DR51LL",
"SubnetId": "subnet-0775dd66f3d1d0c93",
"ComputerName": "A-3IONU2C6Z2WZY",
"WorkspaceProperties": {
"RunningMode": "AUTO_STOP",
"RunningModeAutoStopTimeoutInMinutes": 60,
"RootVolumeSizeGib": 80,
"UserVolumeSizeGib": 10,
"ComputeTypeName": "STANDARD"
"ComputeTypeName": "STANDARD",
"Protocols": [
"PCOIP"
],
"OperatingSystemName": "AMAZON_LINUX_2"
},
"ModificationStates": []
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import json
class PolicyTest(object):

def test_resources_with_client(self, base_test, resources, local_session):
base_test.assertEqual(len(resources), 1)
rules = local_session.client("events").list_rules()
pattern=json.loads(rules['Rules'][0]['EventPattern'])
base_test.assertNotEqual(pattern["detail-type"], "WorkSpaces Access")
base_test.assertNotEqual(pattern["source"], "aws.workspaces")
workspaces=local_session.client("workspaces").describe_workspaces().get("Workspaces",[])
base_test.assertNotEqual(len(workspaces), 0)

0 comments on commit a5b7b3c

Please sign in to comment.