Skip to content

print_config to hide user info #6471

Closed

Description

@wyli

Is your feature request related to a problem? Please describe.

print(f"MONAI __file__: {monai.__file__}")

print_config is extensively used in the notebooks, and would be great to make sure the output not leaking any user-specific information such as /home/username

Activity

  1. owais8 commented on Jul 4, 2023

    @owais8

    Heyy @wyli Just wanted to check if this issue is still open?

  2. wyli commented on Jul 4, 2023

    @wyli
    ContributorAuthor

    yes @owais8 please feel free to create a pull request.

  3. anudeepadi commented on Jul 15, 2023

    @anudeepadi
    Contributor

    Hey @wyli I have noticed there isn't any pull request for this issue and I would like to work on it if it is still open to my knowledge I think I have to replace the code in deviceconfig.py to replace the user's home directory with a generic representation using the os.path.expanduser('~') method.

  4. wyli commented on Jul 15, 2023

    @wyli
    ContributorAuthor

    Thanks @anudeepadi, the goal of the print is to provide diagnostic info about where monai is actually located in user's system, but the usernames in the logs should be masked out. Perhaps you can do it with a simple regex replacing, or if you are interested, feel free to enhance the monai logger to have a generic filter to hide sensitive info.

    https://github.com/Project-MONAI/MONAI/blob/3b6b11a815b2de9e2b1bc1f1dbbca4e66189458f/monai/apps/utils.py#L48C1-L48C1

    Please have a look at the contrib doc https://github.com/Project-MONAI/MONAI/blob/dev/CONTRIBUTING.md and let me know if you have questions regarding new pull requests.

  5. anudeepadi commented on Aug 29, 2023

    @anudeepadi
    Contributor

    Hello @wyli,

    I've worked on the feature to mask out usernames in the print_config function to prevent leaking user-specific information. I've tested the function for paths in different operating systems, and it looks good. The function now masks the username from paths and retains all other information for diagnostic purposes.

    I apologize for the delay in getting to this, and I appreciate your patience.

    Could you please review the code and let me know if anything else is needed before I can raise a pull request?

    import re
    
    def print_config(file=sys.stdout):
        """
        Print the package versions to `file`.
    
        Args:
            file: `print()` text stream file. Defaults to `sys.stdout`.
        """
    
        for k, v in get_config_values().items():
            print(f"{k} version: {v}", file=file, flush=True)
        
        print(f"MONAI flags: HAS_EXT = {HAS_EXT}, USE_COMPILED = {USE_COMPILED}, USE_META_DICT = {USE_META_DICT}")
        print(f"MONAI rev id: {monai.__revision_id__}")
        
        masked_file_path = re.sub(r'/home/\w+/', '/home/<username>/',
                                  re.sub(r'/Users/\w+/', '/Users/<username>/',
                                         re.sub(r'C:\\Users\\\w+\\', r'C:\\Users\\<username>\\',
                                                monai.__file__)))
        
        print(f"MONAI __file__: {masked_file_path}", file=file, flush=True)
    
        print("\nOptional dependencies:", file=file, flush=True)
        for k, v in get_optional_config_values().items():
            print(f"{k} version: {v}", file=file, flush=True)
        print("\nFor details about installing the optional dependencies, please visit:", file=file, flush=True)
        print(
            "    https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies\n",
            file=file,
            flush=True,
        )
  6. wyli commented on Aug 29, 2023

    @wyli
    ContributorAuthor

    thanks @anudeepadi, that's a nice starting point. please submit a pull request https://github.com/Project-MONAI/MONAI/blob/dev/CONTRIBUTING.md#preparing-pull-requests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions