diff --git a/tensorboard/plugins/core/core_plugin.py b/tensorboard/plugins/core/core_plugin.py index 4eeaf7acb6..56fdf0bb80 100644 --- a/tensorboard/plugins/core/core_plugin.py +++ b/tensorboard/plugins/core/core_plugin.py @@ -533,6 +533,18 @@ def define_flags(self, parser): optional and has no effect. The path_prefix can be leveraged for path based routing of an ELB when the website base_url is not available e.g. "example.site.com/path/to/tensorboard/".\ +""", + ) + +parser.add_argument( + "--path_prefix_from_file", + metavar="PATH", + type=str, + default="", + help="""\ +Read the path_prefix from the specified file; avoids the path being +visible by ps or top - and, thus, is useful to improve security on +multi-user systems.\ """, ) @@ -711,6 +723,16 @@ def fix_flags(self, flags): "--detect_file_replacement=true" ) + if flags.path_prefix_from_file and flags.path_prefix is None: + try: + with open(flags.path_prefix_from_file, 'r') as f: + flags.path_prefix = (f.read()).rstrip() + print("NOTE: using path_prefix=" + flags.path_prefix + " as read from file") + except IOError: + raise FlagsError("Cannot read prefix_from_file") + elif: + print("NOTE: Skipping prefix_from_file input due to overwrite by path_prefix") + flags.path_prefix = flags.path_prefix.rstrip("/") if flags.path_prefix and not flags.path_prefix.startswith("/"): raise FlagsError(