Commit Graph

19 Commits

Author SHA1 Message Date
Ashutosh Narkar 7f65b04561 Add a new inter-query cache to cache responses across queries
This commit adds a new inter-query cache that built-in
functions can use to cache responses across queries.

The OPA config includes a new "caching" field that can be used
to set the size of the cache. By default there is no limit.

This change also updates `http.send` to optionally utilize the
inter-query cache.

Fixes #1753

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2020-08-06 14:33:18 -07:00
Ashutosh Narkar 338583c18a Add support for OPA bundle signatures
These changes add support for digital signatures for policy bundles which
can be used to verify their authenticity.

Bundle signature verification involves the following steps:

* Verify the JWT signature
* Verify the files in the JWT payload exist in the bundle
* Verify the file content of the files in bundle match with those in the payload

This commit adds a new `sign` command to generate a digital signature for policy bundles.

For more details, run "opa sign --help"

The signatures generated by the 'sign' command can be verified by the
'build' command. The 'build' command can also sign the bundle it generates.

The 'run' command can verify a signed bundle or skip verification altogether.

OPA 'sign', 'build' and 'run' can be used to
sign/verify bundles in bundle mode (--bundle) mode only. Verification
can be also be performed when bundle downloading is enabled.

Fixes: #1757

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2020-07-14 09:49:59 -04:00
Ashutosh Narkar 5d2b9df39d plugins: Additive updates to services when discovery enabled
Earlier with discovery enabled, there was no protection against accidental
changes to the discovery service. This change prevents the discovery service
from being modified by checking it's config in the service bundle.

Fixes #2058

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2020-04-29 06:36:10 -04:00
Torin Sandall 62f292b6e3 internal: Refactor load/store/compile implementation
This commit refactors the load/store/compile implementation that used
to live inside the runtime package. Specifically:

* Move init-time file loading logic into separate internal package
  (initload) along with store/compile logic. Add tests around
  load/store/compile that don't require the entire Runtime object.
  This also avoids duplication of the "version overwriting" logic.

* Move store/compile calls into the manager. This avoids the need for
  two compile operations on startup.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2020-04-27 15:26:43 -07:00
Torin Sandall f962990758 plugins: Fix race between manager and plugin startup
This change fixes a race condition in the manager that was caused by
registering the storage trigger _after_ the plugins had been
started. The problem was that if the bundle plugin was able to
download and activate before the trigger registration in the manager
went through, the store and the manager would be out-of-sync after
startup. The bundle would activate successfully but the plugin
manager would not see the change. This meant that the server health
check, status plugin, etc. would report successful activation and
clients using either of those APIs for synchronization could start
querying. If they executed a query within this window, virtual docs
would not be visible because the plugin manager would not yet have a
compiler to return to the server. Similarly, if clients queried the
v1/policies API they would see the raw policy contents but no AST
(since the latter is retrieved from the compiler.)

To remove the race condition the plugin manager simply registers the
trigger before starting any of the plugins. This ensures that it sees
all changes made by any of the plugins.

Fixes #2343

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2020-04-27 15:26:43 -07:00
Patrick East 99a6f4da67 plugins: Allow plugins to report status to manager
This defines a new status API on the plugins.Manager for plugins
to be able to update their status.

Signed-off-by: Patrick East <east.patrick@gmail.com>
2020-02-07 09:49:41 -05:00
Christian Muehlhaeuser 0e5b449219 Fixed typos in code
Signed-off-by: Christian Muehlhaeuser <muesli@gmail.com>
2019-07-19 13:46:23 -07:00
Torin Sandall e4ae6a70e5 bundle: Cache compiler on storage context
These changes update the manager and bundle plugin to avoid parsing
and compiling modules during the manager's trigger callback. Since
policy queries are blocked while triggers execute, it's adavantageous
to cache the compiler that is obtained during bundle activation and
reduce the work done in the trigger callback.

Also, as part of these changes, the bundle plugin incorporates
remaining modules when it recompiles. This ensures that remaining
modules are correct.

Fixes #1515

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2019-06-24 11:57:51 -07:00
Torin Sandall 56484c9b14 Refactor custom plugin interface
These changes refactor the custom plugin interface to bring it inline
with the bundle/decision logs/status built-ins. Specifically, the
plugin interface is being refactored to allow configuration to be
validated separate from plugin instantiation.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2019-01-10 14:52:14 -08:00
Torin Sandall 2d425494aa Refactor discovery implementation
These changes refactor the discovery implementation a bit to improve
test coverage and remove duplication of common logic shared with the
bundle plugin.

Specifically, the downloading logic has been moved into a separate
package that is shared by bundle and discovery. Second, test coverage in
the discovery implementation is increased from ~15% to ~85%.

These changes also include a few functional improvements:

- The default decision paths can be updated dynamically
- The decision logger can be enabled dynamically
- Discovery downloading errors are reported in status updates
- Discovery bundle is evaluated with all runtime params
- Custom plugins can be created dynamically
- Status updates include both discovery and bundle status

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-12-08 00:45:36 +01:00
Ashutosh Narkar 2185f1eb86 Add support for configuration discovery
Previously OPA configuration for bundle downloading, status reporting, etc. had to be supplied in a configuration file on startup. With these changes, OPA can be configured to download a bundle that generates the OPA configuration. This allows OPA to boot with minimal configuration and dynamically update that configuration on-the-fly making it much easier to manage large deployments of OPAs for different use cases within the same system.

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2018-11-29 09:19:58 -08:00
Torin Sandall 61420f8e71 Add support for specifying services as object (#1046)
* Fix typo in run short description

Signed-off-by: Torin Sandall <torinsandall@gmail.com>

* Add support for specifying services as object

Previously the services configuration had to be specified as an array,
for example:

services:
- name: foo
  url: https://example.com

In some cases, it's easier to structure the configuration as an object.
Specifically, the Helm package manager does not allow you to override
values nested under arrays. These changes allow the services
configuration to be structured as an object:

services:
  foo:
    url: https://example.com

Ref: https://github.com/helm/helm/issues/1987

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-10-30 08:02:30 -07:00
Varun Mathur 8885997264 Added ability to dynamically load .so objects and the respective required testing.
Signed-off-by: Varun Mathur <varun.mathur@live.com>
2018-08-16 13:11:49 -07:00
Torin Sandall 9e27dc2883 Remove unnecessary comments
Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-04-16 08:35:15 -07:00
Ashutosh Narkar 5b7442cabc Registration framework for integrating plugins
Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2018-04-13 16:12:25 -07:00
Ashutosh Narkar 135911bb5e Register server for compiler change updates
Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2018-04-13 16:12:25 -07:00
Ashutosh Narkar c4e6e6eaef Added compiler instance to the plugin manager
Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2018-04-13 16:12:25 -07:00
Torin Sandall 5e2084595c Add instance ID to OPA runtime
The instance ID can be included in outgoing messages to uniquely
identify the OPA instance.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-04-09 11:05:06 -07:00
Torin Sandall f131cfcff3 Add support for bundle downloading
Previously, policies and data had to be pushed into OPA via the REST API
or loaded via command line arguments at startup.

With these changes, OPA can now be configured to pull down bundles of
policy and data from remote HTTP servers. When a bundle is downloaded
successfully, the policies and data are loaded out of the bundle file
and inserted into storage.
2018-03-16 08:51:37 -07:00