Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic in etcd validate secure endpoints #13810 #13824

Merged
merged 7 commits into from
Mar 24, 2022

Conversation

eval-exec
Copy link
Contributor

@eval-exec eval-exec commented Mar 19, 2022

This pr fix #13810

t := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: dialtimeoutd,
// value taken from http.DefaultTransport
KeepAlive: 30 * time.Second,
}).DialContext,
// value taken from http.DefaultTransport
TLSHandshakeTimeout: 10 * time.Second,
TLSClientConfig: cfg,
}

In etcd/client/pkg/transport/tls.go:
ValidateSecureEndpoints() should call t.DialContext() instead of t.Dial(), because t.Dial is nil

@serathius
Copy link
Member

Can you add a test?

@codecov-commenter
Copy link

codecov-commenter commented Mar 19, 2022

Codecov Report

Merging #13824 (e2e38bf) into main (1b208aa) will decrease coverage by 0.32%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             main   #13824      +/-   ##
==========================================
- Coverage   72.72%   72.39%   -0.33%     
==========================================
  Files         467      467              
  Lines       38280    38282       +2     
==========================================
- Hits        27839    27716     -123     
- Misses       8662     8766     +104     
- Partials     1779     1800      +21     
Flag Coverage Δ
all 72.39% <ø> (-0.33%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
etcdctl/ctlv3/command/compaction_command.go 30.43% <0.00%> (-43.48%) ⬇️
etcdctl/ctlv3/command/alarm_command.go 51.35% <0.00%> (-27.03%) ⬇️
server/storage/quota.go 57.89% <0.00%> (-9.22%) ⬇️
server/auth/simple_token.go 80.00% <0.00%> (-8.47%) ⬇️
server/storage/mvcc/watchable_store.go 85.14% <0.00%> (-7.61%) ⬇️
client/pkg/v3/fileutil/purge.go 66.03% <0.00%> (-7.55%) ⬇️
server/etcdserver/api/v3rpc/lease.go 77.21% <0.00%> (-5.07%) ⬇️
client/v3/concurrency/session.go 88.63% <0.00%> (-4.55%) ⬇️
client/pkg/v3/testutil/leak.go 62.83% <0.00%> (-4.43%) ⬇️
client/v3/leasing/cache.go 87.77% <0.00%> (-3.89%) ⬇️
... and 24 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1b208aa...e2e38bf. Read the comment docs.

@eval-exec
Copy link
Contributor Author

Can you add a test?

Yes, I will add a test today.

@eval-exec
Copy link
Contributor Author

Can you add a test?

Test for ValidateSecureEndpoints() added.

Copy link
Member

@serathius serathius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, confirmed that Dial is deprecated and not used by NewTransport

@serathius
Copy link
Member

cc @ahrtr @ptabor @spzala

t.Error("validate secure endpoints should fail")
}

secureEps := []string{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you sequentially test different cases, fist insecure later secure, also you don't have you considered using subtests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will using subtests.

"http://" + srv.Listener.Addr().String(),
"invalid remote address",
}
if _, err := ValidateSecureEndpoints(*tlsInfo, insecureEps); err == nil || !strings.Contains(err.Error(), "is insecure") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you test case with insecure endpoint that passes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test for ValidateSecureEndpoints() updated.

Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

The only minor concern is the unit test. subtest is better, but since there is only two cases, and they share the same http server, so I am OK.

if !test.expectedErr && err != nil {
t.Errorf("unexpected error: %v", err)
}
if err == nil && !test.expectedErr {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if is not needed, you can still check endpoints. in case mixEndPoints you specified both expectedEndpoints and expectErr true, which is misleading as this if will result in endpoints not being verified.

t.Errorf("unexpected error: %v", err)
}
if err == nil && !test.expectedErr {
if len(secureEps) != len(test.expectedEndpoints) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DeepEqual should already test if length matches.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I removed secureEps's length check.

Copy link
Member

@spzala spzala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm
Running workflow. Thanks @eval-exec

@eval-exec
Copy link
Contributor Author

@serathius I rebased branch (eval-exec:patch-1), please approve running workflows.

@serathius serathius merged commit cc33b7c into etcd-io:main Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Panic in etcd gateway start
5 participants