Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nomad
Commits
4cf34edb
Commit
4cf34edb
authored
8 years ago
by
Michael Schurter
Browse files
Options
Download
Email Patches
Plain Diff
Skip checks with TLSSkipVerify if it's unsupported
Fixes #2218
parent
7c671665
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
command/agent/agent.go
+1
-1
command/agent/agent.go
command/agent/consul/client.go
+25
-15
command/agent/consul/client.go
command/agent/consul/int_test.go
+1
-1
command/agent/consul/int_test.go
command/agent/consul/unit_test.go
+48
-4
command/agent/consul/unit_test.go
with
75 additions
and
21 deletions
+75
-21
command/agent/agent.go
+
1
-
1
View file @
4cf34edb
...
...
@@ -699,7 +699,7 @@ func (a *Agent) setupConsul(consulConfig *config.ConsulConfig) error {
a
.
consulCatalog
=
client
.
Catalog
()
// Create Consul Service client for service advertisement and checks.
a
.
consulService
=
consul
.
NewServiceClient
(
client
.
Agent
(),
a
.
logger
)
a
.
consulService
=
consul
.
NewServiceClient
(
client
.
Agent
(),
a
.
consulSupportsTLSSkipVerify
,
a
.
logger
)
go
a
.
consulService
.
Run
()
return
nil
}
...
...
This diff is collapsed.
Click to expand it.
command/agent/consul/client.go
+
25
-
15
View file @
4cf34edb
...
...
@@ -89,6 +89,9 @@ type ServiceClient struct {
retryInterval
time
.
Duration
maxRetryInterval
time
.
Duration
// skipVerifySupport is true if the local Consul agent suppots TLSSkipVerify
skipVerifySupport
bool
// exitCh is closed when the main Run loop exits
exitCh
chan
struct
{}
...
...
@@ -115,22 +118,23 @@ type ServiceClient struct {
// NewServiceClient creates a new Consul ServiceClient from an existing Consul API
// Client and logger.
func
NewServiceClient
(
consulClient
AgentAPI
,
logger
*
log
.
Logger
)
*
ServiceClient
{
func
NewServiceClient
(
consulClient
AgentAPI
,
skipVerifySupport
bool
,
logger
*
log
.
Logger
)
*
ServiceClient
{
return
&
ServiceClient
{
client
:
consulClient
,
logger
:
logger
,
retryInterval
:
defaultRetryInterval
,
maxRetryInterval
:
defaultMaxRetryInterval
,
exitCh
:
make
(
chan
struct
{}),
shutdownCh
:
make
(
chan
struct
{}),
shutdownWait
:
defaultShutdownWait
,
opCh
:
make
(
chan
*
operations
,
8
),
services
:
make
(
map
[
string
]
*
api
.
AgentServiceRegistration
),
checks
:
make
(
map
[
string
]
*
api
.
AgentCheckRegistration
),
scripts
:
make
(
map
[
string
]
*
scriptCheck
),
runningScripts
:
make
(
map
[
string
]
*
scriptHandle
),
agentServices
:
make
(
map
[
string
]
struct
{}),
agentChecks
:
make
(
map
[
string
]
struct
{}),
client
:
consulClient
,
skipVerifySupport
:
skipVerifySupport
,
logger
:
logger
,
retryInterval
:
defaultRetryInterval
,
maxRetryInterval
:
defaultMaxRetryInterval
,
exitCh
:
make
(
chan
struct
{}),
shutdownCh
:
make
(
chan
struct
{}),
shutdownWait
:
defaultShutdownWait
,
opCh
:
make
(
chan
*
operations
,
8
),
services
:
make
(
map
[
string
]
*
api
.
AgentServiceRegistration
),
checks
:
make
(
map
[
string
]
*
api
.
AgentCheckRegistration
),
scripts
:
make
(
map
[
string
]
*
scriptCheck
),
runningScripts
:
make
(
map
[
string
]
*
scriptHandle
),
agentServices
:
make
(
map
[
string
]
struct
{}),
agentChecks
:
make
(
map
[
string
]
struct
{}),
}
}
...
...
@@ -432,6 +436,11 @@ func (c *ServiceClient) serviceRegs(ops *operations, allocID string, service *st
ops
.
regServices
=
append
(
ops
.
regServices
,
serviceReg
)
for
_
,
check
:=
range
service
.
Checks
{
if
check
.
TLSSkipVerify
&&
!
c
.
skipVerifySupport
{
c
.
logger
.
Printf
(
"[WARN] consul.sync: skipping check %q for task %q alloc %q because Consul doesn't support tls_skip_verify. Please upgrade to Consul >= 0.7.2."
,
check
.
Name
,
task
.
Name
,
allocID
)
continue
}
checkID
:=
createCheckID
(
id
,
check
)
if
check
.
Type
==
structs
.
ServiceCheckScript
{
if
exec
==
nil
{
...
...
@@ -441,6 +450,7 @@ func (c *ServiceClient) serviceRegs(ops *operations, allocID string, service *st
allocID
,
task
.
Name
,
checkID
,
check
,
exec
,
c
.
client
,
c
.
logger
,
c
.
shutdownCh
))
}
host
,
port
:=
serviceReg
.
Address
,
serviceReg
.
Port
if
check
.
PortLabel
!=
""
{
host
,
port
=
task
.
FindHostAndPortFor
(
check
.
PortLabel
)
...
...
This diff is collapsed.
Click to expand it.
command/agent/consul/int_test.go
+
1
-
1
View file @
4cf34edb
...
...
@@ -122,7 +122,7 @@ func TestConsul_Integration(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"error creating consul client: %v"
,
err
)
}
serviceClient
:=
consul
.
NewServiceClient
(
consulClient
.
Agent
(),
logger
)
serviceClient
:=
consul
.
NewServiceClient
(
consulClient
.
Agent
(),
true
,
logger
)
defer
serviceClient
.
Shutdown
()
// just-in-case cleanup
consulRan
:=
make
(
chan
struct
{})
go
func
()
{
...
...
This diff is collapsed.
Click to expand it.
command/agent/consul/unit_test.go
+
48
-
4
View file @
4cf34edb
...
...
@@ -98,7 +98,7 @@ func (t *testFakeCtx) syncOnce() error {
func
setupFake
()
*
testFakeCtx
{
fc
:=
newFakeConsul
()
return
&
testFakeCtx
{
ServiceClient
:
NewServiceClient
(
fc
,
testLogger
()),
ServiceClient
:
NewServiceClient
(
fc
,
true
,
testLogger
()),
FakeConsul
:
fc
,
Task
:
testTask
(),
execs
:
make
(
chan
int
,
100
),
...
...
@@ -445,7 +445,6 @@ func TestConsul_ChangePorts(t *testing.T) {
// TestConsul_RegServices tests basic service registration.
func
TestConsul_RegServices
(
t
*
testing
.
T
)
{
ctx
:=
setupFake
()
port
:=
ctx
.
Task
.
Resources
.
Networks
[
0
]
.
DynamicPorts
[
0
]
.
Value
if
err
:=
ctx
.
ServiceClient
.
RegisterTask
(
"allocid"
,
ctx
.
Task
,
nil
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error registering task: %v"
,
err
)
...
...
@@ -465,8 +464,8 @@ func TestConsul_RegServices(t *testing.T) {
if
!
reflect
.
DeepEqual
(
v
.
Tags
,
ctx
.
Task
.
Services
[
0
]
.
Tags
)
{
t
.
Errorf
(
"expected Tags=%v != %v"
,
ctx
.
Task
.
Services
[
0
]
.
Tags
,
v
.
Tags
)
}
if
v
.
Port
!=
p
ort
{
t
.
Errorf
(
"expected Port=%d != %d"
,
p
ort
,
v
.
Port
)
if
v
.
Port
!=
xP
ort
{
t
.
Errorf
(
"expected Port=%d != %d"
,
xP
ort
,
v
.
Port
)
}
}
...
...
@@ -723,3 +722,48 @@ func TestConsul_ShutdownBlocked(t *testing.T) {
}
}
}
// TestConsul_NoTLSSkipVerifySupport asserts that checks with
// TLSSkipVerify=true are skipped when Consul doesn't support TLSSkipVerify.
func
TestConsul_NoTLSSkipVerifySupport
(
t
*
testing
.
T
)
{
ctx
:=
setupFake
()
ctx
.
ServiceClient
=
NewServiceClient
(
ctx
.
FakeConsul
,
false
,
testLogger
())
ctx
.
Task
.
Services
[
0
]
.
Checks
=
[]
*
structs
.
ServiceCheck
{
// This check sets TLSSkipVerify so it should get dropped
{
Name
:
"tls-check-skip"
,
Type
:
"http"
,
Protocol
:
"https"
,
Path
:
"/"
,
TLSSkipVerify
:
true
,
},
// This check doesn't set TLSSkipVerify so it should work fine
{
Name
:
"tls-check-noskip"
,
Type
:
"http"
,
Protocol
:
"https"
,
Path
:
"/"
,
TLSSkipVerify
:
false
,
},
}
if
err
:=
ctx
.
ServiceClient
.
RegisterTask
(
"allocid"
,
ctx
.
Task
,
nil
);
err
!=
nil
{
t
.
Fatalf
(
"unexpected error registering task: %v"
,
err
)
}
if
err
:=
ctx
.
syncOnce
();
err
!=
nil
{
t
.
Fatalf
(
"unexpected error syncing task: %v"
,
err
)
}
if
len
(
ctx
.
FakeConsul
.
checks
)
!=
1
{
t
.
Errorf
(
"expected 1 check but found %d"
,
len
(
ctx
.
FakeConsul
.
checks
))
}
for
_
,
v
:=
range
ctx
.
FakeConsul
.
checks
{
if
expected
:=
"tls-check-noskip"
;
v
.
Name
!=
expected
{
t
.
Errorf
(
"only expected %q but found: %q"
,
expected
,
v
.
Name
)
}
if
v
.
TLSSkipVerify
{
t
.
Errorf
(
"TLSSkipVerify=true when TLSSkipVerify not supported!"
)
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help