Skip to content
This repository was archived by the owner on Sep 17, 2021. It is now read-only.

Conversation

@zollman
Copy link
Contributor

@zollman zollman commented Sep 2, 2016

We need to run different watchers and auditors depending on which
account is being monitored. This is primarily for two reasons: first,
different AWS accounts are expected to have different security
postures (i.e., dev vs. prod); and second, some of the accounts may
not be AWS accounts at all (e.g. Azure or other accounts that need to
be scanned for watched items).

This PR extends the dynamic watchers & auditors framework from #405 .

Anne Ebie and others added 3 commits September 2, 2016 12:28
Change summary:
  * Fix Error in exception handling
  * Adding audit class to distinguish items created by different
    auditors of the same type
  * Adding custom directories
  * Adding development guidelines documentation
  * Fixing links in documentation
  * Removing duplicate auditors
  * Adding init test for scheduler
  * Fixing DB error in scheduler test
  * Removing unneeded DB insert from test case
  * Race condition with watcher_registry
  * Fixing DB migration conflict
  * Picking up pubspec.lock changes
  * Code style cleanup
  * Update file headers for contribution prep

Change-Id: Id72322f6dbccedc701e9c17dc9a5b8dc26bf30c1
List of added watchers:
    * CloudTrail
    * AWSConfig
    * AWSConfigRecorder
    * DirectConnect::Connection
    * DirectConnect::VirtualGateway
    * EC2::EbsSnapshot
    * EC2::EbsVolume
    * EC2::Image
    * EC2::Instance
    * ENI
    * KMS::Grant
    * KMS::Key
    * Lambda
    * RDS::ClusterSnapshot
    * RDS::DBCluster
    * RDS::DBInstace
    * RDS::Snapshot
    * RDS::SubnetGroup
    * Route53
    * Route53Domains
    * TrustedAdvisor
    * VPC::DHCP
    * VPC::Endpoint
    * VPC::FlowLog
    * VPC::NatGateway
    * VPC::NetworkACL
    * VPC::Peering

Additional changes:
  * Move rds[security_group] to rds/ directory.
  * Update vpc/route_table to use boto3 lib.
  * Add tests for tech types supported by moto
  * Initialize name to avoid UnboundLocalError
  * Update RDS watcher ephemeral values
  * Use boto3.session.get_available_regions in select watchers
  * Convert routetable watcher to decorator pattern
  * Convert route53 domains to decorator pattern
  * Handle the case where the aws principle is a string
  * Catching assume role exception in decorator
@zollman zollman changed the title Adds support for custom account metadata Add support for custom account metadata Sep 2, 2016
@scriptsrc scriptsrc added this to the 0.7.0 milestone Sep 6, 2016
@scriptsrc scriptsrc modified the milestones: 0.7.0, 0.7.5 Sep 20, 2016
@aebie
Copy link

aebie commented Oct 6, 2016

@MonkeySecurity I have a change to this PR that fixes the merge conflicts between this PR and #407 that is based on some streamlining of the common code, but now I see that 407 has been pushed back to 0.7.5 as well. It looks like there are quite a few other merge conflicts and I'd like to submit the merge conflict resolution closer to the release time. Can you ping us when you get to this point?

Curtis Stewart and others added 2 commits October 18, 2016 11:43
Type: Bugfix

Why is this change necessary:
When find_changes is run, it has the ability to update specific tech
types outside of the normal reporter run. In these cases the monitor
must rerun auditors for the updated tech types, plus any other auditors
for other tech types that are dependent on the updated types. It
determines this by checking the support_watcher_indexes and
support_auditor_indexs for each auditor associated with the tech types
updated. The check for the support_watcher_indexes were only being run
for the last auditor because it was indented incorrectly.

This change addresses the need by:
Changing the indent so that it is run for all auditors
@scriptsrc
Copy link
Contributor

Applying "Needs Work" label as I believe Curtis is working on updating this PR. (See gitter.im chat from Oct 13 15:55)

@cstewart87
Copy link

UDPATE: still working on these updates. Hope to post w/in 1 week

Type: generic-large-feature

Why is this change necessary?
Feature allowing for custom account types, which can either be
non-AWS accounts or AWS accounts extended with additional attributes.
By default, the new custom attributes are stored in the database but
can be configured to be retrieved from some other source.

This change addresses the need by:
Implementing account_manager framework
@cstewart87
Copy link

Build will fail until #438 is merged

@cstewart87
Copy link

Looks like #438 fixed any build issues :) This PR should be good to go as well. Let us know if you have any questions

items = relationship("Item", backref="account", cascade="all, delete, delete-orphan")
issue_categories = relationship("AuditorSettings", backref="account")
role_name = Column(String(256))
role_name = Column(String(256)) # (deprecated-custom)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fields are marked as deprecated, but still referenced throughout the codebase.
s3_name, number, role_name.

I'm worried about storing data in multiple places because inconsistencies could occur.

I see the migration is copying account.number to the account.identifier, but it is not copying account.s3_name or account.role_name to a custom field.

I think we should delete these fields instead of deprecating them, and use the upgrade script to move the existing values into the custom fields. (And the reverse in the downgrade script.)

All the tests and the rest of the project will need to be updated to use the new identifier and custom fields. Maybe you could override the Account.__getattr__() to check the custom fields.

Thoughts?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MonkeySecurity we were planning to do that as a seperate task because this change is already rather large, and deprecating these fields would make it a much larger code change, and would require a DB migration for existing data along with a rollback. We could go ahead do that if you would prefer to roll it all into one PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you'd like to keep account.identifier and account.number, I would think you'd need to update security_monkey/account_manager.py::_populate_account(...) so that it sets account.number as well as account.identifier (~ line 128)

Otherwise old and new accounts will be inconsistent.

def _populate_account(self, account, account_type_id, name, active, third_party,
                      notes, identifier, custom_fields=None):
    """
    Creates account DB object to be stored in the DB by create or update.
    May be overridden to store additional data
    """
    account.name = name
    account.identifier = identifier
    account.notes = notes

What would the timeline be for removing the deprecated fields?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I recall, this is handled in the AWSAccountManager. Thinking was that some non-aws accounts types would not case and the AWS account would handle any derived types.

As for the timeline, it wouldn't take more than a day or two, but we would still need to go though the approval process. I would expect at least a working week or so for that.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MonkeySecurity Did you want us to add the changes above based on my last comment ^^^?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this is good. I'll merge in and hope to see a migration update soon.

scriptsrc added a commit that referenced this pull request Nov 15, 2016
…being merged first because of the Alembic upgrade.
@scriptsrc scriptsrc merged commit 6848e71 into Netflix:develop Nov 15, 2016
mikegrima pushed a commit that referenced this pull request Nov 17, 2016
…being merged first because of the Alembic upgrade.
scriptsrc pushed a commit that referenced this pull request Nov 17, 2016
* Adding index to region. Dropping unused item.cloud. Depends on PR #408 being merged first because of the Alembic upgrade.

* Allowing Alembic to recreate foreign keys on Exceptions table to include a deleting cascade.

* Refactored exception logging to account for new `AccountType` class.

- Rebased the `develop` branch here so all DB changes are aligned properly.
@zollman zollman deleted the custom_accounts branch November 30, 2016 20:48
@scriptsrc scriptsrc mentioned this pull request Dec 2, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants