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

Catch nil values for FoundSubjectsByResourceID map and return as errors #1008

Merged
merged 1 commit into from
Nov 21, 2022

Conversation

josephschorr
Copy link
Member

Also ensure we never add nils in the first place

@josephschorr josephschorr requested a review from a team November 21, 2022 19:43
@github-actions github-actions bot added the area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) label Nov 21, 2022
@josephschorr josephschorr requested a review from jakedt November 21, 2022 19:45
@@ -460,7 +464,10 @@ func (lsu *lookupSubjectsUnion) CompletedChildOperations() error {

for _, result := range collector.Results() {
metadata = combineResponseMetadata(metadata, result.Metadata)
foundSubjects.UnionWith(result.FoundSubjectsByResourceId)
err := foundSubjects.UnionWith(result.FoundSubjectsByResourceId)
Copy link
Member

Choose a reason for hiding this comment

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

You should use the if err := thing(); err != nil pattern here and at other callsites.

foundSubjects.UnionWith(result.FoundSubjectsByResourceId)
err := foundSubjects.UnionWith(result.FoundSubjectsByResourceId)
if err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

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

Wrap these errors with higher level context about why you were trying to Union, so we can trace which callsite caused the problem.

@@ -36,12 +42,22 @@ func (ssr SubjectSetByResourceID) AddFromRelationship(relationship *core.Relatio
}

// UnionWith unions the map's sets with the other map of sets provided.
func (ssr SubjectSetByResourceID) UnionWith(other map[string]*v1.FoundSubjects) {
func (ssr SubjectSetByResourceID) UnionWith(other map[string]*v1.FoundSubjects) error {
Copy link
Member

Choose a reason for hiding this comment

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

Can you create a test which reproduces why this happens in real running-systems to verify the fix?

@josephschorr
Copy link
Member Author

Updated

for _, subject := range subjects.FoundSubjects {
ssr.add(resourceID, subject)
err := ssr.add(resourceID, subject)
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 := ...; err != nil

Also ensure we never add nils in the first place
@josephschorr josephschorr merged commit 7f3f207 into authzed:main Nov 21, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Nov 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
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.

2 participants