Skip to content

Commit

Permalink
Merge pull request #15653 from mitake/3.5-backport-15648
Browse files Browse the repository at this point in the history
[3.5] backport 15648
  • Loading branch information
ahrtr committed Apr 6, 2023
2 parents 070341c + e6c2e38 commit b1df3df
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
7 changes: 7 additions & 0 deletions server/etcdserver/v3_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,13 @@ func (s *EtcdServer) Authenticate(ctx context.Context, r *pb.AuthenticateRequest

lg := s.Logger()

// fix https://nvd.nist.gov/vuln/detail/CVE-2021-28235
defer func() {
if r != nil {
r.Password = ""
}
}()

var resp proto.Message
for {
checkedRevision, err := s.AuthStore().CheckPassword(r.Name, r.Password)
Expand Down
55 changes: 55 additions & 0 deletions tests/e2e/ctl_v3_auth_security_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2023 The etcd Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !cluster_proxy

package e2e

import (
"strings"
"testing"

"github.com/stretchr/testify/require"
)

// TestAuth_CVE_2021_28235 verifies https://nvd.nist.gov/vuln/detail/CVE-2021-28235
func TestAuth_CVE_2021_28235(t *testing.T) {
testCtl(t, authTest_CVE_2021_28235, withCfg(*newConfigNoTLS()), withLogLevel("debug"))
}

func authTest_CVE_2021_28235(cx ctlCtx) {
// create root user with root role
rootPass := "changeme123"
err := ctlV3User(cx, []string{"add", "root", "--interactive=false"}, "User root created", []string{rootPass})
require.NoError(cx.t, err)
err = ctlV3User(cx, []string{"grant-role", "root", "root"}, "Role root is granted to user root", nil)
require.NoError(cx.t, err)
err = ctlV3AuthEnable(cx)
require.NoError(cx.t, err)

// issue a put request
cx.user, cx.pass = "root", rootPass
err = ctlV3Put(cx, "foo", "bar", "")
require.NoError(cx.t, err)

// GET /debug/requests
httpEndpoint := cx.epc.procs[0].EndpointsHTTP()[0]
req := cURLReq{endpoint: "/debug/requests?fam=grpc.Recv.etcdserverpb.Auth&b=0&exp=1", timeout: 5}
respData, err := curl(httpEndpoint, "GET", req, clientNonTLS)
require.NoError(cx.t, err)

if strings.Contains(respData, rootPass) {
cx.t.Errorf("The root password is included in the request.\n %s", respData)
}
}
6 changes: 6 additions & 0 deletions tests/e2e/ctl_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ func withSnapshotCount(snapshotCount int) ctlOption {
}
}

func withLogLevel(logLevel string) ctlOption {
return func(cx *ctlCtx) {
cx.cfg.logLevel = logLevel
}
}

func testCtl(t *testing.T, testFunc func(ctlCtx), opts ...ctlOption) {
testCtlWithOffline(t, testFunc, nil, opts...)
}
Expand Down

0 comments on commit b1df3df

Please sign in to comment.