From 58ca5cc2a8196a3274de78685f6c62ffd4619557 Mon Sep 17 00:00:00 2001 From: jveh Date: Mon, 31 Jan 2022 15:08:48 +0100 Subject: [PATCH] add path_prefix_from_file option, adding security by obscurity. This option is helpful on multi-user systems. --- tensorboard/plugins/core/core_plugin.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tensorboard/plugins/core/core_plugin.py b/tensorboard/plugins/core/core_plugin.py index 39e673daa8..1cc39a7b48 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.\ """, ) @@ -684,6 +696,16 @@ def fix_flags(self, flags): elif flags.host is not None and flags.bind_all: raise FlagsError("Must not specify both --host and --bind_all.") + 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(