GithubHelp home page GithubHelp logo

open-policy-agent / gatekeeper Goto Github PK

View Code? Open in Web Editor NEW
3.5K 64.0 725.0 141.99 MB

๐ŸŠ Gatekeeper - Policy Controller for Kubernetes

Home Page: https://open-policy-agent.github.io/gatekeeper/

License: Apache License 2.0

Makefile 1.17% Go 93.88% Shell 2.64% Dockerfile 0.28% Open Policy Agent 0.46% Smarty 0.54% JavaScript 0.59% CSS 0.25% Python 0.20%
cncf opa kubernetes policy-engine hacktoberfest gatekeeper policy security admission mutation

gatekeeper's People

Contributors

acpana avatar becky-hd avatar ctab avatar davis-haba avatar dependabot[bot] avatar fedepaol avatar fish-pro avatar github-actions[bot] avatar grosser avatar jaydipgabani avatar jdolce avatar jeffa5 avatar juliankatz avatar lachie83 avatar luckoseabraham avatar maxsmythe avatar mozillazg avatar mrueg avatar nilekhc avatar prachirp avatar ritazh avatar rite2nikhil avatar robertsheehy-wf avatar salaxander avatar sathieu avatar shomron avatar sozercan avatar stek29 avatar tsandall avatar yiqigao217 avatar

Stargazers

 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

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

gatekeeper's Issues

Create documentation aimed at "template authors"

We need docs that explain how people can extend Gatekeeper with their own templates. For example, we need to explain:

  • Deny rule semantics
  • The structure of the input document
  • How to use JSON Schema to define constraint parameter schema
  • How to write policies that depend on inventory
  • Difference between the raw Rego and template kinds
  • How to upstream templates
  • How build-to-yaml process works
  • How to debug Rego when constraints aren't matching

Nondescriptive status messages when pods are rejected by GK constraints

Suggestion: GK should automatically point to the name of the Constraint Template that caused the deployment to fail, instead of relying on the user to know to provide that information in the Rego in the CT.

Without the user writing a descriptive message in the CT in the rego field themselves, GK does not provide a status message that points to which constraint caused the pod to be rejected.

For example, if this is the Rego written in the CT:

rego: |
  package dumpall

  deny[{"msg": msg}] {
    msg := sprintf("%v", ["bad"])
  }

Then the status message displays admission webhook "validation.gatekeeper.sh" denied the request: bad, providing the user with no information about which constraint stopped the pods from being created.

The message should instead be something like admission webhook "validation.gatekeeper.sh" [CONSTRAINT_TEMPLATE_NAME] denied the request: bad.

Use https endpoint for opa service

Currently the kube-policy-controller uses the http endpoint of OPA service as it is running as a side car
If the webhook is run as a separate POD it is important to use https endpoint of Open Policy agent.

Watch Manager Freezes

On a failed watch manager restart, the manager is frozen until the template roster changes again, triggering a new restart.

We should have a mechanism to self-heal without nudging.

Design policy instantiation and parameterization

The policy library includes a collection of reusable policies that a user may choose from and instantiate with given parameters. We need to design how those policies, instances, and parameters are represented and loaded into OPA so it can make an admission control decision.

Manager app doesn't listen on port specified in installation instructions

It looks like the manager app no longer listens on port 9876 as specified in the installation instructions as part of the deploy-all.sh. Ref https://github.com/open-policy-agent/gatekeeper/blob/master/deploy/kpc.yaml#L124

A deeper look at the code reveals a default of port 7925 in the addr flag, however this isn't used - https://github.com/open-policy-agent/gatekeeper/blob/master/pkg/standalone/server.go#L16

Finally it looks like the code is listening on the default http and https ports
https://github.com/open-policy-agent/gatekeeper/blob/master/pkg/standalone/server.go#L97-L104
https://github.com/open-policy-agent/gatekeeper/blob/master/pkg/standalone/server.go#L107-L120

What is the correct configuration here? Please update the docs to reflect the decision. As a work-around I simply set the following port to 443 on Ref https://github.com/open-policy-agent/gatekeeper/blob/master/deploy/kpc.yaml#L124

cc @rite2nikhil

Document migration guide for existing OPA admission policy users

As part of the documentation effort, we need to put together a migration guide that OPA users can follow to move from their existing OPA admission policies to gatekeeper. Non-comprehensive list of items to consider:

  • Top-level rules to expose (previously users had to implement boilerplate AdmissionReview response rule, now they implement a set of deny rules)
  • K8s context layout changes
  • Patch vs. deny

We also need to document unsupported features in the MVP like support for arbitrary external context.

Support for Authorization Module Webhook mode

Hi,

I'm not sure if it makes sense considering the current scope of the policy manager, but maybe it would be a good idea if the policy manager is also usable as Authorization Module Webhook.

audit is returning empty resource

Expected:

{
  "message": "total violations:1",
  "violations": [
    {
      "id": "ingress-host-fqdn",
      "resource": {
        "kind": "ingresses",
        "namespace": "qa",
        "name": "ingress-bad"
      },
      "resolution": {
        "message": "invalid ingress host fqdn \"acmecorp.com\""
      }
    }
  ]
}

Actual:

{
  "message": "total violations:1",
  "violations": [
    {
      "id": "ingress-host-fqdn",
      "resource": {},
      "resolution": {
        "message": "invalid ingress host fqdn \"acmecorp.com\""
      }
    }
  ]
}

how to unit test with kubernetes policies

reading the documentation it is clear that policies for kubernetes starts with the following:

deny[{
    "type": "always",
    "resource": {"kind": kind, "namespace": namespace, "name": name},
    "resolution": {"message": "test always violate"},
}]

when a policy with that header is run in a unit test it gets an error saying that the kind, namespace and name are not defined. here is a more complete example:

deny[{
	"id": "unreadable secret",
	"resource": {"kind": "secrets", "namespace": "secret_namespace", "name": name},
	"resolution": {"message": "Your're not allowed to see secret in the namespace 'secret_namespace'"},
}] {   
    input.spec.group[_] = "developers"
    input.spec.resourceAttributes.verb = "get"
}

and a test:

package authorization

test_sa_allow {
    not deny with input as {
        "apiVersion": "authorization.k8s.io/v1beta1",
        "kind": "SubjectAccessReview",
        "spec": {
            "resourceAttributes": {
            "namespace": "secret_namespace",
            "verb": "get",
            "group": "core",
            "resource": "secrets",
            "name": "ciao"
            },
            "user": "default",
            "group": [
            "serviceacconts"
            ]
        }
    }
}

If I run this test I get the following error:

1 error occurred: unreadable_secrets.rego:11: rego_unsafe_var_error: var name is unsafe

how can I fix this issue?
Also can you provide a bit of explanation of what is going on from a language syntax perspective? I don't understand what the deny header section really represents.

Thanks
Raffaele

Single policy rule for Mutation and Validation

In current design there are two separate calls for validation and mutation. This is not ideal as

  1. in some cases the API server will not have proximity with the web hooks (for instance on a public network),
  2. validation will fail if the object is not mutated
  3. Policy owner and user have to define two separate ruled for validation and mutation

Can the policies be defined in a manner that they more desired state instead of separate mutation and validation policies and mutation can be indirectly inferred ?

Design for Policy management

Policy are reusable documents and will see contribution from community. Currently these policies are part of this reop in the policy folder and are small in number, but we envision this to be a larger list, Here are some of the thoughts for this

  • Have a separate repo of policy
  • Have a validation tool and a policy creation too in addition to kubernetes controller validating crd as a admission controller
  • Using Helm as the deployment vehicle for policies.
  • The other area of this design is how can these policies be installed on the cluster.
    Do we need a service that can install the policies.

Failure to install on 1.14.2 using Kind

Expected Behavior

Installing Gatekeeper on a new v1.14.2 cluster would succeed

Actual Behavior

Installation fails with the following error:

error: SchemaError(io.k8s.api.core.v1.VolumeDevice): invalid object doesn't have additional properties

Steps to Reproduce the Problem

  1. Provision a Kind cluster using the latest images:
$ kind create cluster --name gatekeeper --wait 200s
$ export KUBECONFIG=(kind get kubeconfig-path --name="gatekeeper")
  1. Install Gatekeeper according to the README instructions:
$ kubectl apply --filename https://raw.githubusercontent.com/open-policy-agent/gatekeeper/master/deploy/gatekeeper-constraint.yaml
error: SchemaError(io.k8s.api.core.v1.VolumeDevice): invalid object doesn't have additional properties

Note that ignoring validation will install the resources:

$ kubectl apply --validate=false --filename https://raw.githubusercontent.com/open-policy-agent/gatekeeper/master/deploy/gatekeeper-constraint.yaml
namespace "gatekeeper-system" created
clusterrolebinding.rbac.authorization.k8s.io "manager-rolebinding" created
clusterrole.rbac.authorization.k8s.io "manager-role" created
statefulset.apps "gatekeeper-controller-manager" created
service "gatekeeper-controller-manager-service" created
secret "gatekeeper-webhook-server-secret" created
validatingwebhookconfiguration.admissionregistration.k8s.io "validation.gatekeeper.sh" created
customresourcedefinition.apiextensions.k8s.io "constrainttemplates.templates.gatekeeper.sh" created
customresourcedefinition.apiextensions.k8s.io "configs.config.gatekeeper.sh" created

Additional Info

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.11", GitCommit:"637c7e288581ee40ab4ca210618a89a555b6e7e9", GitTreeState:"clean", BuildDate:"2018-11-26T14:38:32Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.2", GitCommit:"66049e3b21efe110454d67df4fa62b08ea79a19b", GitTreeState:"clean", BuildDate:"2019-05-17T00:58:35Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}
$ kind version
v0.3.0

RFP - kubernetes-policy-controller design documents

Hi OPA community members. We would like to solicit design proposals from the community for projects that aim to solve the same problem AND/OR function in a similar manner to this project by using OPA to implement desired policy via the Kubernetes API.

The goal is to agree on a design as a community before proceeding with project milestones and/or any further implementation.

Please comment on this issue and attach any design documentation and/or other fodder. We will then review and schedule time for you to present at a community meeting.

@timothyhinrichs will provide further guidance on some areas to include in your proposal.

Feel free to comment should you have any further questions.

cc @timothyhinrichs @tsandall @rite2nikhil @maxsmythe

Allow Per-Request Dumping

Trace dumps specified in the Config resource should also provide the option to dump the state of OPA into the logs

something like dump: true/false

Add E2E tests for basic scenarios

Define the e2e test matrix and implement. The design should be such that new scenarios can be added in a repeatable manner (without too much effort)

question on design: why aren't requests passed as input?

From the Open Policy Agent documentation, it looks like the policy evaluation model is that there are two main packages for rules and facts: data and input. Policies and facts are stored in the data package and when a new request comes it is passed in the input package.
Kubernetes-policy-controller seems to be taking another approach. It parses the incoming request (whether it is authorization or admission) puts it in the data.kubernetes.type.namespace.name.resource structure.
The request ends up being mixed with the other resources that have been loaded by kube-mgmt.
There is, though, a significant semantic difference between the resources already present in etcd and a request referencing a resource that may or may not exist, so perhaps a separation would be more natural and easy to understand.

Why was it decided not to use the standard approach?

I also believe that the current approach has a flaw, consider this policy:

package admission
import data.k8s.matches

deny[{
	"id": "ceph-name",
	"resource": {
		"kind": kind,
		"namespace": namespace,
		"name": name,
	},
	"resolution": {"message": "You are not allowed to objects with the name `ceph`"}
}] {
	matches[[kind, namespace, name, resource]]
    resource.metadata.name = "ceph"
} 

We want to prevent the admission of any new resource named ceph.

Consider what would happen if we turned this on on a cluster that has already some resources named ceph (assume kube-mgmt is replicating all the resources for simplicity of the model). This policy would always fail, no matter the name of the new resource, a match would always be found....

enhancement: clearer ConstraintTemplate creation error messages?

Here's a modified version of the tutorial constraint template (K8sRequiredLabels) I tried to apply recently that just denies every request:

apiVersion: templates.gatekeeper.sh/v1alpha1
kind: ConstraintTemplate
metadata:
  name: dumpall
spec:
  crd:
    spec:
      names:
        kind: DumpAll
        listKind: DumpAllList
        plural: dumpall
        singular: dumpall
targets:
 - target: admission.k8s.gatekeeper.sh
   rego: |
        package dumpall
        deny[{"msg": msg}] {
           msg := sprintf("%v", [input])
        }

Upon a kubectl apply, the response is:
Error from server (ConstraintTemplate must specify one target): error when creating "ct-test.yaml": admission webhook "validation.gatekeeper.sh" denied the request: ConstraintTemplate must specify one target

This makes sense once I noticed that targets: is indented outside of the spec, but it took quite a while to identify that. Perhaps GK could warn or print a more specific error when it doesn't find a spec.targets in a ConstraintTemplate?

CRD based policies

There are two types of policies Deny and Patch which are currently configured as Config Maps and are Posted to OPA, Making policy CRD, This will help prevent deletes of policies on the cluster with CRD using RBAC. The work will be in kube-mgmt which is currently being tracked by open-policy-agent/kube-mgmt#16

Help us rename the kubernetes-policy-controller project

Hi OPA community members! We are looking to enlist your help in finding a new name for this project.

Background:
Given that this project has recently been donated to OPA, the project community through it might make for an apt time to rename this project. Other reasons for a rename include verbosity, and project purpose may be a little vague with the current name.

How:
Feel free to make suggestions on this issue based on the following criteria:

English word: No made-up terms or acronyms please. The name should be discoverable in an English dictionary.
Must convey project intent: Please submit constructive names that relate and convey the purpose of this project.

Suggestions from this issue will be tallied and presented before the community meeting before a final decision is made. Please note that final name selection may require legal and other logistical checks.

When
Please submit your ideas BEFORE Monday, Jan. 28th. Thank you!

Thanks!
Credit to @ncdc via vmware-tanzu/velero#1122 for inspiration on renaming process.

Helm chart for deployment?

๐Ÿ‘‹ thanks for sharing this project. I haven't looked the deployment script into details yet but is there any plan and/or is it possible to get a helm chart for it?

Release process considerations

Would like to have a discussion on the build and release process for the project. Currently, there are several areas for which enhancements can be made which will spur additional contribution and overall adoption:

The primary area of concern is that the image in DockerHub has a finite number of tags available and the most recent version is multiple months old and is out of sync.

Areas include:

  1. Creation of a release process
    1. Tags in git repository
    2. Tags in image registry
    3. Utilization of a latest tag
  2. Formal CI/CD to validate contributions

Make Authz as a separate repo

The proposal is to authz as a separate repo it case use the gatekeeper as a library and continue to use the same policy definitions.

This project has moved to use kube-builder and 'auth' enpoint is really running as a standalone server.

@sbueringer can you please share your thoughts on this issue.

Reconciliation of Synced Data

If we want to use freestanding OPA in the future, we will need to periodically reconcile cached constraint/constraint templates to account for the fact that the query engine and its interface may have separate lifecycles.

Document Request Tracing

Users can indicate they want a request to be traced via the Config resource. This should be document

Document overall architecture of Gatekeeper in markdown

Now that we've got design docs for Gatekeeper as a whole and the policy library, it feels like it's time to start moving that content out of Google docs and into a markdown file in the repository. This document will be useful for people who prefer a "top down" approach to learning about Gatekeeper as well as folks who want to find out more after kicking the tires with the quick start guide.

The initial version of the document should include content from:

The initial version should call out which areas are implemented today versus planned.

Create an audit method in the webhook service

Currently there are two methods supported namely validate and mutate.

This work is to provide a audit method with query parameter to filter on resource, namespace or name (or all (default)).

In addition to get the audit history which use kubernetes api to get the history of audit logs / metrics for all pass/ failed requests.

Note the work will also include the decision to make audit as a separate service from the web-hook (if needed based on performance and customer scenario)

gatekeeper-controller-manager-service is missing the selector

Expected:

apiVersion: v1
kind: Service
metadata:
  labels:
    control-plane: controller-manager
    controller-tools.k8s.io: "1.0"
  name: gatekeeper-controller-manager-service
  namespace: gatekeeper-system
spec:
  selector:
    control-plane: controller-manager
    controller-tools.k8s.io: "1.0"
  ports:
  - port: 443

Actual:

apiVersion: v1
kind: Service
metadata:
  labels:
    control-plane: controller-manager
    controller-tools.k8s.io: "1.0"
  name: gatekeeper-controller-manager-service
  namespace: gatekeeper-system
spec:
  ports:
  - port: 443

Results in error:

failed calling webhook "mutation.styra.com": Post https://gatekeeper-controller-manager-service.gatekeeper-system.svc:443/v1/admit?timeout=30s: dial tcp 10.0.69.83:443: connect: connection refused

Document getting started process with new model

We need to document the getting started process with the new model. The getting started guide should cover how users can:

  1. Install Gatekeeper in a Kubernetes cluster
  2. Discover templates available on the cluster
  3. Instantiate a constraint from a template
  4. Exercise the constraint via kubectl

Once users have completed the basic steps above they could be guided through the process of creating a new template for a common scenario and then running audit on the cluster to detect violations.

self-generated secret non-compliant

by convention, secret containing certificates in kubernetes should be of type "kubernetes.io/tls"
also the entries should be:

  • tls.key
  • tls.crt
  • ca.crt
    compliance helps interoperability with other certificate generation systems, such as for example cert-manager

Create documentation aimed at "gatekeeper admins"

We need to explain how people can manage Gatekeeper installations. Some things that come to mind:

  • How do you install and upgrade Gatekeeper (gotchas?)
  • How do you secure Gatekeeper itself?
  • RBAC configuration required to replicate K8s objects into OPA
  • How do you monitor Gatekeeper performance?
  • Debug FAQ for common problems (webhook misconfigured, network issues, logs, etc.)
  • How are webhook certificates provisioned (this is handled by kube-builder but that's an implementation detail from the admin's POV so we should cover it.)

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.