• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

ast/H27-Apr-2020-

build/H27-Apr-2020-

bundle/H27-Apr-2020-

cmd/H27-Apr-2020-

config/H27-Apr-2020-

cover/H27-Apr-2020-

dependencies/H27-Apr-2020-

docs/H27-Apr-2020-

download/H27-Apr-2020-

format/H27-Apr-2020-

internal/H27-Apr-2020-

loader/H27-Apr-2020-

logo/H03-May-2022-

metrics/H27-Apr-2020-

misc/syntax/H27-Apr-2020-

plugins/H27-Apr-2020-

profiler/H27-Apr-2020-

proposals/attic/H27-Apr-2020-

rego/H27-Apr-2020-

repl/H27-Apr-2020-

runtime/H27-Apr-2020-

server/H27-Apr-2020-

storage/H27-Apr-2020-

test/H27-Apr-2020-

tester/H27-Apr-2020-

topdown/H27-Apr-2020-

types/H27-Apr-2020-

util/H27-Apr-2020-

vendor/H03-May-2022-

version/H27-Apr-2020-

wasm/H03-May-2022-

watch/H27-Apr-2020-

.gitignoreH A D27-Apr-2020295

.go-versionH A D27-Apr-20206

.travis.ymlH A D27-Apr-20204.3 KiB

ADOPTERS.mdH A D27-Apr-20209.5 KiB

CHANGELOG.mdH A D27-Apr-202084.6 KiB

CODE_OF_CONDUCT.mdH A D27-Apr-2020137

CONTRIBUTING.mdH A D27-Apr-20205.1 KiB

DockerfileH A D27-Apr-2020581

GOVERNANCE.mdH A D27-Apr-20201.8 KiB

ISSUE_TEMPLATE.mdH A D27-Apr-2020110

LICENSEH A D27-Apr-202011.1 KiB

MAINTAINERS.mdH A D27-Apr-2020216

MakefileH A D27-Apr-20207.3 KiB

PULL_REQUEST_TEMPLATE.mdH A D27-Apr-20201.2 KiB

README.mdH A D27-Apr-202011.8 KiB

SECURITY.mdH A D27-Apr-202013 KiB

go.modH A D27-Apr-20201.7 KiB

go.sumH A D27-Apr-20208.8 KiB

main.goH A D27-Apr-2020517

netlify.tomlH A D27-Apr-2020552

tools.goH A D27-Apr-2020418

README.md

1# ![logo](./logo/logo-144x144.png) Open Policy Agent
2
3[![Slack Status](http://slack.openpolicyagent.org/badge.svg)](https://slack.openpolicyagent.org) [![Build Status](https://travis-ci.org/open-policy-agent/opa.svg?branch=master)](https://travis-ci.org/open-policy-agent/opa) [![Go Report Card](https://goreportcard.com/badge/open-policy-agent/opa)](https://goreportcard.com/report/open-policy-agent/opa) [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/1768/badge)](https://bestpractices.coreinfrastructure.org/projects/1768) [![Netlify Status](https://api.netlify.com/api/v1/badges/4a0a092a-8741-4826-a28f-826d4a576cab/deploy-status)](https://app.netlify.com/sites/openpolicyagent/deploys)
4
5The Open Policy Agent (OPA) is an open source, general-purpose policy engine that enables unified, context-aware policy enforcement across the entire stack.
6
7OPA is hosted by the [Cloud Native Computing Foundation](https://cncf.io) (CNCF) as an incubating-level project. If you are an organization that wants to help shape the evolution of technologies that are container-packaged, dynamically-scheduled and microservices-oriented, consider joining the CNCF. For details read the CNCF [announcement](https://www.cncf.io/blog/2019/04/02/toc-votes-to-move-opa-into-cncf-incubator/).
8
9## Want to learn more about OPA?
10
11- See [openpolicyagent.org](https://www.openpolicyagent.org) to get started with documentation and tutorials.
12- See [blog.openpolicyagent.org](https://blog.openpolicyagent.org) for blog posts about OPA and policy.
13- See [ADOPTERS.md](./ADOPTERS.md) for a list of production OPA adopters and use cases.
14- See [the Roadmap slides](https://docs.google.com/presentation/d/16QV6gvLDOV3I0_guPC3_19g6jHkEg3X9xqMYgtoCKrs/edit?usp=sharing) for a snapshot of high-level OPA features in-progress and planned.
15- Try [play.openpolicyagent.org](https://play.openpolicyagent.org) to experiment with OPA policies.
16- Join the conversation on [Slack](https://slack.openpolicyagent.org).
17
18## Want to get OPA?
19
20- See [Docker Hub](https://hub.docker.com/r/openpolicyagent/opa/tags/) for Docker images.
21- See [GitHub releases](https://github.com/open-policy-agent/opa/releases) for binary releases and changelogs.
22
23## Want to integrate OPA?
24
25* See
26  [![GoDoc](https://godoc.org/github.com/open-policy-agent/opa?status.svg)](https://godoc.org/github.com/open-policy-agent/opa/rego)
27  to integrate OPA with services written in Go.
28* See [REST API](https://www.openpolicyagent.org/docs/rest-api.html) to
29  integrate OPA with services written in other languages.
30
31
32## Want to contribute to OPA?
33
34* See [DEVELOPMENT.md](./docs/devel/DEVELOPMENT.md) to build and test OPA itself.
35* See [CONTRIBUTING.md](./CONTRIBUTING.md) to get started.
36* Use [GitHub Issues](https://github.com/open-policy-agent/opa/issues) to request features or file bugs.
37* Join bi-weekly meetings every other Tuesday at 10:00 (Pacific Timezone):
38    * [Meeting Notes](https://docs.google.com/document/d/1v6l2gmkRKAn5UIg3V2QdeeCcXMElxsNzEzDkVlWDVg8/edit?usp=sharing)
39    * [Zoom](https://zoom.us/j/97827947600)
40    * [Calendar Invite](https://calendar.google.com/event?action=TEMPLATE&tmeid=MnRvb2M4amtldXBuZ2E1azY0MTJndjh0ODRfMjAxODA5MThUMTcwMDAwWiBzdHlyYS5jb21fY28zOXVzc3VobnE2amUzN2l2dHQyYmNiZGdAZw&tmsrc=styra.com_co39ussuhnq6je37ivtt2bcbdg%40group.calendar.google.com&scp=ALL)
41
42## How does OPA work?
43
44OPA gives you a high-level declarative language to author and enforce policies
45across your stack.
46
47With OPA, you define _rules_ that govern how your system should behave. These
48rules exist to answer questions like:
49
50* Can user X call operation Y on resource Z?
51* What clusters should workload W be deployed to?
52* What tags must be set on resource R before it's created?
53
54You integrate services with OPA so that these kinds of policy decisions do not
55have to be *hardcoded* in your service. Services integrate with OPA by
56executing _queries_ when policy decisions are needed.
57
58When you query OPA for a policy decision, OPA evaluates the rules and data
59(which you give it) to produce an answer. The policy decision is sent back as
60the result of the query.
61
62For example, in a simple API authorization use case:
63
64* You write rules that allow (or deny) access to your service APIs.
65* Your service queries OPA when it receives API requests.
66* OPA returns allow (or deny) decisions to your service.
67* Your service _enforces_ the decisions by accepting or rejecting requests accordingly.
68
69The examples below show different kinds of policies you can define with OPA as
70well as different kinds of queries your system can execute against OPA. The
71example queries are executed inside OPA's
72[REPL](https://www.openpolicyagent.org/docs/get-started.html) which was built to
73make it easy to develop and test policies.
74
75For concrete examples of how to integrate OPA with systems like [Kubernetes](https://www.openpolicyagent.org/docs/kubernetes-admission-control.html), [Terraform](https://www.openpolicyagent.org/docs/terraform.html), [Docker](https://www.openpolicyagent.org/docs/docker-authorization.html), [SSH](https://www.openpolicyagent.org/docs/ssh-and-sudo-authorization.html), and more, see [openpolicyagent.org](https://www.openpolicyagent.org).
76
77### Example: API Authorization
78
79This example shows how you can enforce access controls over salary information
80served by a simple HTTP API. In this example, users are allowed to access their
81own salary as well as the salary of anyone who reports to them.
82
83The management chain is represented in JSON and stored in a file (`data.json`):
84
85```json
86{
87    "management_chain": {
88        "bob": [
89            "ken",
90            "janet"
91        ],
92        "alice": [
93            "janet"
94        ]
95    }
96}
97```
98
99Start OPA and load the `data.json` file:
100
101```bash
102opa run data.json
103```
104
105Inside the REPL you can define rules and execute queries. Paste the following rules into the REPL.
106
107```ruby
108default allow = false
109
110allow {
111    input.method = "GET"
112    input.path = ["salary", id]
113    input.user_id = id
114}
115
116allow {
117    input.method = "GET"
118    input.path = ["salary", id]
119    managers = data.management_chain[id]
120    input.user_id = managers[_]
121}
122```
123
124#### Example Queries
125
126**Is someone allowed to access their own salary?**
127
128```ruby
129> input := {"method": "GET", "path": ["salary", "bob"], "user_id": "bob"}
130> allow
131true
132```
133
134**Display the management chain for Bob:**
135
136```ruby
137> data.management_chain["bob"]
138[
139    "ken",
140    "janet"
141]
142```
143
144**Is Alice allowed to access Bob's salary?**
145
146```ruby
147> input := {"method": "GET", "path": ["salary", "bob"], "user_id": "alice"}
148> allow
149false
150```
151
152**Is Janet allowed to access Bob's salary?**
153
154```ruby
155> input := {"method": "GET", "path": ["salary", "bob"], "user_id": "janet"}
156> allow
157true
158```
159
160### Example: App Placement
161
162This example shows how you can enforce where apps are deployed inside a simple
163orchestrator. In this example, apps must be deployed onto clusters that satisfy
164PCI and jurisdiction requirements.
165
166```ruby
167app_placement[cluster_id] {
168    cluster = data.clusters[cluster_id]
169    satisfies_jurisdiction(input.app, cluster)
170    satisfies_pci(input.app, cluster)
171}
172
173satisfies_jurisdiction(app, cluster) {
174    not app.tags["requires-eu"]
175}
176
177satisfies_jurisdiction(app, cluster) {
178    app.tags["requires-eu"]
179    startswith(cluster.region, "eu-")
180}
181
182satisfies_pci(app, cluster) {
183    not app.tags["requires-pci-level"]
184}
185
186satisfies_pci(app, cluster) {
187    level = to_number(app.tags["requires-pci-level"])
188    level >= cluster.tags["pci-level"]
189}
190```
191
192#### Example Queries
193
194**Where will this app be deployed?**
195
196```ruby
197> input := {"app": {"tags": {"requires-pci-level": "3", "requires-eu": "true"}}}
198> app_placement
199[
200    "prod-eu"
201]
202```
203
204**Display clusters in EU region:**
205
206```ruby
207> startswith(data.clusters[cluster_id].region, "eu-")
208+------------+
209| cluster_id |
210+------------+
211| "prod-eu"  |
212| "test-eu"  |
213+------------+
214```
215
216**Display all clusters:**
217
218```ruby
219> data.clusters[cluster_id]
220+------------+------------------------------------------------+
221| cluster_id |           data.clusters[cluster_id]            |
222+------------+------------------------------------------------+
223| "prod-eu"  | {"region":"eu-central","tags":{"pci-level":2}} |
224| "prod-us"  | {"region":"us-east"}                           |
225| "test-eu"  | {"region":"eu-west","tags":{"pci-level":4}}    |
226| "test-us"  | {"region":"us-west"}                           |
227+------------+------------------------------------------------+
228```
229
230### Example: SSH Auditing
231
232This example shows how you can audit who has SSH access to hosts within
233different clusters. We will assume that SSH access is granted via group access
234in LDAP.
235
236```ruby
237import data.ldap
238import data.clusters
239
240ssh_access[[cluster_name, host_id, user_id]] {
241    host_id = clusters[cluster_name].hosts[_]
242    group_id = ldap.users[user_id].groups[_]
243    group_id = clusters[cluster_name].groups[_]
244}
245
246prod_users = {user_id | ssh_access[["prod", _, user_id]]}
247```
248
249#### Example Queries
250
251**Who can access production hosts?**
252
253```ruby
254> prod_users
255[
256  "alice",
257  "bob"
258]
259```
260
261**Display all LDAP users:**
262
263```ruby
264> data.ldap.users[user_id]
265+-------------------------------+---------+
266|   data.ldap.users[user_id]    | user_id |
267+-------------------------------+---------+
268| {"groups":["dev","platform"]} | "alice" |
269| {"groups":["dev","ops"]}      | "bob"   |
270| {"groups":["dev"]}            | "janet" |
271+-------------------------------+---------+
272```
273
274**Display all cluster/group pairs:**
275
276```ruby
277> data.clusters[cluster_id].groups[_] = group_id
278+------------+------------+
279| cluster_id |  group_id  |
280+------------+------------+
281| "test"     | "dev"      |
282| "test"     | "ops"      |
283| "prod"     | "ops"      |
284| "prod"     | "platform" |
285+------------+------------+
286```
287
288**Does Janet have access to the test cluster?**
289
290```ruby
291> ssh_access[["test", _, "janet"]]
292true
293```
294
295**What are the addresses of the hosts in the test cluster that Janet can access?**
296
297```ruby
298> ssh_access[["test", host_id, "janet"]]; addr = data.hosts[host_id].addr
299+------------+------------+
300|    addr    |  host_id   |
301+------------+------------+
302| "10.0.0.1" | "host-abc" |
303| "10.0.0.2" | "host-cde" |
304| "10.0.0.3" | "host-efg" |
305+------------+------------+
306```
307
308## Further Reading
309
310### Presentations
311
312- Open Policy Agent Introduction @ CloudNativeCon EU 2018: [video](https://youtu.be/XEHeexPpgrA), [slides](https://www.slideshare.net/TorinSandall/opa-the-cloud-native-policy-engine)
313- Rego Deep Dive @ CloudNativeCon EU 2018: [video](https://youtu.be/4mBJSIhs2xQ), [slides](https://www.slideshare.net/TorinSandall/rego-deep-dive)
314- How Netflix Is Solving Authorization Across Their Cloud @ CloudNativeCon US 2017: [video](https://www.youtube.com/watch?v=R6tUNpRpdnY), [slides](https://www.slideshare.net/TorinSandall/how-netflix-is-solving-authorization-across-their-cloud).
315- Policy-based Resource Placement in Kubernetes Federation @ LinuxCon Beijing 2017: [slides](https://www.slideshare.net/TorinSandall/policybased-resource-placement-across-hybrid-cloud), [screencast](https://www.youtube.com/watch?v=hRz13baBhfg&feature=youtu.be).
316- Enforcing Bespoke Policies In Kubernetes @ KubeCon US 2017: [video](https://www.youtube.com/watch?v=llDI8VvkUj8), [slides](https://www.slideshare.net/TorinSandall/enforcing-bespoke-policies-in-kubernetes).
317- Istio's Mixer: Policy Enforcement with Custom Adapters @ CloudNativeCon US 2017: [video](https://www.youtube.com/watch?v=czZLXUqzd24), [slides](https://www.slideshare.net/TorinSandall/istios-mixer-policy-enforcement-with-custom-adapters-cloud-nativecon-17).
318
319## Security
320
321### Security Audit
322
323A third party security audit was performed by Cure53, you can see the full report [here](SECURITY_AUDIT.pdf)
324
325### Reporting Security Vulnerabilities
326
327Please report vulnerabilities by email to [open-policy-agent-security](mailto:open-policy-agent-security@googlegroups.com).
328We will send a confirmation message to acknowledge that we have received the
329report and then we will send additional messages to follow up once the issue
330has been investigated.
331