2013-12-06 23:43:07 +00:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
2014-03-09 22:18:36 +00:00
|
|
|
"fmt"
|
2013-12-31 22:00:25 +00:00
|
|
|
"net"
|
2013-12-06 23:43:07 +00:00
|
|
|
"os"
|
2014-01-09 23:44:25 +00:00
|
|
|
"time"
|
2014-05-26 17:58:57 +00:00
|
|
|
|
2020-10-05 20:28:13 +00:00
|
|
|
"github.com/hashicorp/memberlist"
|
|
|
|
"github.com/hashicorp/raft"
|
|
|
|
"github.com/hashicorp/serf/serf"
|
|
|
|
"golang.org/x/time/rate"
|
|
|
|
|
2019-06-26 15:43:25 +00:00
|
|
|
"github.com/hashicorp/consul/agent/checks"
|
2022-12-13 20:09:55 +00:00
|
|
|
consulrate "github.com/hashicorp/consul/agent/consul/rate"
|
2018-04-09 04:56:46 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2020-10-08 19:02:19 +00:00
|
|
|
libserf "github.com/hashicorp/consul/lib/serf"
|
2014-11-18 22:56:48 +00:00
|
|
|
"github.com/hashicorp/consul/tlsutil"
|
2017-01-18 06:20:11 +00:00
|
|
|
"github.com/hashicorp/consul/types"
|
2017-08-28 10:20:21 +00:00
|
|
|
"github.com/hashicorp/consul/version"
|
2013-12-06 23:43:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2013-12-20 23:33:13 +00:00
|
|
|
DefaultDC = "dc1"
|
2017-05-03 19:02:01 +00:00
|
|
|
DefaultRPCPort = 8300
|
2013-12-09 22:22:23 +00:00
|
|
|
DefaultLANSerfPort = 8301
|
|
|
|
DefaultWANSerfPort = 8302
|
2016-08-25 00:33:53 +00:00
|
|
|
|
2016-08-25 22:36:05 +00:00
|
|
|
// DefaultRaftMultiplier is used as a baseline Raft configuration that
|
2019-04-17 18:17:12 +00:00
|
|
|
// will be reliable on a very basic server. See docs/install/performance.html
|
2016-08-25 22:36:05 +00:00
|
|
|
// for information on how this value was obtained.
|
2016-08-25 00:33:53 +00:00
|
|
|
DefaultRaftMultiplier uint = 5
|
2016-08-25 22:36:05 +00:00
|
|
|
|
|
|
|
// MaxRaftMultiplier is a fairly arbitrary upper bound that limits the
|
|
|
|
// amount of performance detuning that's possible.
|
|
|
|
MaxRaftMultiplier uint = 10
|
2023-02-08 16:50:22 +00:00
|
|
|
|
|
|
|
// LogStoreBackend* are well-known string values used to configure different
|
|
|
|
// log store backends.
|
|
|
|
LogStoreBackendBoltDB = "boltdb"
|
|
|
|
LogStoreBackendWAL = "wal"
|
2013-12-06 23:43:07 +00:00
|
|
|
)
|
|
|
|
|
2014-01-01 00:45:13 +00:00
|
|
|
var (
|
2017-05-03 19:02:01 +00:00
|
|
|
DefaultRPCAddr = &net.TCPAddr{IP: net.ParseIP("0.0.0.0"), Port: DefaultRPCPort}
|
2014-01-01 00:45:13 +00:00
|
|
|
|
2017-05-03 19:02:01 +00:00
|
|
|
// ProtocolVersionMap is the mapping of Consul protocol versions
|
|
|
|
// to Serf protocol versions. We mask the Serf protocols using
|
|
|
|
// our own protocol version.
|
|
|
|
protocolVersionMap map[uint8]uint8
|
|
|
|
)
|
2014-03-09 22:18:36 +00:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
protocolVersionMap = map[uint8]uint8{
|
|
|
|
1: 4,
|
2014-05-27 22:45:30 +00:00
|
|
|
2: 4,
|
2015-10-16 02:28:31 +00:00
|
|
|
3: 4,
|
2014-03-09 22:18:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-30 23:44:04 +00:00
|
|
|
// (Enterprise-only) NetworkSegment is the address and port configuration
|
|
|
|
// for a network segment.
|
2017-08-14 14:36:07 +00:00
|
|
|
type NetworkSegment struct {
|
|
|
|
Name string
|
|
|
|
Bind string
|
|
|
|
Port int
|
|
|
|
Advertise string
|
2017-08-29 00:58:22 +00:00
|
|
|
RPCAddr *net.TCPAddr
|
2017-08-14 14:36:07 +00:00
|
|
|
SerfConfig *serf.Config
|
|
|
|
}
|
|
|
|
|
2013-12-06 23:43:07 +00:00
|
|
|
// Config is used to configure the server
|
|
|
|
type Config struct {
|
2013-12-25 00:48:07 +00:00
|
|
|
// Bootstrap mode is used to bring up the first Consul server.
|
|
|
|
// It is required so that it can elect a leader without any
|
|
|
|
// other nodes being present
|
|
|
|
Bootstrap bool
|
|
|
|
|
2014-06-20 00:08:48 +00:00
|
|
|
// BootstrapExpect mode is used to automatically bring up a collection of
|
2014-06-16 21:36:12 +00:00
|
|
|
// Consul servers. This can be used to automatically bring up a collection
|
|
|
|
// of nodes.
|
2014-06-20 00:08:48 +00:00
|
|
|
BootstrapExpect int
|
2014-06-16 21:36:12 +00:00
|
|
|
|
2018-10-15 16:17:48 +00:00
|
|
|
// Datacenter is the datacenter this Consul server represents.
|
2013-12-06 23:43:07 +00:00
|
|
|
Datacenter string
|
|
|
|
|
2018-10-15 16:17:48 +00:00
|
|
|
// PrimaryDatacenter is the authoritative datacenter for features like ACLs
|
|
|
|
// and Connect.
|
|
|
|
PrimaryDatacenter string
|
|
|
|
|
|
|
|
// DataDir is the directory to store our state in.
|
2013-12-06 23:43:07 +00:00
|
|
|
DataDir string
|
|
|
|
|
2020-01-17 13:20:57 +00:00
|
|
|
// DefaultQueryTime is the amount of time a blocking query will wait before
|
|
|
|
// Consul will force a response. This value can be overridden by the 'wait'
|
|
|
|
// query parameter.
|
|
|
|
DefaultQueryTime time.Duration
|
|
|
|
|
|
|
|
// MaxQueryTime is the maximum amount of time a blocking query can wait
|
|
|
|
// before Consul will force a response. Consul applies jitter to the wait
|
|
|
|
// time. The jittered time will be capped to MaxQueryTime.
|
|
|
|
MaxQueryTime time.Duration
|
|
|
|
|
2015-11-29 04:40:05 +00:00
|
|
|
// DevMode is used to enable a development server mode.
|
|
|
|
DevMode bool
|
|
|
|
|
2017-01-18 06:20:11 +00:00
|
|
|
// NodeID is a unique identifier for this node across space and time.
|
|
|
|
NodeID types.NodeID
|
|
|
|
|
2013-12-06 23:43:07 +00:00
|
|
|
// Node name is the name we use to advertise. Defaults to hostname.
|
|
|
|
NodeName string
|
|
|
|
|
|
|
|
// RaftConfig is the configuration used for Raft in the local DC
|
|
|
|
RaftConfig *raft.Config
|
|
|
|
|
2020-11-17 15:53:57 +00:00
|
|
|
// (Enterprise-only) ReadReplica is used to prevent this server from being added
|
2017-03-21 23:36:44 +00:00
|
|
|
// as a voting member of the Raft cluster.
|
2020-11-17 15:53:57 +00:00
|
|
|
ReadReplica bool
|
2017-03-21 23:36:44 +00:00
|
|
|
|
2017-06-25 19:36:03 +00:00
|
|
|
// NotifyListen is called after the RPC listener has been configured.
|
|
|
|
// RPCAdvertise will be set to the listener address if it hasn't been
|
|
|
|
// configured at this point.
|
|
|
|
NotifyListen func()
|
|
|
|
|
2013-12-07 00:35:13 +00:00
|
|
|
// RPCAddr is the RPC address used by Consul. This should be reachable
|
|
|
|
// by the WAN and LAN
|
2014-01-01 00:45:13 +00:00
|
|
|
RPCAddr *net.TCPAddr
|
2013-12-07 00:35:13 +00:00
|
|
|
|
2013-12-31 22:00:25 +00:00
|
|
|
// RPCAdvertise is the address that is advertised to other nodes for
|
|
|
|
// the RPC endpoint. This can differ from the RPC address, if for example
|
|
|
|
// the RPCAddr is unspecified "0.0.0.0:8300", but this address must be
|
2017-06-25 19:36:03 +00:00
|
|
|
// reachable. If RPCAdvertise is nil then it will be set to the Listener
|
|
|
|
// address after the listening socket is configured.
|
2013-12-31 23:44:27 +00:00
|
|
|
RPCAdvertise *net.TCPAddr
|
2013-12-31 22:00:25 +00:00
|
|
|
|
2017-05-03 10:57:11 +00:00
|
|
|
// RPCSrcAddr is the source address for outgoing RPC connections.
|
|
|
|
RPCSrcAddr *net.TCPAddr
|
|
|
|
|
2022-07-07 18:55:41 +00:00
|
|
|
// GRPCPort is the port the public gRPC server listens on.
|
|
|
|
GRPCPort int
|
|
|
|
|
2022-08-25 16:44:58 +00:00
|
|
|
// GRPCTLSPort is the port the public gRPC TLS server listens on.
|
|
|
|
GRPCTLSPort int
|
|
|
|
|
2017-08-14 14:36:07 +00:00
|
|
|
// (Enterprise-only) The network segment this agent is part of.
|
|
|
|
Segment string
|
|
|
|
|
|
|
|
// (Enterprise-only) Segments is a list of network segments for a server to
|
|
|
|
// bind on.
|
2017-09-07 23:37:11 +00:00
|
|
|
Segments []NetworkSegment
|
2017-08-14 14:36:07 +00:00
|
|
|
|
2013-12-07 01:18:09 +00:00
|
|
|
// SerfLANConfig is the configuration for the intra-dc serf
|
|
|
|
SerfLANConfig *serf.Config
|
2013-12-06 23:43:07 +00:00
|
|
|
|
2013-12-07 01:18:09 +00:00
|
|
|
// SerfWANConfig is the configuration for the cross-dc serf
|
|
|
|
SerfWANConfig *serf.Config
|
2013-12-06 23:43:07 +00:00
|
|
|
|
2017-03-15 19:26:54 +00:00
|
|
|
// SerfFloodInterval controls how often we attempt to flood local Serf
|
|
|
|
// Consul servers into the global areas (WAN and user-defined areas in
|
|
|
|
// Consul Enterprise).
|
|
|
|
SerfFloodInterval time.Duration
|
|
|
|
|
2014-01-09 23:44:25 +00:00
|
|
|
// ReconcileInterval controls how often we reconcile the strongly
|
|
|
|
// consistent store with the Serf info. This is used to handle nodes
|
|
|
|
// that are force removed, as well as intermittent unavailability during
|
|
|
|
// leader election.
|
|
|
|
ReconcileInterval time.Duration
|
|
|
|
|
2014-03-09 22:18:36 +00:00
|
|
|
// ProtocolVersion is the protocol version to speak. This must be between
|
|
|
|
// ProtocolVersionMin and ProtocolVersionMax.
|
|
|
|
ProtocolVersion uint8
|
|
|
|
|
2021-07-09 22:17:42 +00:00
|
|
|
TLSConfig tlsutil.Config
|
2014-04-04 23:22:02 +00:00
|
|
|
|
2014-05-21 19:32:24 +00:00
|
|
|
// RejoinAfterLeave controls our interaction with Serf.
|
|
|
|
// When set to false (default), a leave causes a Consul to not rejoin
|
|
|
|
// the cluster until an explicit join is received. If this is set to
|
|
|
|
// true, we ignore the leave, and rejoin the cluster on start.
|
|
|
|
RejoinAfterLeave bool
|
|
|
|
|
2020-10-08 19:02:19 +00:00
|
|
|
// AdvertiseReconnectTimeout is the duration after which this node should be
|
|
|
|
// assumed to not be returning and thus should be reaped within Serf. This
|
|
|
|
// can only be set for Client agents
|
|
|
|
AdvertiseReconnectTimeout time.Duration
|
|
|
|
|
2014-06-06 22:36:40 +00:00
|
|
|
// Build is a string that is gossiped around, and can be used to help
|
|
|
|
// operators track which versions are actively deployed
|
|
|
|
Build string
|
|
|
|
|
2021-08-06 22:39:39 +00:00
|
|
|
ACLResolverSettings ACLResolverSettings
|
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// ACLEnabled is used to enable ACLs
|
|
|
|
ACLsEnabled bool
|
|
|
|
|
2021-12-07 12:39:28 +00:00
|
|
|
// ACLInitialManagementToken is used to bootstrap the ACL system. It should be specified
|
2021-08-06 22:00:58 +00:00
|
|
|
// on the servers in the PrimaryDatacenter. When the leader comes online, it ensures
|
2021-12-07 12:39:28 +00:00
|
|
|
// that the initial management token is available. This provides the initial token.
|
|
|
|
ACLInitialManagementToken string
|
2014-08-05 22:36:08 +00:00
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// ACLTokenReplication is used to enabled token replication.
|
|
|
|
//
|
|
|
|
// By default policy-only replication is enabled. When token
|
|
|
|
// replication is off and the primary datacenter is not
|
|
|
|
// yet upgraded to the new ACLs no replication will be performed
|
|
|
|
ACLTokenReplication bool
|
2014-08-05 22:20:35 +00:00
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// ACLReplicationRate is the max number of replication rounds that can
|
|
|
|
// be run per second. Note that either 1 or 2 RPCs are used during each replication
|
|
|
|
// round
|
|
|
|
ACLReplicationRate int
|
2016-08-03 05:04:11 +00:00
|
|
|
|
2018-10-19 16:04:07 +00:00
|
|
|
// ACLReplicationBurst is how many replication RPCs can be bursted after a
|
|
|
|
// period of idleness
|
|
|
|
ACLReplicationBurst int
|
2016-08-03 05:04:11 +00:00
|
|
|
|
|
|
|
// ACLReplicationApplyLimit is the max number of replication-related
|
|
|
|
// apply operations that we allow during a one second period. This is
|
|
|
|
// used to limit the amount of Raft bandwidth used for replication.
|
|
|
|
ACLReplicationApplyLimit int
|
|
|
|
|
2017-10-02 22:10:21 +00:00
|
|
|
// ACLEnableKeyListPolicy is used to gate enforcement of the new "list" policy that
|
|
|
|
// protects listing keys by prefix. This behavior is opt-in
|
|
|
|
// by default in Consul 1.0 and later.
|
|
|
|
ACLEnableKeyListPolicy bool
|
|
|
|
|
2020-06-05 19:56:19 +00:00
|
|
|
AutoConfigEnabled bool
|
|
|
|
AutoConfigIntroToken string
|
|
|
|
AutoConfigIntroTokenFile string
|
|
|
|
AutoConfigServerAddresses []string
|
|
|
|
AutoConfigDNSSANs []string
|
|
|
|
AutoConfigIPSANs []net.IP
|
|
|
|
AutoConfigAuthzEnabled bool
|
|
|
|
AutoConfigAuthzAuthMethod structs.ACLAuthMethod
|
|
|
|
AutoConfigAuthzClaimAssertions []string
|
|
|
|
AutoConfigAuthzAllowReuse bool
|
|
|
|
|
2014-12-11 00:38:33 +00:00
|
|
|
// TombstoneTTL is used to control how long KV tombstones are retained.
|
2014-12-01 05:05:18 +00:00
|
|
|
// This provides a window of time where the X-Consul-Index is monotonic.
|
|
|
|
// Outside this window, the index may not be monotonic. This is a result
|
|
|
|
// of a few trade offs:
|
|
|
|
// 1) The index is defined by the data view and not globally. This is a
|
|
|
|
// performance optimization that prevents any write from incrementing the
|
|
|
|
// index for all data views.
|
|
|
|
// 2) Tombstones are not kept indefinitely, since otherwise storage required
|
|
|
|
// is also monotonic. This prevents deletes from reducing the disk space
|
|
|
|
// used.
|
|
|
|
// In theory, neither of these are intrinsic limitations, however for the
|
2015-09-15 12:22:08 +00:00
|
|
|
// purposes of building a practical system, they are reasonable trade offs.
|
2014-12-01 05:05:18 +00:00
|
|
|
//
|
|
|
|
// It is also possible to set this to an incredibly long time, thereby
|
|
|
|
// simulating infinite retention. This is not recommended however.
|
|
|
|
//
|
2014-12-11 00:38:33 +00:00
|
|
|
TombstoneTTL time.Duration
|
|
|
|
|
|
|
|
// TombstoneTTLGranularity is used to control how granular the timers are
|
|
|
|
// for the Tombstone GC. This is used to batch the GC of many keys together
|
|
|
|
// to reduce overhead. It is unlikely a user would ever need to tune this.
|
|
|
|
TombstoneTTLGranularity time.Duration
|
2014-12-01 05:05:18 +00:00
|
|
|
|
2015-03-27 05:30:04 +00:00
|
|
|
// Minimum Session TTL
|
|
|
|
SessionTTLMin time.Duration
|
|
|
|
|
2019-04-08 17:05:51 +00:00
|
|
|
// maxTokenExpirationDuration is the maximum difference allowed between
|
|
|
|
// ACLToken CreateTime and ExpirationTime values if ExpirationTime is set
|
|
|
|
// on a token.
|
|
|
|
ACLTokenMaxExpirationTTL time.Duration
|
|
|
|
|
|
|
|
// ACLTokenMinExpirationTTL is the minimum difference allowed between
|
|
|
|
// ACLToken CreateTime and ExpirationTime values if ExpirationTime is set
|
|
|
|
// on a token.
|
|
|
|
ACLTokenMinExpirationTTL time.Duration
|
|
|
|
|
2014-02-07 20:11:34 +00:00
|
|
|
// ServerUp callback can be used to trigger a notification that
|
|
|
|
// a Consul server is now up and known about.
|
|
|
|
ServerUp func()
|
2014-08-27 02:04:07 +00:00
|
|
|
|
|
|
|
// UserEventHandler callback can be used to handle incoming
|
|
|
|
// user events. This function should not block.
|
|
|
|
UserEventHandler func(serf.UserEvent)
|
2015-05-08 08:31:34 +00:00
|
|
|
|
2019-04-26 17:38:39 +00:00
|
|
|
// ConfigReplicationRate is the max number of replication rounds that can
|
|
|
|
// be run per second. Note that either 1 or 2 RPCs are used during each replication
|
|
|
|
// round
|
|
|
|
ConfigReplicationRate int
|
|
|
|
|
|
|
|
// ConfigReplicationBurst is how many replication rounds can be bursted after a
|
|
|
|
// period of idleness
|
|
|
|
ConfigReplicationBurst int
|
|
|
|
|
|
|
|
// ConfigReplicationApply limit is the max number of replication-related
|
|
|
|
// apply operations that we allow during a one second period. This is
|
|
|
|
// used to limit the amount of Raft bandwidth used for replication.
|
|
|
|
ConfigReplicationApplyLimit int
|
|
|
|
|
2020-03-09 20:59:02 +00:00
|
|
|
// FederationStateReplicationRate is the max number of replication rounds that can
|
|
|
|
// be run per second. Note that either 1 or 2 RPCs are used during each replication
|
|
|
|
// round
|
|
|
|
FederationStateReplicationRate int
|
|
|
|
|
|
|
|
// FederationStateReplicationBurst is how many replication rounds can be bursted after a
|
|
|
|
// period of idleness
|
|
|
|
FederationStateReplicationBurst int
|
|
|
|
|
|
|
|
// FederationStateReplicationApply limit is the max number of replication-related
|
|
|
|
// apply operations that we allow during a one second period. This is
|
|
|
|
// used to limit the amount of Raft bandwidth used for replication.
|
|
|
|
FederationStateReplicationApplyLimit int
|
|
|
|
|
2015-06-06 03:31:33 +00:00
|
|
|
// CoordinateUpdatePeriod controls how long a server batches coordinate
|
|
|
|
// updates before applying them in a Raft transaction. A larger period
|
|
|
|
// leads to fewer Raft transactions, but also the stored coordinates
|
|
|
|
// being more stale.
|
2015-05-14 01:22:34 +00:00
|
|
|
CoordinateUpdatePeriod time.Duration
|
|
|
|
|
2015-06-29 22:53:29 +00:00
|
|
|
// CoordinateUpdateBatchSize controls the maximum number of updates a
|
2015-06-06 03:31:33 +00:00
|
|
|
// server batches before applying them in a Raft transaction.
|
2015-06-29 22:53:29 +00:00
|
|
|
CoordinateUpdateBatchSize int
|
|
|
|
|
|
|
|
// CoordinateUpdateMaxBatches controls the maximum number of batches we
|
|
|
|
// are willing to apply in one period. After this limit we will issue a
|
|
|
|
// warning and discard the remaining updates.
|
|
|
|
CoordinateUpdateMaxBatches int
|
2016-07-10 17:23:43 +00:00
|
|
|
|
2019-06-26 15:43:25 +00:00
|
|
|
// CheckOutputMaxSize control the max size of output of checks
|
|
|
|
CheckOutputMaxSize int
|
|
|
|
|
2022-12-13 20:09:55 +00:00
|
|
|
// RequestLimitsMode will disable or enable rate limiting. If not disabled, it
|
|
|
|
// enforces the action that will occur when RequestLimitsReadRate
|
|
|
|
// or RequestLimitsWriteRate is exceeded. The default value of "disabled" will
|
|
|
|
// prevent any rate limiting from occuring. A value of "enforce" will block
|
|
|
|
// the request from processings by returning an error. A value of
|
|
|
|
// "permissive" will not block the request and will allow the request to
|
|
|
|
// continue processing.
|
|
|
|
RequestLimitsMode string
|
|
|
|
|
|
|
|
// RequestLimitsReadRate controls how frequently RPC, gRPC, and HTTP
|
|
|
|
// queries are allowed to happen. In any large enough time interval, rate
|
|
|
|
// limiter limits the rate to RequestLimitsReadRate tokens per second.
|
|
|
|
RequestLimitsReadRate rate.Limit
|
|
|
|
|
|
|
|
// RequestLimitsWriteRate controls how frequently RPC, gRPC, and HTTP
|
|
|
|
// writes are allowed to happen. In any large enough time interval, rate
|
|
|
|
// limiter limits the rate to RequestLimitsWriteRate tokens per second.
|
|
|
|
RequestLimitsWriteRate rate.Limit
|
|
|
|
|
2020-01-31 16:19:37 +00:00
|
|
|
// RPCHandshakeTimeout limits how long we will wait for the initial magic byte
|
|
|
|
// on an RPC client connection. It also governs how long we will wait for a
|
|
|
|
// TLS handshake when TLS is configured however the timout applies separately
|
|
|
|
// for the initial magic byte and the TLS handshake and inner magic byte.
|
|
|
|
RPCHandshakeTimeout time.Duration
|
|
|
|
|
2016-07-10 17:23:43 +00:00
|
|
|
// RPCHoldTimeout is how long an RPC can be "held" before it is errored.
|
|
|
|
// This is used to paper over a loss of leadership by instead holding RPCs,
|
|
|
|
// so that the caller experiences a slow response rather than an error.
|
|
|
|
// This period is meant to be long enough for a leader election to take
|
|
|
|
// place, and a small jitter is applied to avoid a thundering herd.
|
|
|
|
RPCHoldTimeout time.Duration
|
2017-02-17 18:49:16 +00:00
|
|
|
|
2022-10-18 19:05:09 +00:00
|
|
|
// RPCClientTimeout limits how long a client is allowed to read from an RPC
|
|
|
|
// connection. This is used to set an upper bound for non-blocking queries to
|
|
|
|
// eventually terminate so that RPC connections are not held indefinitely.
|
|
|
|
// Blocking queries will use MaxQueryTime and DefaultQueryTime to calculate
|
|
|
|
// their own timeouts.
|
|
|
|
RPCClientTimeout time.Duration
|
|
|
|
|
2020-09-16 17:29:59 +00:00
|
|
|
// RPCRateLimit and RPCMaxBurst control how frequently RPC calls are allowed
|
2017-09-01 22:02:50 +00:00
|
|
|
// to happen. In any large enough time interval, rate limiter limits the
|
2020-09-16 17:29:59 +00:00
|
|
|
// rate to RPCRateLimit tokens per second, with a maximum burst size of
|
|
|
|
// RPCMaxBurst events. As a special case, if RPCRateLimit == Inf (the infinite
|
2017-09-01 22:02:50 +00:00
|
|
|
// rate), RPCMaxBurst is ignored.
|
|
|
|
//
|
|
|
|
// See https://en.wikipedia.org/wiki/Token_bucket for more about token
|
|
|
|
// buckets.
|
2020-09-16 17:29:59 +00:00
|
|
|
RPCRateLimit rate.Limit
|
|
|
|
RPCMaxBurst int
|
2017-09-01 22:02:50 +00:00
|
|
|
|
2020-01-31 16:19:37 +00:00
|
|
|
// RPCMaxConnsPerClient is the limit of how many concurrent connections are
|
|
|
|
// allowed from a single source IP.
|
|
|
|
RPCMaxConnsPerClient int
|
|
|
|
|
2017-10-10 22:19:50 +00:00
|
|
|
// LeaveDrainTime is used to wait after a server has left the LAN Serf
|
|
|
|
// pool for RPCs to drain and new requests to be sent to other servers.
|
|
|
|
LeaveDrainTime time.Duration
|
|
|
|
|
2017-02-24 04:32:13 +00:00
|
|
|
// AutopilotConfig is used to apply the initial autopilot config when
|
|
|
|
// bootstrapping.
|
2020-09-25 17:46:38 +00:00
|
|
|
AutopilotConfig *structs.AutopilotConfig
|
2017-03-01 22:04:40 +00:00
|
|
|
|
2017-03-10 00:43:07 +00:00
|
|
|
// ServerHealthInterval is the frequency with which the health of the
|
|
|
|
// servers in the cluster will be updated.
|
2017-03-01 22:04:40 +00:00
|
|
|
ServerHealthInterval time.Duration
|
|
|
|
|
2017-03-10 00:43:07 +00:00
|
|
|
// AutopilotInterval is the frequency with which the leader will perform
|
|
|
|
// autopilot tasks, such as promoting eligible non-voters and removing
|
|
|
|
// dead servers.
|
|
|
|
AutopilotInterval time.Duration
|
2018-04-09 04:56:46 +00:00
|
|
|
|
2020-09-02 15:24:17 +00:00
|
|
|
// MetricsReportingInterval is the frequency with which the server will
|
|
|
|
// report usage metrics to the configured go-metrics Sinks.
|
|
|
|
MetricsReportingInterval time.Duration
|
|
|
|
|
2018-04-25 18:34:08 +00:00
|
|
|
// ConnectEnabled is whether to enable Connect features such as the CA.
|
|
|
|
ConnectEnabled bool
|
|
|
|
|
2020-03-09 20:59:02 +00:00
|
|
|
// ConnectMeshGatewayWANFederationEnabled determines if wan federation of
|
|
|
|
// datacenters should exclusively traverse mesh gateways.
|
|
|
|
ConnectMeshGatewayWANFederationEnabled bool
|
|
|
|
|
|
|
|
// DisableFederationStateAntiEntropy solely exists for use in unit tests to
|
|
|
|
// disable a background routine.
|
|
|
|
DisableFederationStateAntiEntropy bool
|
|
|
|
|
2020-10-06 18:24:05 +00:00
|
|
|
// OverrideInitialSerfTags solely exists for use in unit tests to ensure
|
|
|
|
// that a serf tag is initially set to a known value, rather than the
|
|
|
|
// default to test some consul upgrade scenarios with fewer races.
|
|
|
|
OverrideInitialSerfTags func(tags map[string]string)
|
|
|
|
|
2018-04-09 04:56:46 +00:00
|
|
|
// CAConfig is used to apply the initial Connect CA configuration when
|
|
|
|
// bootstrapping.
|
|
|
|
CAConfig *structs.CAConfiguration
|
2019-04-26 18:25:03 +00:00
|
|
|
|
|
|
|
// ConfigEntryBootstrap contains a list of ConfigEntries to ensure are created
|
|
|
|
// If entries of the same Kind/Name exist already these will not update them.
|
|
|
|
ConfigEntryBootstrap []structs.ConfigEntry
|
2019-06-27 20:22:07 +00:00
|
|
|
|
|
|
|
// AutoEncryptAllowTLS is whether to enable the server responding to
|
|
|
|
// AutoEncrypt.Sign requests.
|
|
|
|
AutoEncryptAllowTLS bool
|
2019-10-01 18:34:55 +00:00
|
|
|
|
2020-10-05 20:28:13 +00:00
|
|
|
RPCConfig RPCConfig
|
2020-07-22 23:57:29 +00:00
|
|
|
|
2023-02-08 16:50:22 +00:00
|
|
|
LogStoreConfig RaftLogStoreConfig
|
2021-11-17 23:15:19 +00:00
|
|
|
|
2022-07-22 22:20:21 +00:00
|
|
|
// PeeringEnabled enables cluster peering.
|
|
|
|
PeeringEnabled bool
|
|
|
|
|
2022-07-29 21:36:22 +00:00
|
|
|
PeeringTestAllowPeerRegistrations bool
|
|
|
|
|
2019-10-01 18:34:55 +00:00
|
|
|
// Embedded Consul Enterprise specific configuration
|
|
|
|
*EnterpriseConfig
|
2013-12-06 23:43:07 +00:00
|
|
|
}
|
|
|
|
|
2022-12-06 16:06:36 +00:00
|
|
|
func (c *Config) InPrimaryDatacenter() bool {
|
|
|
|
return c.PrimaryDatacenter == "" || c.Datacenter == c.PrimaryDatacenter
|
|
|
|
}
|
|
|
|
|
2017-05-03 19:02:01 +00:00
|
|
|
// CheckProtocolVersion validates the protocol version.
|
|
|
|
func (c *Config) CheckProtocolVersion() error {
|
2014-03-09 22:18:36 +00:00
|
|
|
if c.ProtocolVersion < ProtocolVersionMin {
|
2017-05-03 19:02:01 +00:00
|
|
|
return fmt.Errorf("Protocol version '%d' too low. Must be in range: [%d, %d]", c.ProtocolVersion, ProtocolVersionMin, ProtocolVersionMax)
|
|
|
|
}
|
|
|
|
if c.ProtocolVersion > ProtocolVersionMax {
|
|
|
|
return fmt.Errorf("Protocol version '%d' too high. Must be in range: [%d, %d]", c.ProtocolVersion, ProtocolVersionMin, ProtocolVersionMax)
|
2014-03-09 22:18:36 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-05-03 19:02:01 +00:00
|
|
|
// CheckACL validates the ACL configuration.
|
2021-08-06 22:39:39 +00:00
|
|
|
// TODO: move this to ACLResolverSettings
|
2014-08-05 22:20:35 +00:00
|
|
|
func (c *Config) CheckACL() error {
|
2021-08-06 22:39:39 +00:00
|
|
|
switch c.ACLResolverSettings.ACLDefaultPolicy {
|
2014-08-05 22:20:35 +00:00
|
|
|
case "allow":
|
|
|
|
case "deny":
|
|
|
|
default:
|
2021-08-06 22:39:39 +00:00
|
|
|
return fmt.Errorf("Unsupported default ACL policy: %s", c.ACLResolverSettings.ACLDefaultPolicy)
|
2014-08-05 22:20:35 +00:00
|
|
|
}
|
2021-08-06 22:39:39 +00:00
|
|
|
switch c.ACLResolverSettings.ACLDownPolicy {
|
2014-08-05 22:20:35 +00:00
|
|
|
case "allow":
|
|
|
|
case "deny":
|
2018-07-02 15:39:34 +00:00
|
|
|
case "async-cache", "extend-cache":
|
2014-08-05 22:20:35 +00:00
|
|
|
default:
|
2021-08-06 22:39:39 +00:00
|
|
|
return fmt.Errorf("Unsupported down ACL policy: %s", c.ACLResolverSettings.ACLDownPolicy)
|
2014-08-05 22:20:35 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-04-16 22:07:52 +00:00
|
|
|
// DefaultConfig returns a default configuration.
|
2013-12-06 23:43:07 +00:00
|
|
|
func DefaultConfig() *Config {
|
|
|
|
hostname, err := os.Hostname()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
conf := &Config{
|
2021-08-06 22:39:39 +00:00
|
|
|
Build: version.Version,
|
|
|
|
Datacenter: DefaultDC,
|
|
|
|
NodeName: hostname,
|
|
|
|
RPCAddr: DefaultRPCAddr,
|
|
|
|
RaftConfig: raft.DefaultConfig(),
|
|
|
|
SerfLANConfig: libserf.DefaultConfig(),
|
|
|
|
SerfWANConfig: libserf.DefaultConfig(),
|
|
|
|
SerfFloodInterval: 60 * time.Second,
|
|
|
|
ReconcileInterval: 60 * time.Second,
|
|
|
|
ProtocolVersion: ProtocolVersion2Compatible,
|
|
|
|
ACLResolverSettings: ACLResolverSettings{
|
|
|
|
ACLsEnabled: false,
|
|
|
|
Datacenter: DefaultDC,
|
|
|
|
NodeName: hostname,
|
|
|
|
ACLPolicyTTL: 30 * time.Second,
|
|
|
|
ACLTokenTTL: 30 * time.Second,
|
|
|
|
ACLRoleTTL: 30 * time.Second,
|
|
|
|
ACLDownPolicy: "extend-cache",
|
|
|
|
ACLDefaultPolicy: "allow",
|
|
|
|
},
|
2020-03-09 20:59:02 +00:00
|
|
|
ACLReplicationRate: 1,
|
|
|
|
ACLReplicationBurst: 5,
|
|
|
|
ACLReplicationApplyLimit: 100, // ops / sec
|
|
|
|
ConfigReplicationRate: 1,
|
|
|
|
ConfigReplicationBurst: 5,
|
|
|
|
ConfigReplicationApplyLimit: 100, // ops / sec
|
|
|
|
FederationStateReplicationRate: 1,
|
|
|
|
FederationStateReplicationBurst: 5,
|
|
|
|
FederationStateReplicationApplyLimit: 100, // ops / sec
|
|
|
|
TombstoneTTL: 15 * time.Minute,
|
|
|
|
TombstoneTTLGranularity: 30 * time.Second,
|
|
|
|
SessionTTLMin: 10 * time.Second,
|
|
|
|
ACLTokenMinExpirationTTL: 1 * time.Minute,
|
|
|
|
ACLTokenMaxExpirationTTL: 24 * time.Hour,
|
2015-06-23 02:14:02 +00:00
|
|
|
|
2015-06-30 19:02:05 +00:00
|
|
|
// These are tuned to provide a total throughput of 128 updates
|
|
|
|
// per second. If you update these, you should update the client-
|
|
|
|
// side SyncCoordinateRateTarget parameter accordingly.
|
2015-06-30 21:25:40 +00:00
|
|
|
CoordinateUpdatePeriod: 5 * time.Second,
|
|
|
|
CoordinateUpdateBatchSize: 128,
|
|
|
|
CoordinateUpdateMaxBatches: 5,
|
2016-07-10 17:23:43 +00:00
|
|
|
|
2019-06-26 15:43:25 +00:00
|
|
|
CheckOutputMaxSize: checks.DefaultBufSize,
|
|
|
|
|
2022-12-13 20:09:55 +00:00
|
|
|
RequestLimitsMode: "disabled",
|
|
|
|
RequestLimitsReadRate: rate.Inf, // ops / sec
|
|
|
|
RequestLimitsWriteRate: rate.Inf, // ops / sec
|
|
|
|
|
2020-09-16 17:29:59 +00:00
|
|
|
RPCRateLimit: rate.Inf,
|
|
|
|
RPCMaxBurst: 1000,
|
2017-09-01 22:02:50 +00:00
|
|
|
|
2017-12-18 20:26:35 +00:00
|
|
|
// TODO (slackpad) - Until #3744 is done, we need to keep these
|
2017-12-13 18:52:06 +00:00
|
|
|
// in sync with agent/config/default.go.
|
2020-09-25 17:46:38 +00:00
|
|
|
AutopilotConfig: &structs.AutopilotConfig{
|
2017-03-01 22:04:40 +00:00
|
|
|
CleanupDeadServers: true,
|
|
|
|
LastContactThreshold: 200 * time.Millisecond,
|
|
|
|
MaxTrailingLogs: 250,
|
|
|
|
ServerStabilizationTime: 10 * time.Second,
|
2017-02-24 04:32:13 +00:00
|
|
|
},
|
2017-12-13 18:52:06 +00:00
|
|
|
|
2018-05-12 08:48:16 +00:00
|
|
|
CAConfig: &structs.CAConfiguration{
|
|
|
|
Provider: "consul",
|
|
|
|
Config: map[string]interface{}{
|
2020-07-23 20:05:28 +00:00
|
|
|
"LeafCertTTL": structs.DefaultLeafCertTTL,
|
|
|
|
"IntermediateCertTTL": structs.DefaultIntermediateCertTTL,
|
2021-11-02 18:02:10 +00:00
|
|
|
"RootCertTTL": structs.DefaultRootCertTTL,
|
2018-05-12 08:48:16 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2020-09-02 15:24:23 +00:00
|
|
|
// Stay under the 10 second aggregation interval of
|
|
|
|
// go-metrics. This ensures we always report the
|
|
|
|
// usage metrics in each cycle.
|
|
|
|
MetricsReportingInterval: 9 * time.Second,
|
2020-09-02 15:24:17 +00:00
|
|
|
ServerHealthInterval: 2 * time.Second,
|
|
|
|
AutopilotInterval: 10 * time.Second,
|
|
|
|
DefaultQueryTime: 300 * time.Second,
|
|
|
|
MaxQueryTime: 600 * time.Second,
|
|
|
|
|
2022-07-29 21:36:22 +00:00
|
|
|
PeeringTestAllowPeerRegistrations: false,
|
2022-07-22 22:20:21 +00:00
|
|
|
|
2020-09-02 15:24:17 +00:00
|
|
|
EnterpriseConfig: DefaultEnterpriseConfig(),
|
2013-12-06 23:43:07 +00:00
|
|
|
}
|
|
|
|
|
2014-03-20 19:39:06 +00:00
|
|
|
// Increase our reap interval to 3 days instead of 24h.
|
|
|
|
conf.SerfLANConfig.ReconnectTimeout = 3 * 24 * time.Hour
|
|
|
|
conf.SerfWANConfig.ReconnectTimeout = 3 * 24 * time.Hour
|
|
|
|
|
2013-12-07 01:18:09 +00:00
|
|
|
// WAN Serf should use the WAN timing, since we are using it
|
2013-12-06 23:43:07 +00:00
|
|
|
// to communicate between DC's
|
2013-12-07 01:18:09 +00:00
|
|
|
conf.SerfWANConfig.MemberlistConfig = memberlist.DefaultWANConfig()
|
2013-12-06 23:43:07 +00:00
|
|
|
|
|
|
|
// Ensure we don't have port conflicts
|
2013-12-27 20:51:15 +00:00
|
|
|
conf.SerfLANConfig.MemberlistConfig.BindPort = DefaultLANSerfPort
|
|
|
|
conf.SerfWANConfig.MemberlistConfig.BindPort = DefaultWANSerfPort
|
2013-12-06 23:43:07 +00:00
|
|
|
|
2019-05-15 18:59:33 +00:00
|
|
|
// Allow dead nodes to be replaced after 30 seconds.
|
|
|
|
conf.SerfLANConfig.MemberlistConfig.DeadNodeReclaimTime = 30 * time.Second
|
|
|
|
conf.SerfWANConfig.MemberlistConfig.DeadNodeReclaimTime = 30 * time.Second
|
|
|
|
|
2017-09-25 22:27:04 +00:00
|
|
|
// Raft protocol version 3 only works with other Consul servers running
|
|
|
|
// 0.8.0 or later.
|
|
|
|
conf.RaftConfig.ProtocolVersion = 3
|
2016-07-28 19:11:28 +00:00
|
|
|
|
2013-12-25 00:48:07 +00:00
|
|
|
// Disable shutdown on removal
|
|
|
|
conf.RaftConfig.ShutdownOnRemove = false
|
|
|
|
|
2018-05-10 22:06:47 +00:00
|
|
|
// Check every 5 seconds to see if there are enough new entries for a snapshot, can be overridden
|
2018-05-11 15:11:15 +00:00
|
|
|
conf.RaftConfig.SnapshotInterval = 30 * time.Second
|
2016-12-12 18:04:52 +00:00
|
|
|
|
2018-05-11 15:11:15 +00:00
|
|
|
// Snapshots are created every 16384 entries by default, can be overridden
|
|
|
|
conf.RaftConfig.SnapshotThreshold = 16384
|
2018-05-10 15:16:38 +00:00
|
|
|
|
2013-12-06 23:43:07 +00:00
|
|
|
return conf
|
|
|
|
}
|
2020-10-05 20:28:13 +00:00
|
|
|
|
2021-10-28 21:11:26 +00:00
|
|
|
// CloneSerfLANConfig clones an existing serf.Config used on the LAN by
|
|
|
|
// reconstructing it from defaults and re-applying changes made in the agent
|
|
|
|
// configs.
|
|
|
|
//
|
|
|
|
// This function is tricky to keep from rotting so we enforce that it MUST work
|
|
|
|
// by cloning our own serf LAN configuration on startup and only using the
|
|
|
|
// cloned one so any configs we need to change have to be changed here for them
|
|
|
|
// to work at all.
|
|
|
|
func CloneSerfLANConfig(base *serf.Config) *serf.Config {
|
|
|
|
cfg := DefaultConfig().SerfLANConfig
|
|
|
|
|
|
|
|
// from consul.DefaultConfig()
|
|
|
|
cfg.ReconnectTimeout = base.ReconnectTimeout
|
|
|
|
cfg.MemberlistConfig.BindPort = base.MemberlistConfig.BindPort
|
|
|
|
cfg.MemberlistConfig.DeadNodeReclaimTime = base.MemberlistConfig.DeadNodeReclaimTime
|
|
|
|
|
|
|
|
// from agent.newConsulConfig()
|
|
|
|
cfg.MemberlistConfig.BindAddr = base.MemberlistConfig.BindAddr
|
|
|
|
cfg.MemberlistConfig.BindPort = base.MemberlistConfig.BindPort
|
|
|
|
cfg.MemberlistConfig.CIDRsAllowed = base.MemberlistConfig.CIDRsAllowed
|
|
|
|
cfg.MemberlistConfig.AdvertiseAddr = base.MemberlistConfig.AdvertiseAddr
|
|
|
|
cfg.MemberlistConfig.AdvertisePort = base.MemberlistConfig.AdvertisePort
|
|
|
|
cfg.MemberlistConfig.GossipVerifyIncoming = base.MemberlistConfig.GossipVerifyIncoming
|
|
|
|
cfg.MemberlistConfig.GossipVerifyOutgoing = base.MemberlistConfig.GossipVerifyOutgoing
|
|
|
|
cfg.MemberlistConfig.GossipInterval = base.MemberlistConfig.GossipInterval
|
|
|
|
cfg.MemberlistConfig.GossipNodes = base.MemberlistConfig.GossipNodes
|
|
|
|
cfg.MemberlistConfig.ProbeInterval = base.MemberlistConfig.ProbeInterval
|
|
|
|
cfg.MemberlistConfig.ProbeTimeout = base.MemberlistConfig.ProbeTimeout
|
|
|
|
cfg.MemberlistConfig.SuspicionMult = base.MemberlistConfig.SuspicionMult
|
|
|
|
cfg.MemberlistConfig.RetransmitMult = base.MemberlistConfig.RetransmitMult
|
2022-08-12 02:09:56 +00:00
|
|
|
cfg.MemberlistConfig.MetricLabels = base.MemberlistConfig.MetricLabels
|
2021-10-28 21:11:26 +00:00
|
|
|
|
|
|
|
// agent/keyring.go
|
|
|
|
cfg.MemberlistConfig.Keyring = base.MemberlistConfig.Keyring
|
|
|
|
|
|
|
|
// tests
|
|
|
|
cfg.KeyringFile = base.KeyringFile
|
|
|
|
cfg.ReapInterval = base.ReapInterval
|
|
|
|
cfg.TombstoneTimeout = base.TombstoneTimeout
|
|
|
|
cfg.MemberlistConfig.SecretKey = base.MemberlistConfig.SecretKey
|
2022-08-12 02:09:56 +00:00
|
|
|
cfg.MetricLabels = base.MetricLabels
|
2021-10-28 21:11:26 +00:00
|
|
|
|
|
|
|
return cfg
|
|
|
|
}
|
|
|
|
|
2020-10-05 20:28:13 +00:00
|
|
|
// RPCConfig settings for the RPC server
|
|
|
|
//
|
|
|
|
// TODO: move many settings to this struct.
|
|
|
|
type RPCConfig struct {
|
|
|
|
EnableStreaming bool
|
|
|
|
}
|
2020-09-16 17:28:03 +00:00
|
|
|
|
2022-12-13 20:09:55 +00:00
|
|
|
// RequestLimits is configuration for serverrate limiting that is a part of
|
|
|
|
// ReloadableConfig.
|
|
|
|
type RequestLimits struct {
|
|
|
|
Mode consulrate.Mode
|
|
|
|
ReadRate rate.Limit
|
|
|
|
WriteRate rate.Limit
|
|
|
|
}
|
|
|
|
|
2020-09-16 17:28:03 +00:00
|
|
|
// ReloadableConfig is the configuration that is passed to ReloadConfig when
|
|
|
|
// application config is reloaded.
|
|
|
|
type ReloadableConfig struct {
|
2022-12-13 20:09:55 +00:00
|
|
|
RequestLimits *RequestLimits
|
2022-10-18 19:05:09 +00:00
|
|
|
RPCClientTimeout time.Duration
|
2021-05-04 14:36:53 +00:00
|
|
|
RPCRateLimit rate.Limit
|
|
|
|
RPCMaxBurst int
|
|
|
|
RPCMaxConnsPerClient int
|
|
|
|
ConfigEntryBootstrap []structs.ConfigEntry
|
|
|
|
RaftSnapshotThreshold int
|
|
|
|
RaftSnapshotInterval time.Duration
|
|
|
|
RaftTrailingLogs int
|
2022-04-25 14:19:26 +00:00
|
|
|
HeartbeatTimeout time.Duration
|
|
|
|
ElectionTimeout time.Duration
|
2020-09-16 17:28:03 +00:00
|
|
|
}
|
2021-11-17 23:15:19 +00:00
|
|
|
|
2023-02-08 16:50:22 +00:00
|
|
|
type RaftLogStoreConfig struct {
|
|
|
|
Backend string
|
|
|
|
DisableLogCache bool
|
|
|
|
Verification RaftLogStoreVerificationConfig
|
|
|
|
BoltDB RaftBoltDBConfig
|
|
|
|
WAL WALConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
type RaftLogStoreVerificationConfig struct {
|
|
|
|
Enabled bool
|
|
|
|
Interval time.Duration
|
|
|
|
}
|
|
|
|
|
2021-11-17 23:15:19 +00:00
|
|
|
type RaftBoltDBConfig struct {
|
|
|
|
NoFreelistSync bool
|
|
|
|
}
|
2023-02-08 16:50:22 +00:00
|
|
|
|
|
|
|
type WALConfig struct {
|
|
|
|
SegmentSize int
|
|
|
|
}
|