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

Only synthesize anonymous token in primary DC #17231

Merged
merged 3 commits into from
May 23, 2023

Conversation

pglass
Copy link

@pglass pglass commented May 5, 2023

Description

Prior to #16200, the anonymous token was only inserted in the primary datacenter. This is a potential fix for WAN fed issues seen in: #16620.

PR Checklist

  • updated test coverage
  • external facing docs updated
  • appropriate backport labels added
  • not a security concern

@pglass pglass added the pr/do-not-merge PR cannot be merged in its current form. label May 5, 2023
@huikang
Copy link
Collaborator

huikang commented May 6, 2023

@pglass , I am wondering if it is possible to add a unit test by extending

func TestAPI_ACLPolicy_List(t *testing.T) {

@skpratt
Copy link
Collaborator

skpratt commented May 11, 2023

I think this is the correct fix. In WAN federation, the primary dc manages all ACLs, so we should not be creating tokens in the secondary DC (especially when the primary DC has not yet completed bootstrapping the ACL system, and is not ready to be the ACL manager).

@skpratt skpratt self-requested a review May 11, 2023 14:40
@pglass pglass force-pushed the pglass/synth-anon-token-wan-fed-fix branch from 6e343a3 to ab66027 Compare May 12, 2023 15:36
@pglass pglass changed the base branch from release/1.15.x to main May 12, 2023 15:37
@pglass pglass added backport/1.15 This release series is no longer active on CE. Use backport/ent/1.15. and removed pr/do-not-merge PR cannot be merged in its current form. labels May 12, 2023
@pglass pglass changed the title WIP: Only synthesize anonymous token in primary DC Only synthesize anonymous token in primary DC May 19, 2023
@pglass pglass force-pushed the pglass/synth-anon-token-wan-fed-fix branch from 9b80620 to d2f4fd7 Compare May 19, 2023 20:24
@pglass pglass marked this pull request as ready for review May 19, 2023 20:24
@pglass pglass requested a review from huikang May 19, 2023 20:24
Copy link
Author

Choose a reason for hiding this comment

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

I ended up adding an integration test for this.

I wanted to test the scenario from the github issue, but I thought that scenario was perhaps slightly too complex to put in the api/ package, where we are really just testing the api client. I did try incorporating a test into the agent/consul/ package where we have some other acl replication tests, but I had some issues reliably reproducing the issue there (and I opted to not spend more cycles on it).

I feel like this is an important scenario for WAN fed that makes sense for an integration test, and the integration tests are pretty straightforward to write 🙂

Comment on lines +34 to +42
func retryFunc[T any](t *testing.T, f func() (T, error)) T {
var result T
retry.RunWith(retryFuncTimer, t, func(r *retry.R) {
val, err := f()
require.NoError(r, err)
result = val
})
return result
}
Copy link
Author

@pglass pglass May 19, 2023

Choose a reason for hiding this comment

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

I added this to try to declutter the retry loops in the test case a little. One gotcha is that the retry.R is not available to the provided function (f), so the caller shouldn't check assertions in f.

Comment on lines +89 to +99
replicationPolicy := retryFunc(t, func() (*api.ACLPolicy, error) {
t.Logf("Create the replication policy")
p, _, err := primary.GetClient().ACL().PolicyCreate(
&api.ACLPolicy{
Name: "consul-server-replication",
Rules: replicationPolicyRules,
},
nil,
)
return p, err
})
Copy link
Author

Choose a reason for hiding this comment

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

I saw there was a helper to create an agent token. I could move this to a helper alongside that?

@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package peering
package wanfed
Copy link
Author

Choose a reason for hiding this comment

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

I noticed another package is called peering so I renamed this to match the directory name.

@pglass pglass merged commit 7f4fd27 into main May 23, 2023
@pglass pglass deleted the pglass/synth-anon-token-wan-fed-fix branch May 23, 2023 14:38
nickethier pushed a commit that referenced this pull request May 26, 2023
* Only synthesize anonymous token in primary DC
* Add integration test for wan fed issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/1.15 This release series is no longer active on CE. Use backport/ent/1.15.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants