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

Update BaseSubjectSet to support caveat expressions #932

Merged
merged 1 commit into from
Nov 7, 2022

Conversation

josephschorr
Copy link
Member

This is the first (massive) step in supporting caveats in LookupSubjects, as this implements all the bookkeeping and tracking associated with each subject added to the subject set

First part of #931

@josephschorr josephschorr requested review from ecordell, vroldanbet and a team October 24, 2022 17:39
@github-actions github-actions bot added area/api v1 Affects the v1 API area/dispatch Affects dispatching of requests area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) labels Oct 24, 2022
Copy link
Contributor

@ecordell ecordell left a comment

Choose a reason for hiding this comment

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

did an initial pass with questions, definitely haven't read the implementation and tests in detail yet

@@ -161,7 +161,8 @@ message DispatchLookupSubjectsRequest {

message FoundSubject {
string subject_id = 1;
repeated string excluded_subject_ids = 2;
CaveatExpression conditional_expression = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know off the top of my head what the best way to break a grpc api is - it might be better to skip 2 here entirely?

Copy link
Member Author

Choose a reason for hiding this comment

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

It only really matters if we intend back compat and to do so we'd have to fill in the excluded IDs as well. We could do that, but it would require keeping around the extra logic

for _, excludedSubject := range fs.excludedSubjects {
// TODO(jschorr): Fix once we add caveats support to debug tooling
if excludedSubject.conditionalExpression != nil {
panic("not yet supported")
Copy link
Contributor

Choose a reason for hiding this comment

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

won't panic-ing here prevent us from cutting an release without the debug tooling implemented?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep! That's intended; I want to do something here, even if it is just returning "(unsupported)", but I don't know exactly what yet, so I added in panics

internal/util/basesubjectset.go Outdated Show resolved Hide resolved
// Add adds the found subject to the set. This is equivalent to a Union operation between the
// existing set of subjects and a set containing the single subject.
// existing set of subjects and a set containing the single subject, but modifies the set
// *in place*.
func (bss BaseSubjectSet[T]) Add(foundSubject T) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't gotten to the callsites yet, but it's not obvious to me why Add should return a bool or why it's helpful to know if the set had a wildcard before the add.

Copy link
Member Author

Choose a reason for hiding this comment

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

standard set semantics: did this subject already exist when I added it

}

// SubtractAll subtracts the other set of subjects from this set of subtracts, modifying this
// set in place.
// set *in place*.
func (bss BaseSubjectSet[T]) SubtractAll(other BaseSubjectSet[T]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just have Subtract(sets ...BaseSubjectSet[T]) to cover Subtract and SubtractAll?

Copy link
Member Author

Choose a reason for hiding this comment

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

Subtract takes in a single element, not a set and to have a combined method, we'd have to convert from one or the other

internal/util/basesubjectset.go Outdated Show resolved Hide resolved
}

bss.wildcard.subtractConcrete(foundSubject)
bss.concrete.subtractConcrete(foundSubject)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this double-bookkeeping is weird but I don't have an alternate suggestion at the moment.

Every operation actually modifies these two underlying sets, and I'll have to figure out how they get combined elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

The combination is just taking the values in each; they each track their own state independently.

internal/util/basesubjectset.go Outdated Show resolved Hide resolved
internal/util/basesubjectset.go Outdated Show resolved Hide resolved
Copy link
Contributor

@vroldanbet vroldanbet left a comment

Choose a reason for hiding this comment

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

Not done with the review, but have some comments

internal/util/basesubjectset.go Outdated Show resolved Hide resolved
internal/util/subjectset_test.go Show resolved Hide resolved
internal/util/subjectset_test.go Show resolved Hide resolved
@josephschorr josephschorr force-pushed the ls-subjectset branch 2 times, most recently from 2e2a07d to 8a0920c Compare October 27, 2022 16:22
@josephschorr
Copy link
Member Author

Updated

Copy link
Contributor

@vroldanbet vroldanbet left a comment

Choose a reason for hiding this comment

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

Had final look, this is some complex stuff and I really appreciate how thorough you were with tests and comments. Could only find one test-test that seems to be missing, touches a portion of code that was untested, and is not giving the result (I, at least) expected

Once that's addressed this LGTM

EDIT: there is also a linter failure

internal/util/subjectset_test.go Outdated Show resolved Hide resolved
internal/util/basesubjectset.go Outdated Show resolved Hide resolved
@josephschorr
Copy link
Member Author

Updated

@josephschorr josephschorr force-pushed the ls-subjectset branch 2 times, most recently from f4aaae0 to 442752d Compare October 27, 2022 20:21
vroldanbet
vroldanbet previously approved these changes Oct 27, 2022
ecordell
ecordell previously approved these changes Nov 1, 2022
Copy link
Contributor

@ecordell ecordell left a comment

Choose a reason for hiding this comment

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

LGTM

I'm convinced this works 👍

Added some extra tests to convince myself in this branch, for future reference: josephschorr/spicedb@josephschorr:dc79c72...ecordell:3b6fbc6

ecordell
ecordell previously approved these changes Nov 1, 2022
@josephschorr josephschorr force-pushed the ls-subjectset branch 2 times, most recently from 4bb3acb to 23fe801 Compare November 3, 2022 00:55
@josephschorr
Copy link
Member Author

Updated and rewritten as discussed, and added additional tests

vroldanbet
vroldanbet previously approved these changes Nov 3, 2022
internal/util/basesubjectset.go Show resolved Hide resolved
internal/util/basesubjectset.go Outdated Show resolved Hide resolved
internal/util/basesubjectset.go Outdated Show resolved Hide resolved
internal/util/basesubjectset.go Outdated Show resolved Hide resolved
internal/util/basesubjectset.go Show resolved Hide resolved
internal/util/basesubjectset.go Show resolved Hide resolved
internal/util/basesubjectset.go Show resolved Hide resolved
internal/util/subjectset_test.go Outdated Show resolved Hide resolved
internal/util/subjectset_test.go Outdated Show resolved Hide resolved
internal/util/basesubjectset.go Outdated Show resolved Hide resolved
@josephschorr
Copy link
Member Author

Updated

vroldanbet
vroldanbet previously approved these changes Nov 3, 2022
@josephschorr
Copy link
Member Author

Updated

vroldanbet
vroldanbet previously approved these changes Nov 3, 2022
This is the first (massive) step in supporting caveats in LookupSubjects, as this implements all the bookkeeping and tracking associated with each subject added to the subject set

First part of authzed#931
Copy link
Contributor

@ecordell ecordell left a comment

Choose a reason for hiding this comment

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

test changes LGTM

@josephschorr josephschorr merged commit ce5587c into authzed:main Nov 7, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Nov 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/api v1 Affects the v1 API area/dispatch Affects dispatching of requests area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants