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

certprovider-api: update api to include certificate name #3797

Merged
merged 9 commits into from Aug 21, 2020

Conversation

easwars
Copy link
Contributor

@easwars easwars commented Aug 6, 2020

No description provided.

@easwars
Copy link
Contributor Author

easwars commented Aug 6, 2020

@ZhenLian : This is the PR I was talking about.

credentials/tls/certprovider/distributor.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/provider.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/provider.go Show resolved Hide resolved
credentials/tls/certprovider/provider.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/store.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/store.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/store.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/provider.go Outdated Show resolved Hide resolved
@dfawley dfawley assigned easwars and unassigned dfawley Aug 6, 2020
@ZhenLian
Copy link
Contributor

ZhenLian commented Aug 6, 2020

@ZhenLian : This is the PR I was talking about.

Thanks for letting me know! Also, I checked with @jiangtaoli2016: currently we don't have any plans to expose the certificate name to users in file_reloading case, so I think using a default cert name to hide this information from users would work for our case here.

Copy link
Contributor Author

@easwars easwars left a comment

Choose a reason for hiding this comment

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

PTAL.

credentials/tls/certprovider/distributor.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/provider.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/provider.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/provider.go Show resolved Hide resolved
credentials/tls/certprovider/provider.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/store.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/store.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/store.go Outdated Show resolved Hide resolved
@easwars easwars assigned dfawley and unassigned easwars Aug 7, 2020
@menghanl menghanl assigned easwars and unassigned dfawley Aug 13, 2020
And get rid of KeyMaterialReader type.
@easwars easwars assigned dfawley and unassigned easwars Aug 14, 2020
credentials/tls/certprovider/provider.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/distributor_test.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/store_test.go Outdated Show resolved Hide resolved
Comment on lines 243 to 246
p, err := fpb1.providerChan.Receive()
if err != nil {
t.Fatal(err)
t.Fatalf("Timeout when expecting certProvider %q to be created", fakeProvider1Name)
}
Copy link
Member

Choose a reason for hiding this comment

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

Not related to this PR but.. It would be more straightforward and useful in more scenarios if Receive (and Send) accepted a context, vs. having a hidden internal timeout. Can this be changed?

Also, we have two copies of this testutils.Channel: one in internal and one in internal/xds -- we need to unify them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do in a follow up PR. Definitely makes sense.

credentials/tls/certprovider/store_test.go Outdated Show resolved Hide resolved
@dfawley dfawley assigned easwars and unassigned dfawley Aug 14, 2020
@easwars easwars assigned dfawley and unassigned easwars Aug 14, 2020
credentials/tls/certprovider/distributor_test.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/store_test.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/store_test.go Outdated Show resolved Hide resolved
@@ -141,13 +131,15 @@ func (s) TestDistributor(t *testing.T) {
waitAndDo(t, proceedCh, errCh, func() {
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this test very well. Why do you need a separate goroutine vs. doing these operations on the distributor when you would push to proceedCh?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to test the case where the calls to Set and the calls to KeyMaterial are happening concurrently. But totally agree. This test wasn't very easy to read. Switched it a straight forward flow.

@easwars easwars self-assigned this Aug 17, 2020
@easwars
Copy link
Contributor Author

easwars commented Aug 17, 2020

@dfawley Still working on a test. Will let you know once this is ready to looked at again. Thanks.

@easwars easwars assigned dfawley and unassigned easwars and dfawley Aug 17, 2020
@easwars
Copy link
Contributor Author

easwars commented Aug 17, 2020

Hope I've got the assignment right.
@dfawley : This is ready to be looked at.

credentials/tls/certprovider/distributor_test.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/distributor_test.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/distributor_test.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/distributor_test.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/distributor_test.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/distributor_test.go Outdated Show resolved Hide resolved
credentials/tls/certprovider/distributor_test.go Outdated Show resolved Hide resolved
return

}
if errors.Is(err, context.DeadlineExceeded) {
Copy link
Member

Choose a reason for hiding this comment

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

if err != nil ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I only want to exit on context deadline errors here. Basically, distributor could have km1 when this function is called. So, the first call to readAndVerifyKeyMaterial will fail. Checking only for context deadline errors here will make sure that we retry till we eventually get what key material we are looking for (or the context expires, at which point, we are done).

Copy link
Member

Choose a reason for hiding this comment

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

For this case, there's not really any reason to do it in parallel then. KeyMaterial will unblock immediately before and after the call to Set the second key material. You could do them sequentially and simplify (i.e. you'd no longer need this function, then).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense.
Got rid of the function, and simplified this test to only exercise the case where the distributor is blocked waiting for key material, and the Set() happens from another goroutine.

Comment on lines 100 to 104
go waitForKeyMaterial(ctx, dist, km1, nil, errCh)
dist.Set(km1, nil)
if err := <-errCh; err != nil {
t.Fatal(err)
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this could be simplified if you reverse what you do:

go dist.Set(km, nil)
if km, err := readAndVerifyKeyMaterial()....

With this you could delete errCh and wouldn't need waitForKeyMaterial.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reversed the order, and got rid of errCh. I still need the waitForKeyMaterial because when I switch the keyMaterial in case #2, I could end up reading the old keyMaterial the first time that I read it.

waitAndDo(t, proceedCh, errCh, func() {
dist.Stop()
})
// TestDistributorConcurrency invokes methods on the distributor in parallel.
Copy link
Member

Choose a reason for hiding this comment

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

You might want to do something to synchronize the timing better.

go fmt.Println("hi")
fmt.Println("bye")

Is probably very likely to be ordered one way 99% of the time. Maybe instead:

start := timer.NewTimer(time.Millisecond)
go func() {
  <-start.C
  fmt.Println("hi")
}()
<-start.C
fmt.Println("bye")

would be more likely to show up races. In this case, if you just want Set to happen while Get is blocked, then:

go func() {
  time.Sleep(50*time.Microsecond)
  Set()
}()
Get()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thanks.

@dfawley dfawley assigned easwars and unassigned dfawley Aug 20, 2020
Copy link
Contributor Author

@easwars easwars left a comment

Choose a reason for hiding this comment

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

Done. PTAL.

Comment on lines 100 to 104
go waitForKeyMaterial(ctx, dist, km1, nil, errCh)
dist.Set(km1, nil)
if err := <-errCh; err != nil {
t.Fatal(err)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reversed the order, and got rid of errCh. I still need the waitForKeyMaterial because when I switch the keyMaterial in case #2, I could end up reading the old keyMaterial the first time that I read it.

waitAndDo(t, proceedCh, errCh, func() {
dist.Stop()
})
// TestDistributorConcurrency invokes methods on the distributor in parallel.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Thanks.

@easwars easwars assigned dfawley and unassigned easwars Aug 20, 2020
@easwars easwars merged commit e14f1c2 into grpc:master Aug 21, 2020
@easwars easwars deleted the provider_certname branch August 21, 2020 20:59
@easwars easwars changed the title certprovider: API update to include certificate name. certprovider-api: API update to include certificate name Mar 4, 2021
@easwars easwars changed the title certprovider-api: API update to include certificate name certprovider-api: api update to include certificate name Mar 4, 2021
@easwars easwars changed the title certprovider-api: api update to include certificate name certprovider-api: update api to include certificate name Mar 4, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Feature New features or improvements in behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants