Use an OAuth 2.0 Identity Provider

    The following figure shows the authentication process between KubeSphere and an external OAuth 2.0 identity provider.

    You need to deploy a Kubernetes cluster and install KubeSphere in the cluster. For details, see Installing on Linux and .

    Note

    KubeSphere provides two built-in OAuth 2.0 plugins: GitHubIdentityProvider for GitHub and for Alibaba Cloud IDaaS. You can develop other plugins according to the built-in plugins.

    1. Clone the KubeSphere repository on your local machine, go to the local KubeSphere repository, and create a package for your plugin in the directory.

      1. // /pkg/apiserver/authentication/identityprovider/identity_provider.go
      2. type Identity interface {
      3. // (Mandatory) Return the identifier of the user at the identity provider.
      4. GetUserID() string
      5. // (Optional) Return the name of the user to be referred as on KubeSphere.
      6. GetUsername() string
      7. // (Optional) Return the email address of the user.
      8. GetEmail() string
      9. }
    2. Import the plugin package in /pkg/apiserver/authentication/options/authenticate_options.go.

      1. // Change <CustomPackage> to the actual name of your plugin package.
      2. ...
      3. _ "kubesphere.io/kubesphere/pkg/apiserver/authentication/identityprovider/<CustomPackage>"
      4. ...
      5. )
    3. and deploy it in your cluster.

    1. Log in to KubeSphere as admin, move the cursor to Use an OAuth 2.0 Identity Provider - 图2 in the lower-right corner, click kubectl, and run the following command to edit ks-installer of the CRD ClusterConfiguration:

    2. Configure fields other than oauthOptions:identityProviders in the spec:authentication section. For details, see Set Up External Authentication.

    3. Configure fields in oauthOptions:identityProviders section according to the identity provider plugin you have developed.

      1. spec:
      2. authentication:
      3. authenticateRateLimiterDuration: 10m0s
      4. oauthOptions:
      5. accessTokenMaxAge: 1h
      6. accessTokenInactivityTimeout: 30m
      7. identityProviders:
      8. - name: github
      9. type: GitHubIdentityProvider
      10. mappingMethod: auto
      11. provider:
      12. clientID: '******'
      13. clientSecret: '******'

      Similarly, you can also use Alibaba Cloud IDaaS as an external identity provider. For details, see the official and the source code of the AliyunIDaasProvider plugin.

    4. After the fields are configured, save your changes, and wait until the restart of ks-installer is complete.

      Note

      The KubeSphere web console is unavailable during the restart of ks-installer. Please wait until the restart is complete.

    5. Go to the KubeSphere login page, click Log In with XXX (for example, Log In with GitHub).