Commit Graph

214 Commits

Author SHA1 Message Date
Ashutosh Narkar f60dfafa1b Initial support for large bundle deployments
Currently bundles are loaded into memory entirely
even when disk storage is used. Then the parsed content
is written to the store. Deserializing data into Go structs
is memory consuming and even if user has configured disk
storage, OPA is still bound by the amount of memory
assigned to it. This change adds a new lazy loading mode
wherein the entire data is not deserialized while bundle
reading and hence if the bundle contains large data files
and the user has enabled disk storage, OPA should be
able to handle this scenario w/o running OOM.

Fixes: #4539

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2022-06-27 08:51:21 -07:00
Ashutosh Narkar f137da2358 plugins/discovery: Check for empty key config
Currently OPA allows users to use unsigned discovery
bundles that themselves point to signed service bundles.
The discovery plugin checks if the keys in the service bundle
do not update those in the boot config. It's possible that
the signing config in the discovery object be a nil pointer.
This is change adds a check for that.

Fixes: #4656

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2022-06-09 12:10:42 -07:00
Ashutosh Narkar 80eb9be78d plugins/logs: Update mechanism to escape field paths (#4756)
Earlier the paths to the field to perform an upsert or
remove operation on were escaped using Go's url.QueryEscape
method. This results in incorrect behavior when the paths contain
a reserved character like ":". This change updates to using
url.PathEscape instead to escape the input and result paths.

Fixes: #4717

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2022-06-09 07:27:00 +02:00
Jason Hall 4dd7fb1c0d Remove use of github.com/pkg/errors (#4696)
This package is deprecated, archived, and in maintenance mode, since Go
errors support wrapping natively.

For #2152.

Signed-off-by: Jason Hall <jason@chainguard.dev>
2022-05-18 11:29:35 +02:00
carabasdaniel 39125a034c downloader: support for downloading bundles from an OCI registry (#4558)
Initial support for #4518.

Configuration uses the 'services' config for registries, via the "type: oci" field.
Bundles configured to pull from that service will then use OCI.

```
services:
  ghcr-registry:
    url: https://ghcr.io
    type: oci
bundles:
  authz:
    service: ghcr-registry
    resource: ghcr.io/${ORGANIZATION}/${REPOSITORY}:${TAG}
    persist: true
    polling:
      min_delay_seconds: 60
      max_delay_seconds: 120
persistence_directory: ${PERSISTENCE_PATH}
```

Service credentials are supported: if you want to pull from a private registry,
use
```
services:
  ghcr-registry:
    url: https://ghcr.io
    type: oci
    credentials:
      bearer:
        token: ${GH_PAT}
```

If no `persistence_directory` is configured, the data is stored in a directory under /tmp.

See docs/devel/OCI.md for manual steps to test this feature with some
OCI registry (like ghcr.io).

Signed-off-by: carabasdaniel <dani@aserto.com>
2022-04-28 11:27:58 +02:00
Bryan Fulton 02c1c1e577 bundle/status: Include bundle type in status information
OPA has support for Delta Bundles. The status object already
contains valuable information such as last activation timestamp but
does not specify if the bundle was a canonical snapshot or delta.

This change updates the bundle.Status object to include the
bundle type string: either "snapshot" or "delta". This can be useful
for status endpoints to differentiate between the bundle types.

Issue: 4477

Signed-off-by: Bryan Fulton <bryan@styra.com>
2022-04-27 15:43:06 -07:00
Costi Muraru d819c1ecbd status: Remove activeRevision label on all but one metric (#4600)
Having one activeRevision label on each of the prometheus metrics emitted
by the status plugin has proven to be problematic with a large number of
bundles. So with this change,

1. we keep the activeRevision label (just on) the last_success_bundle_activation metric.
2. the gauge gets reset, so we only keep the last active_revision (instead of keeping
   them all and therefore avoiding the situation where the /metrics output grows indefinitely)

Fixes #4584.

Signed-off-by: cmuraru <cmuraru@adobe.com>
2022-04-26 13:52:30 +02:00
Ashutosh Narkar ccba4a63d2 Persist activated bundle etag to store
Currently etag from the HTTP response of activated bundles is not
persisted to store. Hence if OPA restarts and an activated bundle
loaded from the disk store is up-to-date, OPA may still download
the same version of the bundle and activate it. With this change,
OPA should include the right etag in the bundle download request
thereby avoiding unnecessary bundle download and activation.

Fixes: #4544

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2022-04-13 09:40:17 -07:00
Stephan Renatus 51181a8257 storage/disk: wildcard partition validation, docs caveat (#4519)
A bunch of smaller follow-up tasks to #4381.

* storage/disk_test: check invalid patches with wildcard partition, too
* docs/disk: add caveat re: bundles loaded into memory
* storage/disk: auto-manage /system partitions

If these are found in the user-provided partitions, we'll error out.

* storage/disk: pretty-print partitions with "*" instead of %2A
* storage/disk: respect wildcard-replacement in partition validation

It is now allowed to replace a partition like

    /foo/bar

by

    /foo/*

also if multiple wildcards are used.

Caveats:

You cannot add a wildcard partition like /*/*, since it would overlap
the managed "/system/*" partition.

When attempting to go back from /foo/* to /foo/bar, an error is
raised _unconditionally_ -- we could check the existing data, but
currently don't.

* storage/disk: check prefix when adding wildcard partitions

The previously done check would have falsely returned that there is no problem
when adding a wildcard partition: lookup of "/foo/*" with '*' not interpreted
as a wildcard, but as a string, would yield a not-found, even if there was any
data under /foo/.

Now, we'll check the prefix-until-wildcard. It's more cautious than
theoretically necessary, but safe.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-03-31 09:52:26 +02:00
Stephan Renatus 516dd47dd1 runtime+storage: integrate disk storage
With this change, the disk backend (badger) becomes available for
use with the OPA runtime properly:

It can be configured using the `storage.disk` key in OPA's config
(see included documentation).

When enabled,
- any data or policies stored with OPA will persist over restarts
- per-query metrics related to disk usage are reported
- Prometheus metrics per storage operation are exported

The main intention behind this feature is to optimize memory usage:
OPA can now operate on more data than fits into the allotted memory
resources. It is NOT meant to be used as a primary source of truth:
there are no backup/restore or desaster recovery procedures -- you
MUST secure the means to restore the data stored with OPA's disk
storage by yourself.

See also #4014. Future improvements around bundle loading are
planned.

Some notes on details:

storage/disk: impose same locking regime used with inmem

With this setup, we'll ensure:

- there is only one open write txn at a time
- there are any number of open read txns at a time
- writes are blocked when reads are inflight
- during a commit (and triggers being run), no read txns can be created

This is to ensure the same atomic policy update semantics when using
'disk" as we have with "inmem". We're basically opting out of badger's
currency control and transactionality guarantees. This is because we
cannot piggy back on that to ensure the atomic update we want.

There might be other ways -- using subscribers, and blocking in some
other place -- but this one seems preferrable since it mirrors inmem.

Part of the problem is ErrTxnTooLarge, and committing and renewing
txns when it occurs: that, which is the prescribed solution to txns
growing too big, also means that reads can see half of the "logical"
transaction having been committed, while the rest is still getting
processed.

Another approach would have been using `WriteBatch`, but that won't
let us read from the batch, only apply Set and Delete operations.
We currently need to read (via an iterator) to figure out if we
need to delete keys to replace something in the store.  There is
no DropPrefix operation on the badger txn, or the WriteBatch API.

storage/disk: remove commit-and-renew-txn code for txn-too-big errors

This would break transactional guarantees we care about: while there
can be only one write transaction at a time, read transactions may
happen while a write txn is underway -- with this commit-and-reset
logic, those would read partial data.

Now, the error will be returned to the caller. The maximum txn size
depends on the size of memtables, and could be tweaked manually.
In general, the caller should try to push multiple smaller increments
of the data.

storage/disk: implement noop MakeDir

The MakeDir operation as implemented in the backend-agnostic storage
code has become an issue with the disk store: to write /foo/bar/baz,
we'd have to read /foo (among other subdirs), and that can be _much_
work for the disk backend. With inmem, it's cheap, so this wasn't
problematic before.

Some of the storage/disk/txn.go logic had to be adjusted to properly
do the MakeDir steps implicitly.

The index argument addition to patch() in storage/disk/txn.go was
necessary to keep the error messages conforming to the previous
code path: previously, conflicts (arrays indexed as objects) would
be surfaced in the MakeDir step, now it's entangled with the patch
calculation.

storage/disk: check ctx.Err() in List/Get operations

This won't abort reading a single key, but it will abort iterations.

storage/disk: support patterns in partitions

There is a potential clash here: "*", the path wildcard, is
a valid path section. However, it only affects the case when
a user would want to have a partition at

    /foo/*/bar

and would really mean "*", and not the wildcard.

Storing data at /foo/*/bar with a literal "*" won't be treated
differently than storing something at /fo/xyz/bar.

storage/disk: keep per-txn-type histograms of stats

This is done by reading off the metrics on commit, and shovelling
their numbers into the prometheus collector.

NOTE: if you were to share a metrics object among multiple transactions,
the results would be skewed, as it's not reset. However, our server
handlers don't do that.

storage/disk: opt out of badger's conflict detection

With only one write transaction in flight at any time, the situation
that badger guards against cannot happen:

A transaction has written to a key after the current, to-be-committed
transaction has last read that key from the store.

Since it can't happen, we can ignore the bookkeeping involved. This
improves the time it takes to overwrite existing keys.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-03-30 10:25:45 +02:00
Stephan Renatus ac7bb1fa70 storage: code cosmetics
Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-03-30 10:25:45 +02:00
Stephan Renatus d2914c0d54 build: bump golang: 1.17 -> 1.18
No change to go.mod's `go` stanza, so no changes in code compatibility.

However, it's used for building our docker images and release
binaries, and for fuzz testing in our nightly workflow.

Some test-related changes with the dns lookup built-in function's
error handling; and the hardcoded signature. Running

    go test ./topdown -run TestTopdownJWTEncodeSignECWithSeedReturnsSameSignature -count 10000

makes me believe that for whatever reason the signature changed,
it's at least stable.

topdown/http_test: Test-only change to accomodate this change in Go (https://go.dev/doc/go1.18):

    Certificate.Verify now uses platform APIs to verify certificate
    validity on macOS and iOS when it is called with a nil
    VerifyOpts.Roots or when using the root pool returned from
    SystemCertPool.

We're keeping the old message for go <= 1.17; in a silly-simple way.

Also:

* ci: build and test two old golang version on macos|linux

  We'll drop golang 1.15, keep one unsupported version (1.16).

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-03-28 07:24:21 +02:00
Anders Eknert 52b621301f logging: mask authorization header value in debug logs (#4496)
Fixes #4495

Signed-off-by: Anders Eknert <anders@eknert.com>
2022-03-26 08:25:28 +01:00
Ashutosh Narkar c08b81d68e plugins/logs: Fix broken retry logic
We were incorrectly resetting the retry counter after
every error condition instead of using the incremented
value. As a result, retry delay would always be 0s.
This meant that if OPA encountered an error while
uploading decision logs it would immediately retry
instead of doing an exponential backoff.

Fixes: #4486

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2022-03-25 15:25:10 -07:00
srlk e240759c98 Support for adding custom parameters and headers for OAuth2 Client Credentials Token request (#4476)
This change enables to add custom body parameters and headers to OAuth2 Client Credentials token request for non-standard authorization servers.

Signed-off-by: skosunda <skosunda@adobe.com>

Co-authored-by: skosunda <skosunda@adobe.com>
2022-03-24 23:44:50 +01:00
Kurt Roekle f42b2db214 SDK: support partial eval (#4240)
Adding the ability to partially evaluate when using the the SDK as a go library.
This allows for utilizing the existing OPA configuration (e.g. bundle, decisions,
etc) when partially evaluating.

Signed-off-by: Kurt Roekle <kroekle@gmail.com>
2022-03-11 18:50:39 +01:00
Stephan Renatus 9afdad7919 Status API: use jsonpb for json marshalling of prometheus metrics (#4324)
* Wrap the prometheus portion of our metrics in such a way that they use jsonpb for
   encoding to JSON, as prescribed by the protobuf library.

   Note: We're using jsonpb, not protojson, because there is no protobuf V2 version of
   github.com/prometheus/client_golang

* build(deps): bump github.com/prometheus/client_golang (#4307)

 This reverts commit 2f298db68c.

* CHANGELOG.md: add note re: JSON encoding of Status API payloads

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2022-02-22 09:25:19 +01:00
Rafael Otero Reinert 8569551dd8 status: publish metrics via prometheus endpoint (#4251)
To improve plugin and bundle monitoring, new metrics related to bundle-activation
are exported via the prometheus endpoint of the OPA service.

Signed-off-by: rafael otero reinert <rafaelreinert@gmail.com>
2022-02-08 14:21:33 +01:00
jkbschmid df2d409cc0 Status API: add http_code to response (#4328)
... so applications can perform more informed error handling, e.g. refresh credentials on 403.

Fixes #4259.

Signed-off-by: Jakob Schmid <jakob.schmid@sap.com>
2022-02-04 18:33:06 +01:00
Ashutosh Narkar dd02a7f848 Add support for delta bundles
Earlier a snapshot bundle would describe the full state of OPA's
policy/data and any update would require first erasing the state from
the existing bundle and then activating the new bundle.

This commit introduces a new bundle type called "delta".
Delta bundles contain patches to data instead of snapshots.
They allow users to efficiently make updates to OPA's data
cache.

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2022-01-29 13:28:54 -08:00
Anders Eknert d613b87e99 Fix error when initializing empty logging plugin (#4302)
Move the check for "emptiness" before validation and
injection of defaults, as there isn't a whole lot we
can do with a logging plugin that doesn't actually
log anything. Rather than error though, just return
nil to skip initialization of the plugin.

Fixes #4291

Signed-off-by: Anders Eknert <anders@eknert.com>
2022-01-29 09:25:08 +01:00
Anders Eknert 9887cd2348 test: fix "too many open files" issue on Mac OS (#4287)
`make test` was crashing on Mac OS due to "too many open files",
which could be traced to two different issues.

The first one was the disk based storage being opened but not closed
in some cases. This change takes the number of open file pointers
from >300 to ~30 after the disk based tests have run.

The second issue was a fixture HTTP server allowing keep-alive
connections, and since each test would call the server on a
random port, no connection reuse was possible. Since the test
ran over 400 iterations, and the max open file handles on Mac
OS by default is 256, things broke.

Signed-off-by: Anders Eknert <anders@eknert.com>
2022-01-27 07:35:34 +01:00
Ashutosh Narkar 4700768448 plugins/bundle: Update persisted bundle activation mechanism
Earlier errors encountered during loading and activating persisted
bundles would cause the OPA runtime to exit. This behavior is different
from when OPA downloads a bundle and activation errors if any would possibly
get resolved in successive download attempts. This fix adds a retry mechanism
to activate persisted bundles in an attempt to mimic the behavior seen during
bundle downloads. Errors if any encountered during the process will be
surfaced in the bundle's status update and not result in an abrupt exit.

Fixes: #3840

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2022-01-14 12:07:13 -08:00
José Carlos Chávez 449fdfee1e chore: improves auth plugin resolution. (#4175)
* chore: improves auth plugin resolution.

Currently when aiming to use a Plugin in credentials section, if the plugin is known then it will be resolved, if it isn't, it will be passed to the supported credentials and tried to be cast as HTTPAuthPlugin which ends up in a casting issue without further feedback on what was the plugin string.

Signed-off-by: José Carlos Chávez <jcchavezs@gmail.com>
2022-01-06 09:13:57 +01:00
Vlad Iovanov c0a692d1ee logging: Remove logger GetFields function (#4116)
This removes the GetFields function from the logger interface, as mentioned in #4114.

GetFields used to be called in one place, creating a new logger using fields from an
http client afaict. I am not sure if my changes have the desired effect in that case,
or how this was desired to work - since the fields of the client are always changing
when making requests.

Fixes #4114.

Signed-off-by: viovanov <vlad@aserto.com>
2022-01-06 07:42:22 +01:00
Torin Sandall a1aba348bc plugins/bundle: update file loader to support directories
Previously the loader only supported tarballs but now we can point
the bundle plugin at directories.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2021-12-22 17:46:37 +01:00
Torin Sandall 0962df058b plugins/bundle: ignore service errors for file:// resources
In 1d79ea97e3 we added support for
file:// urls but we never tested with a configuration missing service
definitions. This commit just relaxes the validation so that missing
serviecs do not cause errors for bundles with file:// urls.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2021-12-22 17:46:37 +01:00
Torin Sandall b68dfd8275 plugins/logs: make the requested_by field optional
Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2021-12-22 17:46:37 +01:00
Torin Sandall 1bc811b929 plugins/discovery: do not panic in Trigger() if downloader is nil
Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2021-12-22 17:46:37 +01:00
Stephan Renatus 883dc8817f plugins: support graceful shutdown through SDK (#4119)
With this change, the manager will respect the shutdown period if
it was supplied, otherwise it will use the passed context. This way,
SDK users can rely on the context (because the SDK doesn't set
the graceful shutdown period), but other callers are unaffected.

The added test is in the SDK, because that's where the problem had
manifested (#3980): when calling Stop(ctx) through the SDK, the
plugins.Manager's Stop function had set a smaller timeout (0, due
to the structs default value that hadn't been set to anything else),
and that would effectively leave the plugins zero time to cleanup.

Fixes #3980.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2021-12-14 09:43:22 +01:00
Stephan Renatus 74473468f2 download+rest: code cosmetics (#4120)
Not much of consequence here, a few code cleanups in tests and interfaces.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2021-12-13 09:35:26 +01:00
Torin Sandall 3d67420a38 server+plugins/status: Add v1/status endpoint
This commit adds a new server endpoint for pulling the status
information from the running OPA. Normally status is pushed by OPA to
remote locations but in some cases users may need to pull it.

The docs changes move the config and health API sections up into the
right location in the REST API page.

Fixes #4089

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2021-12-08 17:06:53 -08:00
Stephan Renatus e8d1b5f490 plugins/rest: refactor AWS credentials provider config validation (#4081)
* plugins/rest: refactor AWS credentials provider config validation

* plugins/rest: cleanup env var handling in tests

The TestNew case of rest_test.go had failed when run in isolation,
but passed when running all of the packages tests. With these
changes to how env vars are handled, it passed both alone and when
run with all the other tests.

Also migrated the TestWebIdentityCredentialService test to use
test.WithTempFS instead of dealing with the files itself.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2021-12-07 18:38:03 +01:00
Torin Sandall b5212fcecc plugins/discovery: Improve error message about prohibited config
Previously the discovery plugin would just log a generic error if any
plugins were enabled. With this commit, it will log an error that
mentions which plugins were enabled, making the source of the problem
a bit more obvious.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2021-12-02 20:52:31 +01:00
Branden Horiuchi cfa4c5afc5 Exposes the http router to the plugin manager
In order to expose the http router to plugins a private router property was added to the plugin manager along with a GetRouter method to access it. A router is also initialized in the NewRuntime function if one is not provided in the runtime params. Fixes #2777

Signed-off-by: Branden Horiuchi <Branden.Horiuchi@blackline.com>
2021-12-01 10:54:51 -08:00
Ashutosh Narkar a4356424ea plugins/rest/aws: Add new credential provider for AWS credential files
Earlier users could provide sensitive values such as AWS
secret keys using environment variables. This change adds
a new AWS credential provider which reads the credential file
to fetch credentials for a named profile. If no profile is
provided, the "default" profile is used. OPA reads the
credentials from the file on each request and uses them
for authentication.

Fixes: #2786

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
Co-authored-by: Stephan Renatus <stephan.renatus@gmail.com>
2021-12-01 11:18:17 +01:00
Anders Eknert 9cc0d2cfe9 Make print() work in decision masking policy
Signed-off-by: Anders Eknert <anders@eknert.com>
2021-12-01 10:39:08 +01:00
Torin Sandall 0649fe96e2 plugins: Fix logger initialization on plugin manager
The plugin manager was initializing the logger _after_ creating
service clients which meant that service clients ended up relying on
the global logger. Since the runtime package did not configure the log
level on the global logger, the logs from the service clients were
missing.

This commit updates the plugin manager to initialize the logger
_before_ creating service clients and updates the runtime package to
set the log level on the global logger as a fallback.

Fixes #4071

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2021-11-30 11:06:07 -08:00
Anders Eknert c30494e7a0 plugins/rest/aws: debug log metadata error (#4061)
A user on Slack is getting 500 responses from the AWS metadata API
using a configuration like the below:

```yaml
 services:
  - name: svc-bundle
    url: https://opa-policies-dev.s3.amazonaws.com
    credentials:
      s3_signing:
        metadata_credentials:
          aws_region: us-east-1
          iam_role: arn:aws:iam::1234:role/opa-bundles
```
It's really hard to know why this might be given how we currently
only log the HTTP status code under this error condition.

This tries to print the response body on debug level (if set).

Signed-off-by: Anders Eknert <anders@eknert.com>
2021-11-29 13:18:46 +01:00
Stephan Renatus 2b7df1c402 plugins/logs: allow for using service AND custom plugin (#4039)
Now any subset of service, plugin, console logger should be usable.

Fixes #4013.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2021-11-19 10:22:57 +01:00
David Lu 41fe76862b Add Azure HTTP auth plugin
This commit adds an HTTP auth plugin that fetches bearer access tokens using managed identities for Azure resources. This plugin will complement the existing AWS and GCP auth plugins.

Signed-off-by: David Lu <david.scowluga@gmail.com>
2021-11-08 19:14:02 +01:00
Ashutosh Narkar 4a48b65d7b Add an adaptive limit for the upload chunk size
This commit adds a chunk adaptive limit that acts as a
measure for encoding as many decisions into each chunk as possible.
This change should help fill-up the chunks close to their allowed
limit and thereby help reduce netwrok and memory resources.

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2021-11-03 09:54:59 -07:00
Torin Sandall 679c3de78b runtime: Enable print calls
This commit enables print() calls inside of the server for INFO and
DEBUG log levels. The print hook is plumbed through to the server via
the manager so that other server implementations (e.g., the Envoy
plugin) can be updated similarly.

The server will compile print() calls for the /v1/query API but not
others since (i) print() calls inside the policies will already have
been compiled and (ii) the queries are limited to fetching `data`
paths and therefore cannot contain print() calls themselves. The
bundle plugin has been updated to compile print() calls as well--this
way the bundle plugin/server will respect incoming bundles and not
attempt to override them.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2021-10-14 09:31:16 -07:00
Torin Sandall e9d04fc1f5 runtime: Refactor logger usage
This commit does not change any functionality except it provides
callers with a way to provide a logger when instantiating the
runtime. Previously, the runtime had hardcoded dependencies on the
global logrus logger which made it problematic to test logging
behaviour. With this change, the logger can be supplied as a
parameter (which allows the caller to mock out the logger in tests...)

As part of this change, the dependencies on logrus have been moved out
of the runtime package entirely.

This commit includes a breaking change to the
runtime.NewLoggingHandler function: the function now requires a logger
to be supplied.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2021-10-14 09:31:16 -07:00
Ashutosh Narkar ea96db6de6 plugins: Fix default trigger mode in the non-discovery path
When individual plugins (except discovery) were configured, the
default trigger mode was set as periodic. So if the plugin specified
a different mode (eg. manual), the configuration check would incorrectly
fail on account of a mode mismatch. This commit fixes the issue by
updating the trigger mode check to not specify a default mode in
scenarios when only plugins (except discovery) are configured.

Fixes: #3797

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2021-09-23 09:10:17 -07:00
Torin Sandall 0b7a2c38af Add support for manual plugin triggers
This commit introduces the idea of manual triggers to trigger
plugins. Currently plugins such as discovery, bundle, decision log etc.
perform their functions in a timer-based loop. For example, the bundle
plugin periodically checks for new bundles by polling a remote server.

This change adds the ability to trigger a plugin thereby allowing callers
to control when a bundle download happens, when a decision log is
uploaded etc. The periodic mode is still the default for the plugins.

This feature allows callers to trigger individual plugins. Plugins perform
their functions and then report back to the caller when done.

Co-authored-by: Torin Sandall <torinsandall@gmail.com>
Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2021-08-26 09:35:02 -07:00
Rafael Fernández López 581ba9c456 documentation: fix uid and message returned to the Kubernetes apiserver (#3730)
* documentation: always return the `uid` to the Kubernetes apiserver

The Kubernetes API server will reject the answer from any webhook that
does not contain the `uid` present in the request [1]. Failing to do
so will not only result in a warning, but in the answer from the
webhook being ignored, and the request rejected [2].

[1] https://github.com/kubernetes/apiserver/blob/464eee4062a8f21f785e657b32b83f19d693af8d/pkg/admission/plugin/webhook/request/admissionreview.go#L52-L55
[2] https://github.com/kubernetes/apiserver/blob/464eee4062a8f21f785e657b32b83f19d693af8d/pkg/admission/plugin/webhook/validating/dispatcher.go#L236-L239

* documentation: rename `reason` to `message` on certain objects

When the object refers to an `AdmissionReview` from Kubernetes, what
OPA calls the `reason` is the `message` field.

* documentation: create `opa-server` secret in the `opa` namspace

Signed-off-by: Rafael Fernández López <rfernandezlopez@suse.com>
2021-08-20 09:51:19 +02:00
Stephan Renatus e732b0b482 topdown/buitins: io.jwt.encode_sign uses BuiltinContext random source (#3738)
It didn't before, so we had not much control over the entropy that is getting into the signature for ecdsa.

This is useful if you want reproducible outcomes over multiple policy evaluations, such as in testing.

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2021-08-19 07:43:16 +02:00
Grant Shively 6369788d31 plugins, runtime: Add visibility for server init
- Plugins can now access a channel which receives a message when the OPA
  server is fully initialized and ready to receive traffic.
- Added ServerInitialized() and ServerInitializedChannel() to plugin
  manager.
- Runtime now calls ServerInitialized() when server listeners are
  initialized.

Fixes #3701

Signed-off-by: Grant Shively <gshively@godaddy.com>
2021-08-12 14:31:56 -07:00
Torin Sandall 8b40acea0a logging: Fix console logger instantiation
This commit fixes the console loggers so that messages are emitted
regardless of the debug log level. The problem was that in 3fcc875 we
updated the plugins to use a console logger obtained from the plugin
manager as opposed to a global logger instantiated in the plugins
package--the console logger obtained from the plugin manager was
instantiated in the runtime package by calling
logging.NewStandardLogger. Unfortunately, logging.NewStandardLogger
does not create a new logger--it returns the global logrus
logger.

This commit fixes the issue by deprecating logging.NewStandardLogger
and introducing two new functions in the logging package:

* logging.Get() - this replaces the old logging.NewStandardLogger
  function--this function should be called to obtain the debug logger
  used throughout OPA.

* logging.New() - this actually returns a new logger that can be
  configured independently from the debug logger used throughout
  OPA.

The runtime and sdk packages have been updated to call logging.New()
to obtain console loggers and the rest of the codebase has been
updated to call logging.Get() in place of logging.NewStandardLogger().

Fixes #3654

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
2021-07-27 09:39:01 -07:00