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

ACL: add ACL binding rule RPC and HTTP API handlers. #15529

Merged
merged 7 commits into from
Dec 15, 2022

Conversation

jrasell
Copy link
Member

@jrasell jrasell commented Dec 12, 2022

Best viewed commit by commit which is split by Nomad subsystem.

Builds on #15511
Related to #13120

This change adds a new table that will store ACL binding rule
objects. The two indexes allow fast lookups by their ID, or by
which auth method they are linked to. Snapshot persist and
restore functionality ensures this table can be saved and
restored from snapshots.

In order to write and delete the object to state, new Raft messages
have been added.

All RPC request and response structs, along with object functions
such as diff and canonicalize have been included within this work
as it is nicely separated from the other areas of work.
This change add the RPC ACL binding rule handlers. These handlers
are responsible for the creation, updating, reading, and deletion
of binding rules.

The write handlers are feature gated so that they can only be used
when all federated servers are running the required version.
Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

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

Left some comments but overall LGTM!

Comment on lines +69 to +71
// TODO: version constraint will be updated for every beta or rc until we reach
// 1.5, otherwise it's hard to test the functionality
var minACLBindingRuleVersion = version.Must(version.NewVersion("1.4.3-dev"))
Copy link
Member

Choose a reason for hiding this comment

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

Once we go to 1.5-beta we can update this to 1.5.0 and then use Version.Core on the version we check.

Comment on lines 2089 to 2095
lookupBindingRule, err := stateSnapshot.GetACLBindingRule(nil, bindingRule.ID)
if err != nil {
return structs.NewErrRPCCodedf(400, "ACL binding rule lookup failed: %v", err)
}
if lookupBindingRule != nil {
reply.ACLBindingRules = append(reply.ACLBindingRules, lookupBindingRule)
}
Copy link
Member

Choose a reason for hiding this comment

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

State store read methods don't usually return an error unless its internal. And in any case if we get either an error or a nil value for this query, that seems like an internal error (5xx) to me rather than a request error (4xx) -- we should have just written this value so if we didn't, something went very wrong!

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed on both counts, thanks! Fixed within 4754d09

api/acl_test.go Outdated
@@ -655,3 +654,85 @@ func TestACLAuthMethods(t *testing.T) {
must.Len(t, 0, aclAuthMethodsListResp)
assertQueryMeta(t, queryMeta)
}

func TestACLACLBindingRules(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func TestACLACLBindingRules(t *testing.T) {
func TestACLBindingRules(t *testing.T) {

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed within 4754d09

// decoded. Only perform this check on updates as a generic error on
// creation might be confusing to operators as there is no specific binding
// rule request path.
if ruleID != "" && ruleID != aclBindingRule.ID {
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this condition imply that we allow users to set the ID on creation if they include it in the request body? The server is supposed to create it as a UUID.

Copy link
Member Author

Choose a reason for hiding this comment

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

This function can be used by new creations or updates to existing binding rules. Therefore I feel it's worth checking that if the caller included an ID within the payload, that this is checked against the request path to ensure they match, otherwise we don't know which the correct one is. The RPC handler will check that the ID is found within state, indicating it is an update, before moving forward.

This comment did get me thinking about this function and I made a small modification within 4754d09 which sets the aclBindingRule.ID to the request path ID, if the former has been left empty by the caller.

Base automatically changed from jrasell/gh-13120-binding-rule-state to main December 14, 2022 07:48
Copy link
Contributor

@pkazmierczak pkazmierczak left a comment

Choose a reason for hiding this comment

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

LGTM! Only some small typos.

api/acl.go Outdated Show resolved Hide resolved
api/acl.go Outdated Show resolved Hide resolved
Co-authored-by: Piotr Kazmierczak <[email protected]>
@jrasell jrasell merged commit 4d60dd3 into main Dec 15, 2022
@jrasell jrasell deleted the jrasell/gh-13120-binding-rule-rpc-api branch December 15, 2022 08:18
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants