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

Bug Fixes (Initialization, AWS Perms, Config), CloudWatch Event Patterns, and More #205

Merged
merged 10 commits into from
Jun 27, 2017

Conversation

jacknagz
Copy link
Contributor

to: @ryandeivert (code) @mime-frame (docs)
cc: @airbnb/streamalert-maintainers @zbuc
size: medium

A combination of various bug fixes and feature additions.

Related Issues

Conf Changes

  • Make sure we are starting with "$LATEST" as the AWS Lambda current_version. This currently throws an error during the first deploy since the versions do not exist yet.
  • Reset the Kinesis and Lambda settings to be a bare minimum.
  • Enable force_destroy for prerequisite buckets. This is makes destroying clusters easier, since this data is not of high value.

CLI Changes

  • Add a stream_alert_cli.py terraform clean command to simply remove any Terraform statefiles and other related files. This is useful to have while troubleshooting issues with initialization.
  • Fix a bug in the init target list: This list of Terraform resources is used during init to create the prerequisite infrastructure. There was a resource naming issue here causing errors.
  • Add a default to the flow_logs module for the log group name. Adds some unit tests too.

Terraform Changes

  • Support all tf_stream_alert_cloudtrail module options. This gives control over how users can configure CloudTrail to send to their StreamAlert cluster. For more information, see the module documentation.

Documentation Changes

  • Update the Account setup page which explains how to configure your admin user
  • Update the clusters section on how to configure flow_logs and cloudtrail modules

@jacknagz jacknagz added this to the 1.4.0 milestone Jun 27, 2017
Copy link
Contributor

@ryandeivert ryandeivert left a comment

Choose a reason for hiding this comment

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

Some comments

@@ -352,6 +352,32 @@ def generate_cloudtrail(cluster_name, cluster_dict, config):
"""
modules = config['clusters'][cluster_name]['modules']
cloudtrail_enabled = bool(modules['cloudtrail']['enabled'])
existing_trail_default = False
existing_trail = modules['cloudtrail'].get('existing_trail', existing_trail_default)
is_global_trail_default = True
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'm just not seeing it elsewhere, but it looks like existing_trail_default and is_global_trail_default are just booleans and only used to hold default values for the .get() calls. Can we just place the boolean value directly in the get for brevity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, they're just booleans. I defined them as variables to be really explicit about what the defaults are for these options.

}
if not set(event_pattern.keys()).issubset(valid_event_pattern_keys):
LOGGER_CLI.error('Invalid CloudWatch Event Pattern!')
sys.exit(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably start returning a value in places like this (maybe just a simple bool == False, or a more comprehensive solution would be returning a non-zero error number) that we could check up the call stack and exit on error. It would avoid having sys.exit(1) calls scattered about the CLI and could allow for us to start using useful exit codes for certain errors (that are not 1). Not a necessary change now, but something to keep in mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I'll make some changes

config['global']['account']['prefix']),
'existing_trail': existing_trail,
'is_global_trail': is_global_trail,
'event_pattern': json.dumps(event_pattern)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we want event_pattern to be a json string within a dictionary as opposed to just another python dict? I assume this has something to do with the config stuff below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jacknagz
Copy link
Contributor Author

PTAL @ryandeivert, tested all CLI commands by bringing up a test cluster, deploying, and destroying

Copy link
Contributor

@ryandeivert ryandeivert left a comment

Choose a reason for hiding this comment

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

Liking this direction a lot - a few comments in-line.

@@ -303,6 +316,8 @@ def generate_kinesis(cluster_name, cluster_dict, config):
's3_logging_bucket': logging_bucket
}

return True
Copy link
Contributor

Choose a reason for hiding this comment

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

@jacknagz in a handful of these functions it looks like we return True and there's really no possibility of the function returning a falsey value. Am I overlooking something? If that's the case, there's not much benefit to having a check for the return value for these function calls.

That said, I do see a few functions below that can return False, so it definitely applies some places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm doing it for consistency, this could change in the future as we add more checks for validity

@@ -87,7 +89,7 @@ def terraform_check():
prereqs_message = ('Terraform not found! Please install and add to '
'your $PATH:\n'
'\t$ export PATH=$PATH:/usr/local/terraform/bin')
run_command(['terraform', 'version'],
return run_command(['terraform', 'version'],
Copy link
Contributor

@ryandeivert ryandeivert Jun 27, 2017

Choose a reason for hiding this comment

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

I think the formatting/indent here got messed up when the return was added. (meaning in the following 2 lines, not this one).

@coveralls
Copy link

coveralls commented Jun 27, 2017

Coverage Status

Coverage remained the same at 79.307% when pulling 61d5a13 on jacknaglieri-cloudtrail-patterns into 2abbcb3 on master.

@airbnb airbnb deleted a comment from coveralls Jun 27, 2017
@airbnb airbnb deleted a comment from coveralls Jun 27, 2017
@jacknagz jacknagz merged commit eaa76bb into master Jun 27, 2017
@jacknagz jacknagz deleted the jacknaglieri-cloudtrail-patterns branch June 27, 2017 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KMS permissions not included in documentation
3 participants