Commit Graph

1085 Commits

Author SHA1 Message Date
Torin Sandall 39cc4ef87f Add eval subcommand to run queries
With opa eval, the --eval flag on opa run is redundant and can be
removed.
2018-03-12 18:14:32 -07:00
Torin Sandall 2b3b3faeed Add parse subcommand to print AST of input 2018-03-12 18:14:32 -07:00
Torin Sandall 49df455339 Update check subcommand to error on empty input 2018-03-12 18:14:32 -07:00
Torin Sandall 3938a3a5b1 Add JSON format to test command 2018-03-12 18:14:32 -07:00
Torin Sandall 39f7b45fb7 Update directory loading convention
Previously, the loader would use directory names as top-level keys when
paths referred to directories. This meant that identical queries against
policies/data in differently named directories would return different
answers.

Now, the loader ignores the first directory name when recursing on
paths. Unfortunately this is not backwards compatible. Scripts and
workflows can be adapted as follows:

Before: opa test *
After:  opa test .

Before: opa test /some/path/to/dir/*
After:  opa test /some/path/to/dir

The same goes for opa run.
2018-03-12 18:14:32 -07:00
Torin Sandall 0c02943b9b Update syntax highlighters for vscode and textmate 2018-03-12 18:14:32 -07:00
Torin Sandall 2a5192ec6c Minor changes to note support
* Check if node is non-nil to prevent panic
* Omit empty message field from API response
* Use native string type for message fields
2018-03-12 17:13:19 -07:00
Unknown dbfccf15e5 Adding test and documentation for the trace builtin 2018-03-12 16:08:54 -07:00
Unknown b57faaa3e2 resolved make check issues 2018-03-12 16:08:54 -07:00
Unknown fe57fe3a70 Adding NoteOp for the Trace builtin 2018-03-12 16:08:54 -07:00
Torin Sandall 4f8ea30c25 Fix format for calls with empty args 2018-03-12 13:43:51 -07:00
Torin Sandall 2ee8f625f4 Escape keyword strings in ast.Ref#String
Previously refs like p["not"] would be represented as p.not which does
not parse because 'not' is an invalid variable name. This change ensures
that ref string operands are escape if they are keywords.
2018-03-09 11:17:36 -08:00
Torin Sandall 31950fda8b Fix location on rules parsed from call exprs 2018-03-09 11:17:36 -08:00
Torin Sandall adc416fe0a Update weekly meeting info 2018-03-09 11:17:22 -08:00
Torin Sandall dda04ef6cb Fix partial evaluation of refs on unknown terms
Previously, if partial evaluation encountered a ref against an unknown
term, it would attempt to evaluate the ref against the binding list and
then fail (because there would not be a binding for the unknown.)

With thes changes partial evaluation deals with unknown terms twofold:

1) When the term being dereferenced is unknown, eval saves the remainder
of the expression and continues.

2) When the ref operand is unknown, eval uses the value obtained by
enumerating the term to continue.
2018-03-08 14:11:43 -08:00
Torin Sandall cd155563b8 Generate support rules for negated expressions
Previously, partial evaluation would save negated expressions and not
perform any inlining. With these changes, partial evaluation inlines
negated expressions into support rules and rewrites the original
expression to refer to the support rule.

These changes will improve the coverage of partial evaluation which
improves the applicability of rule indexing and other optimizations.

Fixes #623
2018-03-08 14:11:43 -08:00
Torin Sandall a048970c95 Update release patch script to cover YAML files
The script was not searching for version numbers in YAML files in the
docs. As a result the Kubernetes admission controller tutorial was out
of date.
2018-03-08 11:16:59 -08:00
Torin Sandall fa28d91d6a Update to Go 1.10 2018-03-08 11:02:41 -08:00
Torin Sandall 09e4106451 Update modulo support
* Add eval test
* Add item to language reference
* Fix type declaration
2018-03-08 09:01:54 -08:00
Lenny Lofberg 98df994dc5 Add reminder/reminder (%) operator 2018-03-08 08:47:30 -08:00
Ashutosh Narkar 74cca19b79 Removed base64.URLEncoding.EncodeToString for header and payload 2018-03-06 18:02:38 -08:00
Torin Sandall 275286fc35 Fix substring built-in bounds checking
Fixes #465
2018-03-06 17:33:13 -08:00
Ashutosh Narkar b4e7d0807c Add RS256 JWT signature verification built-in function
Fixes #421

removed blank line

updated test

added command info documentation

wrap the error messages

used buitin URL decode method

moved verify token code in tokens module
2018-03-06 12:16:58 -08:00
Torin Sandall 972da6e797 Ignore some built-in calls during partial eval
Some buillt-in functions should not be partially evaluated because they
are not pure functions (e.g., http.send and time.now_ns are two exampels
we currently have.)

In the future, we may need to add variants of these functions that can
be evaluated during partial evaluation.

Fixes #622
2018-03-06 10:47:13 -08:00
Torin Sandall 505b8fa793 Update partial eval to check call args recursively
Previously, partial eval was not checking call args recursively for
terms in the save set. As a result, if a call expression passed a term
that had an unknown embedded, the call would be evaluated, which could
potentially result in an internal error.

Fixes #621
2018-03-06 09:05:40 -08:00
Torin Sandall db34907866 Add X.509 certificate parsing built-in function
Fixes #635
2018-03-06 07:49:07 +09:00
Torin Sandall ac9b84375e Add base64 encoding built-in functions 2018-03-06 07:49:07 +09:00
Torin Sandall c264a2b3d2 Update rule index to support == 2018-03-06 04:32:28 +09:00
Torin Sandall 2a61eeae59 Fix gitbook summary for comparisons 2018-03-03 09:57:11 +09:00
Torin Sandall ad9cd887a5 Prepare v0.7.2 development 2018-02-25 15:48:34 -08:00
Torin Sandall 688594c378 Prepare v0.7.1 release v0.7.1 2018-02-25 15:47:52 -08:00
Torin Sandall c7c8e83083 Update query compiler to deep copy parsed query
The query compiler was not deep copying queries like the compiler does
for modules. As a result, the parsed query in the REPL was being
recompiled and the rewritten var mapping was not correct. E.g.,
rewritten vars were not be displayed properly.
2018-02-25 15:44:45 -08:00
Torin Sandall 67022fc71a Add omitempty tag for ad-hoc query result field
Without omitempty, the server returns {"results": null} which is not
consistent with the rest of the APIs.
2018-02-24 10:16:27 -08:00
Torin Sandall 7bc37cb708 Fix rego package to check capture vars
The rego package was not checking capture vars unless the query
contained iteration. As a result, queries like a = 1; b = 2; a > b would
be return a single result when they should be undefined.
2018-02-24 10:16:27 -08:00
Torin Sandall d30a3f2418 Use rego.ParsedInput to provide input from form
The debug form was passing the parsed input as a Go native interface{}
which caused the Rego package to attempt to treat ast.Valeu as a Go
native value (which fails.)

Fixes #571
2018-02-24 10:16:27 -08:00
Torin Sandall b6e1c8eeb4 Fix root document assignment in REPL
The initial assignment support in the REPL was using the expr operand
instead of the rule name for the unset operation. As a result,
assignments to input/data would panic because the expr operand was a ref
and not a var.
2018-02-24 10:16:27 -08:00
Tristan Swadell dde87944e1 Updates to the Rego v2 proposal based on last design meeting. 2018-02-23 10:04:18 -08:00
Torin Sandall d3edd0e4a6 Prepare v0.7.1 development 2018-02-22 12:58:52 -08:00
Torin Sandall d8f6f7f9b3 Prepare v0.7.0 release v0.7.0 2018-02-22 11:23:56 -08:00
Torin Sandall 744d6e5590 Update release script to build for Windows
Fixes #573
2018-02-22 11:06:48 -08:00
Torin Sandall e3216537b0 Fix safety check bug for call args
This bug was introduced in 051157f. If not output value is specified in
a call expression, the ref outputs are still safe.

Fixes #625
2018-02-21 11:01:14 -08:00
Torin Sandall 3ee9c9f0fd Update webhook registration in Kubernetes tutorial
Due to https://github.com/kubernetes/kubernetes/issues/59759, we should
not recommend registering webhooks that match the CONNECT operation as
this can break exec/port-forward functionality.
2018-02-21 10:47:00 -08:00
Torin Sandall 7c0205d7da Add docs on DELETE /v1/data API 2018-02-19 13:23:54 -08:00
Torin Sandall 9d58234c97 Fix comparison document title 2018-02-19 13:23:54 -08:00
Torin Sandall e0711fd32b Add section on := operator 2018-02-19 13:23:54 -08:00
Torin Sandall f77d5634b0 Add == operator to built-in reference 2018-02-19 13:23:54 -08:00
Torin Sandall b647eb7e71 Refactor REPL to use rego package
With these changes, the REPL can now print expression values more
reliably. E.g., simple expressions like 3+5 just do the right thing.

Previously the REPL called topdown directly and reimplemented some of
the logic to format result sets. This was a source of issues because it
was possible for the rego package and the REPL to return different
answers. With these changes, the REPL and rego package results are
equivalent.

A few changes were required. Specifically:

* Query Compiler. Updated to accept user supplied stages. This way users
can perform their own rewriting. This is used by the rego package to
provide the query+functional semantics we want. In the future, this API
could be used to register custom optimization passes to the compiler.

* Compiler. Expose GetArity helper. This allows users to quickly lookup
the arity of a function referred to by a ref. The rego package needs
this to decide whether to capture call outputs.

* Rego package. Expose new args to set parse package, imports, etc. This
is used by the REPL which maintains state to control the currently
active module.
2018-02-17 08:21:04 -08:00
Torin Sandall 3672a3f892 Improve call result handling
Previously, if callers omitted output terms from call expressions, the
result would be ignored. This was fine for most calls which would only
return true if they were defined, however, for functions could return
false this became confusing because an expression like "f(1)" where f(1)
= false would be succeed and yield a result.

With these changes, built-in functions that used to only return true
always return true or false and the eval engine takes care to check if
the result is false when the the caller omits the output term.

This provides consistent behaviour across cases like...

f(1)            => undefined (previously {})
f(1,x)          => {x:false} (previously {x:false})
neq(1,1,x)      => {x:false} (previously undefined)
neq(1,1,false)  => {}        (previously undefined)
neq(1,1,true)   => undefined (previously undefined)

In the next set of changes, the Rego package will be updated to capture
values for expressions like the first one above so that function calls
behave like refs (i.e., their values are returned).
2018-02-17 08:21:04 -08:00
Torin Sandall 03d3bc4d38 Update Docker Authorization tutorial
Updates to the tutorial to incorporate opa-docker-authz v0.2.
2018-02-16 14:40:50 -08:00
Torin Sandall 0f8c6798f2 Add time.clock built-in function 2018-02-16 09:35:56 -08:00