Git Product home page Git Product logo

deprecated-patrol-rules-aws's People

Contributors

alulsh avatar defvol avatar elfakyn avatar ianshward avatar k-mahoney avatar matiskay avatar npeternel avatar rclark avatar tmcw avatar zmully avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deprecated-patrol-rules-aws's Issues

Document

Fill out the readme

  • how to implement a function
  • pointer to streambot and how it is used
  • pointer to cfn-config
  • how to build template node build.js

Add scheduled state checks to IAM rules

Rules that check IAM for policies, roles, etc. should not only handle new events, but should check all existing policies on a schedule. This would catch events missed during a CW outage and resources created before IAM was actively monitored. This addition will also catch the "I'm going to fix it" ("oh sorry I forgot to fix it") type of process errors where the first alert on the event is immediately closed out, but then fix is never done.

Prefix parameters with namespace

Instead of a parameter being blacklistedResourcesArns in a rule config, the parameter could be Arns and then we have lambda-cfn auto prefix all parameters with the value of config.name. This helps avoid running into parameter name collisions.

cc @alulsh

SNS based rules

SNS based rules will allow easy integration of non-AWS event streams (e.g. Zapier) while maintaining a consistent Crowsnest develop/build/deploy experience. I think the easiest way to integrate this will be to create a new empty rule class snsRule.

Requirements for an SNS rule:

  • Preexisting SNS topic ARN (passed in as a template parameter)
  • lambda permission resource for SNS to invoke it
  • SNS subscription to the lambda (created by crowsnest-rules.js)

Since the SNS message is free form, I don't see any way to mimic the existing eventRule format, so the snsRule would act as simply as a flag to the rule builder and creation scripts. The message validation and parsing would be handled by the rule.fn.

I'm hesitant to have Crowsnest create and maintain the SNS topic, but I could see how it would be advantageous to have Crowsnest create and manage all AWS pieces of this security pipeline. The difficulty I think will be how rules are associated to topics. I can see scenario where all events from an external service end up in one topic, and we have multiple rules subscribed to the topic. @alulsh @ianshward any strong opinions as to whether or not SNS topics should be managed by the Crowsnest template?

Rough todo:

  • snsRule: spec and format
  • lambdaCfn.lambdaPermission: handle SNS invoke permissions
  • lambdaCfn.role: requires SNS permissions?
  • crowsnest-rule.js: subscribe lambdas to topics

SNS topic support

Add a catchall SNS topic and subscription to which lambda functions can report

Alarm on exposed access keys

Trusted Adviser is able to report whether an AWS Access Key has been exposed / publicly leaked. The announcement is here

This could be added to the trusted adviser rule, or, as its own rule, depending on whichever makes sense based on what the API looks like.

Rule to rule them all

Couldn't resist that title. We need a meta rule which checks everything about crowsnest is plugged together and working:

  • There's a subscription to the alarm topic
  • That subscription is the email address from the stack
  • The subscription is confirmed
  • CloudTrail is running
  • Optionally send out a heart beat to third party (ie., Librato)

Scheduled rules

A third class of rules, scheduled rules, will be useful for checks on a service that does not generate usable push events, as well as for periodic stateful checks.

Because there is no way to schedule a lambda via the API, either every scheduled rule will need manual intervention, or Crowsnest can create and maintain single timekeeper lambda which pushes messages to Crowsnest managed SNS topics. Rule lambdas would then be subscribed to the appropriate timekeeper SNS topic. The only manual setup would be when first creating a Crowsnest stack and setting the schedule on the timekeeper function. Since CWE schedules have a 5 min precision, the timekeeper could simply be set to run every 5 mins, and generate appropriate events. From looking at existing scheduled lambdas, the CWE scheduler appears to be fairly timely, so generating every 5, 15, 30 and hourly and daily queues should be reasonably robust.

Doh! This is possible via the API, though possibly undocumented. Create the CWE using ScheduleExpression instead of an event, then everything else is the same as an eventRule.

I think it would be good to only create unique schedules, since there is no point in creating an every 5 min CWE for every single scheduled rule. Have to noodle on that.

Examples of such rules:

  • All users in Github organization/team have MFA enabled?
  • Github SSH key lifetime/last rotation

Rough todo:

  • master timekeeper lamdba (just another rule?)
  • crowsnest-rule.js: check master timekeeper lambda is scheduled, create CWE */5 schedule, subscribe SNS topics to rule lambdas.
  • lambda-cfn.js: create SNS topics
  • scheduledRule spec and format

Are all error codes able to be ignored?

Here and in other rules, we ignore errors. This was added in order to ignore 403's since it means the API call was not successful and therefore never executed. However, there may be other error status codes that should not be ignored.

We could put an error handler function in lambda-cfn and rules could implement it, so that if we learn of new error codes that should be ignored, we can add them there.

Template messages

We may want a reusable way to template messages, so that they look good in PagerDuty. Thinking longish list of items that may have been found in violation of a rule, like a list of security groups and the instances they're attached to... We could balance this with an option to link off to a Sumologic search.

CloudWatch events rules

Figure out whether to use a custom lambda function, or direct API calls, to create the CloudWatch Events Rules.

TypeError: Cannot read property 'roleArn' of null

2016-02-23T19:00:29.385Z b4a30993-da5f-11e5-8fd2-374b32524e79 TypeError: Cannot read property 'roleArn' of null at LambdaContext.module.exports.fn (/var/task/rules/assumeRole.js:32:54) at Response.dynamodb.getItem.on.res.error.retryable (/var/task/node_modules/streambot/index.js:57:15) at Request. (/var/runtime/node_modules/aws-sdk/lib/request.js:354:18) at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:105:20) at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:77:10) at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:596:14) at Request.transition (/var/runtime/node_modules/aws-sdk/lib/request.js:21:10) at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12) at /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10 at Request. (/var/runtime/node_modules/aws-sdk/lib/request.js:37:9)

Pretty sure this was because I used a non existant role name

Trusted Advisor service limit check must be refreshed

I'm not sure if this a recent update to TA, but the service limit check needs to be refreshed before requesting the output of the check, else the rule will trigger until someone goes into the console and manually refreshes the check.

Because the refresh can take several minutes this be get interesting.

Alarm on SSL certificate expiration

The idea is to get an alarm before an SSL certificate in IAM expires. For some certificates I would want an alarm a month ahead of time, and others I would want a year ahead of time. The year use-case is for certificates that are pinned in mobile applications, and require updating and getting into new versions of mobile software so that clients update over the course of a year.

aws iam list-server-certificates

This will list certificates in IAM, along with an expiration time. Therefore, this rule will not be event-based. It will be schedule based, and could run once a day.

One question is how to support custom expiration times per-certificate, since the certificate list is going to vary per each person's / company's patrol installation. Maybe it could be a single parameter, in a format like:

certificate-name;1209600,other-certificate-name;31536000

where 1209600 is at how many seconds before expiration you want to be notified.

Allow defining additional CloudWatch alarms

Right now only an Errors and NoInvocations alarm are defined for all lambdas. It will be easy to let a rule define their own alarms by specifying some properties the rule's in module.exports.config.

Reorganization

@alulsh @zmully per talk today, we'll:

  • Rename crowsnest-public to crowsnest-rules-aws, which will just contain the AWS related rules and their tests.
  • Create a new repo called crowsnest, which will contain:
    • a cloudformation directory and template
    • package.json
    • documentation on what crowsnest is, how to use and extend it, and link to:
      • other public repos. containing rules
      • lambda-cfn and the rules spec.
    • the cloudformation template will include rules from crowsnest-rules-aws and maybe crowsnest-rules-github
  • One more repo which we have and will use as our own internal version of this crowsnest repo and which will stay private, which is where we'll handle any necessary private issue tracking, and manage our own cloudformation template with the rules - coming from public repositories - which we want to activate and run on our service.
  • lambda-cfn will contain docs on how to use lambda-cfn, how to write a rule

TypeError: Cannot read property 'policyDocument' of null

On the blacklisted resources rule:

2016-02-22T05:23:58.912Z 79a4516b-d924-11e5-8af8-d74844b07e29 TypeError: Cannot read property 'policyDocument' of null at LambdaContext.module.exports.fn (/var/task/rules/blacklisted_resources.js:41:48) at Response.dynamodb.getItem.on.res.error.retryable (/var/task/node_modules/streambot/index.js:57:15) at Request. (/var/runtime/node_modules/aws-sdk/lib/request.js:354:18) at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:105:20) at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:77:10) at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:596:14) at Request.transition (/var/runtime/node_modules/aws-sdk/lib/request.js:21:10) at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12) at /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10 at Request. (/var/runtime/node_modules/aws-sdk/lib/request.js:37:9)

Fix blacklisted resources subject truncation, and tests

SNS message subject is limited to 100 characters. To get around this for now, i've done a7a97c5

We may not be able to put back the detail in the subject, but the tests should be improved to check that the correct resources were matched in the message body.

Convert blacklisted IAM actions rule

Convert blacklisted IAM actions rule to lambda. I'm thinking to change up the behavior, so that it is like:

  • Must pass explicit list of blacklisted resources, so, not iam:*, but, iam:foo, iam:bar, iam:etc.
  • If a policy is created which has iam:*, then since iam:foo was passed in as a parameter, this will match iam:*
  • As for actions on particular resources, this should be dealt with in #13

Notify when user logs in to AWS console from a new device

It's a industry-wide practice to send an email to a user when a login is made from a unknown device.

A PoC would consist of a lambda function that parses console.login events and matches the user-agent against a database.

Additional parameters for notifying a slack channel or super-admins group could be useful too.

cc: @ianshward @zmully

Update .eslintrc

As @k-mahoney suggest, It would be great to update the .eslintrc file to

module.exports = {
  'env': {
    'node': true,
    'es6': true
  },
  'rules': {
    'quotes': [2, 'single', {'avoidEscape': true, 'allowTemplateLiterals': true}],
    'indent': ['error', 2],
    'no-multi-spaces': [2],
    'no-unused-vars': [1],
    'no-mixed-spaces-and-tabs': [2],
    'no-underscore-dangle': [2],
    'no-loop-func': [2],
    'handle-callback-err': [2],
    'space-unary-ops': [2],
    'space-in-parens': ['error', 'never'],
    'space-before-function-paren': ['error', 'never'],
    'no-trailing-spaces': [2],
    'no-tabs': [2],
    'new-cap': [2],
    'block-spacing': ['error', 'always'],
    'no-multiple-empty-lines': [2],
    'semi': ['error', 'always']
  }
};

Notify when a user signs in far from home

Notify user and a sec group, if my account signs in far away from my last login (e.g. different country, city, 500KM away from home). This could be a sign that an account has been compromised. Potential false positives for users using a VPN, but IMO this would be a small number of users.

This ticket share some ideas: #79

Rule deletion

The crowsnest-rules.js needs a --delete option to remove the ruleset if the main Crowsnest stack is deleted.

State storage

Provide a generic interface for state storage:
Possible backends:

  • DynamoDB
  • SimpleDB
  • S3 files

Possible state usage patterns:

  • compare and insert: if new state != oldstate create new record with new state
  • compare and update: if new state != oldstate, upsert
  • state ring buffer: only keep X recent states
  • state change ring buffer: only keep X recent state changes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.