Skip to content

Commit c4a40aa

Browse files
Merge pull request #18 from AmazonElizabethZhong/master
Version 1.1.0 Release:
2 parents f8f44df + 33acb1d commit c4a40aa

15 files changed

+1720
-955
lines changed

EnableDetective.yaml

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# __author__ = "Amazon Detective"
2+
# __copyright__ = "Amazon 2020"
3+
# __credits__ = "Amazon Detective"
4+
# __license__ = "Apache"
5+
# __version__ = "1.1.0"
6+
# __maintainer__ = "Amazon Detective"
7+
# __email__ = "detective-demo-requests@amazon.com"
8+
# __status__ = "Production"
19
AWSTemplateFormatVersion: 2010-09-09
210
Description: Creates a new role to allow an administrator account to enable and manage Detective.
311

@@ -7,6 +15,10 @@ Parameters:
715
Description: AWS Account Id of the administrator account (the account in which will recieve Detective findings from member accounts).
816
MaxLength: 12
917
MinLength: 12
18+
RoleName:
19+
Type: String
20+
Default: "ManageDetective"
21+
Description: RoleName to create IAM Role in the administrator account and each member account.
1022
CreateInstanceRole:
1123
Type: String
1224
Description: Select Yes to create an EC2 instance role that can be attached to an instnace in the Master account which will allow the instance to assume the exection role. Select No if you plan to run the script locally or are creating the stack in a member account.
@@ -17,7 +29,7 @@ Resources:
1729
ExecutionRole:
1830
Type: AWS::IAM::Role
1931
Properties:
20-
RoleName: ManageDetective
32+
RoleName: !Ref RoleName
2133
AssumeRolePolicyDocument:
2234
Version: 2012-10-17
2335
Statement:
@@ -34,7 +46,10 @@ Resources:
3446
Type: AWS::IAM::Role
3547
Condition: CreateInstanceRole
3648
Properties:
37-
RoleName: ManageDetectiveInstanceRole
49+
RoleName: !Join
50+
- ''
51+
- - !Ref RoleName
52+
- 'InstanceRole'
3853
AssumeRolePolicyDocument:
3954
Version: "2012-10-17"
4055
Statement:
@@ -47,7 +62,10 @@ Resources:
4762
- "sts:AssumeRole"
4863
Policies:
4964
-
50-
PolicyName: ManageDetectivePolicy
65+
PolicyName: !Join
66+
- ''
67+
- - !Ref RoleName
68+
- 'Policy'
5169
PolicyDocument:
5270
Version: "2012-10-17"
5371
Statement:

README.md

+45-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Amazon Detective provides a set of open-source Python scripts in this repository. The scripts require Python 3.
44

55
You can use these to perform the following tasks:
6-
* Enable Detective for an administrator account across Regions. When you enable Detective, you can assign tag values to the behavior graph.
6+
* Enable Detective for an administrator account across Regions. When you enable Detective, you can assign tag values to assign to a new behavior graph.
77
* Add member accounts to an administrator account's behavior graphs across Regions.
88
* Optionally send invitation emails to the member accounts. You can also configure the request to not send invitation emails.
99
* Remove member accounts from an administrator account's behavior graphs across Regions.
@@ -13,12 +13,56 @@ For more information on how to use these scripts, see [Using the Amazon Detectiv
1313

1414
## Contributing to this project
1515

16+
### Complete use case
17+
18+
The following is an example use case of adding multiple accounts in a graph.
19+
20+
1. Create a .csv file of the AWS account ids.
21+
1. (Please check the format in section: *Creating a .csv list of accounts to add or remove*)
22+
2. Add the necessary permissions to each account.
23+
1. (Please check the complete setup in section: *Required permissions for the scripts*)
24+
3. Add the root module into PYTHONPATH.
25+
```
26+
#For example: export PYTHONPATH=$PYTHONPATH:/my_folder/amazon-detective-multiaccount-scripts/src
27+
28+
export PYTHONPATH=$PYTHONPATH:<absolute root module path>
29+
```
30+
4. Go to the root module, and run the python script and specify the .csv file. Make sure the role specified by --assume_role is the one created in Step 2.
31+
```
32+
#For example:
33+
cd /my_folder/amazon-detective-multiaccount-scripts/src/amazon_detective_multiaccount_scripts
34+
python3 enableDetective.py --admin_account 111122223333 --assume_role ManageDetective --input_file inputFile.csv --tags Department=Finance --enabled_regions us-west-1
35+
```
36+
6. Check results of the script in the terminal and/or AWS console.
37+
1. For example, for the command above, the terminal should have the following output:
38+
![plot](./pic/image_1.png)
39+
![plot](./pic/image_2.png)
40+
1641
### Running tests
1742

1843
```
1944
# Install requirements
45+
2046
pip3 install boto3 pytest
2147
2248
# In the tests/ directory...
49+
50+
# Add your root module into PYTHONPATH (if you haven't done this step)
51+
# eg: export PYTHONPATH=$PYTHONPATH:/my_folder/amazon-detective-multiaccount-scripts/src
52+
53+
export PYTHONPATH=$PYTHONPATH:<absolute root module path>
54+
55+
# Run the test
56+
2357
pytest -s
2458
```
59+
60+
## FAQs
61+
1. If you experience the following error Message for opt-in regions while enabling detective in all regions:
62+
63+
`ERROR - error with region <region>: An error occurred (UnrecognizedClientException) when calling the ListGraphs operation:
64+
The security token included in the request is invalid`
65+
66+
Using the scripts in opt-in regions assumes you have your accounts/resources configured in that region, so please double-check your accounts' configuration.
67+
68+
For further information, here is documentation on opt-in regions work: https://docs.aws.amazon.com/general/latest/gr/rande-manage.html.

VERSION.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Version 1.1.0:
2+
- Introduce mechanism to wait for the accounts to be invited in enableDetective.py
3+
- Optional parameters "--skip_prompt"
4+
- Improved unit test coverage
5+
- RoleName parameter added for enable detective cloudformation in EnableDetective.yaml
6+
- BUGFIX: 1. enableDetective.py does not work without --tags option
7+
- BUGFIX: 2. Fix datatype mismatch for delete_members function
8+
## Version 1.0.1:
9+
- BUGFIX: AttributeError: 'tuple' object has no attribute 'keys'
10+
## Version 1.0.0:
11+
- Initial project release

__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Implement your code here.

0 commit comments

Comments
 (0)