hongming 我用的自定义的oauth2 server(java程序写的),是不是就不用开启这个idaas了,在这个配置的type的值就写oauth就行了?

    tjushilei 可以打开我前面发的PR,简单看看,idaas 只是其中一个插件。要使用你们自己的OAuth server 你需要修改一下代码,或是新建IdentityProvider兼容你们私有的API(获取用户信息)。另外我们近期也会加上OIDC 的插件, 你也可以反向兼容一下OIDC(就不需要开发插件了)。

      hongming 我看了您前面发的,我照着配置了一下,然后发现实现不了。新建 identityProvider是在这个配置文件里就像这么建吗,然后type的值改成oauth就可以?

      tjushilei 这个就是示例配置

          identityProviders:
            - name: aliyunidaas
              type: AliyunIDaasProvider
              mappingMethod: mixed
              provider:
                clientID: xxxx
                clientSecret: xxxx
                endpoint:
                  userInfoUrl: "https://xxxxx.login.aliyunidaas.com/api/bff/v1.2/oauth2/userinfo"
                  authURL: "https://xxxx.login.aliyunidaas.com/oauth/authorize"
                  tokenURL: "https://xxxx.login.aliyunidaas.com/oauth/token"
                redirectURL: "http://ks-console/oauth/redirect"
                scopes:
                  - read

      需要用kubespheredev/ks-apiserver:latest 这个镜像或者自己build

        hongming 我们现在用的是kubespheredev/ks-apiserver:3.0.0,也没有生效啊,难道现在的latest是3.0.1吗?

          hongming 还有如果用我们自定义的server那么type字段、mappingMethod字段该填什么?
          我在配置其他产品的oauth2的配置文件的时候并没有见过这两个字段。

          hongming 换了kubespheredev/ks-apiserver:latest之后kubesphere启动不了了,打开页面之后只有一对大括号,请问是不兼容吗,还是我们的操作不对?

            hongming 插件开发是不是要改这个源码部分,我们已经将代码编译好了,但是不知道要改哪一块的代码去适配账户关联部分,您发的这个代码链接我看到了对应的代码,但是不知道从哪一块下手去改,还望请指教一下,感谢!

              tjushilei pod 都正常运行吗,有没有什么明显的错误日志,可以把配置贴出来看看

              kubectl -n kubesphere-system get deploy ks-console -ojsonpath='{.spec.template.spec.containers[0].image}'
              kubectl -n kubesphere-system get deploy ks-apiserver -ojsonpath='{.spec.template.spec.containers[0].image}'
              kubectl -n kubesphere-system get cm kubesphere-config -ojsonpath='{.data.kubesphere\.yaml}'

                hongming 第一条命令的结果:dockerhub.kubekey.local/kubesphere/ks-console:v3.0.0

                第二条命令的结果:dockerhub.kubekey.local/kubesphere/ks-apiserver:v3.1-beta
                (镜像:dockerhub.kubekey.local/kubesphere/ks-apiserver:v3.1-beta对应的就是kubespheredev/ks-apiserver:latest)

                hongming 第三个:
                authentication:
                authenticateRateLimiterMaxTries: 10
                authenticateRateLimiterDuration: 10m0s
                loginHistoryRetentionPeriod: 168h
                maximumClockSkew: 10s
                multipleLogin: False
                kubectlImage: dockerhub.kubekey.local/kubesphere/kubectl:v1.0.0
                jwtSecret: “IKX0fOhGZ1VJonaIDWl1FFcThFedQlip”
                oauthOptions:
                accessTokenMaxAge: 1h
                accessTokenInactivityTimeout: 30m
                identityProviders:
                - name: ldap
                type: LDAPIdentityProvider
                mappingMethod: auto
                provider:
                host: 10.253.124.37:40389
                managerDN: uid=ann,cn=users,dc=hebmc,dc=com
                managerPassword: ann
                userSearchBase: cn=users,dc=hebmc,dc=com
                loginAttribute: uid
                mailAttribute: mail
                - name: oauth2
                mappingMethod: auto
                type: AliyunIDaasProvider
                provider:
                clientID: kubesphere
                clientSecret: kubesphere
                endpoint:
                authURL: http://sam-portal.dev2.ict.cmcc/oauth/authorize
                tokenURL: http://sam-portal.dev2.ict.cmcc/oauth/token
                userInfoUrl: http://sam-portal.dev2.ict.cmcc/user/me
                redirectURL: http://jira2.dev2.ict.cmcc/plugins/servlet/oauth/callback
                scopes:
                -all
                ldap:
                host: openldap.kubesphere-system.svc:389
                managerDN: cn=admin,dc=kubesphere,dc=io
                managerPassword: admin
                userSearchBase: ou=Users,dc=kubesphere,dc=io
                groupSearchBase: ou=Groups,dc=kubesphere,dc=io
                redis:
                host: redis.kubesphere-system.svc
                port: 6379
                password: ""
                db: 0
                s3:
                endpoint: http://minio.kubesphere-system.svc:9000
                region: us-east-1
                disableSSL: true
                forcePathStyle: true
                accessKeyID: openpitrixminioaccesskey
                secretAccessKey: openpitrixminiosecretkey
                bucket: s2i-binaries
                mysql:
                host: mysql.kubesphere-system.svc:3306
                username: root
                password: password
                maxIdleConnections: 100
                maxOpenConnections: 100
                maxConnectionLifeTime: 10s
                network:
                enableNetworkPolicy: true
                devops:
                host: http://ks-jenkins.kubesphere-devops-system.svc/
                username: admin
                password: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImFkbWluQGt1YmVzcGhlcmUuaW8iLCJ1c2VybmFtZSI6ImFkbWluIiwidG9rZW5fdHlwZSI6InN0YXRpY190b2tlbiJ9.X_yErokndO8OvBsiVCIre0agP_qj9PfDZcFJ4rUBkDQ
                maxConnections: 100
                servicemesh:
                istioPilotHost: http://istio-pilot.istio-system.svc:8080/version
                jaegerQueryHost: http://jaeger-query.istio-system.svc:16686
                servicemeshPrometheusHost: http://prometheus-k8s.kubesphere-monitoring-system.svc:9090
                openpitrix:
                runtimeManagerEndpoint: “hyperpitrix.openpitrix-system.svc:9103”
                clusterManagerEndpoint: “hyperpitrix.openpitrix-system.svc:9104”
                repoManagerEndpoint: “hyperpitrix.openpitrix-system.svc:9101”
                appManagerEndpoint: “hyperpitrix.openpitrix-system.svc:9102”
                categoryManagerEndpoint: “hyperpitrix.openpitrix-system.svc:9113”
                attachmentManagerEndpoint: “hyperpitrix.openpitrix-system.svc:9122”
                repoIndexerEndpoint: “hyperpitrix.openpitrix-system.svc:9108”
                monitoring:
                endpoint: http://prometheus-operated.kubesphere-monitoring-system.svc:9090
                logging:
                host: http://elasticsearch-logging-data.kubesphere-logging-system.svc:9200
                indexPrefix: ks-logstash-log
                events:
                host: http://elasticsearch-logging-data.kubesphere-logging-system.svc:9200
                indexPrefix: ks-logstash-events
                auditing:
                enable: true
                host: http://elasticsearch-logging-data.kubesphere-logging-system.svc:9200
                indexPrefix: ks-logstash-auditing
                alerting:
                endpoint: http://alerting-client-server.kubesphere-alerting-system.svc:9200/api/
                notification:
                endpoint: http://notification.kubesphere-alerting-system.svc:9200

                  tjushilei

                  1. 参照kubesphere/pkg/apiserver/authentication/identityprovider/github/github.go 实现 identityprovider.OAuthProviderinit时注册
                  func init() {
                  	identityprovider.RegisterOAuthProvider(&Github{})
                  }
                  1. kubesphere/pkg/apiserver/authentication/options/authenticate_options.go 中引用新的插件
                  import (
                  	"fmt"
                  	"github.com/spf13/pflag"
                  	_ "kubesphere.io/kubesphere/pkg/apiserver/authentication/identityprovider/aliyunidaas"
                  	_ "kubesphere.io/kubesphere/pkg/apiserver/authentication/identityprovider/github"
                  	"kubesphere.io/kubesphere/pkg/apiserver/authentication/oauth"
                  	"time"
                  )
                  1. 插件通过 kubesphere-config 中 authentication.oauthOptions.identityProviders 部分进行配置,其中provider是动态配置, 也就是插件中的 *oauth.DynamicOptions

                    tjushilei
                    正确配置后前端页面应该正常打开, 且展示oauth登录项

                    另外 redirectURL 需要配置为 http(s)://<ks-console域名/IP+端口>/oauth/redirect,另外还需要在 OAuth2 Server 配置好redirectURL , 登录后需要重定向到 "http(s)://<ks-console域名/IP+端口>/oauth/redirect

                      tjushilei 方向不要搞反了, kubesphere OAuth2是通过OAuth2 接入其他 OAuth2 Provider 中的账户,再 redirecrt到kubesphere,而不是把 kubesphere 作为identity provider

                      hongming 您好,能提供一下配置Kubesphere使用github的oauth2协议时的配置文件吗

                        nanjofan 注意用kubespheredev/ks-apiserver:latest

                            authentication:
                              authenticateRateLimiterMaxTries: 10
                              authenticateRateLimiterDuration: 10m0s
                              loginHistoryRetentionPeriod: 7d
                              maximumClockSkew: 10s
                              multipleLogin: true
                              kubectlImage: kubesphere/kubectl:v1.0.0
                              jwtSecret: "xxxxx"
                              oauthOptions:
                                accessTokenMaxAge: 1h
                                accessTokenInactivityTimeout: 30m
                                identityProviders:
                                - name: github
                                  type: GitHubIdentityProvider
                                  mappingMethod: mixed
                                  provider:
                                    clientID: 'xxx'
                                    clientSecret: 'xxx'
                                    endpoint:
                                      authURL: 'https://github.com/login/oauth/authorize'
                                      tokenURL: 'https://github.com/login/oauth/access_token'
                                    redirectURL: 'http(s)://<ks-console域名/IP+端口>/oauth/redirect'
                                    scopes:
                                    - user