-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Fix some data races #10396
Fix some data races #10396
Changes from all commits
baa2b86
970f5d7
0acfc2c
678014d
a0ca381
414ce3f
fa47c04
a77575e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -310,61 +310,73 @@ func testIdentityForToken(token string) (bool, structs.ACLIdentity, error) { | |||||||
func testPolicyForID(policyID string) (bool, *structs.ACLPolicy, error) { | ||||||||
switch policyID { | ||||||||
case "acl-ro": | ||||||||
return true, &structs.ACLPolicy{ | ||||||||
p := &structs.ACLPolicy{ | ||||||||
ID: "acl-ro", | ||||||||
Name: "acl-ro", | ||||||||
Description: "acl-ro", | ||||||||
Rules: `acl = "read"`, | ||||||||
Syntax: acl.SyntaxCurrent, | ||||||||
RaftIndex: structs.RaftIndex{CreateIndex: 1, ModifyIndex: 2}, | ||||||||
}, nil | ||||||||
} | ||||||||
p.SetHash(false) | ||||||||
return true, p, nil | ||||||||
case "acl-wr": | ||||||||
return true, &structs.ACLPolicy{ | ||||||||
p := &structs.ACLPolicy{ | ||||||||
ID: "acl-wr", | ||||||||
Name: "acl-wr", | ||||||||
Description: "acl-wr", | ||||||||
Rules: `acl = "write"`, | ||||||||
Syntax: acl.SyntaxCurrent, | ||||||||
RaftIndex: structs.RaftIndex{CreateIndex: 1, ModifyIndex: 2}, | ||||||||
}, nil | ||||||||
} | ||||||||
p.SetHash(false) | ||||||||
return true, p, nil | ||||||||
case "service-ro": | ||||||||
return true, &structs.ACLPolicy{ | ||||||||
p := &structs.ACLPolicy{ | ||||||||
ID: "service-ro", | ||||||||
Name: "service-ro", | ||||||||
Description: "service-ro", | ||||||||
Rules: `service_prefix "" { policy = "read" }`, | ||||||||
Syntax: acl.SyntaxCurrent, | ||||||||
RaftIndex: structs.RaftIndex{CreateIndex: 1, ModifyIndex: 2}, | ||||||||
}, nil | ||||||||
} | ||||||||
p.SetHash(false) | ||||||||
return true, p, nil | ||||||||
case "service-wr": | ||||||||
return true, &structs.ACLPolicy{ | ||||||||
p := &structs.ACLPolicy{ | ||||||||
ID: "service-wr", | ||||||||
Name: "service-wr", | ||||||||
Description: "service-wr", | ||||||||
Rules: `service_prefix "" { policy = "write" }`, | ||||||||
Syntax: acl.SyntaxCurrent, | ||||||||
RaftIndex: structs.RaftIndex{CreateIndex: 1, ModifyIndex: 2}, | ||||||||
}, nil | ||||||||
} | ||||||||
p.SetHash(false) | ||||||||
return true, p, nil | ||||||||
case "node-wr": | ||||||||
return true, &structs.ACLPolicy{ | ||||||||
p := &structs.ACLPolicy{ | ||||||||
ID: "node-wr", | ||||||||
Name: "node-wr", | ||||||||
Description: "node-wr", | ||||||||
Rules: `node_prefix "" { policy = "write"}`, | ||||||||
Syntax: acl.SyntaxCurrent, | ||||||||
Datacenters: []string{"dc1"}, | ||||||||
RaftIndex: structs.RaftIndex{CreateIndex: 1, ModifyIndex: 2}, | ||||||||
}, nil | ||||||||
} | ||||||||
p.SetHash(false) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering about this fix. Why does the ACL resolver need to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do set the hash on creation in the PolicySet endpoint: https://github.com/hashicorp/consul/blob/main/agent/consul/acl_endpoint.go#L1204 testPolicyForID is used by a test resolver delegate, so I think it's necessary to do it on reads here because there is no write beyond the policy existing in this function. It resolves these hard coded policies as if they had been created by some other process. (But maybe I'm misunderstanding your question) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I think that suggests that this fix is reasonable (because it better matches a production flow), which is reassuring. I think my broader question is about the call to That seems like a very strange place to be calling I think answering that question isn't a blocker for this PR, but it may be worth exploring further to see if we can rationalize where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that's a good point about It also doesn't seem to be used for ACL compatibility, since the function to extract policies from embedded tokens sets the hash itself: Line 475 in 0527dcf
Same with these other synthetic policy extractors: Line 189 in 0527dcf
Line 233 in 0527dcf
My sense is that it was there for tests like this one that don't set the hash in advance. I don't see a non-test use for it. Agreed that it doesn't need to be handled in this PR. |
||||||||
return true, p, nil | ||||||||
case "dc2-key-wr": | ||||||||
return true, &structs.ACLPolicy{ | ||||||||
p := &structs.ACLPolicy{ | ||||||||
ID: "dc2-key-wr", | ||||||||
Name: "dc2-key-wr", | ||||||||
Description: "dc2-key-wr", | ||||||||
Rules: `key_prefix "" { policy = "write"}`, | ||||||||
Syntax: acl.SyntaxCurrent, | ||||||||
Datacenters: []string{"dc2"}, | ||||||||
RaftIndex: structs.RaftIndex{CreateIndex: 1, ModifyIndex: 2}, | ||||||||
}, nil | ||||||||
} | ||||||||
p.SetHash(false) | ||||||||
return true, p, nil | ||||||||
default: | ||||||||
return testPolicyForIDEnterprise(policyID) | ||||||||
} | ||||||||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come this change was only needed for a subset of the cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it is because only the "Concurrent-Token-Resolve" test cases has a race on
SetHash
, and only these two cases are used by the "Concurrent-Token-Resolve" test case.I can add
SetHash
to the other cases as well, if we think that would better imitate production.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think adding it to all of them would be nice for that reason. Would also avoid that confusion when someone looks at this again later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good! Added those in the latest commit