Skip to content

Conversation

@benjirewis
Copy link
Contributor

GODRIVER-2013

Adds tests to ensure that we are redacting security sensitive commands from command monitoring. Updates redactCommand to also redact hello when speculativeAuthenticate is present.

@benjirewis benjirewis marked this pull request as ready for review June 4, 2021 21:15
Copy link
Contributor

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

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

Looking good!

@benjirewis benjirewis requested a review from kevinAlbs June 8, 2021 20:11
Copy link
Contributor

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

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

LGTM with a minor simplification.

Copy link
Contributor

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

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

LGTM-even more!

@benjirewis
Copy link
Contributor Author

The new tests might change depending on the outcome of a new PR for DRIVERS-1653. I'll wait on that before merging.

supportedSchemaVersions = map[int]string{
1: "1.3",
// We do not fully support the 1.5 schema, but we need 1.5 to test with observeSensitiveCommands.
1: "1.5",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since censoring security-sensitive commands in command monitoring is a high priority, this was the suggested way to run the new 1.5 tests.

@benjirewis benjirewis requested a review from kevinAlbs June 18, 2021 05:42
Copy link
Contributor

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

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

LGTM

}
return false
}
return true
Copy link
Collaborator

Choose a reason for hiding this comment

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

Optional: Invert the ignoredCommands condition to make the function more readable.

E.g.

if _, ok := c.ignoredCommands[event.CommandName]; ok {
	return true
}
// Check if command is "hello" or legacy hello.
if event.CommandName == "hello" || strings.ToLower(event.CommandName) == "ismaster" {
	//...
}
return false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Way simpler! Thanks, inverted.

if _, ok := c.ignoredCommands[evt.CommandName]; !ok {
if !c.isIgnoredEvent(evt) {
events = append(events, evt)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we using startedEvents() to assert that an expected set of started events is published during a test? If so, why are we duplicating the command redaction logic in the test runner as well as in the driver? It seems more correct to adjust the expected set of started events in the test case, not redact them in the test runner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are two places in our specifications where we redact security-sensitive commands.

In the command monitoring spec, we require that drivers redact security-sensitive commands and replies at the operation level. This prevents security-sensitive information from appearing in logs or test output due to command monitoring.

In the unified test format:

ignoreCommandMonitoringEvents: Optional array of one or more strings. Command names for which the test runner MUST ignore any observed command monitoring events. The command(s) will be ignored in addition to configureFailPoint and any commands containing sensitive information (per the Command Monitoring spec) unless observeSensitiveCommands is true.

Writing tests and making sure that the expected set of events contains the correct auth-related commands can be problematic. Drivers differ on when certain auth-related commands are sent (particularly in setup), so a unified test runner that always monitors security-sensitive commands might produce different monitoring outputs depending on the driver and prevent a unified test.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool, thanks for the detailed explanation!

@benjirewis
Copy link
Contributor Author

Looks like more changes will be added in DRIVERS-1816 to further test that security-sensitive fields of commands are redacted and start testing that replies from the server are redacted as well.

Merging these changes for now, as I imagine that work will be done as part of a separate ticket.

@benjirewis benjirewis merged commit b945fbd into mongodb:master Jun 25, 2021
@benjirewis benjirewis deleted the commandMonitoringRedaction.2013 branch June 25, 2021 17:06
@benjirewis
Copy link
Contributor Author

FYI for posterity:

When tests are eventually added to test the redaction of replies from the server, a workaround for empty (redacted) Reply fields in CommandSucceededEvents similar to the existing workaround for empty (redacted) Command fields in CommandStartedEvents will need to be added here.

faem pushed a commit to kubedb/mongo-go-driver that referenced this pull request Mar 17, 2022
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.

3 participants