OAuth 2.0 and OIDC Authentication in MATLAB Online Server
In MATLAB® Online Server™, you can configure authentication using an OAuth 2.0 and OpenID Connect (OIDC) identity provider (IdP). OAuth 2.0 is an authorization protocol that allows third-party applications such as MATLAB Online Server to access resources on behalf of a user. For details about this protocol, see the OAuth 2.0 specification. OIDC is an authentication protocol that layers additional functionality on top of OAuth 2.0. For information about how OIDC works, see the OpenID specification.
Prerequisites
MATLAB Online Server is installed. See Installation.
Your organization's IdP follows the OAuth 2.0 protocol and, optionally, the OIDC protocol. If your IdP does not use OIDC, then the server obtains user data from the user information endpoint URL of your OAuth 2.0 IdP.
You have access to your IdP. To obtain access, contact your identity management administrator.
You are familiar with the MATLAB Online Server authentication workflow. See Configure User Authentication in MATLAB Online Server.
Deploy Client Secret
OAuth 2.0 and OIDC IdPs include a password-like attribute called a client secret. MATLAB Online Server uses the client secret to request access tokens on behalf of users. To make the client secret available to MATLAB Online Server, deploy it to the server as a Kubernetes secret.
Note
MATLAB Online Server requires client secret deployment for confidential clients only. If your IdP uses a public client, then proceed to the next section.
Create a YAML file named oauth-client-secret.yaml
with these
contents:
oauth-client-secret.yaml |
---|
apiVersion: "v1" kind: "Secret" metadata: name: "oauth-client" data: secret: <client secret> # must be base-64 encoded |
apiVersion
andkind
are standard fields in Kubernetes® secrets. SetapiVersion
to"v1"
andkind
to"Secret"
.name
is the name you want to give the Kubernetes secret. The default is"oauth-client"
. If you specify a custom name value, then in the Configure Identity Provider step, you must specify this value in thesecretName
field so that MATLAB Online Server can read the correct Kubernetes secret.secret
is the client secret string. This string must use base 64 encoding. To generate a base-64 encoding for a string, use this command:echo -n <client secret> | base64
Deploy the contents of this file to the server as a Kubernetes secret. Replace <namespace-name>
with your
MATLAB
Online Server
namespace.
kubectl apply -f "oauth-client-secret.yaml" --namespace <namespace-name>
Open Configuration File
In a plain-text editor, open the authnz.yaml
file, which configures
information about your IdP.
<server-root>/overrides/<cluster-name>/<namespace-name>/authnz.yaml
<server-root>
is the MATLAB Online Server installation folder.<cluster-name>
is the name of the Kubernetes cluster.<namespace-name>
is the namespace of the MATLAB Online Server deployment.
Sample path:
~/matlab_online_server/overrides/matlab-online-server/mathworks/authnz.yaml
Remove Local Accounts
If your configuration still includes local accounts (type: "local"
), remove
them from the authnz.yaml
file or comment them out. For example:
identityProviders: # - id: "local" # type: "local" # accounts: # - subjectId: "admin" # displayName: "admin" # password: "password" # extra: {} |
Security Considerations: Local user accounts are for testing purposes only and do not meet production security standards. Deploying them to production is not recommended.
Configure Identity Provider
In the identityProviders
section, add the following structure and
update the fields with information from your IdP. Commented-out fields are optional.
Fields with values in angle brackets (<>
) have no defaults.
identityProviders: - id: "<display name used identify IdP on server>" type: "oauth" clientId: "<client ID>" # clientType: "confidential" # oidc: # required if authorizationLocation, tokenLocation, and graphLocation are not specified # enabled: false # discoveryUrl: "<https://user/information/endpoint/URL>" # retryMode: "retry" # authorizationLocation: "<https://authorization/endpoint/URL>" # required if oidc not enabled and disoveryUrl not specified # tokenLocation: "<https://token/endpoint/URL>" # required if oidc not enabled and disoveryUrl not specified # graphLocation: "<https://user/information/endpoint/URL>" # required if oidc not enabled and disoveryUrl not specified # redirectPath: "/authnz/oauth/code" # secretName: "oauth-client" # scopes: "user.read,openid,profile,email" # pkce: # enabled: false # challengeMethod: "S256" # challengeLength: 32 # delegation: # gcp: # <delegation configuration fields> # identityPassthrough: # <delegation configuration fields> # subjectAttributeMapping: # subjectId: "<IdP username attribute>" # displayName: "<IdP display name attribute>" # groups: "<IdP user group attribute>" # extra: # email: "<IdP user email attribute>" # uid: "<IdP UNIX user ID attribute>" # gid: "<IdP UNIX group ID attribute>" |
Field | Default Value | Required or Optional | Description |
---|---|---|---|
id | "" | Required | Display name that identifies the IdP in MATLAB Online Server microservices and log files. |
type | "oauth" | Required | Type of IdP. To configure local user accounts, you must set
|
clientId | "" | Required | Client identifier, which must be the same as the client identifier in the IdP. |
clientType | "confidential" | Optional | Type of client, as specified in the IdP.
|
oidc | "" | Optional (Required if you do not specify
| URL that MATLAB Online Server uses to look up the authorization, token, and user endpoints required by the OIDC protocol. Specify these subfields:
You must specify either the Example: oidc: enabled: true discoveryUrl: https://host/.well-known/... retryMode: "bypass" |
authorizationLocation | "" | Optional (Required if you do not enable
| Authorization endpoint. For details about this endpoint, see its description in the OAuth 2.0 Authorization Framework. If you
set the Example:
|
tokenLocation | "" | Optional (Required if you do not enable
| Token endpoint. For details about this endpoint, see its description in the OAuth 2.0 Authorization Framework. If you
set the Example:
|
graphLocation | "" | Optional (Required if you do not enable
| User information endpoint. For details about this endpoint, see its description in the OIDC specification.This endpoint must use the HTTPS protocol and can include port, path, and query parameters. If you set the Example:
|
redirectPath | "/authnz/oauth/code" | Optional | Path portion of the redirection endpoint. For details about this endpoint, see its description in the OAuth 2.0 Authorization Framework. The default value results in this redirection endpoint:
where
|
secretName | "oauth-client" | Optional | Name of the Kubernetes secret that contains the client secret associated with
the |
scopes | "user.read,openid,profile,email" | Optional | Comma-separated list of permissions that the OAuth 2.0 and OIDC protocols have. Do not insert a space after each comma. |
pkce | "" | Optional | Use the proof key for code exchange (PKCE) protocol for
authentication. PKCE is an extension of the OAuth 2.0 and OIDC
protocols. The
For more details on PKCE, see Authorization Code Flow with Proof Key for Code Exchange on the Auth0 website. Example: pkce: enabled: true challengeMethod: "S256" challengeLength: 32 |
delegation | "" | Optional | Give MATLAB Online Server delegated access to users' remotely stored resources. When you enable delegation, the server acquires the user SSO credentials so resources are available to users when they log in to MATLAB Online™. OAuth 2.0 and OIDC supports delegated access to these resources: Google Cloud Platform™ (GCP) Resources
delegation: gcp: <delegation configuration fields> For details on configuring this type of delegation, see Enable SSO Access to Google Cloud Platform Resources Using Delegation. IdP-Authenticated Resources
delegation: identityPassthrough: <delegation configuration fields> For details on configuring this type of delegation, see Enable SSO Access to OAuth 2.0 and OIDC-Authenticated Resources Using Delegation. |
subjectAttributeMapping | {} | Optional | Map of user-related attributes from your IdP to the corresponding YAML fields in MATLAB Online Server. The server uses these fields to look up information about the user for use across services on the cluster. Valid fields are as follows. Enclose each
subjectAttributeMapping: subjectId: "<IdP username attribute>" displayName: "<IdP display name attribute>" groups: "<IdP user group attribute>" extra: email: "<IdP user email attribute>" uid: "<IdP UNIX user ID attribute>" gid: "<IdP UNIX group ID attribute>"
|
Sample Configuration
replicaCount: 1 identityProviders: - id: "oauth" type: "oauth" clientId: "example-realm-oidc" authorizationLocation: "https://example-keycloak.example.com/realms/example-realm/protocol/openid-connect/auth" tokenLocation: "https://example-keycloak.example.com/realms/example-realm/protocol/openid-connect/token" graphLocation: "https://example-keycloak.example.com/realms/example-realm/protocol/openid-connect/userinfo" scopes: "openid,profile,roles" subjectAttributeMapping: subjectId: "preferred_username" displayName: "preferred_username" groups: "groups" extra: email: "email" uid: "uidNumber" gid: "gidNumber" |
The graphLocation
field (user information endpoint) returns a
JSON response similar to the following:
{\"sub\":\"269e67a3-877a-4525-9c88-fb8707ac7a93\",\"randomAttribute\":\"user1RandomAttribute\", \"resource_access\":{\"account\":{\"roles\":[\"manage-account\",\"manage-account-links\", \"view-profile\"]}},\"email_verified\":false,\"groups\":[\"non-gpu\",\"user\"], \"preferred_username\":\"user1\",\"given_name\":\"user1_FirstName\", \"realm_access\":{\"roles\":[\"non-gpu\",\"user\"]},\"uidNumber\":\"7777\", \"name\":\"user1_FirstName user1_LastName\",\"gidNumber\":\"7777\", \"family_name\":\"user1_LastName\",\"email\":\"user1@example.com\"}
The license server logs an entry similar to the following:
21:52:53 (MLM) OUT: "MATLAB" user1@mathworks-matlab-pool-7b775bc559-ct2vv
Additionally, the MATLAB
Online Server user interface displays "user1"
as the
username.
If other attributes passed as claims from the IdP must appear in the license
server logs and MATLAB
Online Server user interface, then update the mapping. For example, suppose you use
randomAttribute
instead of preferred_name
for the license log entry and the username in the user interface.
identityProviders: - id: "oauth" type: "oauth" clientId: "ex-realm-oidc" authorizationLocation: https://ex-keycloak.matlabonlineserver.com/realms/ex-realm/protocol/openid-connect/auth tokenLocation: https://ex-keycloak.matlabonlineserver.com/realms/ex-realm/protocol/openid-connect/token graphLocation: https://ex-keycloak.matlabonlineserver.com/realms/ex-realm/protocol/openid-connect/userinfo scopes: "openid,profile,roles" subjectAttributeMapping: subjectId: "randomAttribute" displayName: "name" groups: "groups" extra: email: "email" |
The license server would contain an entry similar to the following:
21:52:53 (MLM) OUT: "MATLAB" user1RandomAttribute@mathworks-matlab-pool-7b775bc559-ct2vv
The MATLAB
Online Server user interface would display "user1_FirstName
user1_LastName"
as the username.
Because of the value set for the groups
field in the sample
subjectAttributeMapping
above and the associated values of
the claims returned by the IdP, the user is allowed to access a MATLAB version that has the following configuration in the associated
matlab-pool.yaml
file.
resourceDefinition: allowedGroups: - "gpu" |
Deploy Configuration
To deploy your changes to the server, redeploy the authnz
service. From the MATLAB
Online Server root folder, run these commands.
./mosadm undeploy authnz
./mosadm deploy authnz
If your IdP configures single sign-on (SSO), your users can now sign in to MATLAB Online using their SSO credentials.
If you are configuring multiple IdPs, the server uses the first IdP listed in the
identityProviders
section as the default IdP. To authenticate users
with a nondefault IdP, in the MATLAB
Online URL you give to users, include an IdPId
query parameter
that specifies the ID value of the IdP. For example:
https://<domain-base>/matlabonline?idpId=<id>
where <domain-base>
is the value of the DOMAIN_BASE
property in your install.config
file. For
more information, see Configure Multiple Identity Providers.
Related Topics
- Configure User Authentication in MATLAB Online Server
- Configure Group-Based Authorization in MATLAB Online Server
- Configure File Storage for Users in MATLAB Online Server
- Enable SSO Access to Google Cloud Platform Resources Using Delegation