Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor scenarios #20

Open
wants to merge 88 commits into
base: main
Choose a base branch
from
Open

Conversation

mdorn
Copy link
Contributor

@mdorn mdorn commented Jul 29, 2024

This PR is a significant refactoring which should make it far easier for contributors to add scenarios and to reason about the code generally. Some highlights:

  • The main execution module now reads a YAML scenario configuration from each scenario in the scenarios/ directory rather than using hardcoded scenario details.
  • Contributors of new scenarios can do all of their work of their work in a new scenarios/scenario_X directory without having to touch any code anywhere else. Pulumi infrastructure works exactly the same as before, but the user will need to place deployment of additional infra into an extra.py module, and the attack logic into an attack function in an attack.py module. The new Scenario class (see below) expects that these functions exist.
  • A new Scenario class in the scenario.py module is responsible for executing the scenarios using the Pulumi automation API (rather than simply subprocessing the pulumi CLI) and generating a report from a single HTML template.
  • Files generated from executing a scenario (e.g. reports, Pulumi outputs, etc.) are confined to a single easy to understand location (/files/var).

Remaining work:

  • As of right now there are two available scenarios. I created a very simple example scenario (scenario_0) using a public S3 bucket and an "attack" that gets an object from it. I also refactored scenario_2 to use the new approach. This was actually quite easy to do by just moving some of the existing scenario code around to new locations.
  • I'll want to create a "contributors guide" that explains how to contribute a scenario, but hopefully the scenario_0 example helps.
  • I have some thoughts about other changes I'd recommend going forward but we can discuss them later.

To test:

  • Checkout this branch, ensure your AWS and Pulumi creds are current, and do the following
python3 -m venv ./venv
. venv/bin/activate
python cobra.py aws launch --simulation
# choose 0 for the example scenario or choose 2 for the refactored Scenario 2
python cobra.py aws destroy

NOTE: The PR should not be merged until the remaining work of moving the rest of the scenarios is complete.

@mdorn mdorn mentioned this pull request Jul 29, 2024
@mdorn
Copy link
Contributor Author

mdorn commented Oct 1, 2024

Following up a conversation with @hkoushik and @anandtiwarics , the main things that should be added to this PR before it gets merged are:

  • Refactoring of all scenarios in accordance with the new structure.
  • Add a CONTRIBUTING.md file, perhaps in the scenarios/ directory, explaining how to contribute a scenario.

The following items from the issue tracker should likely get their own branches/PRs after the merge of this PR:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants