feat: add inline auth middleware#148
Open
LucasRoesler wants to merge 5 commits intoopenfaas:masterfrom
Open
Conversation
Create a middleware that allows executing OPA policies prior to invoking the function. The policy can be configurd via the `OPA_POLICY` environment variable. The query is defined via the `OPA_QUERY` variable. The OPA_POLICY can be a comma separated list of paths. The default query input will contain `path`, `method`, and the `authorization` header value. You can optional include the parsed `body` `rawBody` and the raw `headers` via the `OPA_INCLUDE_JSON_BODY`, `OPA_INCLUDE_RAW_BODY` and `OPA_INCLUDE_HEADERS` environment variables. Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
Add `OPA_SKIP_PATHS` configuration and update the implementation to skip these paths. chore: add HMAC auth example in the tests Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
Support parsing structured auth policy results. This allows the policy to customize the error response code. The policy can also attach additional headers to the request so that the implementation. The primary use case for the additional headers is to pass user or client identification to the implmentation to allow for auditing and/or additional authorization checks. Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_eqexposes thebcrypt.CompareHashAndPasswordmethod.constant_compareexposes thesubtle.constant_comparemethod.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/testdataas 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:
forkingandstaticmodes 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