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

oidc-connect plugin, and restricting access to endpoints using scope #10352

Closed
csotiriou opened this issue Oct 17, 2023 · 3 comments · Fixed by #10493
Closed

oidc-connect plugin, and restricting access to endpoints using scope #10352

csotiriou opened this issue Oct 17, 2023 · 3 comments · Fixed by #10493
Assignees

Comments

@csotiriou
Copy link
Contributor

csotiriou commented Oct 17, 2023

Description

Hello, I am using the Ingress Controller and I am trying to support the following scenario using OIDC

  • ClientID A should have access to Endpoints A,B
  • ClientID B should have access to Endpoints B,C

All of them should be of type "client_credentials"

And on top of a test route, I have the following definition:

apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
  name: echoserver-multiple-apisix
  namespace: ${kubernetes_namespace_v1.echonamespace2.metadata.0.name}
spec:
  http:
  - name: echohttp
    match:
      hosts:
      - echo.k8s.orb.local
      paths:
      - "/echo*"
    backends:
    - serviceName: echoserver2-service
      servicePort: 80
    plugins:

      - name: "openid-connect"
        enable: true
        config:
          client_id: "apisix2"
          client_secret: "..."
          discovery: "http://keycloak-proxy.keycloak.svc.cluster.local/realms/apisixrealm/.well-known/openid-configuration"
          introspection_endpoint: "http://keycloak-proxy.keycloak.svc.cluster.local/realms/apisixrealm/protocol/openid-connect/token/introspect"
          realm: "apisixrealm"
          scope: "route1scope"

I am using the OIDC plugin and Keycloak as my authentication provider. Although APISIX can provide access to the endpoints, with tokens accessed it fails to deny access to clients that don't have the required scope. No matter what scope I put in the scope parameter, it always allows anyone with a valid token (but without a scope) to access the route. Perhaps this is a relevant issue: #1272

Therefore, I have two questions:

  • For the scenario originally described, can I have multiple OIDC plugins with different client IDs and secrets on top of a route to achieve what I want? (since multiple clients must be able to access the same route)
  • For the issue where the scopes are not taken into account, is there something I am missing or can do differently?
    • How can I restrict an API to specific scopes with the openid-connect plugin?
@csotiriou csotiriou changed the title feat: As a user, I want have multiple OIDC connect clients, and restrict access using their scope using client_credentials oidc-connect plugin, and restricting access using scope (client_credentials) Oct 17, 2023
@csotiriou csotiriou changed the title oidc-connect plugin, and restricting access using scope (client_credentials) oidc-connect plugin, and restricting access to endpoints using scope Oct 17, 2023
@moonming moonming moved this to 🏗 In progress in Apache APISIX backlog Oct 18, 2023
@Revolyssup Revolyssup moved this from 🏗 In progress to 📋 Backlog in Apache APISIX backlog Oct 27, 2023
@kayx23
Copy link
Member

kayx23 commented Nov 15, 2023

Consolidating #10454 (comment) into this thread. OP mentioned they have customized the openid-connect plugin to suit their need for scope-based authorization.

@csotiriou I was wondering if you have explored authz-keycloak plugin and tried setting the permissions attribute to achieve scope-based authorization?

@csotiriou
Copy link
Contributor Author

Hello,

I have considered it yes - however, for standardization's sake, we want to use the openid-connect (plus I stumbled across other issues as well that I may mention in another thread when I make sure that I have the correct configuration).

I believe that the scope-based approach is more generic than having to resort to putting the permissions attribute in the token.

@csotiriou
Copy link
Contributor Author

I took the liberty of making a PR out of this, here: #10493.

I hope you find this useful.

@Revolyssup Revolyssup moved this from 📋 Backlog to 👀 In review in Apache APISIX backlog Nov 16, 2023
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Apache APISIX backlog Nov 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants