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

plugins/logs: Fixes unintended mutation of result #2808

Merged
merged 1 commit into from
Oct 27, 2020
Merged

plugins/logs: Fixes unintended mutation of result #2808

merged 1 commit into from
Oct 27, 2020

Conversation

gshively11
Copy link
Contributor

When mask rules targeted /result, it was modifying both the result
in the decision logs (intended) and the result in the API
response (unintended). Added a step to deep copy the result only once, if
there is at least one mask rule targeting the result.

Fixes #2752
Signed-off-by: Grant Shively [email protected]

Copy link
Member

@tsandall tsandall left a comment

Choose a reason for hiding this comment

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

@gshively11 thanks for submitting this! Left a few comments on the implementation.

plugins/logs/plugin.go Outdated Show resolved Hide resolved
plugins/logs/plugin.go Outdated Show resolved Hide resolved
plugins/logs/plugin_test.go Outdated Show resolved Hide resolved
@gshively11
Copy link
Contributor Author

Let me know if that OnError pattern is idiomatic for golang...I wasn't sure how to handle the logging since previously the iteration was in plugin.go, which had access to the plugin logger, but doesn't in mask.go, and I didn't want to pass the whole plugin in...

Copy link
Member

@tsandall tsandall left a comment

Choose a reason for hiding this comment

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

Just one comment about adding some test coverage for the deep copy utility. Other than that, LGTM.

// DeepCopy performs a recursive deep copy for nested slices/maps and
// returns the copied object. Supports []interface{}
// and map[string]interface{} only
func DeepCopy(val interface{}) interface{} {
Copy link
Member

Choose a reason for hiding this comment

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

nit: I'd add some test coverage here now that this is exposed for re-use within the rest of OPA.

@@ -254,20 +261,20 @@ func (r maskRule) mkdirp(node map[string]interface{}, path []string, value inter
return nil
}

func resultValueToMaskRules(rv interface{}) ([]*maskRule, error) {

func newMaskRuleSet(rv interface{}, onRuleError func(*maskRule, error)) (*maskRuleSet, error) {
Copy link
Member

Choose a reason for hiding this comment

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

onRuleError looks fine to me; definitely better than creating a cyclic dependency or adding logging into the mask.go file.

@gshively11
Copy link
Contributor Author

I spent a while trying to make something that could recursively compare the reference of the deep copy target/result, but I just don't have enough golang experience to pull that off, so I just went with this more simplistic mutation test, hope that's ok.

tsandall
tsandall previously approved these changes Oct 26, 2020
Copy link
Member

@tsandall tsandall left a comment

Choose a reason for hiding this comment

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

LGTM. @gshively11 can you squash your commits? Once that's done we can merge this.

When mask rules targeted /result, it was modifying both the result
in the decision logs (intended) and the result in the API
response (unintended). Added a step to deep copy the result only once, if
there is at least one mask rule targeting the result.

Fixes #2752
Signed-off-by: Grant Shively <[email protected]>
Copy link
Member

@tsandall tsandall left a comment

Choose a reason for hiding this comment

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

LGTM

@tsandall tsandall merged commit 99a8143 into open-policy-agent:master Oct 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mask data in decision log, but not /v1/data response.
2 participants