GithubHelp home page GithubHelp logo

isabella232 / gatekeeper-2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wish/gatekeeper

0.0 0.0 0.0 40 KB

Verify Kubernetes configuration files against custom rules

License: Apache License 2.0

Makefile 0.33% Go 91.76% Dockerfile 1.84% Jsonnet 6.07%

gatekeeper-2's Introduction

Gatekeeper

Build Status Docker Repository on Quay

gatekeeper is a tool for verifying Kubernetes configuration files against custom rules defined in a Jsonnet ruleset. It will return a list of errors it encounters while verifying the files.

$ gatekeeper -r sample/ruleset.jsonnet sample/service
1. Broken LT() rule: 
{
	"actual": 24,
	"expected": 20,
	"key": "spec.replicas",
	"path": "sample/service/sample.json",
	"rule_type": "allow"
}

Building

First install dep and run dep ensure. Then run make to build a binary inside $GOPATH/bin.

$ dep ensure
$ make

Ruleset Layout

Gatekeeper requires a jsonnet file that defines the rules you want to apply. The jsonnet file must be in the format of:

{
    ignore: ["somefile.yaml"],
    rules: [
        {
            regex: "file.json",
            kind: "Deployment",
            type: "allow",
            ruleTree: {
                ...
            }
        },
        ...
    ]
}

ignore contains filenames that gatekeeper will ignore.

rules is an array of rule objects. Each rule object has 4 required keys.

regex matches the files that this rule will apply to. gatekeeper will check the regex on the filename of each file.

kind matches the kind of resources that this rule will apply to.

type can be either allow or deny. An allow rule will pass if no functions are broken. A deny rule will produce an error if any of the functions pass.

ruleTree defines the actual content of the rule in a json object. It follows the same layout as the resource kind that it's applied to. You can use ruleset functions to check the values of specific fields in the resource. See the sample ruleset.jsonnet for examples.

Ruleset Functions

There are a variety of functions you can use in you ruleset jsonnet to check values in your Kubernetes configuration:

LT()

LT() is used to verify that the field in the configuration is less than the specified number

...
    spec: {
        replicas: LT(3)
    }
...

GT()

GT() is used to verify that the field in the configuration is greater than the specified number

...
    spec: {
        replicas: GT(0)
    }
...

EQ()

EQ() is used to verify that the field in the configuration is equal to the specified value

...
    metadata: {
        name: EQ("service")
    }
...

AND()

AND() is used to verify that both of its child functions are valid.

...
    spec: {
        replicas: AND(GT(0), LT(30))
    }
...

OR()

OR() is used to verify that at least one of its child functions are valid

...
    metadata: {
        name: OR(EQ("serviceA"), EQ("serviceB"))
    }
...

NOT()

NOT() is used to verify that its child functions is not valid

...
    spec: {
        replicas: NOT(EQ(7))
    }
...

TAG()

TAG() is used to verify that all fields in the configuration with the same tag in their TAG() function has the same value

...
    metadata: {
        labels: {
            name: TAG("namespace")
        },
        name: TAG("namespace") 
    }
...

PATH()

PATH() is used to verify that the field in the configuration is equal to the section of the file path indicated by the index.

Verifying file /path/to/file:

...
    metadata: {
        name: PATH(0) //verify name == "file",
        name2: PATH(1) //verify name2 == "to",
        name3: PATH(2) //verify name3 == "path"
    }
...

Contributing

If you would have any suggestions, improvements, or bugs please open issues here. If you would like to contribute to gatekeeper, please make a pull request.

gatekeeper-2's People

Contributors

jacksontj avatar luoyang9 avatar svrana avatar tvi 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.