Configuring the internal OAuth server

    When a person requests a new OAuth token, the OAuth server uses the configured identity provider to determine the identity of the person making the request.

    It then determines what user that identity maps to, creates an access token for that user, and returns the token for use.

    OAuth token request flows and responses

    The OAuth server supports standard and the implicit grant OAuth authorization flows.

    When requesting an OAuth token using the implicit grant flow () with a client_id configured to request WWW-Authenticate challenges (like openshift-challenging-client), these are the possible server responses from /oauth/authorize, and how they should be handled:

    Several configuration options are available for the internal OAuth server.

    The internal OAuth server generates two kinds of tokens:

    TokenDescription

    Access tokens

    Longer-lived tokens that grant access to the API.

    Short-lived tokens whose only use is to be exchanged for an access token.

    You can configure the default duration for both types of token. If necessary, you can override the duration of the access token by using an OAuthClient object definition.

    OAuth grant options

    When the OAuth server receives token requests for a client to which the user has not previously granted permission, the action that the OAuth server takes is dependent on the OAuth client’s grant strategy.

    The OAuth client requesting token must provide its own grant strategy.

    You can apply the following default methods:

    Grant optionDescription

    auto

    Auto-approve the grant and retry the request.

    prompt

    Prompt the user to approve or deny the grant.

    Configuring the internal OAuth server’s token duration

    You can configure default options for the internal OAuth server’s token duration.

    If the default time is insufficient, then this can be modified using the following procedure.

    Procedure

    1. Create a configuration file that contains the token duration options. The following file sets this to 48 hours, twice the default.

      1Set accessTokenMaxAgeSeconds to control the lifetime of access tokens. The default lifetime is 24 hours, or 86400 seconds. This attribute cannot be negative. If set to zero, the default lifetime is used.
    2. Apply the new configuration file:

      Because you update the existing OAuth server, you must use the oc apply command to apply the change.

      1. $ oc apply -f </path/to/file.yaml>
    3. Confirm that the changes are in effect:

      1. $ oc describe oauth.config.openshift.io/cluster

      Example output

      1. ...
      2. Spec:
      3. Token Config:
      4. Access Token Max Age Seconds: 172800
      5. ...

    You can configure OAuth tokens to expire after a set period of inactivity. By default, no token inactivity timeout is set.

    Prerequisites

    • You have access to the cluster as a user with the cluster-admin role.

    • You have configured an identity provider (IDP).

    Procedure

    1. Update the OAuth configuration to set a token inactivity timeout.

      1. Edit the OAuth object:

        1. $ oc edit oauth cluster
        1. apiVersion: config.openshift.io/v1
        2. kind: OAuth
        3. ...
        4. spec:
        5. tokenConfig:
        6. accessTokenInactivityTimeout: 400s (1)
        1Set a value with the appropriate units, for example 400s for 400 seconds, or 30m for 30 minutes. The minimum allowed timeout value is 300s.
      2. Save the file to apply the changes.

    2. Check that the OAuth server pods have restarted:

      Do not continue to the next step until PROGRESSING is listed as False, as shown in the following output:

      Example output

      1. NAME VERSION AVAILABLE PROGRESSING DEGRADED SINCE
      2. authentication 4.6.0 True False False 145m
    3. Check that a new revision of the Kubernetes API server pods has rolled out. This will take several minutes.

      1. $ oc get clusteroperators kube-apiserver

      Do not continue to the next step until PROGRESSING is listed as False, as shown in the following output:

      Example output

      1. NAME VERSION AVAILABLE PROGRESSING DEGRADED SINCE
      2. kube-apiserver 4.6.0 True False False 145m

      If PROGRESSING is showing True, wait a few minutes and try again.

    Verification

    1. Log in to the cluster with an identity from your IDP.

    2. Execute a command and verify that it was successful.

    3. Wait longer than the configured timeout without using the identity. In this procedure’s example, wait longer than 400 seconds.

    4. Try to execute a command from the same identity’s session.

      This command should fail because the token should have expired due to inactivity longer than the configured timeout.

      Example output

      1. error: You must be logged in to the server (Unauthorized)

    OAuth server metadata

    Applications running in OKD might have to discover information about the built-in OAuth server. For example, they might have to discover what the address of the <namespace_route> is without manual configuration. To aid in this, OKD implements the IETF OAuth 2.0 Authorization Server Metadata draft specification.

    Thus, any application running inside the cluster can issue a GET request to to fetch the following information:

    1. {
    2. "issuer": "https://<namespace_route>", (1)
    3. "authorization_endpoint": "https://<namespace_route>/oauth/authorize", (2)
    4. "token_endpoint": "https://<namespace_route>/oauth/token", (3)
    5. "scopes_supported": [ (4)
    6. "user:full",
    7. "user:info",
    8. "user:check-access",
    9. "user:list-scoped-projects",
    10. ],
    11. "response_types_supported": [ (5)
    12. "code",
    13. ],
    14. "grant_types_supported": [ (6)
    15. "authorization_code",
    16. "implicit"
    17. ],
    18. "code_challenge_methods_supported": [ (7)
    19. "plain",
    20. "S256"
    21. ]
    22. }
    1The authorization server’s issuer identifier, which is a URL that uses the https scheme and has no query or fragment components. This is the location where .well-known RFC 5785 resources containing information about the authorization server are published.
    2URL of the authorization server’s authorization endpoint. See .
    3URL of the authorization server’s token endpoint. See RFC 6749.
    4JSON array containing a list of the OAuth 2.0 scope values that this authorization server supports. Note that not all supported scope values are advertised.
    5JSON array containing a list of the OAuth 2.0 response_type values that this authorization server supports. The array values used are the same as those used with the response_types parameter defined by “OAuth 2.0 Dynamic Client Registration Protocol” in RFC 7591.
    6JSON array containing a list of the OAuth 2.0 grant type values that this authorization server supports. The array values used are the same as those used with the grant_types parameter defined by OAuth 2.0 Dynamic Client Registration Protocol in .
    7JSON array containing a list of PKCE RFC 7636 code challenge methods supported by this authorization server. Code challenge method values are used in the code_challenge_method parameter defined in . The valid code challenge method values are those registered in the IANA PKCE Code Challenge Methods registry. See IANA OAuth Parameters.

    In some cases the API server returns an unexpected condition error message that is difficult to debug without direct access to the API master log. The underlying reason for the error is purposely obscured in order to avoid providing an unauthenticated user with information about the server’s state.

    A subset of these errors is related to service account OAuth configuration issues. These issues are captured in events that can be viewed by non-administrator users. When encountering an unexpected condition server error during OAuth, run oc get events to view these events under ServiceAccount.

    The following example warns of a service account that is missing a proper OAuth redirect URI:

    Example output

    1. 1m 1m 1 proxy ServiceAccount Warning NoSAOAuthRedirectURIs service-account-oauth-client-getter system:serviceaccount:myproject:proxy has no redirectURIs; set serviceaccounts.openshift.io/oauth-redirecturi.<some-value>=<redirect> or create a dynamic URI using serviceaccounts.openshift.io/oauth-redirectreference.<some-value>=<reference>

    Running oc describe sa/<service_account_name> reports any OAuth events associated with the given service account name.

    1. $ oc describe sa/proxy | grep -A5 Events

    Example output

    1. Events:
    2. FirstSeen LastSeen Count From SubObjectPath Type Reason Message
    3. --------- -------- ----- ---- ------------- -------- ------ -------
    4. 3m 3m 1 service-account-oauth-client-getter Warning NoSAOAuthRedirectURIs system:serviceaccount:myproject:proxy has no redirectURIs; set serviceaccounts.openshift.io/oauth-redirecturi.<some-value>=<redirect> or create a dynamic URI using serviceaccounts.openshift.io/oauth-redirectreference.<some-value>=<reference>

    The following is a list of the possible event errors:

    No redirect URI annotations or an invalid URI is specified

    1. Reason Message
    2. NoSAOAuthRedirectURIs system:serviceaccount:myproject:proxy has no redirectURIs; set serviceaccounts.openshift.io/oauth-redirecturi.<some-value>=<redirect> or create a dynamic URI using serviceaccounts.openshift.io/oauth-redirectreference.<some-value>=<reference>

    Invalid route specified

    1. Reason Message
    2. NoSAOAuthRedirectURIs [routes.route.openshift.io "<name>" not found, system:serviceaccount:myproject:proxy has no redirectURIs; set serviceaccounts.openshift.io/oauth-redirecturi.<some-value>=<redirect> or create a dynamic URI using serviceaccounts.openshift.io/oauth-redirectreference.<some-value>=<reference>]

    Missing SA tokens

    1. Reason Message