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

Add feature to hide sensitive data in logs #115

Merged
merged 3 commits into from
Dec 12, 2023

Conversation

ahangarha
Copy link
Contributor

@ahangarha ahangarha commented Nov 22, 2023

With this implementation, we can set the sensitive data pattern in the closest place to the sensitive data. This can (hopefully) prevent accidental typos in pattern matching.

I couldn't implement test for this feature.


Closes #97

@ahangarha ahangarha changed the title Hide sensitive data in logs Add feature to hide sensitive data in logs Nov 22, 2023
lib/core/controlplane.rb Outdated Show resolved Hide resolved
lib/core/controlplane.rb Outdated Show resolved Hide resolved
lib/core/controlplane.rb Outdated Show resolved Hide resolved
lib/core/controlplane.rb Outdated Show resolved Hide resolved
lib/core/controlplane.rb Outdated Show resolved Hide resolved
@ahangarha
Copy link
Contributor Author

Having it in a single place (probably in the Shell class, since it implements debug) would make it easier to update later on, and easier to find all patterns.

I initially thought about this but dropped it because

  • That means we pass many other strings through that hiding process for no reason. We have a small number of debugging logs for now. But let's say we add more items to be shown in verbose mode. That time, we should process so many texts where we know there is no sensitive data.
  • Shell class shouldn't know about sensitive data passed to its methods.
  • Separating the patterns from where they get generated increases the chance of leaving out some old and unused patterns. Keeping the pattern close to where it is related to, helps us to make minimal regex for that case only.

Still, if we are sure that we are not going to have any other pattern in the future, we can simplify the logic. In that case, using class constant is a good solution.

@justin808 justin808 marked this pull request as draft November 25, 2023 03:36
@rafaelgomesxyz
Copy link
Collaborator

I initially thought about this but dropped it because

  • That means we pass many other strings through that hiding process for no reason. We have a small number of debugging logs for now. But let's say we add more items to be shown in verbose mode. That time, we should process so many texts where we know there is no sensitive data.
  • Shell class shouldn't know about sensitive data passed to its methods.
  • Separating the patterns from where they get generated increases the chance of leaving out some old and unused patterns. Keeping the pattern close to where it is related to, helps us to make minimal regex for that case only.

Still, if we are sure that we are not going to have any other pattern in the future, we can simplify the logic. In that case, using class constant is a good solution.

My main concern is repetition, since the current implementation means that we'll have a hide_sensitive_data method in each class that logs sensitive data.

Why don't we move hide_sensitive_data to a helper and have it accept the pattern as a param? Then we can use it like:

hide_sensitive_data(message, pattern)

We could then add a sensitive_data_pattern param to the perform and perform! methods, that defaults to nil, and use the params for passing the pattern around, instead of an instance variable.

@ahangarha
Copy link
Contributor Author

We could then add a sensitive_data_pattern param to the perform and perform! methods

I thought about this too. The issue with this is that it is strange to call a method for performing some action but also it accept parameters unrelated to what it is supposed to do. (though it already does more than one thing).

I thought it is better to not change the parameters and limit the changes in the implementation only.

Why don't we move hide_sensitive_data to a helper and have it accept the pattern as a param?

I think this is good. I do it 👍🏾

@ahangarha ahangarha marked this pull request as ready for review November 30, 2023 11:48
Copy link
Collaborator

@rafaelgomesxyz rafaelgomesxyz left a comment

Choose a reason for hiding this comment

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

Approved with one small thing, no need for re-review.

lib/core/shell.rb Outdated Show resolved Hide resolved
lib/core/shell.rb Outdated Show resolved Hide resolved
@ahangarha ahangarha requested a review from justin808 December 2, 2023 19:27
@rafaelgomesxyz rafaelgomesxyz merged commit 6f5acc3 into main Dec 12, 2023
9 checks passed
@rafaelgomesxyz rafaelgomesxyz deleted the hide-sensitive-data-in-verbose-mode branch December 12, 2023 17:03
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.

Feature: Prevent logging sensitive data in verbose mode
3 participants