Giter Site home page Giter Site logo

sentinel-template-terraform-main's Introduction

sentinel-template-terraform

Run Sentinel unit tests

Sentinel starter repo with directory structure and Sentinel functions built out intended to be shared directly with customers.

Sentinel CLI Tested: v0.18.11

Why this repository?

Often with TFE customers who are just getting started in TFE, governance is of interest but the focus is elsewhere. The attempted solution here is a quick repo we can drop into any customer environment, wire up to their TFE install, and leave them with a framework to work off of.

Todo:

  • Debug param?
  • function testing

Testing this repository

To run cloud specific tests, or develop policies, run the following:

cd ./policies/aws
sentinel test
sentinel test -run required-tags 
sentinel test -run required-tags -verbose

To run all the tests for all the policies, run the following:

# Without details
sentinel test ./policies/*        
# With details
sentinel test -verbose ./policies/*        

About this Repo

Initial bootstrap to get you going and includes 2 default policies for each cloud.

  • Required Tags
  • Restrict Instance Size

policies folder

Default policies associated with each of the top 4 clouds, includes tests.

policy-sets folder

3 Policy sets as an example:

  • Global - Meant for all Workspaces
  • Non-Production - Meant for Non-Production Workspaces
  • Production - Meant for Production Workspaces

By default each of these sets connects to all the default policies for all the clouds as advisory to not restrict any workflows.

functions folder

Common functions used by the default policies, these are required for the policy sets to operate in TFE.

Sentinel Policy Writing Flow

At a high level, the following is a good way to break down the process of creating/writing Sentinel Policies:

  1. Gather all resources or filter by resource type (i.e."aws_s3_bucket") and actions (i.e. "create", "update", "no-op").
  2. Evaluate resource attribute values by rule (inline) or function (from custom import).
  3. Return violation summary in main.

Treat a policy like a funnel by filtering out the things you don't care about and only focusing on the things that are important to evaluate. The single most important thing is ensuring that a policy is easy to read, understand, and doesn't require context switching when things break.

Sentinel Best Practices

Tests

  • Create all tests in a policies/<cloud>/test/<policy name>/ folder.
  • Tests should prefix with "test-"
  • Mocks should prefix with "mock-"

At the very least 1 positive and 1 negative test.

Clear Naming

  • enforce
    • cause (something) to happen by necessity or force.
    • enforce a pattern or strategy
  • require
    • need for a particular purpose.
    • require some property to be set or not set
  • restrict
    • put a limit on; keep under control.
    • restrict what values a property can or can not be set to

Format

Sentinel CLI doesn't have a recursive format, this will work:

find . -name "*.sentinel" -type f | xargs sentinel fmt

References

sentinel-template-terraform

sentinel-template-terraform-main's People

Contributors

kardell2006g avatar

Watchers

 avatar

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.