diff --git a/cmd/console/server.go b/cmd/console/server.go index 83b745ed5..92ebbf732 100644 --- a/cmd/console/server.go +++ b/cmd/console/server.go @@ -98,7 +98,7 @@ func buildServer() (*restapi.Server, error) { return nil, err } - api := operations.NewConsoleAPI(swaggerSpec, nil) + api := operations.NewConsoleAPI(swaggerSpec) api.Logger = restapi.LogInfo server := restapi.NewServer(api) diff --git a/integration/buckets_test.go b/integration/buckets_test.go index d931d0b86..2e7fab3fd 100644 --- a/integration/buckets_test.go +++ b/integration/buckets_test.go @@ -71,7 +71,7 @@ func initConsoleServer() (*restapi.Server, error) { restapi.LogInfo = noLog restapi.LogError = noLog - api := operations.NewConsoleAPI(swaggerSpec, nil) + api := operations.NewConsoleAPI(swaggerSpec) api.Logger = noLog server := restapi.NewServer(api) diff --git a/replication/replication_test.go b/replication/replication_test.go index 903ed8010..4aeacc5ad 100644 --- a/replication/replication_test.go +++ b/replication/replication_test.go @@ -50,7 +50,7 @@ func initConsoleServer() (*restapi.Server, error) { restapi.LogInfo = noLog restapi.LogError = noLog - api := operations.NewConsoleAPI(swaggerSpec, nil) + api := operations.NewConsoleAPI(swaggerSpec) api.Logger = noLog server := restapi.NewServer(api) diff --git a/restapi/admin_arns_test.go b/restapi/admin_arns_test.go index c00ce060c..ce620ebe3 100644 --- a/restapi/admin_arns_test.go +++ b/restapi/admin_arns_test.go @@ -69,7 +69,7 @@ func TestRegisterAdminArnsHandlers(t *testing.T) { if err != nil { assert.Fail("Error") } - api := operations.NewConsoleAPI(swaggerSpec, nil) + api := operations.NewConsoleAPI(swaggerSpec) api.SystemArnListHandler = nil registerAdminArnsHandlers(api) if api.SystemArnListHandler == nil { diff --git a/restapi/config.go b/restapi/config.go index 2275e1bf3..b642282f6 100644 --- a/restapi/config.go +++ b/restapi/config.go @@ -22,6 +22,7 @@ import ( "strconv" "strings" + "github.com/minio/console/pkg/auth/idp/oauth2" xcerts "github.com/minio/pkg/certs" "github.com/minio/pkg/env" xnet "github.com/minio/pkg/net" @@ -46,6 +47,25 @@ var ( ConsoleResourceName = "console-ui" ) +var ( + // GlobalRootCAs is CA root certificates, a nil value means system certs pool will be used + GlobalRootCAs *x509.CertPool + // GlobalPublicCerts has certificates Console will use to serve clients + GlobalPublicCerts []*x509.Certificate + // GlobalTLSCertsManager custom TLS Manager for SNI support + GlobalTLSCertsManager *xcerts.Manager +) + +// MinIOConfig represents application configuration passed in from the MinIO +// server to the console. +type MinIOConfig struct { + OpenIDProviders oauth2.OpenIDPCfg +} + +// GlobalMinIOConfig is the global application configuration passed in from the +// MinIO server. +var GlobalMinIOConfig MinIOConfig + func getMinIOServer() string { return strings.TrimSpace(env.Get(ConsoleMinIOServer, "http://localhost:9000")) } @@ -234,12 +254,3 @@ func getPrometheusJobID() string { func getPrometheusExtraLabels() string { return env.Get(PrometheusExtraLabels, "") } - -var ( - // GlobalRootCAs is CA root certificates, a nil value means system certs pool will be used - GlobalRootCAs *x509.CertPool - // GlobalPublicCerts has certificates Console will use to serve clients - GlobalPublicCerts []*x509.Certificate - // GlobalTLSCertsManager custom TLS Manager for SNI support - GlobalTLSCertsManager *xcerts.Manager -) diff --git a/restapi/operations/console_api.go b/restapi/operations/console_api.go index 3be7cd71c..4ed745876 100644 --- a/restapi/operations/console_api.go +++ b/restapi/operations/console_api.go @@ -38,7 +38,6 @@ import ( "github.com/go-openapi/swag" "github.com/minio/console/models" - "github.com/minio/console/pkg/auth/idp/oauth2" "github.com/minio/console/restapi/operations/account" "github.com/minio/console/restapi/operations/auth" "github.com/minio/console/restapi/operations/bucket" @@ -59,7 +58,7 @@ import ( ) // NewConsoleAPI creates a new Console instance -func NewConsoleAPI(spec *loads.Document, openIDProviders oauth2.OpenIDPCfg) *ConsoleAPI { +func NewConsoleAPI(spec *loads.Document) *ConsoleAPI { return &ConsoleAPI{ handlers: make(map[string]map[string]http.Handler), formats: strfmt.Default, @@ -76,8 +75,6 @@ func NewConsoleAPI(spec *loads.Document, openIDProviders oauth2.OpenIDPCfg) *Con APIKeyAuthenticator: security.APIKeyAuth, BearerAuthenticator: security.BearerAuth, - OpenIDProviders: openIDProviders, - JSONConsumer: runtime.JSONConsumer(), MultipartformConsumer: runtime.DiscardConsumer, @@ -484,9 +481,6 @@ type ConsoleAPI struct { Middleware func(middleware.Builder) http.Handler useSwaggerUI bool - // Configuration passed in from MinIO for MinIO console. - OpenIDProviders oauth2.OpenIDPCfg - // BasicAuthenticator generates a runtime.Authenticator from the supplied basic auth function. // It has a default implementation in the security package, however you can replace it for your particular usage. BasicAuthenticator func(security.UserPassAuthentication) runtime.Authenticator diff --git a/restapi/user_login.go b/restapi/user_login.go index 2c4824785..f304d0b81 100644 --- a/restapi/user_login.go +++ b/restapi/user_login.go @@ -35,7 +35,7 @@ import ( func registerLoginHandlers(api *operations.ConsoleAPI) { // GET login strategy api.AuthLoginDetailHandler = authApi.LoginDetailHandlerFunc(func(params authApi.LoginDetailParams) middleware.Responder { - loginDetails, err := getLoginDetailsResponse(params, api.OpenIDProviders, oauth2.DefaultIDPConfig) + loginDetails, err := getLoginDetailsResponse(params, GlobalMinIOConfig.OpenIDProviders, oauth2.DefaultIDPConfig) if err != nil { return authApi.NewLoginDetailDefault(int(err.Code)).WithPayload(err) } @@ -56,7 +56,7 @@ func registerLoginHandlers(api *operations.ConsoleAPI) { }) // POST login using external IDP api.AuthLoginOauth2AuthHandler = authApi.LoginOauth2AuthHandlerFunc(func(params authApi.LoginOauth2AuthParams) middleware.Responder { - loginResponse, err := getLoginOauth2AuthResponse(params, api.OpenIDProviders, oauth2.DefaultIDPConfig) + loginResponse, err := getLoginOauth2AuthResponse(params, GlobalMinIOConfig.OpenIDProviders, oauth2.DefaultIDPConfig) if err != nil { return authApi.NewLoginOauth2AuthDefault(int(err.Code)).WithPayload(err) } diff --git a/sso-integration/sso_test.go b/sso-integration/sso_test.go index 0aa714302..06b1c9b2a 100644 --- a/sso-integration/sso_test.go +++ b/sso-integration/sso_test.go @@ -62,9 +62,13 @@ func initConsoleServer(consoleIDPURL string) (*restapi.Server, error) { restapi.LogInfo = noLog restapi.LogError = noLog - api := operations.NewConsoleAPI(swaggerSpec, pcfg) + api := operations.NewConsoleAPI(swaggerSpec) api.Logger = noLog + restapi.GlobalMinIOConfig = restapi.MinIOConfig{ + OpenIDProviders: pcfg, + } + server := restapi.NewServer(api) // register all APIs server.ConfigureAPI()