-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New HMAC built-in functions #1740
Comments
OPA only exposes built-in functions for verifying signatures on JWTs today. Adding support for verifying arbitrary HMACs would be relatively easy (since we can just wrap the Go standard library). Assuming symmetric keys are being used could do something like this in policy:
The built-in function would return true if the HMAC was valid and be false/undefined otherwise. If you're embedding OPA as a library or building it yourself you can add custom built-in functions. Here's an example: https://www.openpolicyagent.org/docs/latest/plugins/#built-in-functions. Note, we don't recommend using Go shared libraries/plugins anymore. |
@tsandall yea thats basically the idea. I'm not sure what best practice would be in terms of abstraction for rego built-ins. The only major difference between that function prototype and what I was thinking was the first param. Rather than accepting a single header to compare against it would accept a hash of params then they would be sorted and built into a string. The caller then could apply params from a single or combination of sources in the signature calculation Sample in java
I guess I'm not sure how clunky it would be in the calling env in rego to build the param hash, or if that is pretty easy. |
If you wanted to construct the message from multiple fields in the input you could do that as well. For example, with the above signature:
If you wanted to sort a set of values you can do that too:
|
Thanks. I might be able to get to this around the start of the year. |
Add crypto.hmac.* built-in functions for the MD5, SHA-1, SHA-256 and SHA-512 hashing algorithms. Add documentation for how to contribute new built-in functions. Fixes: open-policy-agent#1740 Signed-off-by: Johan Fylling <johan.dev@fylling.se>
Add crypto.hmac.* built-in functions for the MD5, SHA-1, SHA-256 and SHA-512 hashing algorithms. Add documentation for how to contribute new built-in functions. Fixes: #1740 Signed-off-by: Johan Fylling <johan.dev@fylling.se>
I'm interfacing with a 3rd party service that doesn't send JWT tokens and would like todo a custom HMAC calculation on a header. Looking at the docs I only see token signing/verification in the context of JWT. Does Rego only support HMAC with JWT tokens or am I missing something?
Follow up, if not can the hmac be abstracted away from JWT or was there a specific design decision in only supporting JWT? I didn't see much in #1174 describing the decisions.
The text was updated successfully, but these errors were encountered: