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

chore(zetaclient): mask compliance addresses #3216

Merged
merged 2 commits into from
Nov 26, 2024

Conversation

gartnera
Copy link
Member

@gartnera gartnera commented Nov 25, 2024

Mask compliance addresses to prevent log spam on zetaclient. We configure hundreds/thousands of these which are currently spamming the logs every zetaclient boot.

Reference: https://github.com/showa-93/go-mask?tab=readme-ov-file#mask-tags

Summary by CodeRabbit

  • New Features
    • Enhanced privacy measures for handling sensitive data by masking restricted addresses in the compliance configuration.

Copy link
Contributor

coderabbitai bot commented Nov 25, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes involve an update to the ComplianceConfig struct in the zetaclient/config/types.go file. The RestrictedAddresses field has been modified to include a mask:"zero" tag, which ensures that addresses in this field are masked during processing. This adjustment aims to enhance data privacy for sensitive information without altering other configurations or methods within the file.

Changes

File Path Change Summary
zetaclient/config/types.go Updated RestrictedAddresses field in ComplianceConfig struct to include mask:"zero" tag.

Suggested labels

PERFORMANCE_TESTS

Suggested reviewers

  • lumtis
  • fbac
  • kingpinXD
  • swift1337
  • skosito
  • brewmaster012

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
zetaclient/config/types.go (1)

70-72: Consider masking additional sensitive fields

While masking RestrictedAddresses is a good start, consider evaluating whether LogPath in ComplianceConfig could contain sensitive information that should also be masked.

If the log path could contain sensitive information (e.g., usernames in paths), consider adding masking:

 type ComplianceConfig struct {
-	LogPath             string   `json:"LogPath"`
+	LogPath             string   `json:"LogPath" mask:"filled"`
 	RestrictedAddresses []string `json:"RestrictedAddresses" mask:"zero"`
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 771317f and c47f88a.

📒 Files selected for processing (1)
  • zetaclient/config/types.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
zetaclient/config/types.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

🔇 Additional comments (1)
zetaclient/config/types.go (1)

71-71: Verify masking doesn't affect address comparison

The masking implementation correctly only affects the string representation while preserving the actual address values for comparison in GetRestrictedAddressBook(). However, let's verify this behavior.

Also applies to: 184-192

✅ Verification successful

Masking implementation is safe for address comparison

The masking directive mask:"zero" on RestrictedAddresses only affects logging representation while preserving the actual functionality:

  • Address comparison in ContainRestrictedAddress uses strings.ToLower for case-insensitive matching
  • The actual addresses are stored in restrictedAddressBook and used for comparison
  • Test cases in compliance_test.go verify the correct behavior with various address scenarios
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the masking implementation in other parts of the codebase
# only affects logging and not the actual address comparison logic

# Search for direct usage of RestrictedAddresses
rg -l "ComplianceConfig.*RestrictedAddresses|RestrictedAddresses.*ComplianceConfig" --type go

# Search for potential logging of these addresses
rg "log\.[A-Za-z]+\(.*RestrictedAddresses" --type go

Length of output: 363


Script:

#!/bin/bash
# Let's examine how RestrictedAddresses are used in the compliance logic

# Check the implementation of GetRestrictedAddressBook and related functions
ast-grep --pattern 'func $$$GetRestrictedAddressBook$$$($$$) $$$'

# Check the test files to understand the behavior
cat zetaclient/compliance/compliance_test.go

Length of output: 1955


Script:

#!/bin/bash
# Let's examine the actual implementation of address comparison logic

# Check for IsCctxRestricted implementation
ast-grep --pattern 'func IsCctxRestricted($$$) bool {
  $$$
}'

# Look for any address normalization or comparison logic
rg -A 5 "strings\.ToLower.*RestrictedAddresses|RestrictedAddresses.*strings\.ToLower" --type go

Length of output: 612


Script:

#!/bin/bash
# Let's check the ContainRestrictedAddress implementation

# Look for ContainRestrictedAddress function
ast-grep --pattern 'func ContainRestrictedAddress($$$) bool {
  $$$
}'

# Check for any address comparison or normalization in config package
rg -A 5 "func.*ContainRestrictedAddress|strings\.EqualFold.*RestrictedAddresses" zetaclient/config/

Length of output: 958

zetaclient/config/types.go Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
zetaclient/config/types.go (1)

71-71: Consider documenting the masking behavior

Add a comment explaining that the addresses are masked in logs to reduce spam.

type ComplianceConfig struct {
	LogPath             string   `json:"LogPath"`
+	// RestrictedAddresses are masked in logs to reduce boot-time spam
	RestrictedAddresses []string `json:"RestrictedAddresses" mask:"zero"`
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 771317f and c47f88a.

📒 Files selected for processing (1)
  • zetaclient/config/types.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
zetaclient/config/types.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

🔇 Additional comments (1)
zetaclient/config/types.go (1)

71-71: Verify the impact on GetRestrictedAddressBook()

The masking should not affect the actual address values used in GetRestrictedAddressBook().

✅ Verification successful

Masking of RestrictedAddresses does not affect compliance checks

The verification confirms that the masking of RestrictedAddresses does not impact the actual address values used in compliance checks. The implementation shows:

  1. GetRestrictedAddressBook() directly uses the raw values from RestrictedAddresses to build a lookup map
  2. This map is stored in a package-level variable restrictedAddressBook and used for all compliance checks
  3. The compliance system correctly enforces restrictions through IsCctxRestricted() which uses these unmasked values
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that GetRestrictedAddressBook() is not using masked values

# Search for any direct usage of masked addresses
ast-grep --pattern 'GetRestrictedAddressBook()' -A 10

Length of output: 55


Script:

#!/bin/bash
# Let's try a different approach to find the implementation and usage of GetRestrictedAddressBook

# First, find the function definition
ast-grep --pattern 'func $_($$$) GetRestrictedAddressBook($$$) {
  $$$
}'

# Also search for any usage of RestrictedAddresses field
rg "RestrictedAddresses" -A 5

Length of output: 8717


Script:

#!/bin/bash
# Let's find the implementation of GetRestrictedAddressBook and how the values are used

# Search for the function implementation
rg -A 10 "func.*GetRestrictedAddressBook"

# Search for where this function is used
rg "GetRestrictedAddressBook\(" -A 3

Length of output: 1247


Script:

#!/bin/bash
# Let's find where restrictedAddressBook is used to understand the complete flow

rg "restrictedAddressBook" -A 3

# Also check if there are any other functions that might be using the restricted addresses
rg "IsAddressRestricted|IsCctxRestricted" -A 5

Length of output: 6910

zetaclient/config/types.go Show resolved Hide resolved
@gartnera gartnera marked this pull request as draft November 26, 2024 01:48
@gartnera gartnera marked this pull request as ready for review November 26, 2024 16:44
Copy link

codecov bot commented Nov 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.06%. Comparing base (771317f) to head (965029e).
Report is 3 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3216      +/-   ##
===========================================
- Coverage    62.38%   62.06%   -0.32%     
===========================================
  Files          427      428       +1     
  Lines        30416    30439      +23     
===========================================
- Hits         18974    18891      -83     
- Misses       10596    10708     +112     
+ Partials       846      840       -6     
Files with missing lines Coverage Δ
zetaclient/config/types.go 50.64% <100.00%> (+0.64%) ⬆️

... and 12 files with indirect coverage changes

@gartnera gartnera enabled auto-merge November 26, 2024 17:03
@gartnera gartnera added this pull request to the merge queue Nov 26, 2024
Merged via the queue into develop with commit f23fd40 Nov 26, 2024
41 checks passed
@gartnera gartnera deleted the mask-compliance-addresss branch November 26, 2024 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog Skip changelog CI check
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants