Skip to content

client/v3: do not overwrite authTokenBundle on dial#12992

Merged
ptabor merged 1 commit intoetcd-io:mainfrom
awly:client-auth-bundle-overwrite
Jul 1, 2021
Merged

client/v3: do not overwrite authTokenBundle on dial#12992
ptabor merged 1 commit intoetcd-io:mainfrom
awly:client-auth-bundle-overwrite

Conversation

@awly
Copy link
Copy Markdown
Contributor

@awly awly commented May 18, 2021

Client.dial can be called multiple times. For example, from regular
NewClient and from the Maintenance
wrapper
.

This ends up creating two (if Client.dial is called twice) independent
credentials.Bundle instances:

  • the first one is wired into PerRPCCredentials callback in gRPC
    client.
  • the second one is in Client.authTokenBundle and receives the latest
    auth token updates.

When using username/password authentication and the server is configured
to issue JWTs, token rotation logic breaks because of the above
credentials.Bundle confusion.

As a simple solution, do not overwrite Client.authTokenBundle if it's already set.

Please read https://github.com/etcd-io/etcd/blob/main/CONTRIBUTING.md#contribution-flow.

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

Merging #12992 (a1eb7c2) into main (6d451ab) will decrease coverage by 12.56%.
The diff coverage is 0.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##             main   #12992       +/-   ##
===========================================
- Coverage   55.29%   42.72%   -12.57%     
===========================================
  Files         429      413       -16     
  Lines       33181    33221       +40     
===========================================
- Hits        18346    14193     -4153     
- Misses      13102    17121     +4019     
- Partials     1733     1907      +174     
Flag Coverage Δ
all 42.72% <0.00%> (-12.57%) ⬇️

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

Impacted Files Coverage Δ
client/v3/client.go 26.56% <0.00%> (+21.38%) ⬆️
raft/quorum/quorum.go 0.00% <0.00%> (-100.00%) ⬇️
raft/tracker/state.go 0.00% <0.00%> (-100.00%) ⬇️
pkg/ioutil/readcloser.go 0.00% <0.00%> (-100.00%) ⬇️
client/v2/cluster_error.go 0.00% <0.00%> (-100.00%) ⬇️
client/pkg/v3/logutil/zap.go 0.00% <0.00%> (-100.00%) ⬇️
client/pkg/v3/types/slice.go 0.00% <0.00%> (-100.00%) ⬇️
server/mvcc/backend/hooks.go 0.00% <0.00%> (-100.00%) ⬇️
server/etcdserver/api/v2store/ttl_key_heap.go 12.50% <0.00%> (-87.50%) ⬇️
client/pkg/v3/transport/listener_opts.go 0.00% <0.00%> (-86.67%) ⬇️
... and 212 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 6d451ab...a1eb7c2. Read the comment docs.

Copy link
Copy Markdown
Contributor

@ptabor ptabor left a comment

Choose a reason for hiding this comment

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

Thank you. Could you, please, add a regression test for the new behavior.

@awly
Copy link
Copy Markdown
Contributor Author

awly commented Jun 22, 2021

@ptabor sorry for the delay, added a test.
Also realized that authTokenBundle should really just be created in newClient instead of dial, moved it there.

`Client.dial` can be called multiple times. For example, from regular
`NewClient` and [from the `Maintenance`
wrapper](https://github.com/etcd-io/etcd/blob/6d451ab61d2da992622b3e7dbf85ded04ebcc515/client/v3/maintenance.go#L81-L84).

This ends up creating two (if `Client.dial` is called twice) independent
`credentials.Bundle` instances:
- the first one is wired into `PerRPCCredentials` callback in gRPC
  client.
- the second one is in `Client.authTokenBundle` and receives the latest
  auth token updates.

When using username/password authentication and the server is configured
to issue JWTs, token rotation logic breaks because of the above
`credentials.Bundle` confusion.
@awly
Copy link
Copy Markdown
Contributor Author

awly commented Jun 30, 2021

@ptabor could you merge this please?

@ptabor ptabor merged commit 7271ade into etcd-io:main Jul 1, 2021
@biosvs
Copy link
Copy Markdown
Contributor

biosvs commented Jun 15, 2022

@ptabor how do you think, is it possible to make a backport to 3.5 for this fix? For cluster with enable auth this bug is quite annoying and hard to workaround without hot patching.

ahrtr added a commit to ahrtr/etcd that referenced this pull request Jun 17, 2022
Cherry pick the PR etcd-io#12992
to 3.5, so please refer to the original PR for more detailed info.

Signed-off-by: Benjamin Wang <[email protected]>
ahrtr added a commit to ahrtr/etcd that referenced this pull request Jun 17, 2022
Cherry pick the PR etcd-io#12992
to 3.5, so please refer to the original PR for more detailed info.

Signed-off-by: Benjamin Wang <[email protected]>
@serathius serathius mentioned this pull request Jun 21, 2022
16 tasks
openshift-cherrypick-robot pushed a commit to openshift-cherrypick-robot/etcd that referenced this pull request Oct 7, 2022
Cherry pick the PR etcd-io#12992
to 3.5, so please refer to the original PR for more detailed info.

Signed-off-by: Benjamin Wang <[email protected]>
tjungblu pushed a commit to tjungblu/etcd that referenced this pull request Jul 26, 2023
Cherry pick the PR etcd-io#12992
to 3.5, so please refer to the original PR for more detailed info.

Signed-off-by: Benjamin Wang <[email protected]>
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.

5 participants