Skip to content

Commit

Permalink
auto_config implies connect (#8433)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanshasselberg authored and hashicorp-ci committed Aug 7, 2020
1 parent 56fb793 commit ba495cd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 25 deletions.
55 changes: 32 additions & 23 deletions agent/config/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,40 @@ func (b *Builder) Build() (rt RuntimeConfig, err error) {
consulRaftHeartbeatTimeout := b.durationVal("consul.raft.heartbeat_timeout", c.Consul.Raft.HeartbeatTimeout) * time.Duration(performanceRaftMultiplier)
consulRaftLeaderLeaseTimeout := b.durationVal("consul.raft.leader_lease_timeout", c.Consul.Raft.LeaderLeaseTimeout) * time.Duration(performanceRaftMultiplier)

// Connect proxy defaults.
// Connect
connectEnabled := b.boolVal(c.Connect.Enabled)
connectCAProvider := b.stringVal(c.Connect.CAProvider)
connectCAConfig := c.Connect.CAConfig

// autoEncrypt and autoConfig implicitly turns on connect which is why
// they need to be above other settings that rely on connect.
autoEncryptTLS := b.boolVal(c.AutoEncrypt.TLS)
autoEncryptDNSSAN := []string{}
for _, d := range c.AutoEncrypt.DNSSAN {
autoEncryptDNSSAN = append(autoEncryptDNSSAN, d)
}
autoEncryptIPSAN := []net.IP{}
for _, i := range c.AutoEncrypt.IPSAN {
ip := net.ParseIP(i)
if ip == nil {
b.warn(fmt.Sprintf("Cannot parse ip %q from AutoEncrypt.IPSAN", i))
continue
}
autoEncryptIPSAN = append(autoEncryptIPSAN, ip)

}
autoEncryptAllowTLS := b.boolVal(c.AutoEncrypt.AllowTLS)

if autoEncryptAllowTLS {
connectEnabled = true
}

autoConfig := b.autoConfigVal(c.AutoConfig)
if autoConfig.Enabled {
connectEnabled = true
}

// Connect proxy defaults
connectMeshGatewayWANFederationEnabled := b.boolVal(c.Connect.MeshGatewayWANFederationEnabled)
if connectMeshGatewayWANFederationEnabled && !connectEnabled {
return RuntimeConfig{}, fmt.Errorf("'connect.enable_mesh_gateway_wan_federation=true' requires 'connect.enabled=true'")
Expand Down Expand Up @@ -668,27 +698,6 @@ func (b *Builder) Build() (rt RuntimeConfig, err error) {
})
}

autoEncryptTLS := b.boolVal(c.AutoEncrypt.TLS)
autoEncryptDNSSAN := []string{}
for _, d := range c.AutoEncrypt.DNSSAN {
autoEncryptDNSSAN = append(autoEncryptDNSSAN, d)
}
autoEncryptIPSAN := []net.IP{}
for _, i := range c.AutoEncrypt.IPSAN {
ip := net.ParseIP(i)
if ip == nil {
b.warn(fmt.Sprintf("Cannot parse ip %q from AutoEncrypt.IPSAN", i))
continue
}
autoEncryptIPSAN = append(autoEncryptIPSAN, ip)

}
autoEncryptAllowTLS := b.boolVal(c.AutoEncrypt.AllowTLS)

if autoEncryptAllowTLS {
connectEnabled = true
}

aclsEnabled := false
primaryDatacenter := strings.ToLower(b.stringVal(c.PrimaryDatacenter))
if c.ACLDatacenter != nil {
Expand Down Expand Up @@ -908,7 +917,7 @@ func (b *Builder) Build() (rt RuntimeConfig, err error) {
AutoEncryptDNSSAN: autoEncryptDNSSAN,
AutoEncryptIPSAN: autoEncryptIPSAN,
AutoEncryptAllowTLS: autoEncryptAllowTLS,
AutoConfig: b.autoConfigVal(c.AutoConfig),
AutoConfig: autoConfig,
ConnectEnabled: connectEnabled,
ConnectCAProvider: connectCAProvider,
ConnectCAConfig: connectCAConfig,
Expand Down
1 change: 1 addition & 0 deletions agent/config/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3987,6 +3987,7 @@ func TestConfigFlagsAndEdgecases(t *testing.T) {
"Both an intro token and intro token file are set. The intro token will be used instead of the file",
},
patch: func(rt *RuntimeConfig) {
rt.ConnectEnabled = true
rt.AutoConfig.Enabled = true
rt.AutoConfig.IntroToken = "blah"
rt.AutoConfig.IntroTokenFile = "blah"
Expand Down
2 changes: 1 addition & 1 deletion agent/consul/acl_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ func (s *Server) LocalTokensEnabled() bool {
}

if !s.config.ACLTokenReplication || s.tokens.ReplicationToken() == "" {
// token replication is off so local tokens are disabled
return false
}

// token replication is off so local tokens are disabled
return true
}

Expand Down
4 changes: 3 additions & 1 deletion website/pages/docs/agent/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,9 @@ Valid time units are 'ns', 'us' (or 'µs'), 'ms', 's', 'm', 'h'."
The initial RPC uses a JWT specified with either `intro_token`,
`intro_token_file` or the `CONSUL_INTRO_TOKEN` environment variable to authorize
the request. How the JWT token is verified is controlled by the `auto_config.authorizer`
object available for use on Consul servers.
object available for use on Consul servers. Enabling this option also turns
on Connect because it is vital for `auto_config`, more specifically the CA
and certificates infrastructure.
- `intro_token` (Defaults to `""`) This specifies the JWT to use for the initial
`auto_config` RPC to the Consul servers. This can be overridden with the
Expand Down

0 comments on commit ba495cd

Please sign in to comment.