2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2017-09-25 18:40:42 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
2022-06-02 02:37:47 +00:00
|
|
|
"time"
|
2017-09-25 18:40:42 +00:00
|
|
|
|
2020-11-20 23:14:17 +00:00
|
|
|
"github.com/hashicorp/raft"
|
|
|
|
|
2019-06-26 15:43:25 +00:00
|
|
|
"github.com/hashicorp/consul/agent/checks"
|
2017-09-25 18:40:42 +00:00
|
|
|
"github.com/hashicorp/consul/agent/consul"
|
|
|
|
"github.com/hashicorp/consul/version"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DefaultSource is the default agent configuration.
|
|
|
|
// This needs to be merged first in the head.
|
2020-08-10 17:03:33 +00:00
|
|
|
// TODO: return a LiteralSource (no decoding) instead of a FileSource
|
2017-09-25 18:40:42 +00:00
|
|
|
func DefaultSource() Source {
|
2018-07-26 15:39:49 +00:00
|
|
|
cfg := consul.DefaultConfig()
|
|
|
|
serfLAN := cfg.SerfLANConfig.MemberlistConfig
|
|
|
|
serfWAN := cfg.SerfWANConfig.MemberlistConfig
|
|
|
|
|
2020-08-10 16:46:28 +00:00
|
|
|
return FileSource{
|
2017-09-25 18:40:42 +00:00
|
|
|
Name: "default",
|
|
|
|
Format: "hcl",
|
|
|
|
Data: `
|
2018-10-19 16:04:07 +00:00
|
|
|
acl = {
|
2021-09-22 17:38:40 +00:00
|
|
|
token_ttl = "30s"
|
2018-10-19 16:04:07 +00:00
|
|
|
policy_ttl = "30s"
|
2021-09-03 22:00:28 +00:00
|
|
|
default_policy = "allow"
|
|
|
|
down_policy = "extend-cache"
|
2018-10-19 16:04:07 +00:00
|
|
|
}
|
2017-09-25 18:40:42 +00:00
|
|
|
bind_addr = "0.0.0.0"
|
|
|
|
bootstrap = false
|
|
|
|
bootstrap_expect = 0
|
2019-06-26 15:43:25 +00:00
|
|
|
check_output_max_size = ` + strconv.Itoa(checks.DefaultBufSize) + `
|
2017-09-25 18:40:42 +00:00
|
|
|
check_update_interval = "5m"
|
|
|
|
client_addr = "127.0.0.1"
|
|
|
|
datacenter = "` + consul.DefaultDC + `"
|
2020-01-17 13:20:57 +00:00
|
|
|
default_query_time = "300s"
|
2017-09-25 18:40:42 +00:00
|
|
|
disable_coordinates = false
|
|
|
|
disable_host_node_id = true
|
|
|
|
disable_remote_exec = true
|
|
|
|
domain = "consul."
|
2020-10-01 14:19:14 +00:00
|
|
|
enable_central_service_config = true
|
2017-09-25 18:40:42 +00:00
|
|
|
encrypt_verify_incoming = true
|
|
|
|
encrypt_verify_outgoing = true
|
|
|
|
log_level = "INFO"
|
2020-01-17 13:20:57 +00:00
|
|
|
max_query_time = "600s"
|
2020-03-09 20:59:02 +00:00
|
|
|
primary_gateways_interval = "30s"
|
2020-05-29 21:16:03 +00:00
|
|
|
protocol = ` + strconv.Itoa(consul.DefaultRPCProtocol) + `
|
2017-09-25 18:40:42 +00:00
|
|
|
retry_interval = "30s"
|
|
|
|
retry_interval_wan = "30s"
|
2021-12-09 23:36:11 +00:00
|
|
|
|
|
|
|
# segment_limit is the maximum number of network segments that may be declared. Default 64 is highly encouraged
|
|
|
|
segment_limit = 64
|
|
|
|
|
2017-09-25 18:40:42 +00:00
|
|
|
server = false
|
2023-05-15 11:05:47 +00:00
|
|
|
server_rejoin_age_max = "168h"
|
2017-09-25 18:40:42 +00:00
|
|
|
syslog_facility = "LOCAL0"
|
2022-03-18 10:46:58 +00:00
|
|
|
|
|
|
|
tls = {
|
|
|
|
defaults = {
|
2022-03-24 19:32:25 +00:00
|
|
|
tls_min_version = "TLSv1_2"
|
2022-03-18 10:46:58 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-25 18:40:42 +00:00
|
|
|
|
2017-12-13 18:52:06 +00:00
|
|
|
// TODO (slackpad) - Until #3744 is done, we need to keep these
|
|
|
|
// in sync with agent/consul/config.go.
|
2017-12-13 18:31:45 +00:00
|
|
|
autopilot = {
|
|
|
|
cleanup_dead_servers = true
|
|
|
|
last_contact_threshold = "200ms"
|
|
|
|
max_trailing_logs = 250
|
|
|
|
server_stabilization_time = "10s"
|
|
|
|
}
|
2018-07-26 15:39:49 +00:00
|
|
|
gossip_lan = {
|
|
|
|
gossip_interval = "` + serfLAN.GossipInterval.String() + `"
|
|
|
|
gossip_nodes = ` + strconv.Itoa(serfLAN.GossipNodes) + `
|
|
|
|
retransmit_mult = ` + strconv.Itoa(serfLAN.RetransmitMult) + `
|
|
|
|
probe_interval = "` + serfLAN.ProbeInterval.String() + `"
|
|
|
|
probe_timeout = "` + serfLAN.ProbeTimeout.String() + `"
|
|
|
|
suspicion_mult = ` + strconv.Itoa(serfLAN.SuspicionMult) + `
|
|
|
|
}
|
|
|
|
gossip_wan = {
|
|
|
|
gossip_interval = "` + serfWAN.GossipInterval.String() + `"
|
|
|
|
gossip_nodes = ` + strconv.Itoa(serfLAN.GossipNodes) + `
|
|
|
|
retransmit_mult = ` + strconv.Itoa(serfLAN.RetransmitMult) + `
|
|
|
|
probe_interval = "` + serfWAN.ProbeInterval.String() + `"
|
|
|
|
probe_timeout = "` + serfWAN.ProbeTimeout.String() + `"
|
|
|
|
suspicion_mult = ` + strconv.Itoa(serfWAN.SuspicionMult) + `
|
|
|
|
}
|
2017-09-25 18:40:42 +00:00
|
|
|
dns_config = {
|
|
|
|
allow_stale = true
|
2018-03-06 01:07:42 +00:00
|
|
|
a_record_limit = 0
|
2017-09-25 18:40:42 +00:00
|
|
|
udp_answer_limit = 3
|
|
|
|
max_stale = "87600h"
|
|
|
|
recursor_timeout = "2s"
|
|
|
|
}
|
|
|
|
limits = {
|
2020-02-13 15:27:33 +00:00
|
|
|
http_max_conns_per_client = 200
|
2020-01-31 16:19:37 +00:00
|
|
|
https_handshake_timeout = "5s"
|
2022-12-13 20:09:55 +00:00
|
|
|
request_limits = {
|
|
|
|
mode = "disabled"
|
|
|
|
read_rate = -1
|
|
|
|
write_rate = -1
|
|
|
|
}
|
2020-01-31 16:19:37 +00:00
|
|
|
rpc_handshake_timeout = "5s"
|
2022-10-18 19:05:09 +00:00
|
|
|
rpc_client_timeout = "60s"
|
2017-09-25 18:40:42 +00:00
|
|
|
rpc_rate = -1
|
|
|
|
rpc_max_burst = 1000
|
2020-01-31 16:19:37 +00:00
|
|
|
rpc_max_conns_per_client = 100
|
2019-07-24 21:06:39 +00:00
|
|
|
kv_max_value_size = ` + strconv.FormatInt(raft.SuggestedMaxDataSize, 10) + `
|
2020-03-05 21:42:37 +00:00
|
|
|
txn_max_req_len = ` + strconv.FormatInt(raft.SuggestedMaxDataSize, 10) + `
|
2017-09-25 18:40:42 +00:00
|
|
|
}
|
|
|
|
performance = {
|
2017-10-10 22:19:50 +00:00
|
|
|
leave_drain_time = "5s"
|
2017-09-25 18:40:42 +00:00
|
|
|
raft_multiplier = ` + strconv.Itoa(int(consul.DefaultRaftMultiplier)) + `
|
2017-10-10 22:19:50 +00:00
|
|
|
rpc_hold_timeout = "7s"
|
2017-09-25 18:40:42 +00:00
|
|
|
}
|
|
|
|
ports = {
|
|
|
|
dns = 8600
|
|
|
|
http = 8500
|
|
|
|
https = -1
|
2018-10-03 13:05:28 +00:00
|
|
|
grpc = -1
|
2017-09-25 18:40:42 +00:00
|
|
|
serf_lan = ` + strconv.Itoa(consul.DefaultLANSerfPort) + `
|
|
|
|
serf_wan = ` + strconv.Itoa(consul.DefaultWANSerfPort) + `
|
|
|
|
server = ` + strconv.Itoa(consul.DefaultRPCPort) + `
|
2018-06-06 20:35:44 +00:00
|
|
|
proxy_min_port = 20000
|
|
|
|
proxy_max_port = 20255
|
2018-09-27 13:33:12 +00:00
|
|
|
sidecar_min_port = 21000
|
|
|
|
sidecar_max_port = 21255
|
2019-09-26 02:55:52 +00:00
|
|
|
expose_min_port = 21500
|
|
|
|
expose_max_port = 21755
|
2017-09-25 18:40:42 +00:00
|
|
|
}
|
2020-09-25 17:46:38 +00:00
|
|
|
raft_protocol = 3
|
2017-09-25 18:40:42 +00:00
|
|
|
telemetry = {
|
2017-09-27 00:49:55 +00:00
|
|
|
metrics_prefix = "consul"
|
2017-09-25 18:40:42 +00:00
|
|
|
filter_default = true
|
2020-10-02 21:16:02 +00:00
|
|
|
prefix_filter = []
|
2022-05-19 20:03:46 +00:00
|
|
|
retry_failed_connection = true
|
2017-09-25 18:40:42 +00:00
|
|
|
}
|
2020-10-03 23:27:03 +00:00
|
|
|
raft_snapshot_threshold = ` + strconv.Itoa(int(cfg.RaftConfig.SnapshotThreshold)) + `
|
|
|
|
raft_snapshot_interval = "` + cfg.RaftConfig.SnapshotInterval.String() + `"
|
|
|
|
raft_trailing_logs = ` + strconv.Itoa(int(cfg.RaftConfig.TrailingLogs)) + `
|
2023-02-08 16:50:22 +00:00
|
|
|
raft_logstore {
|
|
|
|
backend = "boltdb"
|
|
|
|
wal {
|
|
|
|
segment_size_mb = 64
|
|
|
|
}
|
|
|
|
}
|
2022-10-14 14:52:00 +00:00
|
|
|
xds {
|
|
|
|
update_max_per_second = 250
|
|
|
|
}
|
2022-11-09 17:29:55 +00:00
|
|
|
|
|
|
|
connect = {
|
|
|
|
enabled = true
|
|
|
|
}
|
|
|
|
|
|
|
|
peering = {
|
|
|
|
enabled = true
|
|
|
|
}
|
2017-09-25 18:40:42 +00:00
|
|
|
`,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DevSource is the additional default configuration for dev mode.
|
|
|
|
// This should be merged in the head after the default configuration.
|
2020-08-10 17:03:33 +00:00
|
|
|
// TODO: return a LiteralSource (no decoding) instead of a FileSource
|
2017-09-25 18:40:42 +00:00
|
|
|
func DevSource() Source {
|
2020-08-10 16:46:28 +00:00
|
|
|
return FileSource{
|
2017-09-25 18:40:42 +00:00
|
|
|
Name: "dev",
|
|
|
|
Format: "hcl",
|
|
|
|
Data: `
|
|
|
|
bind_addr = "127.0.0.1"
|
|
|
|
disable_anonymous_signature = true
|
|
|
|
disable_keyring_file = true
|
|
|
|
enable_debug = true
|
2020-09-10 16:25:56 +00:00
|
|
|
ui_config {
|
|
|
|
enabled = true
|
|
|
|
}
|
2017-09-25 18:40:42 +00:00
|
|
|
log_level = "DEBUG"
|
|
|
|
server = true
|
2018-05-04 20:33:05 +00:00
|
|
|
|
2018-07-26 15:39:49 +00:00
|
|
|
gossip_lan = {
|
|
|
|
gossip_interval = "100ms"
|
|
|
|
probe_interval = "100ms"
|
|
|
|
probe_timeout = "100ms"
|
|
|
|
suspicion_mult = 3
|
|
|
|
}
|
|
|
|
gossip_wan = {
|
|
|
|
gossip_interval = "100ms"
|
|
|
|
probe_interval = "100ms"
|
|
|
|
probe_timeout = "100ms"
|
|
|
|
suspicion_mult = 3
|
|
|
|
}
|
2018-05-04 20:33:05 +00:00
|
|
|
connect = {
|
|
|
|
enabled = true
|
|
|
|
}
|
2022-11-09 17:29:55 +00:00
|
|
|
|
|
|
|
peering = {
|
|
|
|
enabled = true
|
|
|
|
}
|
|
|
|
|
2017-09-25 18:40:42 +00:00
|
|
|
performance = {
|
|
|
|
raft_multiplier = 1
|
|
|
|
}
|
2018-10-03 13:05:28 +00:00
|
|
|
ports = {
|
|
|
|
grpc = 8502
|
|
|
|
}
|
2023-06-12 18:34:15 +00:00
|
|
|
experiments = [
|
|
|
|
"resource-apis"
|
|
|
|
]
|
2017-09-25 18:40:42 +00:00
|
|
|
`,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NonUserSource contains the values the user cannot configure.
|
|
|
|
// This needs to be merged in the tail.
|
2020-08-10 17:03:33 +00:00
|
|
|
// TODO: return a LiteralSource (no decoding) instead of a FileSource
|
2017-09-25 18:40:42 +00:00
|
|
|
func NonUserSource() Source {
|
2020-08-10 16:46:28 +00:00
|
|
|
return FileSource{
|
2017-09-25 18:40:42 +00:00
|
|
|
Name: "non-user",
|
|
|
|
Format: "hcl",
|
|
|
|
Data: `
|
|
|
|
check_deregister_interval_min = "1m"
|
|
|
|
check_reap_interval = "30s"
|
|
|
|
ae_interval = "1m"
|
|
|
|
sync_coordinate_rate_target = 64
|
|
|
|
sync_coordinate_interval_min = "15s"
|
|
|
|
|
|
|
|
# SegmentNameLimit is the maximum segment name length.
|
|
|
|
segment_name_limit = 64
|
2022-06-02 02:37:47 +00:00
|
|
|
|
|
|
|
connect = {
|
2020-06-10 20:47:35 +00:00
|
|
|
# 0s causes the value to be ignored and operate without capping
|
|
|
|
# the max time before leaf certs can be generated after a roots change.
|
|
|
|
test_ca_leaf_root_change_spread = "0s"
|
|
|
|
}
|
2022-07-29 21:36:22 +00:00
|
|
|
|
|
|
|
peering = {
|
|
|
|
# We use peer registration for various testing
|
|
|
|
test_allow_peer_registrations = false
|
|
|
|
}
|
2017-09-25 18:40:42 +00:00
|
|
|
`,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-20 23:14:17 +00:00
|
|
|
// versionSource creates a config source for the version parameters.
|
2017-09-25 18:40:42 +00:00
|
|
|
// This should be merged in the tail since these values are not
|
|
|
|
// user configurable.
|
2022-06-02 02:37:47 +00:00
|
|
|
func versionSource(rev, ver, verPre, meta string, buildDate time.Time) Source {
|
2020-11-20 23:14:17 +00:00
|
|
|
return LiteralSource{
|
|
|
|
Name: "version",
|
|
|
|
Config: Config{
|
|
|
|
Revision: &rev,
|
|
|
|
Version: &ver,
|
|
|
|
VersionPrerelease: &verPre,
|
2022-05-05 02:16:18 +00:00
|
|
|
VersionMetadata: &meta,
|
2022-06-02 02:37:47 +00:00
|
|
|
BuildDate: &buildDate,
|
2020-11-20 23:14:17 +00:00
|
|
|
},
|
2017-09-25 18:40:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-20 23:14:17 +00:00
|
|
|
// defaultVersionSource returns the version config source for the embedded
|
2017-09-25 18:40:42 +00:00
|
|
|
// version numbers.
|
2020-11-20 23:14:17 +00:00
|
|
|
func defaultVersionSource() Source {
|
2022-06-02 02:37:47 +00:00
|
|
|
buildDate, _ := time.Parse(time.RFC3339, version.BuildDate) // This has been checked elsewhere
|
|
|
|
return versionSource(version.GitCommit, version.Version, version.VersionPrerelease, version.VersionMetadata, buildDate)
|
2017-09-25 18:40:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultConsulSource returns the default configuration for the consul agent.
|
|
|
|
// This should be merged in the tail since these values are not user configurable.
|
2020-08-10 17:03:33 +00:00
|
|
|
// TODO: return a LiteralSource (no decoding) instead of a FileSource
|
2017-09-25 18:40:42 +00:00
|
|
|
func DefaultConsulSource() Source {
|
|
|
|
cfg := consul.DefaultConfig()
|
|
|
|
raft := cfg.RaftConfig
|
2020-08-10 16:46:28 +00:00
|
|
|
return FileSource{
|
2017-09-25 18:40:42 +00:00
|
|
|
Name: "consul",
|
|
|
|
Format: "hcl",
|
|
|
|
Data: `
|
|
|
|
consul = {
|
|
|
|
coordinate = {
|
|
|
|
update_batch_size = ` + strconv.Itoa(cfg.CoordinateUpdateBatchSize) + `
|
|
|
|
update_max_batches = ` + strconv.Itoa(cfg.CoordinateUpdateMaxBatches) + `
|
|
|
|
update_period = "` + cfg.CoordinateUpdatePeriod.String() + `"
|
|
|
|
}
|
|
|
|
raft = {
|
|
|
|
election_timeout = "` + raft.ElectionTimeout.String() + `"
|
|
|
|
heartbeat_timeout = "` + raft.HeartbeatTimeout.String() + `"
|
|
|
|
leader_lease_timeout = "` + raft.LeaderLeaseTimeout.String() + `"
|
|
|
|
}
|
|
|
|
server = {
|
|
|
|
health_interval = "` + cfg.ServerHealthInterval.String() + `"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DevConsulSource returns the consul agent configuration for the dev mode.
|
|
|
|
// This should be merged in the tail after the DefaultConsulSource.
|
|
|
|
func DevConsulSource() Source {
|
2020-11-20 23:14:17 +00:00
|
|
|
c := Config{}
|
|
|
|
c.Consul.Coordinate.UpdatePeriod = strPtr("100ms")
|
|
|
|
c.Consul.Raft.ElectionTimeout = strPtr("52ms")
|
|
|
|
c.Consul.Raft.HeartbeatTimeout = strPtr("35ms")
|
|
|
|
c.Consul.Raft.LeaderLeaseTimeout = strPtr("20ms")
|
|
|
|
c.Consul.Server.HealthInterval = strPtr("10ms")
|
|
|
|
return LiteralSource{Name: "consul-dev", Config: c}
|
|
|
|
}
|
|
|
|
|
|
|
|
func strPtr(v string) *string {
|
|
|
|
return &v
|
2017-09-25 18:40:42 +00:00
|
|
|
}
|