Commit Graph

365 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
Johan Fylling a179a24c48 v1 API
All packages, except for `cmd` and `internal`, have been moved into a new `v1` root package.

Old packages are kept for backwards-compatibility reasons. All contained code is replaced with simple type aliases and proxy functions to `v1` implementations.

Old packages default to the Rego v0 syntax, new `v1` packages default to the Rego v1 syntax.

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-12-12 15:27:34 +01:00
Johan Fylling 7bb6dbe36b Preparing for v1 API
Moving (most) source to v1 root package to prepare for v0/v1 API separation.

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-12-12 15:09:03 +01:00
Anders Eknert 26ad67812d More reduced allocations (#7193)
For the first time, down  under a 100 million allocations
when running `regal lint bundle` 🎈

**main**
```
BenchmarkLintAllEnabled-10    1	2538350916 ns/op	6182626816 B/op	108424249 allocs/op
```

**pr**
```
BenchmarkLintAllEnabled-10    1	2282894416 ns/op	5310032744 B/op	93674054 allocs/op
```

But there's more to it than just the number of allocations:

```
➜ hyperfine -i --warmup 1 'regal lint bundle' 'regal-new lint bundle'
Benchmark 1: regal lint bundle
  Time (mean ± σ):      2.822 s ±  0.055 s    [User: 19.299 s, System: 0.603 s]
  Range (min … max):    2.743 s …  2.961 s    10 runs

Benchmark 2: regal-new lint bundle
  Time (mean ± σ):      2.373 s ±  0.040 s    [User: 15.940 s, System: 0.575 s]
  Range (min … max):    2.315 s …  2.435 s    10 runs

Summary
  regal-new lint bundle ran
    1.19 ± 0.03 times faster than regal lint bundle
```

Most notable changes:

- Reuse trieTraversalResult in indexing, as these were expensive
  and short-lived. This had the most dramatic impact on the number
  of reduced allocations of all the changes here.

- Optimize *set, *object and *Array operations to minimize
  allocations by using "primitive" form iteration instead of
  the function literal counterparts internally, and to only
  reset the sort guard when needed.

- New Array.Equal implementation does not remove any allocations
  as the old implementation didn't allocate either. It did however
  perform much better for the case where the compared arrays were
  not equal.

Signed-off-by: Anders Eknert <anders@styra.com>

# Conflicts:
#	topdown/casts.go
2024-12-04 16:05:36 +01:00
Hisham Akmal 03f6479c95 to_number : built-in function now rejects "Inf", "Infinity" and "NaN" values #7203 (#7203)
Signed-off-by: sikehish <hisham0502@gmail.com>
2024-12-03 15:42:36 +01:00
berdanA 26e2db328d topdown: improve scientific notation parsing in extractNumAndUnit
- Updated extractNumAndUnit to recognize and correctly parse scientific notation, including cases with 'e' or 'E' followed by an exponent (e.g., "1e10", "3.2E4").
- Ensures that 'e' or 'E' is treated as part of the number if followed by digits, enhancing compatibility with scientific notation inputs.
- Scientific notation with units now also parses correctly (e.g., "1e10GB" extracts "1e10" as the number and "GB" as the unit).
- Maintains behavior for cases without units, allowing either the number or unit portion to be empty, while improving overall string parsing logic.
- Added tests for scientific notation parsing in `units.parse_bytes`, including both SI and binary units (e.g., KB, MiB, GiB, KiB).
- Included cases for uppercase, lowercase, and mixed case formats with scientific notation.
- Added validation for numbers without units defaulting to bytes.

Fixes #7142

Signed-off-by: bakar <berdan.akar@rise-world.com>
2024-11-08 12:48:02 -08:00
Matthew A Johnson c74b50a52a tests: Fixing test-time-0947 (#7093)
Signed-off-by: Matthew Johnson <matjoh@microsoft.com>
2024-10-03 16:37:40 +02:00
Johan Fylling 27dcd29922 rego-v1: Future-proofing misc tests to be 1.0 compatible
This is the last few tests to be refactored before all tests are compatible with the v1-by-default switch coming in OPA 1.0.

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-09-26 09:19:14 -07:00
Johan Fylling f492f96d80 rego-v1: Future-proofing topdown pkg tests to be 1.0 compatible (#7014)
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-09-23 21:17:50 +02:00
Johan Fylling 6bfd4cdf92 rego-v1: Future-proofing Wasm tests to be 1.0 compatible (#7047)
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-09-20 22:35:29 +02:00
Matthew A Johnson c9443d0c45 testcases: fix indentation in v0/test-reachable-paths-0422.yaml (#7039)
Due to insufficient indentation, this file would be rejected by compliant YAML parsers.
This small fix resolves the issue.

Signed-off-by: Matthew Johnson <matjoh@microsoft.com>
2024-09-19 13:11:55 +02:00
Johan Fylling 36dd26ac92 rego-v1: Future-proofing test pkg tests to be 1.0 compatible (#7030)
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-09-18 14:18:00 +02:00
Ptroger 3587ccf4b1 fix: handle "long long" overflow with wasm (#6995)
In the Wasm modules built with OPA, arithmetic comparison for very large numbers
could be wrong, caused by an integer overflow.

Fixes #6991.

Signed-off-by: Pierre Troger <pierre@narval.xyz>
2024-09-05 14:01:31 +02:00
Johan Fylling 5d087830d2 topdown: Adding unification scope to virtual-cache key
Fixing issue where ref-head rules could put evaluation result scoped by call-site ref unification into global virtual-cache, which would later erroneously be read by ref to same rule/virtual document but with different "unification scope".

Fixes: #6926
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-08-28 11:50:31 +02:00
Johan Fylling 3e7e6a00de test: Creating v1 yaml tests from existing v0 tests (#6924)
Fixes: #6864

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-08-20 12:13:25 +02:00
Charlie Egan 14ff052432 builtins: Marshal JWT encode sign inputs as JSON
Fixes https://github.com/open-policy-agent/opa/issues/6925

This change modifies the `io.jwt.encode_sign` built-in to marshal the
parameters as JSON before signing the JWT. The previous implementation
was using String(), which was a sort of pseudo-JSON that was almost
correct but used the wrong JSON syntax for the set type.

I have chosen to marshal the headers in the same way as the payload as
the 'crit' header can also be an array type. I marshal the signature the
same way for consistency with the other two.

Signed-off-by: Charlie Egan <charlie@styra.com>
2024-08-15 09:02:21 -07:00
dependabot[bot] d1fc7e92c1 build(deps): bump the go-opentelemetry-io group across 1 directory with 6 updates (#6847)
* build(deps): bump the go-opentelemetry-io group across 1 directory with 6 updates

Bumps the go-opentelemetry-io group with 3 updates in the / directory: [go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp](https://github.com/open-telemetry/opentelemetry-go-contrib), [go.opentelemetry.io/otel/exporters/otlp/otlptrace](https://github.com/open-telemetry/opentelemetry-go) and [go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc](https://github.com/open-telemetry/opentelemetry-go).


Updates `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` from 0.46.1 to 0.53.0
- [Release notes](https://github.com/open-telemetry/opentelemetry-go-contrib/releases)
- [Changelog](https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/CHANGELOG.md)
- [Commits](https://github.com/open-telemetry/opentelemetry-go-contrib/compare/zpages/v0.46.1...zpages/v0.53.0)

Updates `go.opentelemetry.io/otel` from 1.21.0 to 1.28.0
- [Release notes](https://github.com/open-telemetry/opentelemetry-go/releases)
- [Changelog](https://github.com/open-telemetry/opentelemetry-go/blob/main/CHANGELOG.md)
- [Commits](https://github.com/open-telemetry/opentelemetry-go/compare/v1.21.0...v1.28.0)

Updates `go.opentelemetry.io/otel/exporters/otlp/otlptrace` from 1.21.0 to 1.28.0
- [Release notes](https://github.com/open-telemetry/opentelemetry-go/releases)
- [Changelog](https://github.com/open-telemetry/opentelemetry-go/blob/main/CHANGELOG.md)
- [Commits](https://github.com/open-telemetry/opentelemetry-go/compare/v1.21.0...v1.28.0)

Updates `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc` from 1.21.0 to 1.28.0
- [Release notes](https://github.com/open-telemetry/opentelemetry-go/releases)
- [Changelog](https://github.com/open-telemetry/opentelemetry-go/blob/main/CHANGELOG.md)
- [Commits](https://github.com/open-telemetry/opentelemetry-go/compare/v1.21.0...v1.28.0)

Updates `go.opentelemetry.io/otel/sdk` from 1.21.0 to 1.28.0
- [Release notes](https://github.com/open-telemetry/opentelemetry-go/releases)
- [Changelog](https://github.com/open-telemetry/opentelemetry-go/blob/main/CHANGELOG.md)
- [Commits](https://github.com/open-telemetry/opentelemetry-go/compare/v1.21.0...v1.28.0)

Updates `go.opentelemetry.io/otel/trace` from 1.21.0 to 1.28.0
- [Release notes](https://github.com/open-telemetry/opentelemetry-go/releases)
- [Changelog](https://github.com/open-telemetry/opentelemetry-go/blob/main/CHANGELOG.md)
- [Commits](https://github.com/open-telemetry/opentelemetry-go/compare/v1.21.0...v1.28.0)

---
updated-dependencies:
- dependency-name: go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: go-opentelemetry-io
- dependency-name: go.opentelemetry.io/otel
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: go-opentelemetry-io
- dependency-name: go.opentelemetry.io/otel/exporters/otlp/otlptrace
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: go-opentelemetry-io
- dependency-name: go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: go-opentelemetry-io
- dependency-name: go.opentelemetry.io/otel/sdk
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: go-opentelemetry-io
- dependency-name: go.opentelemetry.io/otel/trace
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: go-opentelemetry-io
...

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Johan Fylling <johan.dev@fylling.se>
2024-07-20 08:25:08 +02:00
Manish Giri c70544045b Implement a built-in function for String count
Fixes #6827

Signed-off-by: Manish Giri <manish.giri.me@gmail.com>
2024-07-03 15:50:34 -07:00
Johan Fylling c2cede76b3 ast: expanding nested expressions in every domain (#6832)
Fixes: #6790
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-06-26 19:45:49 +02:00
Johan Fylling 5464b005e8 Bumping golangci-lint to v1.59.1 (#6817)
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-06-19 15:13:43 +02:00
Johan Fylling 62834a22a6 Asserting every domain is an collection type before evaluation (#6763)
Fixing an issue where a non-collection `every`-domain didn’t fail evaluation.
Removing a possible attack surface, where an attacker with the ability to craft portions of the input document could replace a value with an expected collection type, that is known to be processed by an `every`-statement, with a non-collection value and thereby would cause the policy to accept a query that should otherwise be rejected.

Fixes: #6762
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2024-05-28 10:16:58 +02:00
Sean Williams e0ee7418b0 topdown: Add json.marshal_with_options() builtin for indented/"pretty-printed" and/or line-prefixed JSON (#6636)
Fixes #6630

Signed-off-by: Sean Williams <72675818+sean-r-williams@users.noreply.github.com>
2024-04-05 10:11:01 +02:00
occupyhabit d6c8c1b51b chore: remove repetitive words
Signed-off-by: occupyhabit <wangmengjiao@outlook.com>
2024-03-25 11:28:12 -07:00
Johan Fylling 143a8e6ac9 topdown: Fixing overactive Early Exit suppression
Fixing two issues where Early Exit was being suppressed when it shouldn't have been:

1. A cache hit for a rule/function discards EE for the call-site.
2. Non-EE rule/func discards EE for call-site.

Fixes: #6566
2024-03-21 19:34:33 +01:00
Philip Conrad ebaec38a39 test/e2e: Fix missing import in benchmark. (#6632)
Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
2024-03-15 13:46:49 -04:00
Prasanth Jayachandran 7f5e3a9d1e aws: support for Unsigned Payload or provided content sha256 in AWS signing (#6581)
To support uses cases where OPA is used for signing s3 requests whose payload is
not known upfront or payload is big enough (big file upload) to be sent over wire,
this PR adds support for unsigned payloads.

AWS signer has configurable option to use unsigned payload where the
x-amz-content-sha256 is set to "UNSIGNED-PAYLOAD" and is included as part
of signing process. This PR provides an option for unsigned payload if
aws_config.disable_payload_signing is set to true. If payload signing is
disabled, SignV4 method will not compute the content sha from the request body
but instead use "UNSIGNED-PAYLOAD" string literal for x-amz-content-sha256
header during signature computation.

References:
https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html
https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-auth-using-authorization-header.html
Signed-off-by: Prasanth Jayachandran <p_jayachandran@apple.com>
2024-03-08 10:57:51 -08:00
Ashutosh Narkar 737b213ba6 Allow TLS cipher suites to be set for the OPA server
This change adds a new flag to `opa run` to allow
users to specify a list of enabled TLS 1.0–1.2 cipher
suites. This allows users to control the cipher suites
the OPA server supports during a TLS handshake.

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2024-01-23 14:20:29 -08:00
Philip Conrad 63e1877c48 linters+testdata: Reformat all yaml testcases for linting. (#6511)
This commit adds a config for yamllint, mass-reformats all of
the existing Yaml testcases to pass linting, and adds a Yaml
linting job to the pull-request Github Actions workflow. A few 
careful exceptions and ignores were added to the linter's
config to allow keeping our existing Yaml files with minimal
reformatting.

Signed-off-by: Philip Conrad <philipaconrad@gmail.com>
2024-01-10 13:16:01 -05:00
Peter ef9e8376d3 Preserve user provided http headers in aws.sign_req
Currently while all the headers are signed the headers in the
returned object are missing all the original user provided headers
This means that if you pass the object directly to http.send
amazon will fail the request because the signed data doesn't match
the canonical request. Users can work around it by using object.union
to restore the original headers, but would be nice to avoid that extra
step

Signed-off-by: Peter <c2zwdjnlcg@users.noreply.github.com>
2023-12-11 17:23:16 -08:00
Charlie Egan 7a32e8ffb3 topdown/crypto: Add URIStrings field to JSON certs
This is being added to make it easier to write policy on the contents of
certificate URI SANs. This is where information like SPIFFE IDs etc are
contained and it's helpful to Rego authors to have access to these
values without rebuilding the URI from the parsed data under URIs.

Fixes: #6416

Signed-off-by: Charlie Egan <charlie@styra.com>
2023-11-29 12:24:16 -08:00
Rohan Vasavada d46bc9d2be feat(builtins): add a new builtin function strings.render_template to render templated strings
This adds support for rendering of templated strings utilizing Golang's text/template library.
For a given templated string and key/value mapping of template var inputs, this builtin will
inject the values into the template where they are referenced by key.

Fixes #6371
Signed-off-by: Rohan Vasavada <rohanvasavada@gmail.com>
2023-11-17 08:53:28 -08:00
Stephan Renatus e71e5191b2 internal/planner: Insert general ref head objects starting from the leaves, not root. (#6401)
This way the object insert operations can return a new object instance.

Before, the object construction for a rule like

    p[a][b] := ...

would look like this:

    *ir.BlockStmt BlockStmt (1 blocks)
      *ir.Block Block (3 statements)
        *ir.BlockStmt BlockStmt (1 blocks)
          *ir.Block Block (2 statements)
            *ir.DotStmt &{Source:{Value:Local<2>} Key:{Value:Local<10>} Target:Local<14>}
            *ir.BreakStmt &{Index:1}
        *ir.MakeObjectStmt &{Target:Local<14>}
        *ir.ObjectInsertOnceStmt &{Key:{Value:Local<10>} Value:{Value:Local<14>} Object:Local<2>}
    *ir.ObjectInsertOnceStmt &{Key:{Value:Local<11>} Value:{Value:Local<13>} Object:Local<14>}

Now, it'll look like

    *ir.BlockStmt BlockStmt (1 blocks)
      *ir.Block Block (2 statements)
        *ir.BlockStmt BlockStmt (1 blocks)
          *ir.Block Block (2 statements)
            *ir.DotStmt &{Source:{Value:Local<2>} Key:{Value:Local<10>} Target:Local<14>}
            *ir.BreakStmt &{Index:1}
        *ir.MakeObjectStmt &{Target:Local<14>}
    *ir.ObjectInsertOnceStmt &{Key:{Value:Local<11>} Value:{Value:Local<13>} Object:Local<14>}
    *ir.ObjectInsertStmt &{Key:{Value:Local<10>} Value:{Value:Local<14>} Object:Local<2>}

so the object in Local<14> is built first, and the added to object Local<2>.

Signed-off-by: Stephan Renatus <stephan@styra.com>
Co-authored-by: Teemu Koponen <koponen@styra.com>
2023-11-15 15:23:48 +01:00
Stephan Renatus fb00caa989 wasm: fix re2 bug
When feeding a `char *` into `re->Match()`, it was converted to a StringPiece,
taking its size as `strlen()`. For our (long) input, that wasn't resulting in
the correct size, and did then freak out the re2 match input validation if the
regular expression has an end anchor, but the endpos wasn't the same as its
length. Since the endpos was taken from `s->len`, and the "length" taken via
the mentioned StringPiece's strlen() call, they did indeed not match.

Worked around by feeding it a properly-constructed std::string instead. I'm a
C++ novice at best, but it does the trick, and I'm reasonable certain it's less
wrong than before.

Fixes #6376.

Signed-off-by: Stephan Renatus <stephan@styra.com>
2023-11-09 11:04:20 -08:00
Anders Eknert 7fa6165c27 Walk: skip path creation in wildcard assignment (#6267)
We do a lot of `walk`-ing in [Regal](https://docs.styra.com/regal).
So much that it's by far the single most expensive operation. That means
any optimization of the `walk` built-in function will be a win for us.

Seeing as we rarely make use of the `path` component when `walk`-ing
through AST inputs, I was curious to see if there was any optimization
we could take when the path is a wildcard assignment, and as such clearly
marked as unimportant. Turns out there is. Since the return value is
provided in the operators list, we can check the value provided for the
`path` part of the assigned array, and if it's a wildcard (`_`) skip
path construction entirely. Example:

```rego
walk(input, [_, value])
```

This greatly simplifies the walk, and the performance gains are
substantial. Traversing a ~7MB AST:

**main**
```shell
$ opa bench -d p.rego -i objects.json data.p.w
+-------------------------------------------+---------------+
| samples                                   |             6 |
| ns/op                                     |     168806625 |
| B/op                                      |     197364318 |
| allocs/op                                 |       3855327 |
| histogram_timer_rego_query_eval_ns_75%    |     169968114 |
| histogram_timer_rego_query_eval_ns_90%    |     170513459 |
| histogram_timer_rego_query_eval_ns_95%    |     170513459 |
| histogram_timer_rego_query_eval_ns_99%    |     170513459 |
| histogram_timer_rego_query_eval_ns_99.9%  |     170513459 |
| histogram_timer_rego_query_eval_ns_99.99% |     170513459 |
| histogram_timer_rego_query_eval_ns_count  |          6.00 |
| histogram_timer_rego_query_eval_ns_max    |     170513459 |
| histogram_timer_rego_query_eval_ns_mean   |     168789611 |
| histogram_timer_rego_query_eval_ns_median |     168924020 |
| histogram_timer_rego_query_eval_ns_min    |     166685000 |
| histogram_timer_rego_query_eval_ns_stddev |       1239390 |
+-------------------------------------------+---------------+
```

**no-path-walk**
```shell
$ opa bench -d p.rego -i objects.json data.p.w
+-------------------------------------------+--------------+
| samples                                   |           21 |
| ns/op                                     |     50629984 |
| B/op                                      |     38018790 |
| allocs/op                                 |      1025211 |
| histogram_timer_rego_query_eval_ns_75%    |     51239562 |
| histogram_timer_rego_query_eval_ns_90%    |     51540933 |
| histogram_timer_rego_query_eval_ns_95%    |     51674420 |
| histogram_timer_rego_query_eval_ns_99%    |     51688208 |
| histogram_timer_rego_query_eval_ns_99.9%  |     51688208 |
| histogram_timer_rego_query_eval_ns_99.99% |     51688208 |
| histogram_timer_rego_query_eval_ns_count  |         21.0 |
| histogram_timer_rego_query_eval_ns_max    |     51688208 |
| histogram_timer_rego_query_eval_ns_mean   |     50611103 |
| histogram_timer_rego_query_eval_ns_median |     50871459 |
| histogram_timer_rego_query_eval_ns_min    |     49518833 |
| histogram_timer_rego_query_eval_ns_stddev |       748688 |
+-------------------------------------------+--------------+
```

The real-world impact is not as dramatic, since we aren't *just*
walking, but normally need to actually **do** something with the
values returned, but consistently shaving off about 13% eval time
when linting one of the largest policy libraries isn't bad at all:

**Regal main**
```shell
go run main.go lint ~/tmp/kics/assets  162.16s user 6.04s system 593% cpu 28.362 total
```

**Regal walk-no-path**
```shell
go run main.go lint ~/tmp/kics/assets  145.51s user 5.01s system 597% cpu 25.176 total
```

Signed-off-by: Anders Eknert <anders@eknert.com>
2023-10-03 13:12:29 +02:00
Johan Fylling c5314e357d Removing EXPERIMENTAL_GENERAL_RULE_REFS feature flag (#6252)
Fixes: #6245

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2023-09-27 14:41:39 +02:00
Johan Fylling c9d1a8db1f planner: Adding support for general ref rule heads (#6235)
Fixes: #5995

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2023-09-27 14:06:19 +02:00
Odin Bjørnebo e15996e5a5 Builtin function to parse uuid with google/uuid library
Fixes #6173

Signed-off-by: Odin Bjørnebo <odinbjoernebo@gmail.com>
2023-09-08 12:48:40 -07:00
Johan Fylling 0431567c26 General refs in rule heads (#5913)
* Adding support for multiple variables at arbitrary locations in rule refs
* Updating type-checker to handle general ref heads

Fixes: #5993
Fixes: #5994

Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2023-08-31 12:29:49 +02:00
Sebastian Spaink c28eaf7fb4 topdown: add numbers.range_step built-in function (#6187)
Fixes: #6186
Signed-off-by: Sebastian Spaink <sebastianspaink@gmail.com>
2023-08-30 11:09:54 +02:00
Johan Fylling 9f895711b1 ast: Including "child" rules when fetching rules by ref (#6183)
* ast: Including "child" rules when fetching rules by ref

In order to properly sort rules according to dependencies before performing type-checking.

Also, properly merging types when type-tree produces multiple types for a given ref.

Fixes: #6182
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2023-08-29 13:51:38 +02:00
Johan Fylling 50d8ae8bad ast: Making partial object key rules contribute to dynamic portion of object type (#6177)
... instead of static portion.

This change allows object unification/comparison between an object composed at eval-time (i.e. constructed by rules) and a static object that doesn't contain all keys declared by rules, as those might not be defined at eval-time.

Fixes: #6138
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2023-08-24 14:24:54 +02:00
Anders Eknert 700e2c97de Bind test server to localhost interface (#6164)
Fixes #6162

Signed-off-by: Anders Eknert <anders@styra.com>
2023-08-17 15:56:35 +02:00
Ashutosh Narkar afcf01457c topdown: Honor default keyword on functions
Default functions satisfy the following properties:

* Same arity as other functions with the same name
* Arguments should only be plain variables ie. no composite values. For ex, default f([x]) = 1 is an invalid default function
* Variable names should not be repeated ie. default f(x, x) = 1 is an invalid default function

Fixes: #2445

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
2023-07-19 23:54:23 -07:00
Emil Volckmar Ry cfb03ca495 introduce new builtin crypto.parse_private_keys
* crypto.parse_private_keys parses private keys, returns a list of valid
keys
* consolidated getPrivateKeysFromString  with getPrivateKeysFromPEMData
for crypto.x509.parse_rsa_private_key  and crypto.parse_private_keys

* reworked crypto.x509.parse_rsa_private_key so that we no longer need
getPrivateKeysFromString  but instead determine type of key in builtin
function and added input validation checks

Co-authored-by: Charlie Egan <git@charlieegan3.com>
Signed-off-by: Emil Volckmar Ry <emilvry@gmail.com>
2023-07-19 17:54:51 -07:00
guoguangwu 8fa5b02b53 chore: pkg imported more than once
Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
2023-07-18 07:59:09 -07:00
Stephan Renatus 1fc95f43f8 deps: Bump OpenTelemetry 1.16.0 (#6062)
Fixes #6003

* test/e2e: fix distributed tracing tests
   Fixes provided by @zregvart, thank you!
* build: give up golang 1.18, it blocks OTel 1.16.0

Signed-off-by: Greg Haskins <greg@manetu.com>
Signed-off-by: Stephan Renatus <stephan@styra.com>
Co-authored-by: Greg Haskins <greg@manetu.com>
Co-authored-by: Zoran Regvart <zoran@regvart.com>
2023-06-30 09:36:03 +02:00
Johan Fylling d310c4335c ast: Fixing issue in type-checker where partial objects couldn't have key overrides of divergent type (#5992)
Fixes: #5972
Signed-off-by: Johan Fylling <johan.dev@fylling.se>
2023-06-27 10:04:21 +02:00
Kenneth Jenkins 72fcd514f2 topdown: Format integer numbers without exponent
When evaluating arithmetic operations, numbers are converted from
json.Number to big.Float and back again. Currently the conversion back
to json.Number uses the big.Float Text() method with the 'g' format.
This causes integers with 7 or more digits to be represented with a
decimal point and exponent.

This can be problematic when creating JWT tokens with "iat" and "exp"
timestamps, as apparently some JWT parsing libraries do not handle
NumericDate values formatted with decimal point and exponent.

Instead, modify the FloatToNumber() conversion method to avoid the
exponent format for numbers which are integers.

Fixes #6013.

Signed-off-by: Kenneth Jenkins <kjenkins@pomerium.com>
2023-06-20 11:32:36 -07:00
Tyler Schade 4f5882dd98 Allow time formatting constants in rego time.format and time.parse_ns (#6005)
Allow time formatting constants in `time.format` and `time.parse_ns`

Signed-off-by: Tyler Schade <tyler.schade@solo.io>
2023-06-13 14:51:15 +02:00
DCRUNNN b97ee9daba fix: Fixing the issue of the object.subset method failing to correctly compare array relationships (#5969)
Fixes:#5968

Signed-off-by: DCRUNNN <458891338@qq.com>
2023-06-05 12:20:01 +02:00