Commit Graph

107 Commits

Author SHA1 Message Date
Anders Eknert e43ef0a979 Use any in place of interface{} (#7566)
Earlier this evening I tried to run the Go
[modernize](https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize)
analyzer on OPA. That didn't go as planned:

- https://github.com/golang/go/issues/73661
- https://github.com/golang/go/issues/73663

While we wait for that to be fixed, I figured an old-fashioned
search-and-replace across the repo may work for at least the
`interface{}` to `any` conversion. That should help make it easier
to see the other fixes as applied by the modernize tool once it has
had those issues resolved.

Signed-off-by: Anders Eknert <anders@styra.com>
2025-05-12 13:57:48 +02:00
efi shtain 13f212ba53 add support for aws sso credentials provider (#7527)
Signed-off-by: Efi Shtain <efi@autokitteh.com>
2025-05-09 11:27:17 -05:00
Sebastian Spaink d65888c14f plugins/status: FIFO buffer channel for status events to prevent slow status API blocking (#7522)
If a status API is slow to respond it can cause OPA to be blocked writing to an unbuffered channel. This fixes it by using a buffered channel that never blocks but drops the oldest status update if full.

Signed-off-by: Sebastian Spaink <3441183+sspaink@users.noreply.github.com>
2025-04-23 11:53:09 +02:00
robmyersrobmyers 31c7d8b966 graphql: Cache GraphQL schema parse results (#7457)
This commit stores parsed GraphQL schemas to the cache, which improves
the performance of GraphQL operations that parse the schema more than once.

Queries are not cached.

Resolves: #5377

Signed-off-by: Rob Myers <1243316+robmyersrobmyers@users.noreply.github.com>
2025-04-17 17:59:08 +02:00
Charlie Egan aa2a16f139 docs: Add manual trigger to integration docs (#7473)
Following: https://github.com/orgs/open-policy-agent/discussions/685

This comes up often enough that it should be documented.

Based on the handy example in: https://github.com/open-policy-agent/opa/issues/3828#issuecomment-1013211919

Signed-off-by: Charlie Egan <charlie@styra.com>
2025-03-31 12:07:32 +01:00
Sebastian Spaink cd66fa36e2 feat: new event-based decisions log buffer implementation (#7446)
This new event-based buffer provides a performance improvement over
the existing buffer by reducing locks and allowing concurrent writes and uploads.
The buffer size is managed by number of individual events opposed to total bytes.

Signed-off-by: sspaink <sspaink@styra.com>
2025-03-26 16:35:45 -05:00
Shiqi Yang c8febc8625 feat: add more distributed tracing options (#7421)
Resolves: #7412

Signed-off-by: Shiqi Yang <syang482@bloomberg.net>
2025-03-24 19:29:00 +01:00
Brian Cullen 08f98e9527 Add Additional Resource Attributes for OpenTelemetry
Adds the "deployment.environment" resource attribute to those that can
be configured for OpenTelemetry. This was done as some collectors,
including Datadog, require this value to properly classify traces.

Note: the "deployment.environment" attribute is being deprecated in
future versions of the OTel schemas and this may need to be
updated when that library is upgraded.

Fixes #7322

Signed-off-by: Brian Cullen <brianc@kahoot.com>
2025-02-04 11:35:29 -08:00
Johan Fylling 6e83f2ac53 topdown: jwt cache (#7274)
Adding cache to `io.jwt` token verification built-ins

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2025-01-24 23:03:26 +01:00
Jessie Wu 0d50f52f45 Customize status bundle_loading_duration_ns and add tests
Signed-off-by: Jessie Wu <jwu730@bloomberg.net>
2024-11-19 09:35:17 -08:00
Hitoshi Kamezaki 2c76de45a1 plugins/rest/azure: Support managed identity for App Servivce / Container Apps
IDENTITY_ENDPOINT and IDENTITY_HEADER envirnnment variables are
provided on Azure App Service for getting the token.
We can detect these variables and switch the endpoint
and header value from IMDS.

Fixes: #7085
Signed-off-by: Hitoshi Kamezaki <kamezaki@ap-com.co.jp>
2024-10-08 20:18:14 -07:00
Anders Eknert 6303aa201c Use new value cache for json.match_schema (#7081)
I figured I'd test this out anyway, and this seemed like
a good case given that there was an actual issue on this.

Testing response times with OPA running as a server, and
the first request is ~800 ms while the following ones are
~10 ms.

Fixes #7011

Signed-off-by: Anders Eknert <anders@styra.com>
2024-10-01 14:46:10 +02:00
Ashutosh Narkar 2c56293695 Add a new inter-query value cache to cache data across queries
This commit adds a new inter-query value cache that built-in
functions can use to cache information across queries.
For example, the `regex` and `glob` builtins can use this
to cache compiled regex and glob match patterns respectively.

The number of entries in the cache can be configured via the OPA
config. By default there is no limit.

Fixes: #6908

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2024-09-23 13:03:03 -07:00
Anders Eknert 7b535a79a6 Docs: suggest using opa-config.yaml as name for config file (#6966)
And update some references throughout the docs.

Fixes #6959

Signed-off-by: Anders Eknert <anders@styra.com>
2024-08-27 23:57:15 +02:00
Brett McBride fd0821c1b3 distributedtracing: adding distributed tracing resource attributes
Adding a resource map to the distributed_tracing
config. Entries in this map will be passed through to the OpenTelemetry SDK where they will be
added as resource attributes. The available resource attributes are service.namespace,
service.version and service.instance.id. see
https://opentelemetry.io/docs/specs/semconv/resource/

Fixes: #6492

Signed-off-by: Brett McBride <brett@deakin.edu.au>
2024-08-26 14:39:08 -07:00
Anders Eknert 47c1e2ea2f docs: mention http.send in inter-query cache config docs (#6953)
It wasn't obvious when configuring the inter-query cache might be needed, as
it wasn't mentioned which built-in made use of it.

Also fixed the docs on annotations where it said `scope` only applies to
`schemas`.

Signed-off-by: Anders Eknert <anders@styra.com>
2024-08-22 15:27:11 +02:00
Matthew Bamber 971a7219f3 fix: Support AWS_CONTAINER_CREDENTIALS_FULL_URI metadata endpoint
Support loading credentials from the AWS_CONTAINER_CREDENTIALS_FULL_URI
metadata endpoint which is helpful for AWS SnapStart lambdas

Fixes #6893
Signed-off-by: Matthew Bamber <mattb@grabyo.com>
2024-07-29 10:40:05 -07:00
Philip Conrad c5706eef7c server+util: Limit max request sizes, prealloc request buffers (#6868)
This commit introduces a few major changes:
 - (Breaking change) Limits now exist for maximum request body sizes.
 - Buffers are preallocated for reading request bodies.
 - Buffers are preallocated for decompressing request bodies.
 - Gzip decoder instances are reused in a `sync.Pool` across requests.

The effect on garbage collection is dramatically fewer GC pauses, giving
a roughly 9% RPS improvement in load tests with gzipped request bodies.
For larger request sizes, the number of GC pauses is dramatically
reduced, although the peak pause time may increase by a few percent.

Implementation notes:
 - The DecodingLimits handler enforces the max request body size both
   through a Content-Length check, and a MaxBytesReader wrapper around
   the payload.
 - The DecodingLimits handler passes the gzip payload size limit down
   using a context key.

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
2024-07-22 13:15:08 -04:00
Sven Grosen e2721d3e01 Resurrect Workload Identity Work (#6802)
Add support for using Azure Workload Identity authentication.

Signed-off-by: Sven Grosen <svengrosen@gmail.com>
2024-07-01 20:02:06 +02:00
Ashutosh Narkar a8ac7b38bb plugins/logs: Include http request context in decision logs
It would be useful if users had the ability to enhance the
decision log with info from the incoming HTTP request such as
headers. This change allows users to configure headers whose
values if present in the incoming HTTP request would be
surfaced via the decision log. This can be extended in the
future to include more context from the request.

Fixes: #6693

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2024-05-20 11:08:42 -07:00
Torin Sandall 93ff7191f1 docs/configuration: Tidy up headers in Services section (#6695)
Signed-off-by: Torin Sandall <torin@styra.com>
2024-04-13 04:58:26 +02:00
Ashutosh Narkar d3a4a87f50 plugins/rest: Update service name while generating signature
The service name used for signing the request must be same as
the host header which is of the form https://sts.*

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2024-03-27 12:08:00 -07:00
Ashutosh Narkar 5f16f4a238 plugins/rest: Add support to get temp creds via AssumeRole
Adds support for signing AWS requests using temporary credentials
obtained from AWS STS via AssumeRole operation. One use-case of
this mechanism is for allowing existing IAM users to access AWS resources
that they don't already have access to. It is also useful as a means to
temporarily gain privileged access.

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2024-03-26 15:29:09 -07:00
Rudrakh Panigrahi 018b8adc04 Add documentation for new cache config parameters (#6518)
Related to commit: f063c90

Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
2024-01-10 08:55:39 +01:00
Charlie Egan 5aa3524d75 docs: Update note about use of manual triggers (#6465)
This option is only available when using OPA from go and not in the
server.

Context: https://github.com/open-policy-agent/opa/issues/1336

Signed-off-by: Charlie Egan <charlie@styra.com>
2023-12-07 19:18:20 +01:00
francoisauclair911 a8b57b0664 fix: Disk storage broken link
Signed-off-by: francoisauclair911 <francois.auclair.911@gmail.com>
2023-11-21 08:28:25 -08:00
aarnautu 38c997eef4 This change adds support to configurable prometheus buckets
http_request_duration has fixed, hardcoded number of buckets with no possibility to tweak them
For cases when the most of the latencies are above 1ms, with only 4 available buckets there's no good insight on OPA's performance.

This implementation:
- adds the possibility for the buckets to be configurable in ```server.metrics.prom.http_request_duration_seconds.buckets``` key
- it's not a breaking change, if the buckets are not present in the configuration, the metric is configured with the existing values as a fallback

Signed-off-by: aarnautu <aarnautu@adobe.com>
2023-10-06 13:27:46 -07:00
Dennis Geurts b9f2e892e8 Update documentation on GCS bundles (#6264)
When an object in GCS contains special characters such as slashes (/) these
need to be url-encoded in the configuration. If not, the bundle will not be found.

e.g. `bundles/bundle.tar.gz` should be entered as `bundles%2fbundle.tar.gz`

This PR adds a small note to help the reader know about this.

Signed-off-by: Dennis Geurts <dennisg@dennisg.nl>
2023-10-01 19:38:10 +02:00
guangwu 6abb668205 Fix typos (#6135)
Fix typos

Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
2023-08-02 10:05:57 +02:00
Prasanth Ullattil db2f8ae7bb Add AWS KMS support for OAuth2 Client Credentials JWT authentication
This implementaion adds new configuration properties to "oauth2"
aws_kms: AWS KMS key details
aws_signing: Infomation for signing AWS requestion, similar to s3_signing

References:
1) https://github.com/go-jose/go-jose/blob/v3/asymmetric.go#L501
2) https://github.com/codelittinc/gobitauth/blob/master/sign.go#L101

Signed-off-by: Prasanth Ullattil <prasanth.ullattil@dnb.no>
2023-07-03 11:01:15 -07:00
Johan Fylling 77475dc2ab rest: Make Amazon AWS STS domain configurable for AWS rest plugin
Fixes: #5915

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2023-05-17 11:41:53 -07:00
DerGut b626a2c93b Use existing auth plugins with OCIDownloader
This change addresses solutions 2) and 3) of the related issue #5553.
It mainly starts using the (now exposed) `Config.AuthPlugin()` function
of the `rest` package in the `download.OCIDownloader`. This allows it
to use any `HTTPAuthPlugin` that is defined in the `Config.Credentials`
section and makes it much more consistent with behavior of the
`download.Downloader` and potential other uses of the rest package.

Fixes #5553

Signed-off-by: DerGut <jannik.steinmann@gmx.de>
2023-04-25 17:15:46 -07:00
AdrianArnautu 9e97f98d12 This change allows the HTTP clients to consume and send gzip compressed response and request body. (#5696)
It is available for the following REST API endpoints:
- GET & POST HTTP methods on /v0/data & /v1/data endpoints
- POST HTTP method on /v1/compile endpoint

HTTP clients can optionally:
- send 'Accept-Encoding: gzip' header and expect a gzip compressed body and a Content-Encoding: gzip response header. The server will send the content encoded as gzip only after a threshold defined by server.encoding.gzip.min_length (default value is 1024). If the size is below the threshold, the body is not compressed
- send 'Content-Encoding: gzip' header and a gzip compressed body and expect the server to correctly interpret the request

Fixes #5310

Signed-off-by: aarnautu <aarnautu@adobe.com>
2023-03-09 09:38:39 +01:00
Anders Eknert eb087de363 cli: allow remote bundle URL shorthand for run command (#5675)
Fixes: #5674

Signed-off-by: Anders Eknert <anders@styra.com>
2023-02-21 13:45:51 +01:00
Ashutosh Narkar 16300529a2 plugins/discovery: Support to persist and load discovery bundle from disk
This commit adds support to persist and load discovery bundle from disk.
Only the discovery bundle itself is persisted and not the configuration produced
by the discovery bundle. A new field is introduced in OPA's discovery
configuration that can be optionally set to enable OPA to write and
read the discovery bundle from disk. This feature would enable OPA to evaluate
the discovery bundle in scenarios where it is unable to communicate with the
bundle server on start-up.

Fixes #2886

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2023-02-06 13:43:02 -08:00
Anders Eknert ed455fb806 Fix doc typos (#5514)
Signed-off-by: Anders Eknert <anders@eknert.com>
2023-01-02 11:29:34 +01:00
Jay Wineinger ea39bf35b9 Feat: Add support for AWS Signing Version 4A (#5489)
AWS is rolling out an extension to SigV4 called Signature Version 4A (SigV4A)
which enables signatures that are valid in more than one AWS Region. This is
required for signing multi-region API requests, for example with Amazon S3
Multi-Region Access Points (MRAP). This commit lets OPA use an S3 MRAP as
a bundle source.

The SigV4A implementation used in this commit is a modified version of
internal code from the `aws-sdk-go-v2` project:
https://github.com/aws/aws-sdk-go-v2/tree/93c3f18/internal/v4a

This commit also refactors the existing V4 signing code into a shared
`internal/providers/aws` package that contains both the existing V4 signing
code as well as the V4A signing code added by this PR.

Fixes #5429

Signed-off-by: Jay Wineinger <jawineinger@spscommerce.com>
2022-12-19 16:11:50 -05:00
Omri Gazitt 41b35e9a94 docs/oci: corrected config section (#5492)
"scheme" is correct, "schema" was not.

Signed-off-by: Omri Gazitt <ogazitt@gmail.com>
2022-12-19 08:18:31 +01: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
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
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
Anders Eknert 824aae68fe Fix typo in configuration docs
Signed-off-by: Anders Eknert <anders@eknert.com>
2022-09-19 18:20:19 -04:00
Paul Foryt 060bcf495a docs: Fix AWS Signature section in Configuration
Fix two issues with the AWS Signature section in the Configuration doc:

* Update broken link to the AWS EKS IAM Roles for Service Accounts doc
* Move displaced note on service array/object definition to the Services section

Signed-off-by: Paul Foryt <7229568+pauly4it@users.noreply.github.com>
2022-08-24 17:04:07 -07:00
Li Wang 53b8192101 docs/configuration: Fix profile_credentials AWS docs (#4831)
Signed-off-by: Li Wang <li.wang3@fmr.com>
2022-06-30 09:35:56 +02:00
carabasdaniel c7f734acba Update configuration docs for private images in OCI registries (#4702)
Signed-off-by: carabasdaniel <dani@aserto.com>
2022-06-05 21:49:36 +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
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
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
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
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