Skip to content
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

Support function authentication with OpenFaaS IAM #158

Merged
merged 5 commits into from
Jun 17, 2024

Conversation

welteki
Copy link
Member

@welteki welteki commented May 9, 2024

Description

If JWT authentication is enabled by setting the env variable jwt_auth: true in the stack.yml file the watchdog requires an OpenFaaS function token for request authentication.

Authentication tokens can be optioned through OpenFaaS IAM.

The watchdog verifies the token is valid and checks of an actor is authorized to invoke the function by looking at the function claim in the token and validating the permissions.

Motivation and Context

  • I have raised an issue to propose this change (required)

Support IAM authentication for functions.

How Has This Been Tested?

  • Unit tests were added.

  • Changes have been tested by running the watchdog locally and invoking it with and without a function token.
    During these test the OPENFAAS_NAME and OPENFAAS_NAMESPACE env variable were changed to simulate different functions in multiple namespaces.

    fprocess="env" \
    mode="serializing" \
    jwt_auth=true \
    jwt_auth_local=true \
    jwt_auth_debug=true \
    OPENFAAS_NAMESPACE=staging \
    OPENFAAS_NAME=env \
    port=8083 ./bin/fwatchdog-amd64
  • Changes have been tested E2E in cluster with the updated oidc-provider.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have signed-off my commits with git commit -s
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
Compare the auth permissions in the function claim with the function
name and namespace the verify if the provided JWT token is authorized
to invoke the function.

Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
Read the function namespace from the OPENFAAS_NAMESPACE env variable.
Fallback to getting the nemsapce from the service account if the
variable is not present.

Required setting the namespace when running functions locally with jwt_auth.

Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
@welteki welteki marked this pull request as ready for review May 16, 2024 11:12
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
@welteki welteki marked this pull request as draft May 23, 2024 09:15
@welteki welteki force-pushed the jwt-permissions-auth branch 2 times, most recently from 2219821 to a6e9140 Compare May 29, 2024 08:42
@@ -474,3 +495,26 @@ func (nc *WriterCounter) Write(p []byte) (int, error) {
nc.bytes += int64(n)
return n, err
}

func getFnName() (string, error) {
name, ok := os.LookupEnv("OPENFAAS_NAME")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should faas-cli local-run inject this variable then? I don't think it does presently.

cc @rgee0

Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
@welteki welteki marked this pull request as ready for review June 17, 2024 09:32
Copy link
Member

@alexellis alexellis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

@alexellis alexellis merged commit a7b8b44 into openfaas:master Jun 17, 2024
1 check passed
@welteki welteki deleted the jwt-permissions-auth branch June 17, 2024 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants