Riffdog Terraform scanner - finding 'things' in the Real World (aka AWS) which Terraform didn't put there.

Overview

riffdog

Riffdog Terraform / Reality scanner - finding 'things' in the Real World which Terraform didn't put there.

This project works by firstly loading your terraform state files - not your terraform files, and building a memory object that represents what terraform thinks it has deployed. The second step is then to access your environment and actually look what is there, and it builds another memory object.

Then it compares the two, and looks for:

  • Things that TF put there, but arn't there
  • Things that are there, that TF doesn't know about

For this to work, you must install a resouce pack, for instance riffdog_aws

Command line vs Library

Riffdog is both a command line tool and a python library. The command line tool basically creates a config object and calls the scan method.

To install (for example with the AWS resources)

$ pip install riffdog[aws]

To run:

$ riffdog -b bucketname_containing_states

For full command line reference, please see the docs #FIXME - link to docs!

Light vs Full Scan mode

AWS and Terraform are very complex: for instance, a EC2 instance is a computer, a collection of network cards, volumes, etc. In 'light' mode, we do a high level scan to see if all the main components are there - in 'full' mode, it inspects all elements (as far as RiffDog is aware of, see below) - i.e. checks that all network cards, volumes, etc are mounted as intended.

Ignores

Its important to realise that not all infrastructure is deployed via TF - for instance auto scaling, or service discovery systems may be interacting with your infrastructure, and this is OK, but you don't want RiffDog raising alerts on those.

Caveats:

This is pretty much always a work under development, as AWS adds more features modules etc. The system is designed to be modular, but we're only able to keep up with modules that we use - so if you use a feature of AWS that we don't scan please feel free to add a module. If you need help, please contact us or file a ticket.

Testing

Automated testing of this system is quite difficult. Ultimatly these are here to make sure that changes to internal data structures do not break other functions (e.g. some data objects such as network interfaces are used by multiple features: both EC2 instances and Lambdas). The real test is whether it works against the current Terraform and AWS API's, not a snapshot from previous years.

  • Tests go into the tests folder,
  • Tox is used to make sure compatibility with various versions of python & libraries
Comments
  • Run tests on GitHub actions

    Run tests on GitHub actions

    Since I added a couple of tests, would be nice to actually run them presumably on GH actions if we can.

    Also, I used pytest because it's much nicer than nose (is nose even still used nowadays)?

    opened by dreynolds 2
  • Change the to_scan module process

    Change the to_scan module process

    This is an issue where new modules need to be added - but does it make sense to actually require this setting, i.e. shouldn't it be based on what modules there are in the discovery mode? And then allow (in future) config to --exclude particular modules (or white list), but by default use all available modules?

    enhancement question 
    opened by jmons 2
  • Dynamic Module Loading & Registration

    Dynamic Module Loading & Registration

    This comes with some notes, and items which might want to be changed:

    1. New 'resource' (was called modules) go into the resources folder. EAch file should contain One (or more) classes
    2. Should implement the Resource class - I've steered clear of "aws" terminology here so that in future resources can be for anything - I've used 'terraform' for the terraform and 'real' for things that actually exist (or don't)... (debate naming strategy)
    3. must decorate the class with the register decorator so that it links the state file to the class.

    Nothing else is needed - the class instance management is handled by the scanner, and it will find all classes in that folder.

    What I think is very much up for debate is this particular class interface - I don't think you can get away from the 'process state' (which is process an element in the state, not process the entire state file) being called multiple times, but perhaps the fetch_real_resources shouldn't take 'region' but a config, and in that config if its AWS it looks for aws_regions or something?

    from ..resource import Resource, register
    
    @register("aws-name-in-state-file")
    class MyResource(Resource):
        _local_real_things = {}
        _local_terraform_things = {} 
    
        def fetch_real_resources(self, region):
            # This may be called multiple times for each region in the scan list
            # i.e. append
            raise NotImplementedError()
    
        def process_state_resource(state_resource):
            # This function is called potentilly multiple times as each resource
            # is discovered by the state scanner i.e. append results to local store
            raise NotImplementedError()
    
        def compare(self, depth):
            # this function should be called once, take the local data and return
            # an array of result elements.
            raise NotImplementedError()
    

    More code cleanup is probably possible, I think I got all the debug entries into debug (don't try running with -vvv unless you're very brave (boto debug output becomes manic - fixing that requires a full logging config i.e. waiting for the configure file ticket).

    enhancement 
    opened by jmons 2
  • Fix `--exclude-resource` support and add `--include-resource` support

    Fix `--exclude-resource` support and add `--include-resource` support

    Fixes #45 If anything is in include-resource it completely overrides exclude-resource so it's like starting from a blank list.

    I went for --include-resource instead of --only so that the arguments are logically matched with --exclude-resource

    Happy to change if others disagree

    opened by dreynolds 1
  • Logging initialisation (First & Second Arg Parse)

    Logging initialisation (First & Second Arg Parse)

    Logging is not initialised until the Second argparse, which means logging in the initial import scan is impossible. This means exceptions in the import are completely silent and ignored.

    Some arguments need to be in both first and second - first to be parsed and second so the help works. Perhaps all core arguments?

    bug 
    opened by jmons 1
  • Framework to handle modules arguments

    Framework to handle modules arguments

    --region is really an aws argument - i.e. --aws_region but how does argparser (which hasn't had the module scanner run) know what the extra arguments are? Does it need to run twice, once before and one after loading?

    enhancement 
    opened by jmons 1
  • Adding basics for RDS Clusters (cluster, instances and param groups)

    Adding basics for RDS Clusters (cluster, instances and param groups)

    Implements https://github.com/jmons/riffdog/issues/17

    Added

    • RDS Cluster basics (cluster, instances, parameter groups.

    Fixed

    • Minor bug where the ResourceDirectory didnt have self in its str.
    • In order to support foldered module structure, the dynamic importing has changed a little.
    opened by Jamian 1
  • Documentation & Homepage revamp

    Documentation & Homepage revamp

    Giant homepage and docs revamp

    • making the home page more welcoming / project home page
    • added youtube video link (video needs review as well, see dm's)
    • added mailchimp (this may need a patch) for signup to news etc
    • added core team

    Then

    • fixed some of the help docs with some examples - because --help is quite good but brief, perhaps the command line reference morphs to being some tips and tricks type help? Don't want to really duplicate the wording of --help?
    • updated release notes to include the 0.1.0 release.
    opened by jmons 0
  • Initial command line tests using resource pack and module loader.

    Initial command line tests using resource pack and module loader.

    This is a relatively larger refactor

    1. It removes support for v3 state file (see #55 )
    2. It adds support for a file based state (and folder based state) - these don't have a named arguments but just go on the end of the command.
    3. it also adds support for the -b option to be a single folder or path e.g. -b bucketname/folder/ which speeds up dev/testing, especially with the --include-resource
    4. It fixes a bug in the alias - where before we had a bug that the --include-resource option did not apply to the scanning in state files, that fix introduced a new one where it excluded aliased. This fix now means that it will be included if the 'root' is in the list.

    In terms of testing, it now contains 2 state files, so when testing the core you can now do

    $ pip install -e tests/test_resource_pack
    $ riffdog -i test_resource_pack tests/test_state_files/
    

    The tox tests install the resource pack & then check that a scan finds the right items etc.

    opened by jmons 0
  • Bucket to Scan Hard Coded

    Bucket to Scan Hard Coded

    Looks like last merge we accidentally left in some code that was there to help with local devving. Flipping that back out (commenting it) and uncommenting the actual, release ready code that scans buckets dynamically.

    opened by Jamian 0
  • Revisit `--exclude` and create an `--only` option

    Revisit `--exclude` and create an `--only` option

    Using --exclude is more difficult now there are lots of resources - instead we should consider using an --only element to specify.

    I don't like the word --only though so feedback and ideas here appreciated.

    enhancement hot 
    opened by jmons 0
  • Proposal: Drop State file V3 support

    Proposal: Drop State file V3 support

    Whilst I added explicit support for V3 state files in 0.1.0, it seems that the structure of the individual states in the file are not compatible with V4- I had assumed they were because v4 states have schema_versions set to 0, which I assumed meant the state structure hadn't changed.

    But they have.

    In an upcoming PR, I have removed support for v3- explicitly with a warning.

    I think we need to set an overall output flag and change the table to indicate that there were states which look like tf states but we could not understand - but I think this ties into a statistics output so that a user knows what 'coverage' they are getting of their environment.

    documentation enhancement hot 
    opened by jmons 2
  • Dirty Reasons (not just a flag)

    Dirty Reasons (not just a flag)

    Implement a framework on the FoundItem (and then outputs) to store a Dirty Reason list, so that you know why a thing is dirty, not just given a flag.

    Consider output, and also perhaps guidance how to use it so outputs are concise.

    enhancement hot 
    opened by jmons 0
  • Investigate potential conflict of `depends_on` and `--exclude-resource`

    Investigate potential conflict of `depends_on` and `--exclude-resource`

    Consider the edge case:

    class Foo:
         ...
    
    class Bar:
        depends_on = [Foo]
        ...
    

    and then $ riffdog --exclude-resource Foo

    I think without checking that this means foo's real gets executed even though its states got ignored (?) (or it will error because Foo wasn't registered, not sure where the --exclude kicks in).

    question 
    opened by jmons 0
  • Config File Support

    Config File Support

    At the moment we're heading rapidly towards using just command line arguments, but I think we need to support a config file especially as we head towards more complex arguments such as AWS credentials etc.

    What do we want for this? YAML? (and then problems with yaml library imports - the pyyaml parser seems to have a lot of security patches which are mostly irrelevant in our case, but looks bad if we don't roll updates).

    enhancement 
    opened by jmons 1
  • Output to HTML

    Output to HTML

    It would be nice for this to have the option to generate a pretty output in HTML form. Useful if running this in an automated environment and you want to be able to link to a page/report. Something that is a bit more human friendly.

    One suggestion was to use Jinja and have it as optional?

    enhancement hot 
    opened by Jamian 2
Releases(0.1.0)
  • 0.1.0(Mar 2, 2020)

    Welcome to the beta release of Riffdog.

    To install this, please follow the guide - you will need at least one 'resource pack', and at the time of writing only the riffdog_aws resource pack exists.

    pip install riffdog[aws]

    Then to run:

    riffdog -b bucket_name_containing_states --show-matched

    Major changes:

    • The return data structure is radically different to before, which makes resource pack developers life easier.
    • Streamlined tabulated data outputs.
    • Introduced 'dirty' flag to indicate where resources exist, but do not match in some form of sub-data element.
    Source code(tar.gz)
    Source code(zip)
Owner
Riffdog
Community to support the riffdog app, riffdog plugins and associated repositories.
Riffdog
This is the repository for HalpyBOT, the Hull Seals IRC Chatbot Assistant.

HalpyBOT 1.4.2 This is the repository for HalpyBOT, the Hull Seals IRC Chatbot Assistant. Description This repository houses all of the files required

The Hull Seals 3 Nov 03, 2022
Messing around with GitHub API to look at omicron build times

gh-workflow-runs This is a very simple tool to dump out basic information about workflow runs for a GitHub repo. The structure is based on gh-subscrip

David Pacheco 1 Nov 30, 2021
Reddit bot that uses sentiment analysis

Reddit Bot Project 2: Neural Network Boogaloo Reddit bot that uses sentiment analysis from NLTK.VADER WIP_WIP_WIP_WIP_WIP_WIP Link to test subreddit:

TpK 1 Oct 24, 2021
A high level library for building Discord bots.

Qord A high level library for building Discord bots. 🚧 This library is currently in development. Questions that you are having What is this? This is

Izhar Ahmad 16 May 14, 2022
WIOpy - Walmart Affiliate API Python wrapper

WalmartIO Python Wrapper - WIOpy A python wrapper for the Walmart io API. Only s

6 Nov 14, 2022
A modular telegram Python bot running on python3 with an sqlalchemy database.

Saber A modular telegram Python bot running on python3 with an sqlalchemy database. Originally a marie fork - Saber has evolved further and was built

ZERO • アクバル . 4 Nov 09, 2021
This is Source Code of PdiskUploaderBot

PdiskUploaderBot This is the source code of PdiskUploaderBot. And the developer of this bot is AJTimePyro, His Telegram Channel & Group. You can use t

Abhijeet 8 Oct 20, 2022
Simple Telegram Bot To Get Feedback from users & Some Other Features

FeedbackBot Simple Telegram Bot To Get Feedback from users & Some Other Features. Features Get Feedback from users Reply to user's feedback Customisab

Arun 18 Dec 29, 2022
A fork of discord.py meant to replace it

Texus A modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python. Key Features Modern Pythonic API using async and

Texus 1 Nov 18, 2021
Deploy a STAC API and a dynamic mosaic tiler API using AWS CDK.

Earth Observation API Deploy a STAC API and a dynamic mosaic tiler API using AWS CDK.

Development Seed 39 Oct 30, 2022
Python client for the Datadog API

datadog-api-client-python This repository contains a Python API client for the Datadog API. The code is generated using openapi-generator and apigento

Datadog, Inc. 58 Dec 16, 2022
DSAIL repos - DSAIL Repository Template

DSAIL Repository Template DSAIL @ KAIST . ├── configs ('--F', help='for configur

yunhak 2 Feb 14, 2022
PyMusic Player is a music player written in python3.

PyMusic Player is a music player written in python3. It harvests r

PythonSerious 2 Jan 30, 2022
An powerfull telegram group management anime themed bot.

ErzaScarlet Erza Scarlet is the female deuteragonist of the anime/manga series Fairy Tail. She is an S-class Mage from the Guild Fairy Tail. Like most

ꜱōʜᴇʀᴜ ᴋāɴ (AKA) ꜱᴏʜᴀɪʟ ᴋʜᴀɴ 2 May 19, 2022
This software's intent is to automate all activities related to manage Axie Infinity Scholars. It is specially aimed to mangers with large scholar roasters.

Axie Scholars Utilities This software's intent is to automate all activities related to manage Scholars. It is specially aimed to mangers with large s

Ferran Marin 153 Nov 16, 2022
Erhalten Sie wichtige Warnmeldungen des Bevölkerungsschutzes für Gefahrenlagen wie zum Beispiel Gefahrstoffausbreitung oder Unwetter per Programmierschnittstelle.

nina-api Erhalten Sie wichtige Warnmeldungen des Bevölkerungsschutzes für Gefahrenlagen wie zum Beispiel Gefahrstoffausbreitung oder Unwetter per Prog

Bundesstelle für Open Data 68 Dec 19, 2022
CRUD database for python discord bot developers that stores data on discord text channels

Discord Database A CRUD (Create Read Update Delete) database for python Discord bot developers. All data is stored in key-value pairs directly on disc

Ankush Singh 7 Oct 22, 2022
:lock: Python 2.7/3.X client for HashiCorp Vault

hvac HashiCorp Vault API client for Python 3.x Tested against the latest release, HEAD ref, and 3 previous minor versions (counting back from the late

hvac 1k Dec 29, 2022
SpamBot.py allows you, to spam other Chat Partners etc.

SpamBot -SpamBot.py allows you, to spam other Chat Partners etc. Install If you downloaded it yet, you have to install "requirements.txt" write the di

Marco 1 Jan 16, 2022
Ap lokit lokit

🎵 FANDA MUSIC BOT Fanda Music adalah proyek bot telegram yang memungkinkan Anda memutar musik di obrolan suara grup telegram. a href="https://www.py

Fatur 2 Nov 18, 2021