storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/globals.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2015, 2016, 2017, 2018 MinIO, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package cmd
    18  
    19  import (
    20  	"crypto/x509"
    21  	"errors"
    22  	"net/http"
    23  	"os"
    24  	"sync"
    25  	"time"
    26  
    27  	"github.com/dustin/go-humanize"
    28  	"github.com/minio/minio-go/v7/pkg/set"
    29  
    30  	"storj.io/minio/cmd/config/cache"
    31  	"storj.io/minio/cmd/config/compress"
    32  	xldap "storj.io/minio/cmd/config/identity/ldap"
    33  	"storj.io/minio/cmd/config/identity/openid"
    34  	"storj.io/minio/cmd/config/policy/opa"
    35  	"storj.io/minio/cmd/config/storageclass"
    36  	xhttp "storj.io/minio/cmd/http"
    37  	"storj.io/minio/pkg/auth"
    38  	"storj.io/minio/pkg/bucket/bandwidth"
    39  	"storj.io/minio/pkg/certs"
    40  	"storj.io/minio/pkg/event"
    41  	"storj.io/minio/pkg/handlers"
    42  	"storj.io/minio/pkg/kms"
    43  	"storj.io/minio/pkg/pubsub"
    44  )
    45  
    46  // minio configuration related constants.
    47  const (
    48  	GlobalMinioDefaultPort = "9000"
    49  
    50  	globalMinioDefaultRegion = ""
    51  	// This is a sha256 output of ``arn:aws:iam::minio:user/admin``,
    52  	// this is kept in present form to be compatible with S3 owner ID
    53  	// requirements -
    54  	//
    55  	// ```
    56  	//    The canonical user ID is the Amazon S3–only concept.
    57  	//    It is 64-character obfuscated version of the account ID.
    58  	// ```
    59  	// http://docs.aws.amazon.com/AmazonS3/latest/dev/example-walkthroughs-managing-access-example4.html
    60  	GlobalMinioDefaultOwnerID      = "02d6176db174dc93cb1b899f7c6078f08654445fe8cf1b6ce98d8855f66bdbf4"
    61  	globalMinioDefaultStorageClass = "STANDARD"
    62  	globalWindowsOSName            = "windows"
    63  	globalMacOSName                = "darwin"
    64  	globalMinioModeFS              = "mode-server-fs"
    65  	globalMinioModeErasure         = "mode-server-xl"
    66  	globalMinioModeDistErasure     = "mode-server-distributed-xl"
    67  	globalMinioModeGatewayPrefix   = "mode-gateway-"
    68  	globalDirSuffix                = "__XLDIR__"
    69  	globalDirSuffixWithSlash       = globalDirSuffix + slashSeparator
    70  
    71  	// Add new global values here.
    72  )
    73  
    74  const (
    75  	// Limit fields size (except file) to 1Mib since Policy document
    76  	// can reach that size according to https://aws.amazon.com/articles/1434
    77  	maxFormFieldSize = int64(1 * humanize.MiByte)
    78  
    79  	// Limit memory allocation to store multipart data
    80  	maxFormMemory = int64(5 * humanize.MiByte)
    81  
    82  	// The maximum allowed time difference between the incoming request
    83  	// date and server date during signature verification.
    84  	globalMaxSkewTime = 15 * time.Minute // 15 minutes skew allowed.
    85  
    86  	// GlobalStaleUploadsExpiry - Expiry duration after which the uploads in multipart, tmp directory are deemed stale.
    87  	GlobalStaleUploadsExpiry = time.Hour * 24 // 24 hrs.
    88  
    89  	// GlobalStaleUploadsCleanupInterval - Cleanup interval when the stale uploads cleanup is initiated.
    90  	GlobalStaleUploadsCleanupInterval = time.Hour * 12 // 12 hrs.
    91  
    92  	// GlobalServiceExecutionInterval - Executes the Lifecycle events.
    93  	GlobalServiceExecutionInterval = time.Hour * 24 // 24 hrs.
    94  
    95  	// Refresh interval to update in-memory iam config cache.
    96  	globalRefreshIAMInterval = 5 * time.Minute
    97  
    98  	// Limit of location constraint XML for unauthenticated PUT bucket operations.
    99  	maxLocationConstraintSize = 3 * humanize.MiByte
   100  
   101  	// Maximum size of default bucket encryption configuration allowed
   102  	maxBucketSSEConfigSize = 1 * humanize.MiByte
   103  
   104  	// diskFillFraction is the fraction of a disk we allow to be filled.
   105  	diskFillFraction = 0.95
   106  )
   107  
   108  var GlobalCLIContext = struct {
   109  	JSON, Quiet    bool
   110  	Anonymous      bool
   111  	Addr           string
   112  	StrictS3Compat bool
   113  }{}
   114  
   115  var (
   116  	// Indicates if the running minio server is distributed setup.
   117  	globalIsDistErasure = false
   118  
   119  	// Indicates if the running minio server is an erasure-code backend.
   120  	globalIsErasure = false
   121  
   122  	// Indicates if the running minio is in gateway mode.
   123  	GlobalIsGateway = false
   124  
   125  	// Name of gateway server, e.g S3, GCS, Azure, etc
   126  	globalGatewayName = ""
   127  
   128  	// This flag is set to 'true' by default
   129  	globalBrowserEnabled = true
   130  
   131  	// This flag is set to 'true' when MINIO_UPDATE env is set to 'off'. Default is false.
   132  	globalInplaceUpdateDisabled = false
   133  
   134  	// This flag is set to 'us-east-1' by default
   135  	globalServerRegion = globalMinioDefaultRegion
   136  
   137  	// MinIO local server address (in `host:port` format)
   138  	globalMinioAddr = ""
   139  	// MinIO default port, can be changed through command line.
   140  	globalMinioPort = GlobalMinioDefaultPort
   141  	// Holds the host that was passed using --address
   142  	globalMinioHost = ""
   143  	// Holds the possible host endpoint.
   144  	globalMinioEndpoint = ""
   145  
   146  	// globalConfigSys server config system.
   147  	globalConfigSys *ConfigSys
   148  
   149  	GlobalNotificationSys  *NotificationSys
   150  	globalConfigTargetList *event.TargetList
   151  	// globalEnvTargetList has list of targets configured via env.
   152  	globalEnvTargetList *event.TargetList
   153  
   154  	globalBucketMetadataSys *BucketMetadataSys
   155  	globalBucketMonitor     *bandwidth.Monitor
   156  	globalPolicySys         *PolicySys
   157  	GlobalIAMSys            *IAMSys
   158  
   159  	globalLifecycleSys       *LifecycleSys
   160  	globalBucketSSEConfigSys *BucketSSEConfigSys
   161  	globalBucketTargetSys    *BucketTargetSys
   162  	// globalAPIConfig controls S3 API requests throttling,
   163  	// healthcheck readiness deadlines and cors settings.
   164  	globalAPIConfig = apiConfig{listQuorum: 3}
   165  
   166  	globalStorageClass storageclass.Config
   167  	globalLDAPConfig   xldap.Config
   168  	globalOpenIDConfig openid.Config
   169  
   170  	// CA root certificates, a nil value means system certs pool will be used
   171  	globalRootCAs *x509.CertPool
   172  
   173  	// IsSSL indicates if the server is configured with SSL.
   174  	GlobalIsTLS bool
   175  
   176  	globalTLSCerts *certs.Manager
   177  
   178  	globalHTTPServer        *xhttp.Server
   179  	globalHTTPServerErrorCh = make(chan error)
   180  	globalOSSignalCh        = make(chan os.Signal, 1)
   181  
   182  	// global Trace system to send HTTP request/response
   183  	// and Storage/OS calls info to registered listeners.
   184  	globalTrace = pubsub.New()
   185  
   186  	// global Listen system to send S3 API events to registered listeners
   187  	globalHTTPListen = pubsub.New()
   188  
   189  	// global console system to send console logs to
   190  	// registered listeners
   191  	globalConsoleSys *HTTPConsoleLoggerSys
   192  
   193  	globalEndpoints EndpointServerPools
   194  
   195  	// The name of this local node, fetched from arguments
   196  	globalLocalNodeName string
   197  
   198  	globalRemoteEndpoints map[string]Endpoint
   199  
   200  	// Global server's network statistics
   201  	globalConnStats = newConnStats()
   202  
   203  	// Global HTTP request statisitics
   204  	globalHTTPStats = newHTTPStats()
   205  
   206  	// Time when the server is started
   207  	globalBootTime = UTCNow()
   208  
   209  	globalActiveCred auth.Credentials
   210  
   211  	// Hold the old server credentials passed by the environment
   212  	globalOldCred auth.Credentials
   213  
   214  	// Indicates if config is to be encrypted
   215  	globalConfigEncrypted bool
   216  
   217  	globalPublicCerts []*x509.Certificate
   218  
   219  	globalDomainNames []string      // Root domains for virtual host style requests
   220  	globalDomainIPs   set.StringSet // Root domain IP address(s) for a distributed MinIO deployment
   221  
   222  	globalOperationTimeout       = newDynamicTimeout(10*time.Minute, 5*time.Minute) // default timeout for general ops
   223  	globalDeleteOperationTimeout = newDynamicTimeout(5*time.Minute, 1*time.Minute)  // default time for delete ops
   224  
   225  	globalBucketObjectLockSys *BucketObjectLockSys
   226  	GlobalBucketQuotaSys      *BucketQuotaSys
   227  	globalBucketVersioningSys *BucketVersioningSys
   228  
   229  	// Disk cache drives
   230  	globalCacheConfig cache.Config
   231  
   232  	// Initialized KMS configuration for disk cache
   233  	globalCacheKMS kms.KMS
   234  
   235  	// GlobalKMS initialized KMS configuration
   236  	GlobalKMS kms.KMS
   237  
   238  	// Auto-Encryption, if enabled, turns any non-SSE-C request
   239  	// into an SSE-S3 request. If enabled a valid, non-empty KMS
   240  	// configuration must be present.
   241  	globalAutoEncryption bool
   242  
   243  	// Is compression enabled?
   244  	globalCompressConfigMu sync.Mutex
   245  	globalCompressConfig   compress.Config
   246  
   247  	// Some standard object extensions which we strictly dis-allow for compression.
   248  	standardExcludeCompressExtensions = []string{".gz", ".bz2", ".rar", ".zip", ".7z", ".xz", ".mp4", ".mkv", ".mov", ".jpg", ".png", ".gif"}
   249  
   250  	// Some standard content-types which we strictly dis-allow for compression.
   251  	standardExcludeCompressContentTypes = []string{"video/*", "audio/*", "application/zip", "application/x-gzip", "application/x-zip-compressed", " application/x-compress", "application/x-spoon"}
   252  
   253  	// Authorization validators list.
   254  	globalOpenIDValidators *openid.Validators
   255  
   256  	// OPA policy system.
   257  	GlobalPolicyOPA *opa.Opa
   258  
   259  	// Deployment ID - unique per deployment
   260  	globalDeploymentID string
   261  
   262  	// GlobalGatewaySSE sse options
   263  	GlobalGatewaySSE gatewaySSE
   264  
   265  	globalAllHealState *allHealState
   266  
   267  	// The always present healing routine ready to heal objects
   268  	globalBackgroundHealRoutine *healRoutine
   269  	globalBackgroundHealState   *allHealState
   270  
   271  	// If writes to FS backend should be O_SYNC.
   272  	globalFSOSync bool
   273  
   274  	globalProxyEndpoints []ProxyEndpoint
   275  
   276  	globalInternodeTransport http.RoundTripper
   277  
   278  	globalProxyTransport http.RoundTripper
   279  
   280  	globalDNSCache *xhttp.DNSCache
   281  
   282  	globalForwarder *handlers.Forwarder
   283  	// Add new variable global values here.
   284  )
   285  
   286  var errSelfTestFailure = errors.New("self test failed. unsafe to start server")
   287  
   288  // Returns minio global information, as a key value map.
   289  // returned list of global values is not an exhaustive
   290  // list. Feel free to add new relevant fields.
   291  func getGlobalInfo() (globalInfo map[string]interface{}) {
   292  	globalInfo = map[string]interface{}{
   293  		"serverRegion": globalServerRegion,
   294  		"domains":      globalDomainNames,
   295  		// Add more relevant global settings here.
   296  	}
   297  
   298  	return globalInfo
   299  }