Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This feature adds an authentication middleware to the of-watchdog. The authentication logic is loaded from external OPA policy files, so that function authors can customize the auth logic.
This policy can even be loaded via a Secret.
This middleware is configurable via several new environment variables, the user can customize: the policy, set a list of paths to skip authentication, control what request content is passed to the policy during evaluation (headers, raw body, json body, additional secret values, additional env variables).
In addition to loading and evaluating plain OPA rego policy files, the middleware defines two custom functions to enable more secure policy rules:
bcrypt_eq
exposes thebcrypt.CompareHashAndPassword
method.constant_compare
exposes thesubtle.constant_compare
method.Extensive documentation of the configurations and behavior are now included in the README. Additional, example policies for Basic Auth, HMAC, JWT, and OIDC flows are included in the
auth/testdata
as well as unit tests that demonstrate how those policies behave.Motivation and Context
If a function author is using a HTTP mode with a popular language and popular framework, they can probably implement this logic directly in the function. Adding it in the of-watchdog middleware means that:
forking
andstatic
modes will more easily support advanced auth flows like OAuth and OIDC.OPA was chosen because it is part of the CloudNative landscape as a Graduated project and, for example, it is used by Istio.
How Has This Been Tested?
I have tested it locally with various test functions and via unit tests
Types of changes
Checklist:
git commit -s