Fixed fetcher to not pick up environment variables it should not see. Review: https://reviews.apache.org/r/56711/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/e1c11f09 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/e1c11f09 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/e1c11f09 Branch: refs/heads/1.2.x Commit: e1c11f097ff091f9f30797a3d0c373e2f79960b5 Parents: 4683320 Author: Till Toenshoff <[email protected]> Authored: Thu Feb 23 01:53:42 2017 +0100 Committer: Till Toenshoff <[email protected]> Committed: Thu Feb 23 03:43:26 2017 +0100 ---------------------------------------------------------------------- src/slave/containerizer/fetcher.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/e1c11f09/src/slave/containerizer/fetcher.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/fetcher.cpp b/src/slave/containerizer/fetcher.cpp index 9ec38dc..34a5fbb 100644 --- a/src/slave/containerizer/fetcher.cpp +++ b/src/slave/containerizer/fetcher.cpp @@ -22,8 +22,10 @@ #include <process/dispatch.hpp> #include <process/owned.hpp> +#include <stout/hashset.hpp> #include <stout/net.hpp> #include <stout/path.hpp> +#include <stout/strings.hpp> #ifdef __WINDOWS__ #include <stout/windows.hpp> #endif // __WINDOWS__ @@ -45,6 +47,8 @@ using std::string; using std::transform; using std::vector; +using strings::startsWith; + using mesos::fetcher::FetcherInfo; using process::async; @@ -822,12 +826,27 @@ Future<Nothing> FetcherProcess::run( // We pass arguments to the fetcher program by means of an // environment variable. - map<string, string> environment = os::environment(); - - // The libprocess port is explicitly removed because this will conflict - // with the already-running agent. - environment.erase("LIBPROCESS_PORT"); - environment.erase("LIBPROCESS_ADVERTISE_PORT"); + // For assuring that we pass on variables that may be consumed by + // the mesos-fetcher, we whitelist them before masking out any + // unwanted agent->fetcher environment spillover. + // TODO(tillt): Consider using the `mesos::internal::logging::Flags` + // to determine the whitelist. + const hashset<string> whitelist = { + "MESOS_EXTERNAL_LOG_FILE", + "MESOS_INITIALIZE_DRIVER_LOGGING", + "MESOS_LOG_DIR", + "MESOS_LOGBUFSECS", + "MESOS_LOGGING_LEVEL", + "MESOS_QUIET" + }; + + map<string, string> environment; + foreachpair (const string& key, const string& value, os::environment()) { + if (whitelist.contains(strings::upper(key)) || + (!startsWith(key, "LIBPROCESS_") && !startsWith(key, "MESOS_"))) { + environment.emplace(key, value); + } + } environment["MESOS_FETCHER_INFO"] = stringify(JSON::protobuf(info));
