Commit Graph

1238 Commits

Author SHA1 Message Date
cli-docs-updater db168a22b8 docs: Update generated CLI docs 2022-11-15 08:38:13 +00:00
Peter Macdonald 77b6b3f7cb Adding strict flag to opa eval (#5228)
You can now enable strict mode with `opa eval` by passing `--strict` (`-S`).

Fixes #5182.

Signed-off-by: Peter Macdonald <macdonald.peter90@gmail.com>
2022-11-15 09:35:58 +01:00
Anders Eknert 8f97616b6d ecosystem: add datadog and terraform cloud (#5383)
Signed-off-by: Anders Eknert <anders@eknert.com>
2022-11-14 11:21:49 +01:00
dependabot[bot] da2fb4b12f build(deps): bump loader-utils in /docs/website/scripts/live-blocks (#5371) 2022-11-08 12:34:34 +00:00
Stephan Renatus a75c487e55 website: add "canonical" link to latest (#5358)
The logic is as follows:

If, for a given versioned docs page /docs/vx.y.z/page, /docs/latest/page
exists, then that's the canonical link for that page.
If it doesn't exist, then there's no canonical link.

The underlying hope here is that search engines will prefer the "latest" docs
pages, instead of linking to older-version content.

Informed by https://github.com/nodejs/node-v0.x-archive/issues/941 and
https://developers.google.com/search/docs/crawling-indexing/consolidate-
duplicate-urls

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-11-07 13:43:42 +01:00
UTKARSH MISHRA e5bc273e58 website: Updated Footer Color (#5334)
Fixes #5254.

Signed-off-by: Utkarsh Mishra <nasautkarsh@gmail.com>
2022-11-04 10:25:10 +01:00
Stephan Renatus 49faef8c6d docs/policy-testing: don't advise to "import future.keywords" (#5338)
Fixes #5333.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-11-02 15:21:56 +01:00
Stephan Renatus f477e7ff7f docs/website: make "outdated version" banner red if ancient (#5339)
Where "ancient" means it's not among the latest five releases.

Also, in, netlify.toml: declare framework for dev. I've found that
adding this live means I can use

    netlify dev --offline

without any further switches. For some reason, I had run into
trouble with "cecil" when using it like that.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-11-02 11:42:50 +01:00
cli-docs-updater c067f1deda docs: Update generated CLI docs 2022-11-02 08:21:39 +00:00
Ashutosh Narkar c1d33562f6 docs: Add note about new OPA-Envoy plugin config param to skip body parsing
Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2022-11-01 12:00:37 -07:00
cli-docs-updater a86973763d docs: Update generated CLI docs 2022-11-01 17:51:57 +00:00
Anders Eknert 055e67e791 Add CircleCI to ecosystem page (#5329)
Signed-off-by: Anders Eknert <anders@eknert.com>
2022-10-31 20:03:23 +01:00
Omri Gazitt 251c92e059 Add Topaz to ecosystem (#5308)
Add Topaz to ecosystem

Signed-off-by: Omri Gazitt <ogazitt@gmail.com>
2022-10-28 23:06:29 +02:00
Stephan Renatus 3406e96789 ast/compile: rewrite ref-replacements with non-function values (#5301)
Before, this was OK:

    test_a {
    . mock_f := true
      allow with f as mock_f
    }

but this had panicked:

    mock_f := true
    test_a {
      allow with f as mock_f
    }

Which, from a user perspective, is quite incomprehensible. Technically,
the first snippet was a (supported) replacement-by-value, and the second
was an unsupported replacement by a rule that was not a function.

Furthermore, the second case wasn't properly caught in the 'with' validations.

Now, we'll capture the situation, and start supporting it. Both snippets will
now work the same, as one would expect from the language surface.

Fixes #5299.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-10-27 12:05:26 +02:00
cli-docs-updater fff3e0aeff docs: Update generated CLI docs 2022-10-26 08:45:26 +00:00
Byron Lagrone 235ee309da cmd/exec: add --fail and --fail-defined flags (#5295)
Adds the ability to exit with a non-zero exit code for 'opa exec' by adding the
--fail and --fail-defined flags matching their respective behaviors in 'opa eval':

- Setting the --fail-defined flag allows exit of opa exec with a zero code if all
   results are undefined and there are no errors, or a non-zero code in the
   event of any defined results and/or errors.
   On non-zero exits the error message includes the number of failures/errors
   as well as a reference to the --fail-defined flag being set.
- The --fail flag behaves as the inverse of --fail-defined.

Fixes: #5007

Signed-off-by: Byron Lagrone <byron.lagrone@seqster.com>
2022-10-26 10:43:07 +02:00
cli-docs-updater 476e04f377 docs: Update generated CLI docs 2022-10-24 18:37:46 +00:00
Philip Conrad e2eabe88c1 ast+compile+cmd: Support entrypoint annotations. (#5246)
This commit adds support to the `compile` package for extracting
entrypoints from Rego `entrypoint` metadata annotations. The new
entrypoint annotations can be applied to any valid entrypoint target,
e.g. rules and packages.

An example policy using the new entrypoint annotations:

    package test

    # METADATA
    # entrypoint: true
    allow {
        input.x
    }

The `build` and `eval` CLI commands have been updated so that they do
not require an entrypoint to be explicitly provided with `-e`, so long
as at least one valid rule/package is marked with an entrypoint
annotation.

The new feature is additive; entrypoints can still be explicitly
provided to these commands by `-e`, and those will be used alongside the
entrypoints discovered from the metadata annotations.

Fixes: #3459

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
2022-10-24 14:35:17 -04:00
Stephan Renatus 8d864c323d docs/envoy-tutorial: use latest proxy_init (v8) (#5256)
The latest image has the fix for avoiding a crash loop when run twice.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-10-24 13:19:52 +02:00
Stephan Renatus 482769dd12 nightly: address recent findings, update trivyignore (#5287)
This is a bit of a bag of a few smaller things:

* workflows/nightly: skip imported gqlparser package.json
   It is not used anywhere.

* .trivyignore: remove docker CVE
   This has been bumped away when updating ORAS.

* website/livescripts: bump minimatch
   This also updated the lockfile version... I think that's OK.

* workflows/pull-request: don't setup opa for docker image smoke test
* address netlify ignore script failure on large output

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-10-21 12:06:38 +02:00
Humberto Corrêa da Silva f1761ac77e server+runtime+logs: Add the req_id attribute on the decision logs (#5196)
Today it is not possible to correlate the decision log with
other types of logs (server, print, etc.) when the server log
level is >= INFO. The log correlation could be helpful in
troubleshooting.

A solution is to add a common attribute in all logs to make
the log correlation possible, so adding the req_id attribute
on decision logs, when server log level is >= INFO, will make it
possible.

Fixes: #5006

* Add documentation about decision log req_id attribute

The documentation purpose is to explain the relation with
others logs, how it could be used, and when it is included
on decision logs.

Signed-off-by: Humberto Corrêa da Silva <humbertoc_silva@hotmail.com>
2022-10-14 13:12:15 +02:00
Stephan Renatus 965301f90e ast: support dotted heads (#4660)
This change allows rules to have string prefixes in their heads -- we've
come to call them "ref heads".

String prefixes means that where before, you had

    package a.b.c
    allow = true

you can now have

    package a
    b.c.allow = true

This allows for more concise policies, and different ways to structure
larger rule corpuses.

Backwards-compatibility:

- There are code paths that accept ast.Module structs that don't necessarily
  come from the parser -- so we're backfilling the rule's Head.Reference
  field from the Name when it's not present.
  This is exposed through (Head).Ref() which always returns a Ref.

  This also affects the `opa parse` "pretty" output:

  With x.rego as

    package x
    import future.keywords
    a.b.c.d if true
    e[x] if true

  we get

    $ opa parse x rego
    module
     package
      ref
       data
       "x"
     import
      ref
       future
       "keywords"

     rule
      head
       ref
        a
        "b"
        "c"
        "d"
       true
      body
       expr index=0
        true
     rule
      head
       ref
        e
        x
       true
      body
       expr index=0
        true

  Note that

    Name: e
    Key: x

  becomes

    Reference: e[x]

  in the output above (since that's how we're parsing it, back-compat edge cases aside)

- One special case for backcompat is `p[x] { ... }`:

    rule                    | ref   | key | value | name
    ------------------------+-------+-----+-------+-----
    p[x] { ... }            | p     | x   | nil   | "p"
    p contains x if { ... } | p     | x   | nil   | "p"
    p[x] if { ... }         | p[x]  | nil | true  | ""

  For interpreting a rule, we now have the following procedure:

  1. if it has a Key, it's a multi-value rule; and its Ref defines the set:

     Head{Key: x, Ref: p} ~> p is a set
     ^-- we'd get this from `p contains x if true`
         or `p[x] { true }` (back compat)

  2. if it has a Value, it's a single-value rule; its Ref may contain vars:

     Head{Ref: p.q.r[s], Value: 12} ~> body determines s, `p.q.r.[s]` is 12
     ^-- we'd get this from `p.q.r[s] = 12 { s := "whatever" }`

     Head{Key: x, Ref: p[x], Value: 3} ~> `p[x]` has value 3, `x` is determined
                                          by the rule body
     ^-- we'd get this from `p[x] = 3 if x := 2`
         or `p[x] = 3 { x := 2 }` (back compat)

     Here, the Key isn't used, it's present for backwards compatibility: for ref-
     less rule heads, `p[x] = 3` used to be a partial object: key x, value 3,
     name "p"

- The destinction between complete rules and partial object rules disappears.
  They're both single-value rules now.

- We're now outputting the refs of the rules completely in error messages, as
  it's hard to make sense of "rule r" when there's rule r in package a.b.c and
  rule b.c.r in package a.

Restrictions/next steps:

- Support for ref head rules in the REPL is pretty poor so far. Anything that
  works does so rather accidentally. You should be able to work with policies
  that contain ref heads, but you cannot interactively define them.
  
  This is because before, we'd looked at REPL input like

      p.foo.bar = true

  and noticed that it cannot be a rule, so it's got to be a query. This is no
  longer the case with ref heads.

- Currently vars in Refs are only allowed in the last position. This is expected
 to change in the future.

- Also, for multi-value rules, we can not have a var at all -- so the following
  isn't supported yet:

      p.q.r[s] contains t if { ... }

-----

Most of the work happens when the RuleTree is derived from the ModuleTree -- in
the RuleTree, it doesn't matter if a rule was `p` in `package a.b.c` or `b.c.p`
in `package a`.

As such, the planner and wasm compiler hasn't seen that many adaptations:

- We're putting rules into the ruletree _including_ the var parts, so

  p.q.a = 1
  p.q.[x] = 2 { x := "b" }

  end up in two different leaves:

  p
  `-> q
       `-> a = 1
       `-> [x] = 2`

- When planing a ref, we're checking if a rule tree node's children have
  var keys, and plan "one level higher" accordingly:

  Both sets of rules, p.q.a and p.q[x] will be planned into one function
  (same as before); and accordingly return an object {"a": 1, "b": 2}

- When we don't have vars in the last ref part, we'll end up planning
  the rules separately. This will have an effect on the IR.

  p.q = 1
  p.r = 2

  Before, these would have been one function; now, it's two. As a result,
  in Wasm, some "object insertion" conflicts can become "var assignment
  conflicts", but that's in line with the now-new view of "multi-value"
  and "single-value" rules, not partial {set/obj} vs complete.
* planner: only check ref.GroundPrefix() for optimizations

In a previous commit, we've only mapped

    p.q.r[7]

as p.q.r;  and as such, also need to lookup the ref

    p.q.r[__local0__]

via p.q.r

(I think. Full disclosure: there might be edge cases here that are unaccounted
for, but right now, I'm aiming for making the existing tests green...)


New compiler stage:

In the compiler, we're having a new early rewriting step to ensure that the
RuleTree's keys are comparible. They're ast.Value, but some of them cause us
grief:

- ast.Object cannot be compared structurally; so

      _, ok := map[ast.Value]bool{ast.NewObject([2]*ast.Term{ast.StringTerm("foo"), ast.StringTerm("bar")}): true}[ast.NewObject([2]*ast.Term{ast.StringTerm("foo"), ast.StringTerm("bar")})]

  `ok` will never be true here.

- ast.Ref is a slice type, not hashable, so adding that to the RuleTree would
  cause a runtime panic:

      p[y.z] { y := input }

  is now rewritten to

    p[__local0__] { y := input; __local0__ := y.z }

This required moving the InitLocalVarGen stage up the chain, but as it's still
below ResolveRefs, we should be OK.

As a consequence, we've had to adapt `oracle` to cope with that rewriting:

1. The compiler rewrites rule head refs early because the rule tree expects
   only simple vars, no refs, in rule head refs. So `p[x.y]` becomes
   `p[local] { local = x.y }`
2. The oracle circles in on the node it's finding the definition for based
   on source location, and the logic for doing that depends on unaltered
   modules.

So here, (2.) is relaxed: the logic for building the lookup node stack can
now cope with generated statements that have been appended to the rule bodies.


There is a peculiarity about ref rules and extents:

See the added tests: having a ref rule implies that we get an empty object
in the full extent:

    package p
    foo.bar if false

makes the extent of data.p: {"foo": {}}

This is somewhat odd, but also follows from the behaviour we have right now
with empty modules:

    package p.foo
    bar if false

this also gives data.p the extent {"foo": {}}.

This could be worked around by recording, in the rule tree, when a node was
added because it's an intermediary with no values, but only children.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-10-14 10:15:54 +02:00
Philip Conrad a12ecb720b docs/policy-reference: Add semver examples. (#5238)
This commit adds some examples of valid/invalid syntax to the `semver` builtin docs.

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
2022-10-12 18:22:40 -04:00
Anders Eknert 5fea310bda docs: provide some tips for style fixes (#5237)
Also, update docs to clarify that forking is needed before
cloning, as that was not immediately apparent.

Signed-off-by: Anders Eknert <anders@eknert.com>
2022-10-12 23:07:50 +02:00
Marius Larsen 49c0051f24 plugins/logs: allow rule-based dropping of decision log entries (#5221)
Fixes: #3945

Signed-off-by: Marius Larsen <larsen.b.marius@gmail.com>
Co-authored-by: Lukas Menzel <lmenzel@united-internet.de>
Co-authored-by: Maren-Sofie Weien Stubø <msws@live.no>
2022-10-12 21:01:39 +02:00
Jasper Van der Jeugt a56c231269 feature: add UnifyOp to tracer events (#5203)
This would be useful for us for two immediate use cases:

1.  Show how and why rules failed in more detail in verbose tooling,
    we can show the unification happening step by step.
2.  We can trace which parts of the input document were used, if we
    add `Location` info those terms.

However, I think it's generally useful for debugging tools.

This increases verbosity in the explain logs, so we decided to add a new explain
mode `debug` in addition to the existing `full`, `notes`, `fails`, `off` modes.
This can be set using the `--explain=debug` flag on the CLI, or by using `trace
debug` in the REPL.

Signed-off-by: Jasper Van der Jeugt <m@jaspervdj.be>
2022-10-10 11:57:31 +02:00
Philip Conrad ac20ef2bf5 server+sdk+plugins: Integrate NDBCache into decision logging. (#5147)
This commit integrates the non-deterministic builtins caching system
into decision logging, both in the server and sdk packages. Some
reworking of the NDBCache's serialization format were required to
accommodate this. The feature is disabled by default, and must be
opted into by user configuration.

The feature can be enabled via a top-level config key:

    nd_builtin_cache=true

The NDBCache is exposed to the masking system under the
`/nd_builtin_cache` path, which allows masking or dropping sensitive
values from decision logs selectively.

Note: If a decision log event exceeds the `upload_size_limit_bytes`
value for the OPA instance, OPA will reattempt uploading it, after
dropping the NDBCache from the event. This behavior will trigger a log
error, and will increment the `decision_logs_nd_builtin_cache_dropped`
metrics counter.

Fixes: #1514

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
2022-10-06 16:27:54 -04:00
Peter Macdonald f3c0630ea5 Added Gloo Edge Tutorial with some neat examples.
Signed-off-by: Peter Macdonald <macdonald.peter90@gmail.com>
2022-10-04 09:47:46 -07:00
Anders Eknert be2d75310a Add IR to integration docs (#5205)
* Also update Rego snippets to use future keywords
* Fixup of outdated description of Wasm

Signed-off-by: Anders Eknert <anders@eknert.com>
2022-10-04 11:04:11 +02:00
nasa9084 15b9a884cd Fix typo in Future Keywords (#5192)
Signed-off-by: nasa9084 <nasa.9084.bassclarinet@gmail.com>
2022-09-30 12:40:54 +02:00
S. Hutchins da0bbde369 doc update on performance metrics (#5198)
Signed-off-by: Shane Hutchins <shane.hutchins@hitachivantara.com>
2022-09-29 16:35:43 +02:00
Stephan Renatus 2f01fe904f ast/parser+formatter: allow 'if' in rule 'else'
This follows the same rules as 'if' used with ordinary rules:

1. if the future keyword is present, 'if' will be used in `opa fmt`'s output
2. shorthands are allowed:

    p := true if 2>1
    else := "blah" if 1 < 0
3. the formatter will only use the shorthand if the body was on one line with
   the rest before:

    else := 1 { whatever }

becomes

    else := 1 if whatever

but

    else := 1 {
        whatever
    }

becomes

    else := 1 if {
        whatever
    }

Fixes #5002.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-09-28 12:45:04 -04:00
Philip Conrad ab385e9c17 topdown/builtins: Add object support for GraphQL builtins. (#4752)
This commit adds support for AST objects to be usable in place of
strings for several of the GraphQL built-in functions, to improve
the composability of the GraphQL set of built-ins, and to dramatically
reduce the amount of redundant parsing when writing GraphQL policies.

Fixes: #4742

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
2022-09-26 11:47:40 +02:00
Philip Conrad c309c55ef4 topdown+builtins: Restore legacy IgnoreDuringPartialEval list. (#5175)
This commit is a followup to the work done in PR #5172, and partially
reverts the changes there to avoid breaking library users of OPA.

The fix restores the `IgnoreDuringPartialEval` list while still
ensuring that non-deterministic builtins are not run during partial
evaluation.

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
2022-09-26 11:02:39 +02:00
Peter Macdonald 2df5c190c3 docs/annoations: add policy example and a link to the policy reference (#5180)
Added Rego subheading to the annotations documentation section and
added an example of using annotations, then below that a link to the
Rego policy reference.

Fixes #4937.

Signed-off-by: Peter Macdonald <macdonald.peter90@gmail.com>
2022-09-26 09:57:31 +02:00
Charlie Flowers 4cb755e5ba docs: Update mentions of #development to #contributors 2022-09-24 22:54:05 +02:00
cli-docs-updater fc328b43e1 docs: Update generated CLI docs 2022-09-23 18:38:53 +00:00
Ashutosh Narkar 6c6494e42e internal/report: Include heap usage in the telemetry report
Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2022-09-23 11:36:53 -07:00
Anders Holmefjord b1168448d0 docs: Added quotes so both examples are consistent. No quotes can give wrong values. Also fixed minor typo.
Signed-off-by: Anders Holmefjord <andersholmefjord@gmail.com>
2022-09-22 16:34:43 +02:00
cli-docs-updater f266848ffe docs: Update generated CLI docs 2022-09-21 12:32:01 +00:00
Anders Eknert 363ceee117 Update examples for CLI commands
* And fix a type in IR docs

Signed-off-by: Anders Eknert <anders@eknert.com>
2022-09-21 14:30:14 +02:00
Anders Eknert 0f912fcbe2 Fix typo in OPA document model docs
Credits to @rahulratnagiri-wmt

Signed-off-by: Anders Eknert <anders@eknert.com>
2022-09-21 10:50:37 +02:00
Peter ONeill 2106ac7900 ecosystem: Update Styra Logo (#5154)
Update Styra DAS Logo

Signed-off-by: Peter ONeill <peteroneilljr@gmail.com>
2022-09-21 07:18:17 +02:00
cli-docs-updater 1919dc07f0 docs: Update generated CLI docs 2022-09-20 12:52:18 +00:00
Anders Eknert 824aae68fe Fix typo in configuration docs
Signed-off-by: Anders Eknert <anders@eknert.com>
2022-09-19 18:20:19 -04:00
Wang Bing 0f479704bb docs/security: Fix role declared above (#5140)
Signed-off-by: pigletfly <wangbing.adam@gmail.com>
2022-09-15 10:58:37 +02:00
Or Weis f2d1466d46 website/security: style improvements (#5119)
Signed-off-by: orweis <orweis@gmail.com>
2022-09-10 20:07:15 +02:00
Stephan Renatus 6b4c3936e8 docs/policy-language: be more explicit about future keywords (#5106)
Before, we started using `if` and `contains` rather casually. Adding a few
paragraphs to point out what those keywords are and how do without them.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-09-08 11:56:53 +02:00
Paolo 15412b17c9 ecosystem: add some links to Rönd (#5102)
Signed-off-by: Paolo <ugho16@users.noreply.github.com>
2022-09-07 13:02:40 +02:00
Stephan Renatus ebf19976bf SECURITY: migrate policy to web site, update content (#5094)
This commit migrates the security policy to the OPA website. Also, it is
deliberately not part of the versioned docs; we don't want anyone to find old
information when it's important to get up-to-date information.

Fixes #4272.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-09-06 12:50:53 -04:00