Commit Graph

106 Commits

Author SHA1 Message Date
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 eee76c6365 Update subcommands to support loader filter
These changes update the subcommands to support a file/directory name
filter. This allows users to exclude certain files from being loaded.
With these changes users can excldue private directories created by
Kubernetes for volume-mounted ConfigMaps.

As part of this change, update the Kubernetes deployment documentation
to use the new --ignore flag, run OPA as a Deployment instead of as a
ReplicationController, and generally improve the example.

Fixes #782

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-06-22 14:22:14 -07:00
Torin Sandall d1551d2366 Refactor HTTP and HTTPS listener creation
With the #762 and #764 there is no need to keep the logic for creating
the HTTP and HTTPS listeners inside the function. These changes just
split listener creation into separate functions for clarity.

Also, update runtime to use logrus for reporting initialization errors
instead of println for consistency.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-05-30 15:34:47 -07:00
Juan Antonio Osorio Robles e6bb5d6b90 Allow passing multiple addresses to the server
This makes the --addr CLI parameter to be a slice and refactors the code
to allow several addresses to be passed. Hence we can listen on as many
HTTP and UNIX sockets as we want.

Signed-off-by: Juan Antonio Osorio Robles <jaosorior@redhat.com>
2018-05-30 10:58:36 -07:00
Torin Sandall 53fcf9f5e7 Fix log message punctuation in runtime.go
Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-05-29 09:06:15 -07:00
Juan Antonio Osorio Robles 59bee17b2b Use slices instead of explicit output variables for server loops
Previously, the server loop functions were returned explicitly as
outputs (having three outputs for the loop functions and one for the
error). If we want to add more this approach doesn't work very well. So
this introduced a slice as the output of the Listen function for the
Server struct, which allows us to loop over it and iterate over however
many loop functions we need.

This keeps the same logic as before, and is merely a first step in
refactoring this logic.

Signed-off-by: Juan Antonio Osorio Robles <jaosorior@redhat.com>
2018-05-29 07:56:38 -07:00
Torin Sandall b8b826dbd6 Update UNIX domain socket support
These changes tweak the UNIX domain socket to (1) return an error
instead of panicing (because the server may be embedded as a library)
and (2) to unlink the domain socket file before binding. The latter is
required so that OPA can be stopped and started without manually
removing the socket file.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-05-24 18:23:31 -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
Stephan Renatus 161722214d logging: log escaped path
Signed-off-by: Stephan Renatus <srenatus@chef.io>
2018-04-12 16:37:08 -07:00
Torin Sandall e850a121aa Wire up decision logging plugin to runtime
If decision logging is enabled and the decision ID factory is not set,
use a uuid generator.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-04-10 13:58:36 -07:00
Torin Sandall aacbd8bb91 Update server to accept a decision logger
In the past, services embedding OPA relied on the diagnostic buffer to
hook into decision logs. This required that all services embedding OPA
wrap the existing diagnostic buffer so that the server could still
support that feature.

With these changes, services embedding OPA can simply register a
function to be called whenver a decision is made. This simplifies the
implementation for services embedding OPA.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-04-10 13:58:36 -07:00
Torin Sandall bd1df06959 Only start plugins if config provided
The runtime was starting the bundle and status plugins even if the
config was missing.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-04-10 08:50:05 -07:00
Torin Sandall baa0e43840 Wire up status plugin to runtime
Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-04-09 11:05:06 -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 c5eb5495ea Refactor bundle configuration to be singleton
The initial implementation allowed for N bundles to be configured. While
this is more flexible, it introduces unnecessary complexity around
management (e.g., how do you know which bundle a decision was comoputed
from?) and performance (e.g., you would expect OPA to dedup data between
bundles.)

Moving to a single bundle DOES NOT prevent admins from bundling
multiple policies and data sets together.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-04-04 11:54:21 -07:00
Torin Sandall 6ee2d92a11 Fix test case to wait for correct error
We were seeing intermittent failures on Travis CI for this test case.
The error being delivered was an empty file parse error. With these
changes, the test will wait for up to 1 second to observe the expected
type error.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2018-03-22 10:57:32 -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
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 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
Tristan Swadell 582f47074d Remove lint errors detected during 'make check' 2018-01-10 15:17:10 -08:00
Torin Sandall 81e847ba37 Fix file watch bug causing panic in server mode
Previously, the runtime file watcher would not include the policies in
storage when recompiling after a file watch update. As a result, if a
policy snuck into storage "somehow" then the server would panic when it
attempted to reload the policies.

A policy could sneak into storage in two cases...

1) File removed AFTER FS notification sent but BEFORE loader.All()
called by file watcher.

2) File watcher enabled and policies pushed into server via API.

In either case, the policies would need to conflict with each other such
that compilation would fail in the server (e.g., with a type error.)
2017-09-29 10:02:13 -07:00
Torin Sandall 35a6f87fb1 Expose decision ID factory parameter
Users embedding the runtime package will need to be able to specify the
decision ID generator function.
2017-09-19 16:26:20 -07:00
Torin Sandall 05e9eb601c Refactor diagnostics support in server and runtime
- These changes update the server to always report performance metrics
  and the remote client address. The metrics are cheap to compute and
  there is no significant reason to require more complex configuration
  at this point.

- These changes update the runtime to allow callers to supply the
  diagnostics buffer implementation. This way callers can hook up their
  own sinks to the server's diagnostics.
2017-09-19 15:54:26 -07:00
Torin Sandall 9570a4acc7 Refactor runtime to separate init and start
Previously, the runtime could only be initialized and started in one
shot. In some cases, callers want to be able to separate these into two
steps, especially since the start call will block.
2017-09-19 12:06:18 -07:00
Torin Sandall c612260af4 Refactor file loading for OPA
The file loading logic implemented in the runtime package is generally
useful within OPA. These changes factor the file loading into a separate
package that can be reused without taking a dependency on the runtime.
2017-09-07 11:40:22 -07:00
Torin Sandall 38871c87d0 Revendoring logrus to deal with rename
See https://github.com/sirupsen/logrus/issues/570#issuecomment-313933276 for more info.
2017-08-24 09:32:55 -07:00
Matthew Mussomele 93e408b290 Make the server's diagnostics buffer size configurable 2017-08-08 15:45:12 -07:00
Matthew Mussomele ca783539f8 Add support to cancel compilation after some number of errors
Sometimes compiling large policies with many errors causes more output
errors than is easily sorted through. The compiler has been updated to
cancel after a configurable number of errors (default no limit), and the
server, repl and check command support options for setting that limit.
2017-07-21 07:59:51 -07:00
Matthew Mussomele 4435880658 Implement watch API in the server 2017-07-20 17:07:51 -07:00
Matthew Mussomele ee50506743 Add check command to verify that modules parse and compile 2017-06-28 22:46:55 -04:00
Torin Sandall 98d5da7826 Register server for policy change triggers
Users that embed the OPA server can now manage policies more easily via
the storage package instead of having to go through the REST API. This
also makes it trivial to support the --watch flag in server mode.
2017-06-23 13:18:15 -07:00
Torin Sandall ce24a5ae3b Add file watcher integration test 2017-06-23 13:18:15 -07:00
Torin Sandall c786fc9d33 Add support for concurrent r/w txns
These changes update the storage layer to support
multi-reader/single-writer txns:

- Writers can read their own writes
- Writers can rollback changes
- Readers only see writes after a successful commit
- Readers can progress during a write txn and only block during a commit

These changes also refactor the trigger interface to better support
transactions.
2017-06-23 13:18:15 -07:00
Torin Sandall 10f22906b5 Refactor storage layer interfaces
This is a large change set that contains a few backwards incompatible
changes. Summary of breaking changes:

- Remove storage.Storage in favour of storage.Store interface.
- Remove mount support.
- Remove storage of compiled policies.
- Modify storage.Store to support rollback.
- Modify storage.Store to support raw policy storage.
- Modify storage.Store to support indexing.
2017-06-23 13:18:15 -07:00
Torin Sandall 54d9193662 Improve OPA logging
This changes how OPA logs API requests and responses.

Before:
- OPA would not log at level.Info
- OPA would log request header and body and response header (but not
  body) at level.Debug.

After:
- OPA logs request and response headers at level.Info
- OPA includes request and response body at level.Debug.
2017-05-15 17:20:03 -07:00
Torin Sandall ed23bfee70 Improve file loader error handling
The file loader now handles empty modules properly (previously, it would
include an empty/nil module in the results which resulted in a panic
later on).

Also, the file loader now accumulates errors instead of bailing on the
first one. This makes it easier to find and fix errors when loading
files into OPA.
2017-03-27 03:00:10 -07:00
Torin Sandall b1fc681590 Remove persist/--policy-dir option
This is the first in series of Spring cleaning around the storage layer.
In the near future we will add local disk-based persistence support to
OPA. That support will handle storage of source files.

The --policy-dir option is almost entirely unused today. Removing it
will make it easier to get rid of the policyStore entirely.

The next thing to do will be to remove the specialized *Policy methods
from the storage layer. This way the storage layer can just accept
policies as normal data.

If policies need to be persisted until then, users can treat the
policies as config files and manage them outside of OPA.
2017-03-12 13:23:22 -07:00
Torin Sandall 6933a84482 Strip slashes in file loader
The REST API now supports slashes *inside* the path but the HTTP server
will not allow leading or trailing slashes (it redirects to a URL w/o
them). Because of this, the runtime should not add policies with these
leading or trailing slashes, as API callers won't be able to access
them.
2017-03-12 13:23:22 -07:00
Torin Sandall 6cdcb31f43 Add support for additional HTTP listener
Fixes #289
2017-03-12 12:04:35 -07:00
Torin Sandall 7d7d2912ae Replace glog with logrus 2017-03-12 12:04:35 -07:00
Torin Sandall 0e39da4664 Improve request logging
Use httputil.DumpRequest as this is much cleaner than previous approach
and handles all requests (instead of just /data). With new approach we
can get rid of getInputParam and related tests.

Also, move slack link around.

Fixes #281
2017-02-28 17:14:41 -08:00
Torin Sandall 96aad95475 Add identifier and authorizer to server 2017-02-22 14:49:21 -08:00
Torin Sandall 68fe788626 Split server types into separate package
This will let them be re-used by other sub-packages such as the
authorizer.
2017-02-22 14:49:21 -08:00
Torin Sandall 18ba055449 Add support for server-side HTTPS 2017-02-21 20:00:38 -08:00
Torin Sandall b48c80010c Refactor server to make new config more extensible 2017-02-21 20:00:38 -08:00
Torin Sandall 49a963f16a Fix test cases to work with new syntax 2017-02-10 10:37:43 -08:00
Torin Sandall ebc753cfd8 Rename the request document
Naming is hard. The "request" document is now the "input" document.
2017-01-18 16:37:32 -08:00
Torin Sandall 5ba261a6d8 Fix empty request parameter parsing
Return an error if the request parameter is empty. This indicates an error in
the caller.

Fixes #212
2017-01-17 13:32:56 -08:00