Skip to content

Commit 8bc3271

Browse files
clwluvwArkaSaha30
authored andcommitted
config: support AllowedCN and AllowedHostname through config file
Allow setting AllowedCN and AllowedHostname tls fields through config file for peer transport security. Signed-off-by: Seena Fallah <seenafallah@gmail.com>
1 parent 3afe949 commit 8bc3271

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

etcd.conf.yml.sample

+6
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ peer-transport-security:
125125
# Peer TLS using generated certificates.
126126
auto-tls: false
127127

128+
# Allowed CN for inter peer authentication.
129+
allowed-cn:
130+
131+
# Allowed TLS hostname for inter peer authentication.
132+
allowed-hostname:
133+
128134
# The validity period of the self-signed certificate, the unit is year.
129135
self-signed-cert-validity: 1
130136

server/embed/config.go

+11-7
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,15 @@ type configJSON struct {
443443
}
444444

445445
type securityConfig struct {
446-
CertFile string `json:"cert-file"`
447-
KeyFile string `json:"key-file"`
448-
ClientCertFile string `json:"client-cert-file"`
449-
ClientKeyFile string `json:"client-key-file"`
450-
CertAuth bool `json:"client-cert-auth"`
451-
TrustedCAFile string `json:"trusted-ca-file"`
452-
AutoTLS bool `json:"auto-tls"`
446+
CertFile string `json:"cert-file"`
447+
KeyFile string `json:"key-file"`
448+
ClientCertFile string `json:"client-cert-file"`
449+
ClientKeyFile string `json:"client-key-file"`
450+
CertAuth bool `json:"client-cert-auth"`
451+
TrustedCAFile string `json:"trusted-ca-file"`
452+
AutoTLS bool `json:"auto-tls"`
453+
AllowedCN string `json:"allowed-cn"`
454+
AllowedHostname string `json:"allowed-hostname"`
453455
}
454456

455457
// NewConfig creates a new Config populated with default values.
@@ -629,6 +631,8 @@ func (cfg *configYAML) configFromFile(path string) error {
629631
tls.ClientKeyFile = ysc.ClientKeyFile
630632
tls.ClientCertAuth = ysc.CertAuth
631633
tls.TrustedCAFile = ysc.TrustedCAFile
634+
tls.AllowedCN = ysc.AllowedCN
635+
tls.AllowedHostname = ysc.AllowedHostname
632636
}
633637
copySecurityDetails(&cfg.ClientTLSInfo, &cfg.ClientSecurityJSON)
634638
copySecurityDetails(&cfg.PeerTLSInfo, &cfg.PeerSecurityJSON)

server/embed/config_test.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ func notFoundErr(service, domain string) error {
4040

4141
func TestConfigFileOtherFields(t *testing.T) {
4242
ctls := securityConfig{TrustedCAFile: "cca", CertFile: "ccert", KeyFile: "ckey"}
43-
ptls := securityConfig{TrustedCAFile: "pca", CertFile: "pcert", KeyFile: "pkey"}
43+
// Note AllowedCN and AllowedHostname are mutually exclusive, this test is just to verify the fields can be correctly marshalled & unmarshalled.
44+
ptls := securityConfig{TrustedCAFile: "pca", CertFile: "pcert", KeyFile: "pkey", AllowedCN: "etcd", AllowedHostname: "whatever.example.com"}
4445
yc := struct {
4546
ClientSecurityCfgFile securityConfig `json:"client-transport-security"`
4647
PeerSecurityCfgFile securityConfig `json:"peer-transport-security"`
@@ -155,7 +156,12 @@ func TestUpdateDefaultClusterFromNameOverwrite(t *testing.T) {
155156
func (s *securityConfig) equals(t *transport.TLSInfo) bool {
156157
return s.CertFile == t.CertFile &&
157158
s.CertAuth == t.ClientCertAuth &&
158-
s.TrustedCAFile == t.TrustedCAFile
159+
s.TrustedCAFile == t.TrustedCAFile &&
160+
s.ClientCertFile == t.ClientCertFile &&
161+
s.ClientKeyFile == t.ClientKeyFile &&
162+
s.KeyFile == t.KeyFile &&
163+
s.AllowedCN == t.AllowedCN &&
164+
s.AllowedHostname == t.AllowedHostname
159165
}
160166

161167
func mustCreateCfgFile(t *testing.T, b []byte) *os.File {

0 commit comments

Comments
 (0)