mirror of
https://github.com/minio/minio.git
synced 2025-04-19 02:05:24 -04:00
fix: handle redirects for specific resources (#12629)
This commit is contained in:
parent
25f55d6051
commit
c99d399d09
@ -114,13 +114,16 @@ func minioConfigToConsoleFeatures() {
|
|||||||
os.Setenv("CONSOLE_MINIO_SERVER", getAPIEndpoints()[0])
|
os.Setenv("CONSOLE_MINIO_SERVER", getAPIEndpoints()[0])
|
||||||
if value := env.Get("MINIO_LOG_QUERY_URL", ""); value != "" {
|
if value := env.Get("MINIO_LOG_QUERY_URL", ""); value != "" {
|
||||||
os.Setenv("CONSOLE_LOG_QUERY_URL", value)
|
os.Setenv("CONSOLE_LOG_QUERY_URL", value)
|
||||||
}
|
if value := env.Get("MINIO_LOG_QUERY_AUTH_TOKEN", ""); value != "" {
|
||||||
if value := env.Get("MINIO_LOG_QUERY_AUTH_TOKEN", ""); value != "" {
|
os.Setenv("CONSOLE_LOG_QUERY_AUTH_TOKEN", value)
|
||||||
os.Setenv("CONSOLE_LOG_QUERY_AUTH_TOKEN", value)
|
}
|
||||||
}
|
}
|
||||||
// Enable if prometheus URL is set.
|
// Enable if prometheus URL is set.
|
||||||
if value := env.Get("MINIO_PROMETHEUS_URL", ""); value != "" {
|
if value := env.Get("MINIO_PROMETHEUS_URL", ""); value != "" {
|
||||||
os.Setenv("CONSOLE_PROMETHEUS_URL", value)
|
os.Setenv("CONSOLE_PROMETHEUS_URL", value)
|
||||||
|
if value := env.Get("MINIO_PROMETHEUS_JOB_ID", "minio-job"); value != "" {
|
||||||
|
os.Setenv("CONSOLE_PROMETHEUS_JOB_ID", value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Enable if LDAP is enabled.
|
// Enable if LDAP is enabled.
|
||||||
if globalLDAPConfig.Enabled {
|
if globalLDAPConfig.Enabled {
|
||||||
@ -413,11 +416,6 @@ func handleCommonEnvVars() {
|
|||||||
logger.Fatal(config.ErrInvalidBrowserValue(err), "Invalid MINIO_BROWSER value in environment variable")
|
logger.Fatal(config.ErrInvalidBrowserValue(err), "Invalid MINIO_BROWSER value in environment variable")
|
||||||
}
|
}
|
||||||
|
|
||||||
globalBrowserRedirect, err = config.ParseBool(env.Get(config.EnvBrowserRedirect, config.EnableOn))
|
|
||||||
if err != nil {
|
|
||||||
logger.Fatal(config.ErrInvalidBrowserValue(err), "Invalid MINIO_BROWSER_REDIRECT value in environment variable")
|
|
||||||
}
|
|
||||||
|
|
||||||
globalFSOSync, err = config.ParseBool(env.Get(config.EnvFSOSync, config.EnableOff))
|
globalFSOSync, err = config.ParseBool(env.Get(config.EnvFSOSync, config.EnableOff))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatal(config.ErrInvalidFSOSyncValue(err), "Invalid MINIO_FS_OSYNC value in environment variable")
|
logger.Fatal(config.ErrInvalidFSOSyncValue(err), "Invalid MINIO_FS_OSYNC value in environment variable")
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
@ -161,10 +162,9 @@ func guessIsBrowserReq(r *http.Request) bool {
|
|||||||
func setBrowserRedirectHandler(h http.Handler) http.Handler {
|
func setBrowserRedirectHandler(h http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
// Re-direction is handled specifically for browser requests.
|
// Re-direction is handled specifically for browser requests.
|
||||||
if guessIsBrowserReq(r) && globalBrowserRedirect {
|
if guessIsBrowserReq(r) {
|
||||||
// Fetch the redirect location if any.
|
// Fetch the redirect location if any.
|
||||||
u := getRedirectLocation(r)
|
if u := getRedirectLocation(r); u != nil {
|
||||||
if u != nil {
|
|
||||||
// Employ a temporary re-direct.
|
// Employ a temporary re-direct.
|
||||||
http.Redirect(w, r, u.String(), http.StatusTemporaryRedirect)
|
http.Redirect(w, r, u.String(), http.StatusTemporaryRedirect)
|
||||||
return
|
return
|
||||||
@ -184,33 +184,36 @@ func shouldProxy() bool {
|
|||||||
// serves only limited purpose on redirect-handler for
|
// serves only limited purpose on redirect-handler for
|
||||||
// browser requests.
|
// browser requests.
|
||||||
func getRedirectLocation(r *http.Request) *url.URL {
|
func getRedirectLocation(r *http.Request) *url.URL {
|
||||||
hostname, _, _ := net.SplitHostPort(r.Host)
|
resource, err := getResource(r.URL.Path, r.Host, globalDomainNames)
|
||||||
if hostname == "" {
|
if err != nil {
|
||||||
hostname = r.Host
|
return nil
|
||||||
}
|
}
|
||||||
var rurl = &url.URL{
|
for _, prefix := range []string{
|
||||||
Host: net.JoinHostPort(hostname, globalMinioConsolePort),
|
"favicon-16x16.png",
|
||||||
|
"favicon-32x32.png",
|
||||||
|
"favicon-96x96.png",
|
||||||
|
"index.html",
|
||||||
|
minioReservedBucket,
|
||||||
|
} {
|
||||||
|
bucket, _ := path2BucketObject(resource)
|
||||||
|
if path.Clean(bucket) == prefix || resource == slashSeparator {
|
||||||
|
hostname, _, _ := net.SplitHostPort(r.Host)
|
||||||
|
if hostname == "" {
|
||||||
|
hostname = r.Host
|
||||||
|
}
|
||||||
|
return &url.URL{
|
||||||
|
Host: net.JoinHostPort(hostname, globalMinioConsolePort),
|
||||||
|
Scheme: func() string {
|
||||||
|
scheme := "http"
|
||||||
|
if r.TLS != nil {
|
||||||
|
scheme = "https"
|
||||||
|
}
|
||||||
|
return scheme
|
||||||
|
}(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
urlPath := r.URL.Path
|
return nil
|
||||||
scheme := "http"
|
|
||||||
if r.TLS != nil {
|
|
||||||
scheme = "https"
|
|
||||||
}
|
|
||||||
rurl.Scheme = scheme
|
|
||||||
if urlPath == minioReservedBucketPath {
|
|
||||||
rurl.Path = minioReservedBucketPath + SlashSeparator
|
|
||||||
}
|
|
||||||
if contains([]string{
|
|
||||||
SlashSeparator,
|
|
||||||
"/webrpc",
|
|
||||||
"/login",
|
|
||||||
"/favicon-16x16.png",
|
|
||||||
"/favicon-32x32.png",
|
|
||||||
"/favicon-96x96.png",
|
|
||||||
}, urlPath) {
|
|
||||||
rurl.Path = minioReservedBucketPath + urlPath
|
|
||||||
}
|
|
||||||
return rurl
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// guessIsHealthCheckReq - returns true if incoming request looks
|
// guessIsHealthCheckReq - returns true if incoming request looks
|
||||||
|
@ -137,9 +137,6 @@ var (
|
|||||||
// This flag is set to 'true' by default
|
// This flag is set to 'true' by default
|
||||||
globalBrowserEnabled = true
|
globalBrowserEnabled = true
|
||||||
|
|
||||||
// This flag is set to 'true' by default.
|
|
||||||
globalBrowserRedirect = true
|
|
||||||
|
|
||||||
// This flag is set to 'true' when MINIO_UPDATE env is set to 'off'. Default is false.
|
// This flag is set to 'true' when MINIO_UPDATE env is set to 'off'. Default is false.
|
||||||
globalInplaceUpdateDisabled = false
|
globalInplaceUpdateDisabled = false
|
||||||
|
|
||||||
|
@ -29,14 +29,13 @@ const (
|
|||||||
EnvRootUser = "MINIO_ROOT_USER"
|
EnvRootUser = "MINIO_ROOT_USER"
|
||||||
EnvRootPassword = "MINIO_ROOT_PASSWORD"
|
EnvRootPassword = "MINIO_ROOT_PASSWORD"
|
||||||
|
|
||||||
EnvBrowser = "MINIO_BROWSER"
|
EnvBrowser = "MINIO_BROWSER"
|
||||||
EnvBrowserRedirect = "MINIO_BROWSER_REDIRECT"
|
EnvDomain = "MINIO_DOMAIN"
|
||||||
EnvDomain = "MINIO_DOMAIN"
|
EnvRegionName = "MINIO_REGION_NAME"
|
||||||
EnvRegionName = "MINIO_REGION_NAME"
|
EnvPublicIPs = "MINIO_PUBLIC_IPS"
|
||||||
EnvPublicIPs = "MINIO_PUBLIC_IPS"
|
EnvFSOSync = "MINIO_FS_OSYNC"
|
||||||
EnvFSOSync = "MINIO_FS_OSYNC"
|
EnvArgs = "MINIO_ARGS"
|
||||||
EnvArgs = "MINIO_ARGS"
|
EnvDNSWebhook = "MINIO_DNS_WEBHOOK_ENDPOINT"
|
||||||
EnvDNSWebhook = "MINIO_DNS_WEBHOOK_ENDPOINT"
|
|
||||||
|
|
||||||
EnvRootDiskThresholdSize = "MINIO_ROOTDISK_THRESHOLD_SIZE"
|
EnvRootDiskThresholdSize = "MINIO_ROOTDISK_THRESHOLD_SIZE"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user