Skip to content

Commit

Permalink
Merge pull request etcd-io#16240 from liangyuanpeng/backport_13577_3.4
Browse files Browse the repository at this point in the history
[3.4] Backport etcd-io#13577 to 3.4
  • Loading branch information
ahrtr authored Jul 14, 2023
2 parents 8175511 + 47cef60 commit 05d7c10
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions auth/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,9 @@ func (as *authStore) AuthInfoFromTLS(ctx context.Context) (ai *AuthInfo) {
}

func (as *authStore) AuthInfoFromCtx(ctx context.Context) (*AuthInfo, error) {
if !as.IsAuthEnabled() {
return nil, nil
}
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
return nil, nil
Expand Down
1 change: 1 addition & 0 deletions clientv3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ func (c *Client) getToken(ctx context.Context) error {
if err != nil {
// return err without retrying other endpoints
if err == rpctypes.ErrAuthNotEnabled {
c.authTokenBundle.UpdateAuthToken("")
return err
}
continue
Expand Down
45 changes: 45 additions & 0 deletions tests/e2e/ctl_v3_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

func TestCtlV3AuthEnable(t *testing.T) { testCtl(t, authEnableTest) }
func TestCtlV3AuthDisable(t *testing.T) { testCtl(t, authDisableTest) }
func TestCtlV3AuthGracefulDisable(t *testing.T) { testCtl(t, authGracefulDisableTest) }
func TestCtlV3AuthWriteKey(t *testing.T) { testCtl(t, authCredWriteKeyTest) }
func TestCtlV3AuthRoleUpdate(t *testing.T) { testCtl(t, authRoleUpdateTest) }
func TestCtlV3AuthUserDeleteDuringOps(t *testing.T) { testCtl(t, authUserDeleteDuringOpsTest) }
Expand Down Expand Up @@ -158,6 +159,50 @@ func authDisableTest(cx ctlCtx) {
}
}

func authGracefulDisableTest(cx ctlCtx) {
if err := authEnable(cx); err != nil {
cx.t.Fatal(err)
}

cx.user, cx.pass = "root", "root"

donec := make(chan struct{})

go func() {
defer close(donec)

// sleep a bit to let the watcher connects while auth is still enabled
time.Sleep(1000 * time.Millisecond)

// now disable auth...
if err := ctlV3AuthDisable(cx); err != nil {
cx.t.Fatalf("authGracefulDisableTest ctlV3AuthDisable error (%v)", err)
}

// ...and restart the node
node0 := cx.epc.procs[0]
node0.WithStopSignal(syscall.SIGINT)
if rerr := node0.Restart(); rerr != nil {
cx.t.Fatal(rerr)
}

// the watcher should still work after reconnecting
if perr := ctlV3Put(cx, "key", "value", ""); perr != nil {
cx.t.Errorf("authGracefulDisableTest ctlV3Put error (%v)", perr)
}
}()

err := ctlV3Watch(cx, []string{"key"}, kvExec{key: "key", val: "value"})

if err != nil {
if cx.dialTimeout > 0 && !isGRPCTimedout(err) {
cx.t.Errorf("authGracefulDisableTest ctlV3Watch error (%v)", err)
}
}

<-donec
}

func ctlV3AuthDisable(cx ctlCtx) error {
cmdArgs := append(cx.PrefixArgs(), "auth", "disable")
return spawnWithExpect(cmdArgs, "Authentication Disabled")
Expand Down

0 comments on commit 05d7c10

Please sign in to comment.