You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: mkdocs/installation/IAM.md
+7-2
Original file line number
Diff line number
Diff line change
@@ -108,15 +108,20 @@ Resources:
108
108
If you do decide to go with the CloudFormation StackSets route, you need to keep in mind that StackSets will _NOT_ deploy to the Organization Root account. If you do choose to use StackSets, you will need to _manually_ create an IAM role in the organization root account that has the exact same permissions as what is documented in the StackSet YAML above.
109
109
110
110
!!! Note
111
-
If you leverage the `AccountIndexGeneratorShip` worker ship for your AWS account inventory (recommended), you will need to make sure that the Starfleet IAM roles in the Organization Root has the following permissions:
111
+
If you leverage the `AccountIndexGeneratorShip` worker ship for your AWS account inventory (recommended), you will need to make sure that the Starfleet IAM roles in the Organization Root account has the following permissions (in addition to the permissions you grant to the other worker roles):
This will resolve the parents for a given account's parent OU. the `resolved_parents` map is a dictionary that contains a list of the parents for the given OU ID passed in.
121
+
If we have an OU ID that is not resolved, then we need to build the parent tree for it. This involves recursively calling the list_parents call so that we can
122
+
resolve all parents up to one that we have already resolved parents for.
123
+
124
+
Before this function runs, the `resolved_parents` parameter should at a minimum have the ROOT resolved. It should also have all the ROOT's immediate children OUs resolved
125
+
as well.
126
+
127
+
This function is required to address issue #24. Orgs does not provide an API to just get the Org OU tree. When this worker ship first runs, we list the OUs that are under
128
+
the ROOT, but that doesn't list all the nested OUs. This addresses that by fetching and updating the map as missing OUs are encountered. Very annoying but is required. :/
129
+
"""
130
+
ou_id=ou_dict["Id"]
131
+
ifparents:=resolved_parents.get(ou_id):
132
+
returnparents
133
+
134
+
# We have not yet resolved the parent OUs and we need to resolve it:
135
+
LOGGER.debug(f"[🌲] Need to query the Orgs API to fetch the parents for OU ID: {ou_dict['Id']}...")
136
+
137
+
# We also need to get the name of this OU because we haven't seen it yet:
LOGGER.debug(f"[🆔] OU ID: {ou_id} has name: {ou_response['Name']}.")
143
+
144
+
# Append this OU as the first parent in the list:
145
+
resolved_parents[ou_id] = [resolved_ou]
146
+
147
+
# Unfortunately, when we list_parents, we only get back the immediate parent. This sucks. So we need to have the following logic:
148
+
# 1. Get the immediate parent that is returned (it should only be 1) -- but it's a list that's returned.
149
+
# 2. Call this function again (recurse) with the parent provided. Keep going until we find a parent we know about (we should always map to ROOT at a minimum).
150
+
# 3. As we continue, we are traversing the Org tree. As we go along we continue to update the parents and grandparents parents
151
+
# 4. After the tree traversal is completed, we update the current OU list with the list of resolved parents.
152
+
# 5. We now have the full parents list for an Account with the passed in OU ID. In future calls regarding this OU ID, it will reside in the resolved_parents map
153
+
# and will simply be returned without additional API calls necessary!
154
+
LOGGER.debug(f"[👪] Fetching parents for OU ID: {ou_id}/{resolved_ou['Name']}...")
Mocks out the direct boto3 client creator. The mocked boto3 object has a new client() function that will return the normal boto3 client (gets mocked with moto)
134
-
for all services *except* organizations. For organizations, we're making a MagicMock that mocks out the `list_tags_for_resource` call.
166
+
for all services *except* organizations. For organizations, we're making a MagicMock that mocks out the `list_tags_for_resource` and `list_parents` call.
This very specifically mocks out the boto3 call for listing the parent OUs. Not using Moto for this. The original function is wrapped by CloudAux's STS wrapper,
176
-
and it's easier to just mock out what we need vs. test the boto3 stuff itself.
"""This mostly tests that our code will pull out the proper (mocked) results from the AWS API. This also ensures that our fixture is working properly."""
0 commit comments