Giter VIP home page Giter VIP logo

amazon-guardduty-multiaccount-scripts's Introduction

amazon-guardduty-multiaccount-scripts

These scripts automate the process of enabling and disabling Amazon GuardDuty simultaneously across a group of AWS accounts that are in your control. (Note, that you can have one master account and up to a 1000 member accounts).

enableguardduty.py will enable GuardDuty, send invitations from the master account and accept invitations in all member accounts. The result will be a master account that contains all security findings for all member accounts. Since GuardDuty is regionally isolated, findings for each member account will roll up to the corresponding region in the master account. For example, the us-east-1 region in your GuardDuty master account will contain the security findings for all us-east-1 findings from all associated member accounts.

Note: Account owners of member accounts will recieve an email for each region requesting that they accept the invitation to link their accounts, these emails can be ignored as the script accepts the inventation on their behalf.

Prerequisites

  • The scripts depend on a pre-existing role in the master account and all of the member accounts that will be linked, the role name must be the same in all accounts and the role trust relationship needs to allow your instance or local credentials to assume the role. The AmazonGuardDutyFullAccess managed poilicy (shown below) contains the required permissions for the script to succeed:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "guardduty:*",
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": "iam:CreateServiceLinkedRole",
            "Resource": "*",
            "Condition": {
                "StringLike": {
                    "iam:AWSServiceName": [
                        "guardduty.amazonaws.com",
                        "malware-protection.guardduty.amazonaws.com"
                    ]
                }
            }
        },
        {
            "Effect": "Allow",
            "Action": [
                "organizations:EnableAWSServiceAccess",
                "organizations:RegisterDelegatedAdministrator",
                "organizations:ListDelegatedAdministrators",
                "organizations:ListAWSServiceAccessForOrganization",
                "organizations:DescribeOrganizationalUnit",
                "organizations:DescribeAccount",
                "organizations:DescribeOrganization"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": "iam:GetRole",
            "Resource": "arn:aws:iam::*:role/*AWSServiceRoleForAmazonGuardDutyMalwareProtection"
        }
    ]
}

If you do not have a common role that includes at least the above permissions you will need to create a role in each member account as well as the master account with at least the above permissions. When creating the role ensure you use the same role name in every account and select the AmazonGuardDutyFullAccess managed policy. You can use the EnableGuardDuty.yaml CloudFormation Template to automate this process, as the tempalte creates only global resources it can be created in any region.

  • A CSV file that includes the list of accounts to be linked to the master account. Accounts should be listed one per line in the format of AccountId,EmailAddress. The EmailAddress must be the email associated with the root account.
  • Master AccountId which will recieve findings for all the linked accounts within the CSV file

Steps

1. Setup execution environment:

Option 1: Launch EC2 instance:

Option 2: Locally:

2. Execute Scripts

2a. Enable GuardDuty

  • Copy the required CSV file to this directory
    • Should be in the formation of "AccountId,EmailAddress" with one AccountID and EmailAddress per line.
usage: enableguardduty.py [-h] --master_account MASTER_ACCOUNT --assume_role
                          ASSUME_ROLE
                          input_file

Link AWS Accounts to central GuardDuty Account

positional arguments:
  input_file            Path to CSV file containing the list of account IDs
                        and Email addresses

optional arguments:
  -h, --help            show this help message and exit
  --master_account MASTER_ACCOUNT
                        AccountId for Central AWS Account
  --assume_role ASSUME_ROLE
                        Role Name to assume in each account
  

2b. Disable GuardDuty

  • Copy the required CSV file to this directory
    • Should be in the formation of "AccountId,EmailAddress,..."
usage: disableguardduty.py [-h] --master_account MASTER_ACCOUNT --assume_role
                           ASSUME_ROLE [--delete_master]
                           input_file

Link AWS Accounts to central GuardDuty Account

positional arguments:
  input_file            Path to CSV file containing the list of account IDs
                        and Email addresses

optional arguments:
  -h, --help            show this help message and exit
  --master_account MASTER_ACCOUNT
                        AccountId for Central AWS Account
  --assume_role ASSUME_ROLE
                        Role Name to assume in each account
  --delete_master       Delete the master Gd Detector

2b. Change GuardDuty Features

Guardduty has multiple optional detection features that can be edited on a per-account basis.

updatefeature.py allows you to toggle these on and off in bulk. Note that this only works on accounts that are already enabled and associated with enableguardduty.py.

For any given feature, enable_<feature> will turn it on, disable_<feature> will turn it off. If a flag for a <feature> is not provided, the previous value will be kept, which can be enabled or disabled.

usage: updatefeature.py [-h] --master_account MASTER_ACCOUNT --assume_role ASSUME_ROLE [--enabled_regions ENABLED_REGIONS] [--enable_malware [ENABLE_MALWARE]] [--enable_eks [ENABLE_EKS]] [--enable_s3 [ENABLE_S3]] [--disable_malware [DISABLE_MALWARE]] [--disable_eks [DISABLE_EKS]]
                        [--disable_s3 [DISABLE_S3]] [--debug]
                        input_file

Link AWS Accounts to central GuardDuty Account

positional arguments:
  input_file            Path to CSV file containing the list of account IDs and Email addresses

optional arguments:
  -h, --help            show this help message and exit
  --master_account MASTER_ACCOUNT
                        AccountId for Central AWS Account
  --assume_role ASSUME_ROLE
                        Role Name to assume in each account
  --enabled_regions ENABLED_REGIONS
                        comma separated list of regions to enable GuardDuty. If not specified, all available regions enabled
  --enable_malware [ENABLE_MALWARE]
                        Enables GuardDuty Malware Protection
  --enable_eks [ENABLE_EKS]
                        Enables GuardDuty for EKS
  --enable_s3 [ENABLE_S3]
                        Enables GuardDuty S3 Protection
  --disable_malware [DISABLE_MALWARE]
                        Disable GuardDuty Malware Protection
  --disable_eks [DISABLE_EKS]
                        Disable GuardDuty for EKS
  --disable_s3 [DISABLE_S3]
                        Disable GuardDuty S3 Protection
  --debug               Turns on more verbose logging

amazon-guardduty-multiaccount-scripts's People

Contributors

asantos-fuze avatar gabrielsoltz avatar hyandell avatar mr26 avatar ryanholland avatar sthristov avatar str3tch avatar tomstickle avatar underscorenygren avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

amazon-guardduty-multiaccount-scripts's Issues

Released version

Thanks for this sample!

Would it be possible to get a release created in github please? I want to grab a version of this and would like to grab a tagged version instead of a commit version.

Issues with disableguardduty.py

Accounts created with enabladeguardduty.py then followed up by running disableguardduty.py results in the following error.

amazon-guardduty-multiaccount-scripts$ python3.6 disableguardduty.py
Assumed session for xxxxxxxxxxx in region ap-south-1.
GuardDuty is active in ap-south-1
There are members in ap-south-1
Deleted members for xxxxxxxxxxx in ap-south-1
Traceback (most recent call last):
File "disableguardduty.py", line 187, in
main()
File "disableguardduty.py", line 69, in main
delete_detector(gd_client, detector_id)
File "disableguardduty.py", line 79, in delete_detector
DetectorId=detector_id
File "/Users/riad/anaconda3/lib/python3.6/site-packages/botocore/client.py", line 317, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Users/riad/anaconda3/lib/python3.6/site-packages/botocore/client.py", line 615, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.BadRequestException: An error occurred (BadRequestException) when calling the DeleteDetector operation: The request is rejected because the current account cannot delete detector while it has invited or associated members.

Most recent version of botocore/boto3 is not compatible with this code

Most recent versions of botocore (1.12.253) & boto3 (1.12.9) causes this script to fail.

Enabling members in all available GuardDuty regions ['ap-east-1', 'ap-northeast-1', 'ap-northeast-2', 'ap-south-1', 'ap-southeast-1', 'ap-southeast-2', 'ca-central-1', 'eu-central-1', 'eu-north-1', 'eu-west-1', 'eu-west-2', 'eu-west-3', 'me-south-1', 'sa-east-1', 'us-east-1', 'us-east-2', 'us-west-1', 'us-west-2']
Assumed session for ---------.
Failed to list detectors in Master account for region: {} due to an authentication error. Either your credentials are not correctly configured or the region is an OptIn region that is not enabled on the master account. Skipping {} and attempting to continue
Traceback (most recent call last):
File "enableguardduty.py", line 187, in
detector_dict = list_detectors(gd_client, aws_region)
File "enableguardduty.py", line 110, in list_detectors
detector_dict = client.list_detectors()
File "/usr/local/lib/python3.7/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python3.7/site-packages/botocore/client.py", line 661, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (UnrecognizedClientException) when calling the ListDetectors operation: The security token included in the request is invalid

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "enableguardduty.py", line 214, in
print("Failed to list detectors in Master account for region: {} due to an authentication error. Either your credentials are not correctly configured or the region is an OptIn region that is not enabled on the master account. Skipping {} and attempting to continue").format(aws_region, aws_region)
AttributeError: 'NoneType' object has no attribute 'format'

I was able to get this working by downgrading my packages -

pip install boto3==1.9.86
pip install botocore==1.12.88

I think this is due to the script attempting to enable ap-east-1 (HongKong), an opt-in only region. I do not (and will not) have this region enabled.

Issues with enabledguardduty script

Script stuck in ap-northeast-1 region:

Assumed session for XXXXXXXXXXXX.
Beginning XXXXXXXXXXXX in ap-northeast-1
Found existing detector 26a6a6a6a6a6a6a7a451 in ap-northeast-1 for XXXXXXXXXXXX
Account XXXXXXXXXXXX is already a member of YYYYYYYYYYY in region ap-northeast-1

But, did not get any problem with disabledguardduty script (enabled GuardDuty manually). Any reason it is failing while enabling GuardDuty?

Document other tools for guard duty multi-account enablement in readme

Worth adding to the readme as another tool for handling this.

https://github.com/capitalone/cloud-custodian/tree/master/tools/c7n_guardian

Its pre-dates this script and has a few more features and error handling conditions, also works in parallel across many accounts, and sets up users for next steps post guard duty enablement for configuring remediation policies. Its config file can also be auto generated instead of manually listing out accounts, etc.

Enable Guard Duty on Stolkhome region

Hello Team
We are enabling Guard duty using enableguardduty.py via switch role. But we can see it is not working properly.for Stolkholm region it is not working. Can you please confirm? But it is enabling all other region.

We are executing the following command to enabling Guard duty -
python amazon-guardduty-multiaccount-scripts/enableguardduty.py --master_account <master ac no> --assume_role <guard_duty_assume_role> <guardduty_fileName>

guardduty_fileName contents -
AccountxNoxxxxxxxxxxxxxx,account_root_email

Assume role with MFA condition

Hello,

It would be nice if the script supported MFA tokens as there might be a condition "aws:MultiFactorAuthPresent" on the assumed role.

Thanks,
Stan

enableguardduty script - argument to disable email invite?

This is not an issue with the script as it works beautifully! (apart from the issues with the disable script as part of issues highlighted already) Thank you to everyone who has worked on this so far! - but i am just wondering if there is a simple way to add an argument to disable the invite emails?

We were looking to enable this across 30+ accounts.
When testing it across 4 accounts for all regions we received 68 emails (one for each account and region GD was enabled in).

Like I said not a big problem, but worth noting if you are the recipient for all the accounts root emails or alternatively advise your customers that they will individual email for each region GD is enabled in as part of the script.

Cheers

Role for EC2 not defined

It's unclear what role the EC2 instance running the script would need linked to it in deployment option 1, step 2.

Issues with enabledguardduty script

When running the enabledguardduty script we get the following error. It keeps looping with the same message. Anyone else that have this issue?

Added Account xxxxxxxxxxxx to member list in GuardDuty master account yyyyyyyyyyyyu for region ap-south-1
Assumed session for yyyyyyyyyyyyu in region ap-south-1.
Assumed session for yyyyyyyyyyyyu in region ap-south-1.
Invited Account xxxxxxxxxxxx to GuardDuty master account yyyyyyyyyyyyu in region ap-south-1
Assumed session for yyyyyyyyyyyyu in region ap-south-1.
Finished xxxxxxxxxxxx in ap-south-1
Assumed session for yyyyyyyyyyyyu in region ap-south-1.
Finished xxxxxxxxxxxx in ap-south-1
Assumed session for yyyyyyyyyyyyu in region ap-south-1.
Finished xxxxxxxxxxxx in ap-south-1
Assumed session for yyyyyyyyyyyyu in region ap-south-1.
Finished xxxxxxxxxxxx in ap-south-1
Assumed session for yyyyyyyyyyyyu in region ap-south-1.
Finished xxxxxxxxxxxx in ap-south-1
Assumed session for yyyyyyyyyyyyu in region ap-south-1.

disableguardduty.py does not work

When running disableguardduty.py this comes back:

GuardDuty is active in eu-west-1
There are members in eu-west-1
Traceback (most recent call last):
  File "disableguardduty.py", line 164, in <module>
    DetectorId=detector_id
  File "/Users/jimsmith/.local/lib/python3.6/site-packages/botocore/client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/Users/jimsmith/.local/lib/python3.6/site-packages/botocore/client.py", line 634, in _make_api_call
    api_params, operation_model, context=request_context)
  File "/Users/jimsmith/.local/lib/python3.6/site-packages/botocore/client.py", line 682, in _convert_to_request_dict
    api_params, operation_model)
  File "/Users/jimsmith/.local/lib/python3.6/site-packages/botocore/validate.py", line 297, in serialize_to_request
    raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:

Command that was used:

python disableguardduty.py --master_account=<aws guardduty master account id> --assume_role=OrganizationAccountAccessRole ./guardduty_account_list.txt --enabled_regions=eu-west-1 --delete_master

Exceptions thrown in eu-west-3

When I run this script I get a bunch of exceptions and errors when enabling GuardDuty in eu-west-3. The error is thrown immediately upon running the script. All other regions seem to operate fine.

when running boto3 1.7.54 (botocore 1.10.54) this is the error that is thrown:

python enableguardduty.py --master_account ######## ./AWS/cloudformation-np+p-accounts.csv --assume_role AWSCloudFormationStackSetExecutionRole --enabled_regions eu-west-3

Enabling members in these regions: ['eu-west-3']

Assumed session for ########.

Traceback (most recent call last):
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\vendored\requests\packages\urllib3\connectionpool.py", line 544, in urlopen
    body=body, headers=headers)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\vendored\requests\packages\urllib3\connectionpool.py", line 341, in _make_request
    self._validate_conn(conn)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\vendored\requests\packages\urllib3\connectionpool.py", line 761, in _validate_conn
    conn.connect()
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\vendored\requests\packages\urllib3\connection.py", line 238, in connect
    ssl_version=resolved_ssl_version)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\vendored\requests\packages\urllib3\util\ssl_.py", line 279, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 412, in wrap_socket
    session=session
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 850, in _create
    self.do_handshake()
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1108, in do_handshake
    self._sslobj.do_handshake()
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\vendored\requests\adapters.py", line 370, in send
    timeout=timeout
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\vendored\requests\packages\urllib3\connectionpool.py", line 597, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\vendored\requests\packages\urllib3\util\retry.py", line 245, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\vendored\requests\packages\urllib3\packages\six.py", line 309, in reraise
    raise value.with_traceback(tb)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\vendored\requests\packages\urllib3\connectionpool.py", line 544, in urlopen
    body=body, headers=headers)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\vendored\requests\packages\urllib3\connectionpool.py", line 341, in _make_request
    self._validate_conn(conn)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\vendored\requests\packages\urllib3\connectionpool.py", line 761, in _validate_conn
    conn.connect()
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\vendored\requests\packages\urllib3\connection.py", line 238, in connect
    ssl_version=resolved_ssl_version)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\vendored\requests\packages\urllib3\util\ssl_.py", line 279, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 412, in wrap_socket
    session=session
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 850, in _create
    self.do_handshake()
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1108, in do_handshake
    self._sslobj.do_handshake()
botocore.vendored.requests.packages.urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "enableguardduty.py", line 168, in <module>
    detector_dict = list_detectors(gd_client, aws_region)
  File "enableguardduty.py", line 102, in list_detectors
    detector_dict = client.list_detectors()
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\client.py", line 314, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\client.py", line 599, in _make_api_call
    operation_model, request_dict)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\endpoint.py", line 148, in make_request
    return self._send_request(request_dict, operation_model)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\endpoint.py", line 177, in _send_request
    success_response, exception):
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\endpoint.py", line 273, in _needs_retry
    caught_exception=caught_exception, request_dict=request_dict)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\hooks.py", line 227, in emit
    return self._emit(event_name, kwargs)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\hooks.py", line 210, in _emit
    response = handler(**kwargs)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\retryhandler.py", line 183, in __call__
    if self._checker(attempts, response, caught_exception):
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\retryhandler.py", line 251, in __call__
    caught_exception)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\retryhandler.py", line 277, in _should_retry
    return self._checker(attempt_number, response, caught_exception)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\retryhandler.py", line 317, in __call__
    caught_exception)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\retryhandler.py", line 223, in __call__
    attempt_number, caught_exception)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\retryhandler.py", line 359, in _check_caught_exception
    raise caught_exception
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\endpoint.py", line 222, in _get_response
    proxies=self.proxies, timeout=self.timeout)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\vendored\requests\sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "C:\...\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\vendored\requests\adapters.py", line 415, in send
    raise ConnectionError(err, request=request)
botocore.vendored.requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))

I updated my boto3 (1.8.7) and botocore (1.11.7) to the most recent version, and now new errors are thrown...

Enabling members in these regions: ['eu-west-3']
Assumed session for #####.

Traceback (most recent call last):
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 849, in _validate_conn
    conn.connect()
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connection.py", line 356, in connect
    ssl_context=context)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\util\ssl_.py", line 359, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 412, in wrap_socket
    session=session
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 850, in _create
    self.do_handshake()
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1108, in do_handshake
    self._sslobj.do_handshake()
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\httpsession.py", line 242, in send
    decode_content=False,
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\util\retry.py", line 343, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\packages\six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py", line 849, in _validate_conn
    conn.connect()
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connection.py", line 356, in connect
    ssl_context=context)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\util\ssl_.py", line 359, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 412, in wrap_socket
    session=session
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 850, in _create
    self.do_handshake()
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\ssl.py", line 1108, in do_handshake
    self._sslobj.do_handshake()
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "enableguardduty.py", line 168, in <module>
    detector_dict = list_detectors(gd_client, aws_region)
  File "enableguardduty.py", line 102, in list_detectors
    detector_dict = client.list_detectors()
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\client.py", line 314, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\client.py", line 599, in _make_api_call
    operation_model, request_dict)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\endpoint.py", line 102, in make_request
    return self._send_request(request_dict, operation_model)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\endpoint.py", line 135, in _send_request
    success_response, exception):
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\endpoint.py", line 202, in _needs_retry
    caught_exception=caught_exception, request_dict=request_dict)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\hooks.py", line 227, in emit
    return self._emit(event_name, kwargs)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\hooks.py", line 360, in _emit
    aliased_event_name, kwargs, stop_on_response
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\hooks.py", line 210, in _emit
    response = handler(**kwargs)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\retryhandler.py", line 183, in __call__
    if self._checker(attempts, response, caught_exception):
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\retryhandler.py", line 251, in __call__
    caught_exception)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\retryhandler.py", line 277, in _should_retry
    return self._checker(attempt_number, response, caught_exception)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\retryhandler.py", line 317, in __call__
    caught_exception)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\retryhandler.py", line 223, in __call__
    attempt_number, caught_exception)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\retryhandler.py", line 359, in _check_caught_exception
    raise caught_exception
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\endpoint.py", line 173, in _get_response
    http_response = self._send(request)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\endpoint.py", line 215, in _send
    return self.http_session.send(request)
  File "C:\Users\...\AppData\Local\Programs\Python\Python37\lib\site-packages\botocore\httpsession.py", line 273, in send
    endpoint_url=request.url
botocore.exceptions.ConnectionClosedError: Connection was closed before we received a valid response from endpoint URL: "https://guardduty.eu-west-3.amazonaws.com/detector".

Enable Guard Duty on Asia Pacific (Hong Kong) region

Hello Team
We are enabling Guard duty using enableguardduty.py via switch role. But we can see it is not working properly for Asia Pacific (Hong Kong)region it is not working.

We are executing the following command to enabling Guard duty -
python amazon-guardduty-multiaccount-scripts/enableguardduty.py --master_account --assume_role <guard_duty_assume_role> <guardduty_fileName>

guardduty_fileName contents -
AccountxNoxxxxxxxxxxxxxx,account_root_email

boto version -

-bash-4.2$ aws --version
aws-cli/1.16.183 Python/2.7.5 Linux/3.10.0-862.6.3.el7.x86_64 botocore/1.12.173

Organisation account in Removed state

Testing the script I found a special case where an organization member can be in Removed state.

By modifying a few lines, the script handles that too:

                # Check if Verification Was failed before, delete and add it again.
                if member_dict[account] == 'EmailVerificationFailed' or member_dict[account] == 'Removed':
                    if member_dict[account] == 'Removed':
                        print('The account is in the Removed state so we will delete and re invite')
                    else:
                        # Member is enabled and already being monitored
                        print('Account {account} Error: EmailVerificationFailed'.format(account=account))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.