allow using wsl only when explicitly allowed by the user

Signed-off-by: Vitalii Koshura <lestat.de.lionkur@gmail.com>
This commit is contained in:
Vitalii Koshura 2024-08-16 12:54:54 +02:00
parent ecc6d7899c
commit f2c1511659
No known key found for this signature in database
GPG Key ID: CE0DB1726070A5A3
8 changed files with 64 additions and 8 deletions

View File

@ -262,7 +262,7 @@ void CLIENT_STATE::show_host_info() {
}
}
} else {
msg_printf(NULL, MSG_INFO, "No WSL found.");
msg_printf(NULL, MSG_INFO, "WSL is not found or not allowed to be used. For more details see https://github.com/BOINC/boinc/wiki/Client-configuration");
}
#endif
@ -280,13 +280,35 @@ void CLIENT_STATE::show_host_info() {
}
#endif
}
#ifndef _WIN64
if (host_info.docker_available && strlen(host_info.docker_version)) {
msg_printf(NULL, MSG_INFO, "Docker %s is installed and available", host_info.docker_version);
#else
if (host_info.docker_available) {
msg_printf(NULL, MSG_INFO, "Docker is installed and available");
msg_printf(NULL, MSG_INFO, "Docker is installed and available on next WSLs:");
for (size_t i = 0; i < host_info.wsls.wsls.size(); ++i) {
const WSL& wsl = host_info.wsls.wsls[i];
if (wsl.is_docker_available) {
msg_printf(NULL, MSG_INFO, " [%s]: Docker version is: %s", wsl.distro_name.c_str(), wsl.docker_version.c_str());
}
}
#endif
} else {
msg_printf(NULL, MSG_INFO, "Docker is not installed or is not available for running task");
}
#ifndef _WIN64
if (host_info.docker_compose_available && strlen(host_info.docker_compose_version)) {
msg_printf(NULL, MSG_INFO, "Docker compose %s is installed and available", host_info.docker_compose_version);
#else
if (host_info.docker_compose_available) {
msg_printf(NULL, MSG_INFO, "Docker compose is installed and available");
msg_printf(NULL, MSG_INFO, "Docker compose is installed and available on next WSLs:");
for (size_t i = 0; i < host_info.wsls.wsls.size(); ++i) {
const WSL& wsl = host_info.wsls.wsls[i];
if (wsl.is_docker_compose_available) {
msg_printf(NULL, MSG_INFO, " [%s]: Docker compose version is: %s", wsl.distro_name.c_str(), wsl.docker_compose_version.c_str());
}
}
#endif
} else {
msg_printf(NULL, MSG_INFO, "Docker compose is not installed or is not available for running task");
}

View File

@ -1669,7 +1669,7 @@ int HOST_INFO::get_host_info(bool init) {
if (!cc_config.dont_use_wsl) {
OSVERSIONINFOEX osvi;
if (get_OSVERSIONINFO(osvi) && osvi.dwMajorVersion >= 10) {
get_wsl_information(wsl_available, wsls, !cc_config.dont_use_docker, docker_available, docker_compose_available);
get_wsl_information(cc_config.allowed_wsls, wsl_available, wsls, !cc_config.dont_use_docker, docker_available, docker_compose_available);
}
}
#endif

View File

@ -20,7 +20,7 @@
#include "boinc_win.h"
#include "str_replace.h"
#include "client_msgs.h"
#include "hostinfo.h"
bool get_available_wsls(std::vector<std::pair<std::string, DWORD>>& wsls, std::string& default_wsl) {
@ -262,7 +262,7 @@ void parse_sysctl_output(const std::vector<std::string>& lines, std::string& ost
// Returns the OS name and version for WSL when enabled
//
int get_wsl_information(bool& wsl_available, WSLS& wsls, bool detect_docker, bool& docker_available, bool& docker_compose_available) {
int get_wsl_information(std::vector<std::string> allowed_wsls, bool& wsl_available, WSLS& wsls, bool detect_docker, bool& docker_available, bool& docker_compose_available) {
std::vector<std::pair<std::string, DWORD>> distros;
std::string default_distro;
@ -292,6 +292,12 @@ int get_wsl_information(bool& wsl_available, WSLS& wsls, bool detect_docker, boo
if (distro == "docker-desktop-data"){
continue;
}
// skip distros that are not allowed except for 'docker-desktop'
if (distro != "docker-desktop" && std::find(allowed_wsls.begin(), allowed_wsls.end(), distro) == allowed_wsls.end()) {
msg_printf(0, MSG_INFO, "WSL distro '%s' detected but is not allowed", distro.c_str());
continue;
}
WSL wsl;
wsl.distro_name = distro;
if (distro == default_distro) {

View File

@ -198,6 +198,11 @@ void CC_CONFIG::show() {
if (dont_use_wsl) {
msg_printf(NULL, MSG_INFO, "Config: don't use the Windows Subsystem for Linux");
}
for (i=0; i<allowed_wsls.size(); i++) {
msg_printf(NULL, MSG_INFO,
"Config: allowed WSL: %s", allowed_wsls[i].c_str()
);
}
if (dont_use_docker) {
msg_printf(NULL, MSG_INFO, "Config: don't use the Docker");
}
@ -376,6 +381,10 @@ int CC_CONFIG::parse_options_client(XML_PARSER& xp) {
if (xp.parse_bool("dont_suspend_nci", dont_suspend_nci)) continue;
if (xp.parse_bool("dont_use_vbox", dont_use_vbox)) continue;
if (xp.parse_bool("dont_use_wsl", dont_use_wsl)) continue;
if (xp.parse_string("allowed_wsl", s)) {
allowed_wsls.push_back(s);
continue;
}
if (xp.parse_bool("dont_use_docker", dont_use_docker)) continue;
if (xp.match_tag("exclude_gpu")) {
EXCLUDE_GPU eg;

View File

@ -215,6 +215,7 @@ void CC_CONFIG::defaults() {
dont_suspend_nci = false;
dont_use_vbox = false;
dont_use_wsl = false;
allowed_wsls.clear();
dont_use_docker = false;
exclude_gpus.clear();
exclusive_apps.clear();
@ -350,6 +351,10 @@ int CC_CONFIG::parse_options(XML_PARSER& xp) {
if (xp.parse_bool("dont_use_vbox", dont_use_vbox)) continue;
if (xp.parse_bool("dont_use_docker", dont_use_docker)) continue;
if (xp.parse_bool("dont_use_wsl", dont_use_wsl)) continue;
if (xp.parse_string("allowed_wsl", s)) {
allowed_wsls.push_back(s);
continue;
}
if (xp.match_tag("exclude_gpu")) {
EXCLUDE_GPU eg;
retval = eg.parse(xp);
@ -579,6 +584,13 @@ int CC_CONFIG::write(MIOFILE& out, LOG_FLAGS& log_flags) {
dont_use_docker
);
for (i=0; i<allowed_wsls.size(); ++i) {
out.printf(
" <allowed_wsl>%s</allowed_wsl>\n",
allowed_wsls[i].c_str()
);
}
for (i=0; i<exclude_gpus.size(); i++) {
exclude_gpus[i].write(out);
}

View File

@ -151,7 +151,7 @@ struct EXCLUDE_GPU {
// client/log_flags.cpp:
// parse_options_client()
// possibly show()
// the web doc: https://boinc.berkeley.edu/wiki/Client_configuration
// the web doc: https://github.com/BOINC/boinc/wiki/Client-configuration
//
struct CC_CONFIG {
bool abort_jobs_on_exit;
@ -167,6 +167,7 @@ struct CC_CONFIG {
bool dont_suspend_nci;
bool dont_use_vbox;
bool dont_use_wsl;
std::vector<std::string> allowed_wsls;
bool dont_use_docker;
std::vector<EXCLUDE_GPU> exclude_gpus;
std::vector<std::string> exclusive_apps;

View File

@ -372,6 +372,9 @@ bool HOST_INFO::get_docker_version_string(std::string raw, std::string& parsed)
return false;
}
parsed = raw.substr(pos1 + prefix.size() + 1, pos2 - pos1 - prefix.size() - 1);
if (!parsed.empty() && parsed[parsed.length() - 1] == '\n') {
parsed.erase(parsed.length() - 1);
}
return true;
}
bool HOST_INFO::get_docker_compose_version_string(std::string raw, std::string& parsed) {
@ -381,6 +384,9 @@ bool HOST_INFO::get_docker_compose_version_string(std::string raw, std::string&
return false;
}
parsed = raw.substr(pos1 + prefix.size(), raw.size() - pos1 - prefix.size());
if (!parsed.empty() && parsed[parsed.length() - 1] == '\n') {
parsed.erase(parsed.length() - 1);
}
return true;
}

View File

@ -172,7 +172,7 @@ public:
extern void make_secure_random_string(char*);
#ifdef _WIN64
extern int get_wsl_information(bool& wsl_available, WSLS& wsls, bool detect_docker, bool& docker_available, bool& docker_compose_available);
extern int get_wsl_information(std::vector<std::string> allowed_wsls, bool& wsl_available, WSLS& wsls, bool detect_docker, bool& docker_available, bool& docker_compose_available);
extern int get_processor_group(HANDLE);
#endif