gemini-oss / starfleet Goto Github PK
View Code? Open in Web Editor NEWWhole-infrastructure automation tooling for AWS
Home Page: https://gemini-oss.github.io/starfleet/
License: Apache License 2.0
Whole-infrastructure automation tooling for AWS
Home Page: https://gemini-oss.github.io/starfleet/
License: Apache License 2.0
Slack needs to have the retry decorator added to it to prevent workers from failing even though they are successful.
There is some improvements that can be made to the config worker:
exclusionByResourceTypes
field that was recently introducedOne potential issue that can arise is that our singletons may contain stale cached data. AWS Lambda will periodically rotate out the container running the lambda function but until it does, there could be stale data affecting workloads.
This can particularly be an issue with the Account Index and the Starbase. The following scenario can happen:
AccountIndexGeneratorShip
runs to update the account index in S3Eventually, everything will iron itself out. However, I can see value in having the default account index keep a timestamp variable of when it was last instantiated and have it refresh after maybe 30 minutes after that timestamp has passed. That would reduce the likelihood staleness in the Starbase.
Docs link is outdated or dead - under https://gemini-oss.github.io/starfleet/installation/RunSAM/#sam-configuration:
samconfig.toml doesn't exist at docs link
When setting up SAM, it will create a configuration. A sample configuration has been provided here that you should use: samconfig.toml.
Starfleet should support IAMbic's expires_at
field with a custom field that follows a YYYY-MM-DD
format instead of the field supported by IAMbic as Starfleet's workers are idempotent and lack state.
https://docs.iambic.org/reference/schemas/aws_iam_role_template
The AccountIndexGeneratorShip
experiences an unhandled KeyError
exception and subsequent fatal crash when attempting to generate the account inventory when deployed in an organization with a nested OU hierarchy.
Root (r-olgb)
├── Core Infrastructure (ou-olgb-q97w37sn)
│ ├── Prod (ou-olgb-7puk9u2d)
│ │ ├── secops-account-prod (123456789012)
├── Workloads (ou-olgb-e604f59w)
│ ├── Prod (ou-olgb-q8z9vop9)
│ │ ├── auth-service-account-prod (123456789033)
│ ├── Non-Prod (ou-olgb-nndadfrq)
├── org-managment-account-prod (123456789441)
Fig 1. An example organization structure with a valid nested OU hierarchy.
The AccountIndexGeneratorShip
should be capable of successfully generating an account inventory when deployed in any valid environment that adheres to AWS Organizations standards and service quota limits.
With the AccountIndexGeneratorShip
deployed correctly in an organization that includes a nested OU hierarchy (see Figure 1 above), executing the starfleet account-inventory generate
command throws an unhandled KeyError
exception resulting in a fatal crash of the AccountIndexGeneratorShip
and no account inventory output.
starfleet on main [$] is 📦 v0.0.1 via 🐍 v3.9.16 (starfleet) on ☁️ aws-security-research-lab-secops-admin (us-east-2)
❯ starfleet account-inventory generate \
--commit \
--payload SaveAccountInventory.yaml
[...]
[🆗] Template OK: Executing worker: AccountIndexGeneratorShip...
2023-05-08 17:52:15,401 - INFO - [📡] Reaching out to the Orgs API to get the list of AWS accounts in account: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/ship.py - execute:61
2023-05-08 17:52:17,325 - INFO - [📡] Reaching out to the Orgs API to get the list of all OUs in the org... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/ship.py - execute:68
2023-05-08 17:52:18,375 - INFO - [🚚] Fetching tags and enabled regions for each account... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/ship.py - execute:76
[...]
2023-05-08 17:52:20,706 - DEBUG - [👪] Fetching parents for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_tags_and_parents:81
Traceback (most recent call last):
File "/Users/erwestfa/.pyenv/versions/starfleet/bin/starfleet", line 8, in <module>
sys.exit(cli())
File "/Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/ship.py", line 120, in generate
worker.execute(commit=commit)
File "/Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/ship.py", line 77, in execute
fetch_additional_details(
File "/Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py", line 168, in fetch_additional_details
parent_ous.append({"Id": parent["Id"], "Type": parent["Type"], "Name": all_ous[parent["Id"]]})
KeyError: 'ou-olgb-q8z9vop9'
Fig 2. Account inventory generate command output showing unhandled exception.
In the target environment where Starfleet will be deployed, ensure the organization has at least one member account that is contained within a nested OU hierarchy with a minimum of 2 levels of OU nesting (see Figure 1 above for more detail).
Deploy Starfleet to a delegated member account in accordance with the installation guide.
Using the CLI, trigger a new account inventory generation tasking:
starfleet account-inventory generate \
--commit \
--payload SaveAccountInventory.yaml
The AccountIndexGeneratorShip
executes the AWS Organizations ListOrganizationalUnitsForParent
API call, passing the organization root ID to the ParentId
request parameter, which returns only the top-level OUs under the root. However, the AccountIndexGeneratorShip
never recursively checks if the top-level OUs contain any nested OUs.
The results of this API call are then used to generate a map of OU names keyed to their respective OU identifiers. This map is passed to an asynchronous utility function fetch_additional_details()
that retrieves additional metadata about member accounts. As this function iterates over member accounts, it references the map to retrieve the friendly name of the OU that contains the account, assuming the identifier exists in the map.
starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py
Lines 159 to 174 in 3d495f1
In the scenario where the member account is contained in an OU that is nested one or more levels below the top-level OUs under the root, the OU identifier that contains the member account will not be in the map, resulting in the unhandled KeyError
exception.
starfleet on main [$] is 📦 v0.0.1 via 🐍 v3.9.16 (starfleet) on ☁️ aws-security-research-lab-secops-admin (us-east-2)
❯ starfleet account-inventory generate \
--commit \
--payload SaveAccountInventory.yaml
_/ _/_/ _/ _/
_/_/_/ _/_/_/_/ _/_/_/ _/ _/_/ _/ _/ _/_/ _/_/ _/_/_/_/
_/_/ _/ _/ _/ _/_/ _/_/_/_/ _/ _/_/_/_/ _/_/_/_/ _/
_/_/ _/ _/ _/ _/ _/ _/ _/ _/ _/
_/_/_/ _/_/ _/_/_/ _/ _/ _/ _/_/_/ _/_/_/ _/_/
2023-05-08 17:52:15,218 - DEBUG - [📄] Loading the base configuration from /Users/erwestfa/projects/oss/starfleet/src/starfleet/configuration_files... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/utils/configuration.py - load_base_configuration:43
2023-05-08 17:52:15,218 - DEBUG - [⚙️] Processing configuration file: configuration.yaml... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/utils/configuration.py - load_base_configuration:49
2023-05-08 17:52:15,223 - DEBUG - [⚙️] Successfully loaded configuration file: configuration.yaml - /Users/erwestfa/projects/oss/starfleet/src/starfleet/utils/configuration.py - load_base_configuration:56
2023-05-08 17:52:15,225 - DEBUG - [🪵] Configuring the logger for the rest of the application... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/utils/configuration.py - load_base_configuration:74
2023-05-08 17:52:15,225 - DEBUG - [🆗️] Base configuration loaded successfully - /Users/erwestfa/projects/oss/starfleet/src/starfleet/utils/configuration.py - load_base_configuration:83
2023-05-08 17:52:15,225 - DEBUG - [📦] Loading worker ship plugins... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/loader.py - load_all_plugins:44
2023-05-08 17:52:15,225 - DEBUG - [🏗️] Loading plugins in the ['/Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins'] location... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/utils/plugin_loader.py - find_plugins:40
2023-05-08 17:52:15,226 - DEBUG - [⚙️] Processing module named: starfleet.worker_ships.plugins.account_index_generator - /Users/erwestfa/projects/oss/starfleet/src/starfleet/utils/plugin_loader.py - find_plugins:42
2023-05-08 17:52:15,242 - DEBUG - [👍] Found 1 plugins in ['/Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins'] - /Users/erwestfa/projects/oss/starfleet/src/starfleet/utils/plugin_loader.py - find_plugins:61
2023-05-08 17:52:15,242 - DEBUG - [⚙️] Processing module named: starfleet.worker_ships.plugins.aws_config - /Users/erwestfa/projects/oss/starfleet/src/starfleet/utils/plugin_loader.py - find_plugins:42
2023-05-08 17:52:15,296 - DEBUG - [👍] Found 1 plugins in ['/Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins'] - /Users/erwestfa/projects/oss/starfleet/src/starfleet/utils/plugin_loader.py - find_plugins:61
2023-05-08 17:52:15,296 - DEBUG - [⚙️] Processing module named: starfleet.worker_ships.plugins.github_sync - /Users/erwestfa/projects/oss/starfleet/src/starfleet/utils/plugin_loader.py - find_plugins:42
2023-05-08 17:52:15,398 - DEBUG - [👍] Found 1 plugins in ['/Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins'] - /Users/erwestfa/projects/oss/starfleet/src/starfleet/utils/plugin_loader.py - find_plugins:61
2023-05-08 17:52:15,398 - DEBUG - [🔧] Configuring worker ship: AccountIndexGeneratorShip - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/loader.py - load_all_plugins:48
2023-05-08 17:52:15,398 - DEBUG - [👍] Worker ship: AccountIndexGeneratorShip is properly configured and ENABLED. - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/loader.py - load_all_plugins:65
2023-05-08 17:52:15,398 - DEBUG - [🔧] Configuring worker ship: AwsConfigWorkerShip - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/loader.py - load_all_plugins:48
2023-05-08 17:52:15,399 - DEBUG - [⏭️] Worker ship: AwsConfigWorkerShip has no discovered configuration. Skipping... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/loader.py - load_all_plugins:68
2023-05-08 17:52:15,399 - DEBUG - [🔧] Configuring worker ship: GitHubSyncWorkerShip - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/loader.py - load_all_plugins:48
2023-05-08 17:52:15,399 - DEBUG - [⏭️] Worker ship: GitHubSyncWorkerShip has no discovered configuration. Skipping... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/loader.py - load_all_plugins:68
2023-05-08 17:52:15,399 - DEBUG - [🚀] Completed loading 1 worker ships - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/loader.py - load_all_plugins:79
2023-05-08 17:52:15,399 - DEBUG - [🖥️] Loading CLIs (which are just plugins)... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/cli/components.py - load_clis:43
2023-05-08 17:52:15,399 - DEBUG - [🏗️] Loading plugins in the ['/Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins'] location... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/utils/plugin_loader.py - find_plugins:40
2023-05-08 17:52:15,399 - DEBUG - [⚙️] Processing module named: starfleet.worker_ships.plugins.account_index_generator - /Users/erwestfa/projects/oss/starfleet/src/starfleet/utils/plugin_loader.py - find_plugins:42
2023-05-08 17:52:15,399 - DEBUG - [👍] Found 1 plugins in ['/Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins'] - /Users/erwestfa/projects/oss/starfleet/src/starfleet/utils/plugin_loader.py - find_plugins:61
2023-05-08 17:52:15,399 - DEBUG - [⚙️] Processing module named: starfleet.worker_ships.plugins.aws_config - /Users/erwestfa/projects/oss/starfleet/src/starfleet/utils/plugin_loader.py - find_plugins:42
2023-05-08 17:52:15,399 - DEBUG - [👍] Found 1 plugins in ['/Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins'] - /Users/erwestfa/projects/oss/starfleet/src/starfleet/utils/plugin_loader.py - find_plugins:61
2023-05-08 17:52:15,399 - DEBUG - [⚙️] Processing module named: starfleet.worker_ships.plugins.github_sync - /Users/erwestfa/projects/oss/starfleet/src/starfleet/utils/plugin_loader.py - find_plugins:42
2023-05-08 17:52:15,399 - DEBUG - [👍] Found 1 plugins in ['/Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins'] - /Users/erwestfa/projects/oss/starfleet/src/starfleet/utils/plugin_loader.py - find_plugins:61
2023-05-08 17:52:15,399 - DEBUG - [🖥️] Completed loading 3 CLIs - /Users/erwestfa/projects/oss/starfleet/src/starfleet/cli/components.py - load_clis:48
[🛃] Validating the template...
[🆗] Template OK: Executing worker: AccountIndexGeneratorShip...
2023-05-08 17:52:15,401 - INFO - [📡] Reaching out to the Orgs API to get the list of AWS accounts in account: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/ship.py - execute:61
2023-05-08 17:52:17,325 - INFO - [📡] Reaching out to the Orgs API to get the list of all OUs in the org... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/ship.py - execute:68
2023-05-08 17:52:18,375 - INFO - [🚚] Fetching tags and enabled regions for each account... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/ship.py - execute:76
2023-05-08 17:52:19,894 - DEBUG - [🏷️] Fetching tags for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_tags_and_parents:70
2023-05-08 17:52:19,895 - DEBUG - [🌍️] Fetching enabled regions for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_regions:91
2023-05-08 17:52:19,898 - DEBUG - [🏷️] Fetching tags for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_tags_and_parents:70
2023-05-08 17:52:19,899 - DEBUG - [🌍️] Fetching enabled regions for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_regions:91
2023-05-08 17:52:19,899 - DEBUG - [🏷️] Fetching tags for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_tags_and_parents:70
2023-05-08 17:52:19,906 - DEBUG - [🌍️] Fetching enabled regions for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_regions:91
2023-05-08 17:52:19,907 - DEBUG - [🏷️] Fetching tags for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_tags_and_parents:70
2023-05-08 17:52:19,910 - DEBUG - [🌍️] Fetching enabled regions for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_regions:91
2023-05-08 17:52:19,911 - DEBUG - [🏷️] Fetching tags for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_tags_and_parents:70
2023-05-08 17:52:19,915 - DEBUG - [🌍️] Fetching enabled regions for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_regions:91
2023-05-08 17:52:19,921 - DEBUG - [🏷️] Fetching tags for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_tags_and_parents:70
2023-05-08 17:52:19,927 - DEBUG - [🌍️] Fetching enabled regions for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_regions:91
2023-05-08 17:52:19,930 - DEBUG - [🏷️] Fetching tags for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_tags_and_parents:70
2023-05-08 17:52:19,931 - DEBUG - [🌍️] Fetching enabled regions for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_regions:91
2023-05-08 17:52:20,630 - DEBUG - [👪] Fetching parents for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_tags_and_parents:81
2023-05-08 17:52:20,633 - DEBUG - [👪] Fetching parents for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_tags_and_parents:81
2023-05-08 17:52:20,666 - DEBUG - [👪] Fetching parents for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_tags_and_parents:81
2023-05-08 17:52:20,700 - DEBUG - [👪] Fetching parents for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_tags_and_parents:81
2023-05-08 17:52:20,702 - DEBUG - [👪] Fetching parents for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_tags_and_parents:81
2023-05-08 17:52:20,705 - DEBUG - [👪] Fetching parents for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_tags_and_parents:81
2023-05-08 17:52:20,706 - DEBUG - [👪] Fetching parents for account id: <REDACTED>... - /Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py - fetch_tags_and_parents:81
Traceback (most recent call last):
File "/Users/erwestfa/.pyenv/versions/starfleet/bin/starfleet", line 8, in <module>
sys.exit(cli())
File "/Users/erwestfa/.pyenv/versions/3.9.16/envs/starfleet/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/Users/erwestfa/.pyenv/versions/3.9.16/envs/starfleet/lib/python3.9/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/Users/erwestfa/.pyenv/versions/3.9.16/envs/starfleet/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/erwestfa/.pyenv/versions/3.9.16/envs/starfleet/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/cli_utils.py", line 137, in invoke
return super().invoke(ctx)
File "/Users/erwestfa/.pyenv/versions/3.9.16/envs/starfleet/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/erwestfa/.pyenv/versions/3.9.16/envs/starfleet/lib/python3.9/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/Users/erwestfa/.pyenv/versions/3.9.16/envs/starfleet/lib/python3.9/site-packages/click/decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File "/Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/ship.py", line 120, in generate
worker.execute(commit=commit)
File "/Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/ship.py", line 77, in execute
fetch_additional_details(
File "/Users/erwestfa/projects/oss/starfleet/src/starfleet/worker_ships/plugins/account_index_generator/utils.py", line 168, in fetch_additional_details
parent_ous.append({"Id": parent["Id"], "Type": parent["Type"], "Name": all_ous[parent["Id"]]})
KeyError: 'ou-olgb-q8z9vop9'
Fig 3. Full stack trace of Starfleet account inventory generation command.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.