github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/cmd/globals.go (about) 1 // Copyright (c) 2015-2021 MinIO, Inc. 2 // 3 // This file is part of MinIO Object Storage stack 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package cmd 19 20 import ( 21 "crypto/x509" 22 "errors" 23 "net/http" 24 "os" 25 "sync" 26 "time" 27 28 consoleapi "github.com/minio/console/api" 29 "github.com/minio/dnscache" 30 "github.com/minio/madmin-go/v3" 31 "github.com/minio/minio-go/v7" 32 "github.com/minio/minio-go/v7/pkg/set" 33 "github.com/minio/minio/internal/bpool" 34 "github.com/minio/minio/internal/bucket/bandwidth" 35 "github.com/minio/minio/internal/config" 36 "github.com/minio/minio/internal/config/browser" 37 "github.com/minio/minio/internal/grid" 38 "github.com/minio/minio/internal/handlers" 39 "github.com/minio/minio/internal/kms" 40 "go.uber.org/atomic" 41 42 "github.com/dustin/go-humanize" 43 "github.com/minio/minio/internal/auth" 44 "github.com/minio/minio/internal/config/cache" 45 "github.com/minio/minio/internal/config/callhome" 46 "github.com/minio/minio/internal/config/compress" 47 "github.com/minio/minio/internal/config/dns" 48 "github.com/minio/minio/internal/config/drive" 49 idplugin "github.com/minio/minio/internal/config/identity/plugin" 50 polplugin "github.com/minio/minio/internal/config/policy/plugin" 51 "github.com/minio/minio/internal/config/storageclass" 52 "github.com/minio/minio/internal/config/subnet" 53 xhttp "github.com/minio/minio/internal/http" 54 etcd "go.etcd.io/etcd/client/v3" 55 56 levent "github.com/minio/minio/internal/config/lambda/event" 57 "github.com/minio/minio/internal/event" 58 "github.com/minio/minio/internal/pubsub" 59 "github.com/minio/pkg/v2/certs" 60 "github.com/minio/pkg/v2/env" 61 xnet "github.com/minio/pkg/v2/net" 62 ) 63 64 // minio configuration related constants. 65 const ( 66 GlobalMinioDefaultPort = "9000" 67 68 globalMinioDefaultRegion = "" 69 // This is a sha256 output of ``arn:aws:iam::minio:user/admin``, 70 // this is kept in present form to be compatible with S3 owner ID 71 // requirements - 72 // 73 // ``` 74 // The canonical user ID is the Amazon S3–only concept. 75 // It is 64-character obfuscated version of the account ID. 76 // ``` 77 // http://docs.aws.amazon.com/AmazonS3/latest/dev/example-walkthroughs-managing-access-example4.html 78 globalMinioDefaultOwnerID = "02d6176db174dc93cb1b899f7c6078f08654445fe8cf1b6ce98d8855f66bdbf4" 79 globalMinioDefaultStorageClass = "STANDARD" 80 globalWindowsOSName = "windows" 81 globalMacOSName = "darwin" 82 globalMinioModeFS = "mode-server-fs" 83 globalMinioModeErasureSD = "mode-server-xl-single" 84 globalMinioModeErasure = "mode-server-xl" 85 globalMinioModeDistErasure = "mode-server-distributed-xl" 86 globalDirSuffix = "__XLDIR__" 87 globalDirSuffixWithSlash = globalDirSuffix + slashSeparator 88 89 // Add new global values here. 90 ) 91 92 const ( 93 // Limit fields size (except file) to 1Mib since Policy document 94 // can reach that size according to https://aws.amazon.com/articles/1434 95 maxFormFieldSize = int64(1 * humanize.MiByte) 96 97 // The maximum allowed time difference between the incoming request 98 // date and server date during signature verification. 99 globalMaxSkewTime = 15 * time.Minute // 15 minutes skew allowed. 100 101 // GlobalStaleUploadsExpiry - Expiry duration after which the uploads in multipart, 102 // tmp directory are deemed stale. 103 GlobalStaleUploadsExpiry = time.Hour * 24 // 24 hrs. 104 105 // GlobalStaleUploadsCleanupInterval - Cleanup interval when the stale uploads cleanup is initiated. 106 GlobalStaleUploadsCleanupInterval = time.Hour * 6 // 6 hrs. 107 108 // Refresh interval to update in-memory iam config cache. 109 globalRefreshIAMInterval = 10 * time.Minute 110 111 // Limit of location constraint XML for unauthenticated PUT bucket operations. 112 maxLocationConstraintSize = 3 * humanize.MiByte 113 114 // Maximum size of default bucket encryption configuration allowed 115 maxBucketSSEConfigSize = 1 * humanize.MiByte 116 117 // diskFillFraction is the fraction of a disk we allow to be filled. 118 diskFillFraction = 0.99 119 120 // diskReserveFraction is the fraction of a disk where we will fill other server pools first. 121 // If all pools reach this, we will use all pools with regular placement. 122 diskReserveFraction = 0.15 123 124 // diskAssumeUnknownSize is the size to assume when an unknown size upload is requested. 125 diskAssumeUnknownSize = 1 << 30 126 127 // diskMinInodes is the minimum number of inodes we want free on a disk to perform writes. 128 diskMinInodes = 1000 129 130 // tlsClientSessionCacheSize is the cache size for client sessions. 131 tlsClientSessionCacheSize = 100 132 ) 133 134 func init() { 135 // Injected to prevent circular dependency. 136 pubsub.GetByteBuffer = grid.GetByteBuffer 137 } 138 139 type poolDisksLayout struct { 140 cmdline string 141 layout [][]string 142 } 143 144 type disksLayout struct { 145 legacy bool 146 pools []poolDisksLayout 147 } 148 149 type serverCtxt struct { 150 JSON, Quiet bool 151 Anonymous bool 152 StrictS3Compat bool 153 Addr, ConsoleAddr string 154 ConfigDir, CertsDir string 155 configDirSet, certsDirSet bool 156 Interface string 157 158 RootUser, RootPwd string 159 160 FTP []string 161 SFTP []string 162 163 UserTimeout time.Duration 164 ConnReadDeadline time.Duration 165 ConnWriteDeadline time.Duration 166 ConnClientReadDeadline time.Duration 167 ConnClientWriteDeadline time.Duration 168 169 ShutdownTimeout time.Duration 170 IdleTimeout time.Duration 171 ReadHeaderTimeout time.Duration 172 MaxIdleConnsPerHost int 173 174 CrossDomainXML string 175 // The layout of disks as interpreted 176 Layout disksLayout 177 } 178 179 var ( 180 // Global user opts context 181 globalServerCtxt serverCtxt 182 183 // Indicates if the running minio server is distributed setup. 184 globalIsDistErasure = false 185 186 // Indicates if the running minio server is an erasure-code backend. 187 globalIsErasure = false 188 189 // Indicates if the running minio server is in single drive XL mode. 190 globalIsErasureSD = false 191 192 // Indicates if server code should go through testing path. 193 globalIsTesting = false 194 195 // This flag is set to 'true' by default 196 globalBrowserEnabled = true 197 198 // Custom browser redirect URL, not set by default 199 // and it is automatically deduced. 200 globalBrowserRedirectURL *xnet.URL 201 202 // Disable redirect, default is enabled. 203 globalBrowserRedirect bool 204 205 // globalBrowserConfig Browser user configurable settings 206 globalBrowserConfig browser.Config 207 208 // This flag is set to 'true' when MINIO_UPDATE env is set to 'off'. Default is false. 209 globalInplaceUpdateDisabled = false 210 211 globalSite = config.Site{ 212 Region: globalMinioDefaultRegion, 213 } 214 215 // MinIO local server address (in `host:port` format) 216 globalMinioAddr = "" 217 218 // MinIO default port, can be changed through command line. 219 globalMinioPort = GlobalMinioDefaultPort 220 globalMinioConsolePort = "13333" 221 222 // Holds the host that was passed using --address 223 globalMinioHost = "" 224 // Holds the host that was passed using --console-address 225 globalMinioConsoleHost = "" 226 227 // Holds the possible host endpoint. 228 globalMinioEndpoint = "" 229 globalMinioEndpointURL *xnet.URL 230 231 // globalConfigSys server config system. 232 globalConfigSys *ConfigSys 233 234 globalNotificationSys *NotificationSys 235 236 globalEventNotifier *EventNotifier 237 globalNotifyTargetList *event.TargetList 238 globalLambdaTargetList *levent.TargetList 239 240 globalBucketMetadataSys *BucketMetadataSys 241 globalBucketMonitor *bandwidth.Monitor 242 globalPolicySys *PolicySys 243 globalIAMSys *IAMSys 244 globalBytePoolCap *bpool.BytePoolCap 245 246 globalLifecycleSys *LifecycleSys 247 globalBucketSSEConfigSys *BucketSSEConfigSys 248 globalBucketTargetSys *BucketTargetSys 249 // globalAPIConfig controls S3 API requests throttling, 250 // healthCheck readiness deadlines and cors settings. 251 globalAPIConfig = apiConfig{listQuorum: "strict", rootAccess: true} 252 253 globalStorageClass storageclass.Config 254 255 globalAuthNPlugin *idplugin.AuthNPlugin 256 257 // CA root certificates, a nil value means system certs pool will be used 258 globalRootCAs *x509.CertPool 259 260 // IsSSL indicates if the server is configured with SSL. 261 globalIsTLS bool 262 263 globalTLSCerts *certs.Manager 264 265 globalHTTPServer *xhttp.Server 266 globalTCPOptions xhttp.TCPOptions 267 globalHTTPServerErrorCh = make(chan error) 268 globalOSSignalCh = make(chan os.Signal, 1) 269 270 // global Trace system to send HTTP request/response 271 // and Storage/OS calls info to registered listeners. 272 globalTrace = pubsub.New[madmin.TraceInfo, madmin.TraceType](8) 273 274 // global Listen system to send S3 API events to registered listeners 275 globalHTTPListen = pubsub.New[event.Event, pubsub.Mask](0) 276 277 // global console system to send console logs to 278 // registered listeners 279 globalConsoleSys *HTTPConsoleLoggerSys 280 281 // All unique drives for this deployment 282 globalEndpoints EndpointServerPools 283 // All unique nodes for this deployment 284 globalNodes []Node 285 286 // The name of this local node, fetched from arguments 287 globalLocalNodeName string 288 globalLocalNodeNameHex string 289 globalNodeNamesHex = make(map[string]struct{}) 290 291 // The global subnet config 292 globalSubnetConfig subnet.Config 293 294 // The global callhome config 295 globalCallhomeConfig callhome.Config 296 297 // The global drive config 298 globalDriveConfig drive.Config 299 300 // The global cache config 301 globalCacheConfig cache.Config 302 303 // Global server's network statistics 304 globalConnStats = newConnStats() 305 306 // Global HTTP request statistics 307 globalHTTPStats = newHTTPStats() 308 309 // Global bucket network and API statistics 310 globalBucketConnStats = newBucketConnStats() 311 globalBucketHTTPStats = newBucketHTTPStats() 312 313 // Time when the server is started 314 globalBootTime = UTCNow() 315 316 globalActiveCred auth.Credentials 317 globalSiteReplicatorCred siteReplicatorCred 318 319 // Captures if root credentials are set via ENV. 320 globalCredViaEnv bool 321 322 globalPublicCerts []*x509.Certificate 323 324 globalDomainNames []string // Root domains for virtual host style requests 325 globalDomainIPs set.StringSet // Root domain IP address(s) for a distributed MinIO deployment 326 327 globalOperationTimeout = newDynamicTimeout(10*time.Minute, 5*time.Minute) // default timeout for general ops 328 globalDeleteOperationTimeout = newDynamicTimeout(5*time.Minute, 1*time.Minute) // default time for delete ops 329 330 globalBucketObjectLockSys *BucketObjectLockSys 331 globalBucketQuotaSys *BucketQuotaSys 332 globalBucketVersioningSys *BucketVersioningSys 333 334 // Allocated etcd endpoint for config and bucket DNS. 335 globalEtcdClient *etcd.Client 336 337 // Cluster replication manager. 338 globalSiteReplicationSys SiteReplicationSys 339 340 // Cluster replication resync metrics 341 globalSiteResyncMetrics *siteResyncMetrics 342 343 // Is set to true when Bucket federation is requested 344 // and is 'true' when etcdConfig.PathPrefix is empty 345 globalBucketFederation bool 346 347 // Allocated DNS config wrapper over etcd client. 348 globalDNSConfig dns.Store 349 350 // GlobalKMS initialized KMS configuration 351 GlobalKMS kms.KMS 352 353 // Common lock for various subsystems performing the leader tasks 354 globalLeaderLock *sharedLock 355 356 // Auto-Encryption, if enabled, turns any non-SSE-C request 357 // into an SSE-S3 request. If enabled a valid, non-empty KMS 358 // configuration must be present. 359 globalAutoEncryption bool 360 361 // Is compression enabled? 362 globalCompressConfigMu sync.Mutex 363 globalCompressConfig compress.Config 364 365 // Some standard object extensions which we strictly dis-allow for compression. 366 standardExcludeCompressExtensions = []string{".gz", ".bz2", ".rar", ".zip", ".7z", ".xz", ".mp4", ".mkv", ".mov", ".jpg", ".png", ".gif"} 367 368 // Some standard content-types which we strictly dis-allow for compression. 369 standardExcludeCompressContentTypes = []string{"video/*", "audio/*", "application/zip", "application/x-gzip", "application/x-zip-compressed", " application/x-compress", "application/x-spoon"} 370 371 // AuthZ Plugin system. 372 globalAuthZPlugin *polplugin.AuthZPlugin 373 374 // Deployment ID - unique per deployment 375 globalDeploymentIDPtr atomic.Pointer[string] 376 globalDeploymentID = func() string { 377 ptr := globalDeploymentIDPtr.Load() 378 if ptr == nil { 379 return "" 380 } 381 return *ptr 382 } 383 384 globalAllHealState = newHealState(GlobalContext, true) 385 386 // The always present healing routine ready to heal objects 387 globalBackgroundHealRoutine = newHealRoutine() 388 globalBackgroundHealState = newHealState(GlobalContext, false) 389 390 globalMRFState = mrfState{ 391 opCh: make(chan partialOperation, mrfOpsQueueSize), 392 } 393 394 // If writes to FS backend should be O_SYNC. 395 globalFSOSync bool 396 397 globalProxyEndpoints []ProxyEndpoint 398 399 globalInternodeTransport http.RoundTripper 400 401 globalProxyTransport http.RoundTripper 402 403 globalRemoteTargetTransport http.RoundTripper 404 405 globalHealthChkTransport http.RoundTripper 406 407 globalDNSCache = &dnscache.Resolver{ 408 Timeout: 5 * time.Second, 409 } 410 411 globalForwarder *handlers.Forwarder 412 413 globalTierConfigMgr *TierConfigMgr 414 415 globalConsoleSrv *consoleapi.Server 416 417 // handles service freeze or un-freeze S3 API calls. 418 globalServiceFreeze atomic.Value 419 420 // Only needed for tracking 421 globalServiceFreezeCnt int32 422 globalServiceFreezeMu sync.Mutex // Updates. 423 424 // List of local drives to this node, this is only set during server startup, 425 // and is only mutated by HealFormat. Hold globalLocalDrivesMu to access. 426 globalLocalDrives []StorageAPI 427 globalLocalDrivesMu sync.RWMutex 428 429 globalDriveMonitoring = env.Get("_MINIO_DRIVE_ACTIVE_MONITORING", config.EnableOn) == config.EnableOn 430 431 // Is MINIO_CI_CD set? 432 globalIsCICD bool 433 434 globalRootDiskThreshold uint64 435 436 // Used for collecting stats for netperf 437 globalNetPerfMinDuration = time.Second * 10 438 globalNetPerfRX netPerfRX 439 globalSiteNetPerfRX netPerfRX 440 globalObjectPerfBucket = "minio-perf-test-tmp-bucket" 441 globalObjectPerfUserMetadata = "X-Amz-Meta-Minio-Object-Perf" // Clients can set this to bypass S3 API service freeze. Used by object pref tests. 442 443 // MinIO version unix timestamp 444 globalVersionUnix uint64 445 446 // MinIO client 447 globalMinioClient *minio.Client 448 449 // Public key for subnet confidential information 450 subnetAdminPublicKey = []byte("-----BEGIN PUBLIC KEY-----\nMIIBCgKCAQEAyC+ol5v0FP+QcsR6d1KypR/063FInmNEFsFzbEwlHQyEQN3O7kNI\nwVDN1vqp1wDmJYmv4VZGRGzfFw1q+QV7K1TnysrEjrqpVxfxzDQCoUadAp8IxLLc\ns2fjyDNxnZjoC6fTID9C0khKnEa5fPZZc3Ihci9SiCGkPmyUyCGVSxWXIKqL2Lrj\nyDc0pGeEhWeEPqw6q8X2jvTC246tlzqpDeNsPbcv2KblXRcKniQNbBrizT37CKHQ\nM6hc9kugrZbFuo8U5/4RQvZPJnx/DVjLDyoKo2uzuVQs4s+iBrA5sSSLp8rPED/3\n6DgWw3e244Dxtrg972dIT1IOqgn7KUJzVQIDAQAB\n-----END PUBLIC KEY-----") 451 subnetAdminPublicKeyDev = []byte("-----BEGIN PUBLIC KEY-----\nMIIBCgKCAQEArhQYXQd6zI4uagtVfthAPOt6i4AYHnEWCoNeAovM4MNl42I9uQFh\n3VHkbWj9Gpx9ghf6PgRgK+8FcFvy+StmGcXpDCiFywXX24uNhcZjscX1C4Esk0BW\nidfI2eXYkOlymD4lcK70SVgJvC693Qa7Z3FE1KU8Nfv2bkxEE4bzOkojX9t6a3+J\nR8X6Z2U8EMlH1qxJPgiPogELhWP0qf2Lq7GwSAflo1Tj/ytxvD12WrnE0Rrj/8yP\nSnp7TbYm91KocKMExlmvx3l2XPLxeU8nf9U0U+KOmorejD3MDMEPF+tlk9LB3JWP\nZqYYe38rfALVTn4RVJriUcNOoEpEyC0WEwIDAQAB\n-----END PUBLIC KEY-----") 452 453 globalConnReadDeadline time.Duration 454 globalConnWriteDeadline time.Duration 455 456 // Controller for deleted file sweeper. 457 deletedCleanupSleeper = newDynamicSleeper(5, 25*time.Millisecond, false) 458 459 // Is _MINIO_DISABLE_API_FREEZE_ON_BOOT set? 460 globalDisableFreezeOnBoot bool 461 462 // Contains NIC interface name used for internode communication 463 globalInternodeInterface string 464 globalInternodeInterfaceOnce sync.Once 465 466 // Set last client perf extra time (get lock, and validate) 467 globalLastClientPerfExtraTime int64 468 469 // Captures all batch jobs metrics globally 470 globalBatchJobsMetrics batchJobMetrics 471 472 // Indicates if server was started as `--address ":0"` 473 globalDynamicAPIPort bool 474 475 // Add new variable global values here. 476 ) 477 478 var globalAuthPluginMutex sync.Mutex 479 480 func newGlobalAuthNPluginFn() *idplugin.AuthNPlugin { 481 globalAuthPluginMutex.Lock() 482 defer globalAuthPluginMutex.Unlock() 483 return globalAuthNPlugin 484 } 485 486 func newGlobalAuthZPluginFn() *polplugin.AuthZPlugin { 487 globalAuthPluginMutex.Lock() 488 defer globalAuthPluginMutex.Unlock() 489 return globalAuthZPlugin 490 } 491 492 func setGlobalAuthNPlugin(authn *idplugin.AuthNPlugin) { 493 globalAuthPluginMutex.Lock() 494 globalAuthNPlugin = authn 495 globalAuthPluginMutex.Unlock() 496 } 497 498 func setGlobalAuthZPlugin(authz *polplugin.AuthZPlugin) { 499 globalAuthPluginMutex.Lock() 500 globalAuthZPlugin = authz 501 globalAuthPluginMutex.Unlock() 502 } 503 504 var errSelfTestFailure = errors.New("self test failed. unsafe to start server")