Policy-based control for cloud native environments
Empower your administrators with flexible, fine-grained control across your entire stack.
Empower your administrators with flexible, fine-grained control across your entire stack.
Open Policy Agent (OPA) is a general-purpose policy engine with uses ranging from authorization and admission control to data filtering. OPA provides greater flexibility and expressiveness than hard-coded service logic or ad-hoc domain-specific languages. And it comes with powerful tooling to help you get started.
Here are just a few examples of what you can do with OPA:
# Kubernetes Admission Control Invariants package kubernetes.invariants import data.kubernetes.ingresses import data.kubernetes.namespaces # --------------------------------------------------------------------- # Ingress Invariants # Generates a list of non-compliant ingresses identified by `namespace` # and ingress specification `name`. violations[{ "namespace": namespace, "name": name, "message": "ingress hostname must match whitelist" }] { ingress := ingresses[namespace][name] host := ingress.spec.rules[_].host not contains(whitelist[namespace], host) } # Generates a list of allowed hostnames per namespace. whitelist[namespace] = hosts { obj := namespaces[namespace] annotations := obj.metadata.annotations annotation := annotations["acmecorp.com/hostname-whitelist"] hosts := json.unmarshal(annotation) } # --------------------------------------------------------------------- # Helpers # Checks if `list` includes an element matching `item`. contains(list, item) { list[_] = item }
# Fine-Grained SSH Authorization package ssh.fine_grained # Allow users in the "dev" organization to SSH into hosts if they # possess a certificate proving they are assigned to an application # running on the host. allow { # Extract the X.509 certificate provided in the policy query. certs := crypto.x509.parse_certificates(input.certificates) # Check that the user is part of the "dev" organization for an app # running on this host. certs[i].Subject.Organization[j] == data.host_info.apps[_] certs[i].Subject.OrganizationalUnit[j] == "dev" # Check the certificate's validity period at the time of login. time.now_ns() >= certs[i].NotBefore time.now_ns() <= certs[i].NotAfter }
# Partial Evaluation package app.filtering # --------------------------------------------------------------------- # Data Filtering # Allow users to see their own posts. posts[post] { post := data.posts[_] post.owner = input.subject.name } # Allow users to see posts from their own department # that they have sufficient clearance for. posts[post] { post := data.posts[_] post.department = input.subject.department post.security_level <= input.subject.clearance_level } # Example Output: # # Conditions (1) # -------------- # data.posts[x].owner = "bob" # # Conditions (2) # -------------- # data.posts[x].department = "ops" # data.posts[x].clearance_level <= 3