Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

V2-telemetry: Simplify sensitive metadata allowlist to accept feature only#63325

Merged
akalia25 merged 28 commits into
mainfrom
ak/update-sensitivemetadataallowlist-to-accept-feature-only
Jun 27, 2024
Merged

V2-telemetry: Simplify sensitive metadata allowlist to accept feature only#63325
akalia25 merged 28 commits into
mainfrom
ak/update-sensitivemetadataallowlist-to-accept-feature-only

Conversation

@akalia25

@akalia25 akalia25 commented Jun 18, 2024

Copy link
Copy Markdown
Contributor

This PR adds another option to the sensitive metadata allowlist by simplifying the input requirements. to accept feature and the allowlisted privateMetadata keys for that feature.

This change is particularly beneficial when a feature has multiple associated action(s), and the privateMetadata key needs to be allowed for all events related to that feature.

Building upon this initial PR:

Test plan

CI and unit tests

Changelog

@cla-bot cla-bot Bot added the cla-signed label Jun 18, 2024
@akalia25 akalia25 changed the title update to only require feature when creating sensitive metadata allow… V2-telemetry: Simplify sensitive metadata allowlist to accept feature only Jun 18, 2024
@akalia25 akalia25 requested review from bobheadxi and jac June 18, 2024 22:40
@akalia25 akalia25 marked this pull request as ready for review June 18, 2024 22:41
@bobheadxi

bobheadxi commented Jun 18, 2024

Copy link
Copy Markdown
Member

@akalia25 ah, I misunderstood - I was hoping we could make action optional, not always omitted. Could we do that instead here?

In env var maybe the action segment could accept "-" to omit it, eg feature::-::..., and in code we don't check the action if it's empty

@akalia25 akalia25 marked this pull request as draft June 18, 2024 22:58
@akalia25 akalia25 marked this pull request as ready for review June 21, 2024 15:22
Comment thread internal/telemetry/sensitivemetadataallowlist/sensitivemetadataallowlist.go Outdated
Comment thread internal/telemetry/sensitivemetadataallowlist/sensitivemetadataallowlist.go Outdated
Comment thread internal/telemetry/sensitivemetadataallowlist/sensitivemetadataallowlist.go Outdated
Comment thread internal/telemetry/sensitivemetadataallowlist/sensitivemetadataallowlist.go Outdated
Comment thread internal/telemetry/sensitivemetadataallowlist/sensitivemetadataallowlist.go Outdated
func TestEventTypesRedact(t *testing.T) {
allowedTypes := eventTypes(EventType{
Feature: "example",
Action: "exampleAction",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Removing this should cause a failure right? Empty value is unsupported, only explicit wildcard is supported

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Either way, these tests should remain unchanged to ensure the existing behaviour works. What should happen instead is you add a few new test cases that demonstrate the wildcard behaviour

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is the test I added for the wildcard behavior, should I add more?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That one tests "is allowed", this test is TestEventTypesRedact which tests redaction. If redaction behaviour is unchanged, then the tests should remain unchanged as well

(i.e. just remove all your changes to this test :) )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ahhh whoops 🙈 sorry, got the tests mixed up. No change to the redaction logic. I'll remove this. Thank you!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the changes I had for TestEventTypesRedact and added a new test allowlisted, with wildcard(*) action match and the expected redaction it should do. Let me know if it's unnecessary and I can remove that . Thanks again!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's a good test to have, thanks! Can you add an assertion on the resulting data?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the function directly mutates the value you give it

Comment on lines -44 to +49
name: "disallowed event with additional allowed event type",
name: "disallowed event with additional allowed event type (feature only)",
event: &v1.Event{
Feature: "cody.completion",
Action: "accepted",
Action: "*",
},
expectAllowed: true,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This might be a carry-over from what was here before, but the test case says "disallowed event" but the result is expectAllowed: true, it sounds like the test name is incorrect?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, I think the test name is confusing. I tried keeping the same convention, and had to interpret it like this event has privateMetadata ("disallowed event") and there is an allowlist of keys ("with additional allowed event type"). I'll update to make more clear?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the test case should say, "event with private metadata, that has fields it is allwoed to export"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated with new naming :)

Comment on lines 55 to 60
name: "disallowed event with additional allowed event type",
event: &v1.Event{
Feature: "cody.hoverCommands",
Action: "visible",
},
expectAllowed: true,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same here, the test case says "disallowed event" but the result is expectAllowed: true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated with new naming

Comment on lines +114 to +115
Feature: "baz.bar",
AllowedPrivateMetadataKeys: []string{"field"},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't the expected result here have Action: "*"?

type EventTypes struct {
types []EventType
// index of '{feature}.{action}:{allowedfields}' for checking
// index of '{feature}:{action}:{allowedfields}' for checking

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// index of '{feature}:{action}:{allowedfields}' for checking
// index of '{feature}/{action}:{allowedfields}' for checking

Comment on lines +246 to +258
// add condition that if Action is "*"
if parts[1] == "*" {
types = append(types, EventType{
Feature: parts[0],
AllowedPrivateMetadataKeys: parts[2:],
})
} else {
types = append(types, EventType{
Feature: parts[0],
Action: parts[1],
AllowedPrivateMetadataKeys: parts[2:],
})
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this is needed because we should have Action: "*" explicitly right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct! this is not needed, and this was also affecting this, because we would not get back action: * on EventType. Updated this. Thank you!

Comment thread internal/telemetry/sensitivemetadataallowlist/sensitivemetadataallowlist.go Outdated
Comment thread internal/telemetry/sensitivemetadataallowlist/sensitivemetadataallowlist_test.go Outdated
Comment thread internal/telemetry/sensitivemetadataallowlist/sensitivemetadataallowlist_test.go Outdated
Comment thread internal/telemetry/sensitivemetadataallowlist/sensitivemetadataallowlist_test.go Outdated
event: &v1.Event{
Feature: "cody.completion",
Action: "accepted",
Action: "*",

@bobheadxi bobheadxi Jun 27, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is the event that goes into the "is allowed" check, I think there shouldn't be a wildcard here? We can note that this is defined as a wildcard in the "is allowed" check's list of known events

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Action: "*",
Action: "accepted",

event: &v1.Event{
Feature: "cody.completion",
Action: "accepted",
Action: "Accepted",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

per naming convention:

Suggested change
Action: "Accepted",
Action: "accepted",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ahh 🤦 thank you, sorry about that!

Comment on lines +223 to +225
mode := allowedTypes.Redact(ev)

assert.Equal(t, redactMarketingAndUnallowedPrivateMetadataKeys, mode)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for another spacing nit 😆

Suggested change
mode := allowedTypes.Redact(ev)
assert.Equal(t, redactMarketingAndUnallowedPrivateMetadataKeys, mode)
mode := allowedTypes.Redact(ev)
assert.Equal(t, redactMarketingAndUnallowedPrivateMetadataKeys, mode)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh you're good! Do you have a linter you use, I'm surprised its not auto-corrected sometimes

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No, this is just eyeing it and see if it looks good to read :)

@bobheadxi bobheadxi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice work!

@akalia25 akalia25 merged commit 0777ced into main Jun 27, 2024
@akalia25 akalia25 deleted the ak/update-sensitivemetadataallowlist-to-accept-feature-only branch June 27, 2024 19:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants