OIDC Authenticated Group Mapping

Using Kong’s OpenID Connect plugin (OIDC), you can map identity provider (IdP) groups to Kong roles. Adding a user to Kong in this way gives them access to Kong based on their group in the IdP.

Admin accounts are now created automatically when you map your identity provider (IdP) groups to Kong roles. You do not need to create the users, groups, and roles separately. These users then accept invitations to join Kong Manager and log in with their IdP credentials.

Important: In v2.7.x, the admin_claim parameter replaces the consumer_claim parameter required by previous versions.

If an admin’s group changes in the IdP, their Kong admin account’s associated role also changes in Kong Gateway the next time they log in to Kong Manager. The mapping removes the task of manually managing access in Kong Gateway, because it makes the IdP the system of record.

Prerequisites

Apply OIDC auth mapping to Kong Gateway

Review important values

In the following examples, you specify the admin_claim and authenticated_groups_claim parameters to identify which admin value and role name to map from the IdP to Kong Gateway, as well as the admin_auto_create_rbac_token_disabled to specify whether an RBAC token is created for admins in Kong.

  • The admin_claim value specifies which IdP username value should map to Kong Manager. The username and password are required for the user to log into the IdP.

  • The authenticated_groups_claim value specifies which IdP claim should be used to assign Kong Gateway roles to the specified Kong Gateway admin.

    This value depends on your IdP – for example, Okta configures claims for groups, and another IdP might configure them as roles.

    In the IdP, the group claim value must follow the format <workspace_name>:<role_name>.

    For example, if "authenticated_groups_claim": ["groups"] is specified, and in the IdP groups:["default:super-admin"] is specified, the administrators specified in admin_claim are assigned to the super-admin role in the default Kong Gateway workspace.

    If the mapping does not work as expected, decode the JWT that’s created by your IdP, and make sure that the admin ID token includes the key:value pair groups:["default:super-admin"] for the case of this example, or the appropriate claim name and claim value as set in your IdP.

  • The admin_auto_create_rbac_token_disabled boolean enables or disables RBAC token creation when automatically creating admins with OpenID Connect. The default is false.

    • Set to true to disable automatic token creation for admins
    • Set to false to enable automatic token creation for admins
  • The admin_auto_create boolean enables or disables admin auto-creation with OpenID Connect. The default is true.
    • Set to true to enable automatic admin creation
    • Set to false to disable automatic admin creation

Set up mapping

Kubernetes with Helm

Docker

kong.conf

  1. Create a configuration file for the OIDC plugin and save it as admin_gui_auth_conf.

    Provide your own values for all fields indicated by curly braces ({}):

    1. {
    2. "issuer": "{YOUR_IDP_URL}",
    3. "admin_claim": "email",
    4. "client_id": ["{CLIENT_ID}"],
    5. "client_secret": ["{CLIENT_SECRET}"],
    6. "authenticated_groups_claim": ["{CLAIM_NAME}"],
    7. "ssl_verify": false,
    8. "leeway": 60,
    9. "redirect_uri": ["{YOUR_REDIRECT_URI}"],
    10. "login_redirect_uri": ["{YOUR_LOGIN_REDIRECT_URI}"],
    11. "logout_methods": ["GET", "DELETE"],
    12. "logout_query_arg": "logout",
    13. "logout_redirect_uri": ["{YOUR_LOGOUT_REDIRECT_URI}"],
    14. "scopes": ["openid","profile","email","offline_access"],
    15. "auth_methods": ["authorization_code"],
    16. "admin_auto_create_rbac_token_disabled": false,
    17. "admin_auto_create": true
    18. }

    For detailed descriptions of all OIDC parameters, see the OpenID Connect parameter reference.

  2. Create a secret from the file you just created:

    1. kubectl create secret generic kong-idp-conf --from-file=admin_gui_auth_conf -n kong
  3. Update the RBAC section of the deployment values.yml file with the following parameters:

    1. rbac:
    2. enabled: true
    3. admin_gui_auth: openid-connect
    4. session_conf_secret: kong-session-conf
    5. admin_gui_auth_conf_secret: kong-idp-conf
  4. Using Helm, upgrade the deployment with your YAML filename:

    1. helm upgrade --install kong-ee kong/kong -f ./myvalues.yaml -n kong

If you have a Docker installation, run the following command to set the needed environment variables and reload the Kong Gateway configuration.

Provide your own values for all fields indicated by curly braces ({}):

  1. echo "
  2. KONG_ENFORCE_RBAC=on \
  3. KONG_ADMIN_GUI_AUTH=openid-connect \
  4. KONG_ADMIN_GUI_AUTH_CONF='{
  5. \"issuer\": \"{YOUR_IDP_URL}\",
  6. \"admin_claim\": \"email\",
  7. \"client_id\": [\"<someid>\"],
  8. \"client_secret\": [\"<somesecret>\"],
  9. \"authenticated_groups_claim\": [\"{CLAIM_NAME}\"],,
  10. \"ssl_verify\": false,
  11. \"leeway\": 60,
  12. \"redirect_uri\": [\"{YOUR_REDIRECT_URI}\"],
  13. \"login_redirect_uri\": [\"{YOUR_LOGIN_REDIRECT_URI}\"],
  14. \"logout_methods\": [\"GET\", \"DELETE\"],
  15. \"logout_query_arg\": \"logout\",
  16. \"logout_redirect_uri\": [\"{YOUR_LOGOUT_REDIRECT_URI}\"],
  17. \"scopes\": [\"openid\",\"profile\",\"email\",\"offline_access\"],
  18. \"auth_methods\": [\"authorization_code\"],
  19. \"admin_auto_create_rbac_token_disabled\": false,
  20. \"admin_auto_create\": true
  21. }' kong reload exit" | docker exec -i {KONG_CONTAINER_ID} /bin/sh

Replace {KONG_CONTAINER_ID} with the ID of your container.

For detailed descriptions of all the parameters used here, and many other customization options, see the OpenID Connect parameter reference.

  1. Navigate to your kong.conf file.

  2. With RBAC enabled, add the admin_gui_auth and admin_gui_auth_conf properties to the file.

    Provide your own values for all fields indicated by curly braces ({}):

    1. enforce_rbac = on
    2. admin_gui_auth = openid-connect
    3. admin_gui_auth_conf = {
    4. "issuer": "{YOUR_IDP_URL}",
    5. "admin_claim": "email",
    6. "client_id": ["{CLIENT_ID}"],
    7. "client_secret": ["{CLIENT_SECRET}"],
    8. "authenticated_groups_claim": ["{CLAIM_NAME}"],
    9. "ssl_verify": false,
    10. "leeway": 60,
    11. "redirect_uri": ["{YOUR_REDIRECT_URI}"],
    12. "login_redirect_uri": ["{YOUR_LOGIN_REDIRECT_URI}"],
    13. "logout_methods": ["GET", "DELETE"],
    14. "logout_query_arg": "logout",
    15. "logout_redirect_uri": ["{YOUR_LOGOUT_REDIRECT_URI}"],
    16. "scopes": ["openid","profile","email","offline_access"],
    17. "auth_methods": ["authorization_code"],
    18. "admin_auto_create_rbac_token_disabled": false,
    19. "admin_auto_create": true
    20. }

    For detailed descriptions of all the parameters used here, and many other customization options, see the OpenID Connect parameter reference.

  3. Restart Kong Gateway to apply the file.

    1. kong restart -c /path/to/kong.conf