mirror of
https://github.com/openappsec/openappsec.git
synced 2025-09-29 11:16:30 +03:00
Feb_06_2024-Dev
This commit is contained in:
@@ -69,19 +69,11 @@ checkIDP(shared_ptr<istream> file_stream)
|
||||
#if defined(gaia) || defined(smb)
|
||||
|
||||
Maybe<string>
|
||||
checkIsCpviewRunning(const string &command_output)
|
||||
checkIsInstallHorizonTelemetrySucceeded(const string &command_output)
|
||||
{
|
||||
if (command_output == "true" || command_output == "false") return command_output;
|
||||
if (command_output == "" ) return string("false");
|
||||
|
||||
return genError("cpview is not running");
|
||||
}
|
||||
|
||||
Maybe<string>
|
||||
checkIsCPotelcolGRET64(const string &command_output)
|
||||
{
|
||||
if (command_output == "true" || command_output == "false") return command_output;
|
||||
|
||||
return genError("CPotelcol is not installed or its take is below T64");
|
||||
return command_output;
|
||||
}
|
||||
|
||||
Maybe<string>
|
||||
@@ -103,6 +95,10 @@ checkCanUpdateSDWanData(const string &command_output)
|
||||
Maybe<string>
|
||||
getMgmtObjType(const string &command_output)
|
||||
{
|
||||
if (getenv("WAAP_DIR")) {
|
||||
return string("CloudGuard WAF Gateway");
|
||||
}
|
||||
|
||||
if (!command_output.empty()) {
|
||||
if (command_output[0] == '1') return string("management");
|
||||
if (command_output[0] == '0') return string("gateway");
|
||||
|
@@ -39,14 +39,10 @@ SHELL_PRE_CMD("read sdwan data",
|
||||
#ifdef SHELL_CMD_HANDLER
|
||||
#if defined(gaia) || defined(smb)
|
||||
SHELL_CMD_HANDLER("cpProductIntegrationMgmtObjectType", "cpprod_util CPPROD_IsMgmtMachine", getMgmtObjType)
|
||||
SHELL_CMD_HANDLER("isCpviewRunning",
|
||||
"pidof cpview_api_service > /dev/null 2>&1 && [ -f $CPDIR/conf/cpview_api_service.version ] "
|
||||
"&& echo 'true' || echo 'false'",
|
||||
checkIsCpviewRunning)
|
||||
SHELL_CMD_HANDLER("isCPotelcolGRET64",
|
||||
"grep -A 10 '(BUNDLE_CPOTELCOL_AUTOUPDATE' ${CPDIR}/registry/HKLM_registry.data | "
|
||||
"awk '/SU_Build_Take/{val = substr($2, 2, length($2)-2); if (val >=64) print \"true\"; else print \"false\" }'",
|
||||
checkIsCPotelcolGRET64)
|
||||
SHELL_CMD_HANDLER("prerequisitesForHorizonTelemetry",
|
||||
"[ -f /var/log/nano_agent/cp-nano-horizon-telemetry-prerequisites.log ] "
|
||||
"&& head -1 /var/log/nano_agent/cp-nano-horizon-telemetry-prerequisites.log || echo ''",
|
||||
checkIsInstallHorizonTelemetrySucceeded)
|
||||
SHELL_CMD_HANDLER("hasSDWan", "[ -f $FWDIR/bin/sdwan_steering ] && echo '1' || echo '0'", checkHasSDWan)
|
||||
SHELL_CMD_HANDLER(
|
||||
"canUpdateSDWanData",
|
||||
|
@@ -18,6 +18,7 @@
|
||||
#include <sys/socket.h>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "reverse_proxy_defaults.h"
|
||||
#include "config.h"
|
||||
#include "log_generator.h"
|
||||
#include "health_check_manager.h"
|
||||
@@ -28,6 +29,8 @@ using namespace ReportIS;
|
||||
|
||||
USE_DEBUG_FLAG(D_HEALTH_CHECK);
|
||||
|
||||
static const std::string all_services_running = "/tmp/wd.all_running";
|
||||
|
||||
class HealthChecker::Impl
|
||||
{
|
||||
public:
|
||||
@@ -36,6 +39,7 @@ public:
|
||||
{
|
||||
i_mainloop = Singleton::Consume<I_MainLoop>::by<HealthChecker>();
|
||||
i_socket = Singleton::Consume<I_Socket>::by<HealthChecker>();
|
||||
i_orchestration_status = Singleton::Consume<I_OrchestrationStatus>::by<HealthChecker>();
|
||||
initConfig();
|
||||
initServerSocket();
|
||||
|
||||
@@ -255,35 +259,33 @@ private:
|
||||
{
|
||||
if (!getenv("DOCKER_RPM_ENABLED")) return HealthCheckStatus::IGNORED;
|
||||
|
||||
static const string standalone_cmd = "/usr/sbin/cpnano -s --docker-rpm; echo $?";
|
||||
static int timeout_tolerance = 1;
|
||||
static HealthCheckStatus health_status = HealthCheckStatus::HEALTHY;
|
||||
|
||||
dbgTrace(D_HEALTH_CHECK) << "Checking the standalone docker health status with command: " << standalone_cmd;
|
||||
|
||||
auto maybe_result = Singleton::Consume<I_ShellCmd>::by<HealthChecker>()->getExecOutput(standalone_cmd, 5000);
|
||||
if (!maybe_result.ok()) {
|
||||
if (maybe_result.getErr().find("Reached timeout") != string::npos) {
|
||||
dbgWarning(D_HEALTH_CHECK)
|
||||
<< "Reached timeout while querying standalone health status, attempt number: "
|
||||
<< timeout_tolerance;
|
||||
|
||||
return health_status == HealthCheckStatus::UNHEALTHY || timeout_tolerance++ > 3 ?
|
||||
HealthCheckStatus::UNHEALTHY :
|
||||
health_status;
|
||||
}
|
||||
|
||||
dbgWarning(D_HEALTH_CHECK) << "Unable to get the standalone docker status. Returning unhealthy status.";
|
||||
if (i_orchestration_status->getPolicyVersion().empty()) {
|
||||
dbgTrace(D_HEALTH_CHECK) << "Policy version is empty, returning unhealthy status";
|
||||
return HealthCheckStatus::UNHEALTHY;
|
||||
}
|
||||
dbgTrace(D_HEALTH_CHECK) << "Got response: " << maybe_result.unpack();
|
||||
|
||||
auto response = NGEN::Strings::removeTrailingWhitespaces(maybe_result.unpack());
|
||||
if (!NGEN::Filesystem::exists(all_services_running)) {
|
||||
dbgTrace(D_HEALTH_CHECK) << all_services_running << " does not exist, returning unhealthy status";
|
||||
return HealthCheckStatus::UNHEALTHY;
|
||||
}
|
||||
|
||||
if (response.back() == '1') return health_status = HealthCheckStatus::UNHEALTHY;
|
||||
if (NGEN::Filesystem::exists(rpm_full_load_path)) {
|
||||
dbgTrace(D_HEALTH_CHECK) << rpm_full_load_path << " exists, returning healthy status";
|
||||
return HealthCheckStatus::HEALTHY;
|
||||
}
|
||||
|
||||
timeout_tolerance = 1;
|
||||
return health_status = (response.back() == '0') ? HealthCheckStatus::HEALTHY : HealthCheckStatus::DEGRADED;
|
||||
if (NGEN::Filesystem::exists(rpm_partial_load_path)) {
|
||||
dbgTrace(D_HEALTH_CHECK) << rpm_partial_load_path << " exists, returning degraded status";
|
||||
return HealthCheckStatus::DEGRADED;
|
||||
}
|
||||
|
||||
if (!NGEN::Filesystem::exists(first_rpm_policy_load_path)) {
|
||||
dbgTrace(D_HEALTH_CHECK) << "Could not load latest RPM policy, returning degraded status";
|
||||
return HealthCheckStatus::DEGRADED;
|
||||
}
|
||||
|
||||
dbgTrace(D_HEALTH_CHECK) << "RPM is not loaded, returning unhealthy status";
|
||||
return HealthCheckStatus::UNHEALTHY;
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -390,7 +392,7 @@ private:
|
||||
|
||||
if (standalone_status == HealthCheckStatus::UNHEALTHY) {
|
||||
dbgDebug(D_HEALTH_CHECK)
|
||||
<< "Standalone status in unhealthy, returning the following response: "
|
||||
<< "Standalone status is unhealthy, returning the following response: "
|
||||
<< failure_response;
|
||||
i_socket->writeData(curr_client_socket, failure_response_buffer);
|
||||
closeCurrentSocket(curr_client_socket, curr_routine_id);
|
||||
@@ -439,6 +441,7 @@ private:
|
||||
I_MainLoop *i_mainloop = nullptr;
|
||||
I_Socket *i_socket = nullptr;
|
||||
I_Health_Check_Manager *i_health_check_manager = nullptr;
|
||||
I_OrchestrationStatus *i_orchestration_status = nullptr;
|
||||
};
|
||||
|
||||
HealthChecker::HealthChecker() : Component("HealthChecker"), pimpl(make_unique<Impl>()) {}
|
||||
|
@@ -7,6 +7,7 @@
|
||||
#include "mock/mock_socket_is.h"
|
||||
#include "mock/mock_mainloop.h"
|
||||
#include "mock/mock_shell_cmd.h"
|
||||
#include "mock/mock_orchestration_status.h"
|
||||
#include "health_check_manager.h"
|
||||
|
||||
#include "config.h"
|
||||
@@ -65,6 +66,7 @@ public:
|
||||
AgentDetails agent_details;
|
||||
StrictMock<MockSocketIS> mock_socket;
|
||||
NiceMock<MockShellCmd> mock_shell_cmd;
|
||||
NiceMock<MockOrchestrationStatus> mock_orchestration_status;
|
||||
I_Socket::socketFd server_socket = -1;
|
||||
Context ctx;
|
||||
ConfigComponent config;
|
||||
@@ -72,7 +74,6 @@ public:
|
||||
I_MainLoop::Routine connection_handler_routine;
|
||||
I_MainLoop::Routine client_connection_handler_routine;
|
||||
I_MainLoop::Routine handle_probe_routine;
|
||||
//StrictMock<MockHealthCheckManager> mock_health_check_manager;
|
||||
HealthCheckManager health_check_manager;
|
||||
I_Health_Check_Manager *i_health_check_manager;
|
||||
};
|
||||
|
@@ -102,6 +102,7 @@ public:
|
||||
|
||||
Maybe<void> authenticateAgent() override;
|
||||
void setAddressExtenesion(const std::string &extension) override;
|
||||
static std::string getUserEdition();
|
||||
|
||||
protected:
|
||||
class UserCredentials
|
||||
@@ -142,7 +143,6 @@ protected:
|
||||
std::string base64Encode(const std::string &in) const;
|
||||
std::string buildBasicAuthHeader(const std::string &username, const std::string &pass) const;
|
||||
std::string buildOAuth2Header(const std::string &token) const;
|
||||
std::string getUserEdition() const;
|
||||
|
||||
// This apps which the orchestrations requires them from Fog.
|
||||
std::vector<std::string> required_security_apps;
|
||||
|
@@ -56,7 +56,9 @@ public:
|
||||
|
||||
private:
|
||||
Maybe<std::string> getNewVersion();
|
||||
void doLocalFogOperations(const std::string &policy) const;
|
||||
|
||||
std::string tuning_host;
|
||||
I_DeclarativePolicy *i_declarative_policy = nullptr;
|
||||
};
|
||||
|
||||
|
@@ -41,6 +41,7 @@
|
||||
#include "env_details.h"
|
||||
#include "hybrid_communication.h"
|
||||
#include "agent_core_utilities.h"
|
||||
#include "fog_communication.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace chrono;
|
||||
@@ -190,7 +191,8 @@ public:
|
||||
);
|
||||
|
||||
auto orchestration_tools = Singleton::Consume<I_OrchestrationTools>::by<OrchestrationComp>();
|
||||
orchestration_tools->getClusterId();
|
||||
|
||||
if (getAttribute("no-setting", "IGNORE_CLUSTER_ID") != "TRUE") orchestration_tools->getClusterId();
|
||||
|
||||
hybrid_mode_metric.init(
|
||||
"Watchdog Metrics",
|
||||
@@ -1484,6 +1486,8 @@ private:
|
||||
agent_data_report << AgentReportFieldWithLabel("managedMode", "management");
|
||||
}
|
||||
|
||||
agent_data_report << AgentReportFieldWithLabel("userEdition", FogCommunication::getUserEdition());
|
||||
|
||||
#if defined(gaia) || defined(smb)
|
||||
if (i_details_resolver->compareCheckpointVersion(8100, greater_equal<int>())) {
|
||||
agent_data_report << AgentReportFieldWithLabel("isCheckpointVersionGER81", "true");
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#include <string>
|
||||
|
||||
std::string
|
||||
FogAuthenticator::getUserEdition() const
|
||||
FogAuthenticator::getUserEdition()
|
||||
{
|
||||
return "community";
|
||||
}
|
||||
|
@@ -27,15 +27,19 @@ using namespace std;
|
||||
|
||||
USE_DEBUG_FLAG(D_ORCHESTRATOR);
|
||||
|
||||
#define TUNING_HOST_ENV_NAME "TUNING_HOST"
|
||||
static const string defaultTuningHost = "appsec-tuning-svc";
|
||||
static const string agent_resource_api = "/api/v2/agents/resources";
|
||||
|
||||
void
|
||||
HybridCommunication::init()
|
||||
{
|
||||
dbgTrace(D_ORCHESTRATOR) << "Initializing the Hybrid Communication Component";
|
||||
|
||||
FogAuthenticator::init();
|
||||
i_declarative_policy = Singleton::Consume<I_DeclarativePolicy>::from<DeclarativePolicyUtils>();
|
||||
dbgTrace(D_ORCHESTRATOR) << "Initializing the Hybrid Communication Component";
|
||||
|
||||
auto env_tuning_host = getenv("TUNING_HOST");
|
||||
tuning_host = env_tuning_host != nullptr ? env_tuning_host : "appsec-tuning-svc";
|
||||
|
||||
if (getConfigurationFlag("otp") != "") {
|
||||
otp = getConfigurationFlag("otp");
|
||||
} else {
|
||||
@@ -49,10 +53,9 @@ HybridCommunication::getUpdate(CheckUpdateRequest &request)
|
||||
string manifest_checksum = "";
|
||||
dbgTrace(D_ORCHESTRATOR) << "Getting updates in Hybrid Communication";
|
||||
if (access_token.ok()) {
|
||||
static const string check_update_str = "/api/v2/agents/resources";
|
||||
auto request_status = Singleton::Consume<I_Messaging>::by<HybridCommunication>()->sendSyncMessage(
|
||||
HTTPMethod::POST,
|
||||
check_update_str,
|
||||
agent_resource_api,
|
||||
request
|
||||
);
|
||||
|
||||
@@ -78,45 +81,7 @@ HybridCommunication::getUpdate(CheckUpdateRequest &request)
|
||||
|
||||
string policy_response = i_declarative_policy->getUpdate(request);
|
||||
|
||||
auto env = Singleton::Consume<I_EnvDetails>::by<HybridCommunication>()->getEnvType();
|
||||
if (env == EnvType::K8S && !policy_response.empty()) {
|
||||
dbgDebug(D_ORCHESTRATOR) << "Policy has changes, sending notification to tuning host";
|
||||
I_AgentDetails *agentDetails = Singleton::Consume<I_AgentDetails>::by<HybridCommunication>();
|
||||
|
||||
auto get_tuning_host = []()
|
||||
{
|
||||
static string tuning_host;
|
||||
if (tuning_host != "") return tuning_host;
|
||||
|
||||
char* tuning_host_env = getenv(TUNING_HOST_ENV_NAME);
|
||||
if (tuning_host_env != NULL) {
|
||||
tuning_host = string(tuning_host_env);
|
||||
return tuning_host;
|
||||
}
|
||||
dbgWarning(D_ORCHESTRATOR) << "tuning host is not set. using default";
|
||||
tuning_host = defaultTuningHost;
|
||||
|
||||
return tuning_host;
|
||||
};
|
||||
|
||||
MessageMetadata update_policy_crd_md(get_tuning_host(), 80);
|
||||
update_policy_crd_md.insertHeader("X-Tenant-Id", agentDetails->getTenantId());
|
||||
UpdatePolicyCrdObject policy_change_object(policy_response);
|
||||
|
||||
auto i_messaging = Singleton::Consume<I_Messaging>::by<HybridCommunication>();
|
||||
bool tuning_req_status = i_messaging->sendSyncMessageWithoutResponse(
|
||||
HTTPMethod::POST,
|
||||
"/api/update-policy-crd",
|
||||
policy_change_object,
|
||||
MessageCategory::GENERIC,
|
||||
update_policy_crd_md
|
||||
);
|
||||
if (!tuning_req_status) {
|
||||
dbgWarning(D_ORCHESTRATOR) << "Failed to send tuning notification";
|
||||
} else {
|
||||
dbgDebug(D_ORCHESTRATOR) << "Successfully sent tuning policy update notification";
|
||||
}
|
||||
}
|
||||
doLocalFogOperations(policy_response);
|
||||
|
||||
request = CheckUpdateRequest(manifest_checksum, policy_response, "", "", "", "");
|
||||
|
||||
@@ -141,10 +106,9 @@ HybridCommunication::downloadAttributeFile(const GetResourceFile &resourse_file,
|
||||
|
||||
auto unpacked_access_token = access_token.unpack().getToken();
|
||||
|
||||
static const string file_attribute_str = "/api/v2/agents/resources/";
|
||||
auto attribute_file = Singleton::Consume<I_Messaging>::by<HybridCommunication>()->downloadFile(
|
||||
resourse_file.getRequestMethod(),
|
||||
file_attribute_str + resourse_file.getFileName(),
|
||||
agent_resource_api + '/' + resourse_file.getFileName(),
|
||||
file_path
|
||||
);
|
||||
if (!attribute_file.ok()) {
|
||||
@@ -164,3 +128,33 @@ HybridCommunication::sendPolicyVersion(const string &policy_version, const strin
|
||||
policy_version.empty();
|
||||
return Maybe<void>();
|
||||
}
|
||||
|
||||
void
|
||||
HybridCommunication::doLocalFogOperations(const string &policy) const
|
||||
{
|
||||
if (policy.empty()) return;
|
||||
if (Singleton::Consume<I_EnvDetails>::by<HybridCommunication>()->getEnvType() != EnvType::K8S) return;
|
||||
|
||||
dbgDebug(D_ORCHESTRATOR) << "Policy has changes, sending notification to tuning host";
|
||||
|
||||
MessageMetadata update_policy_crd_md(tuning_host, 80);
|
||||
const auto &tenant_id = Singleton::Consume<I_AgentDetails>::by<HybridCommunication>()->getTenantId();
|
||||
update_policy_crd_md.insertHeader("X-Tenant-Id", tenant_id);
|
||||
|
||||
UpdatePolicyCrdObject policy_change_object(policy);
|
||||
auto i_messaging = Singleton::Consume<I_Messaging>::by<HybridCommunication>();
|
||||
bool tuning_req_status = i_messaging->sendSyncMessageWithoutResponse(
|
||||
HTTPMethod::POST,
|
||||
"/api/update-policy-crd",
|
||||
policy_change_object,
|
||||
MessageCategory::GENERIC,
|
||||
update_policy_crd_md
|
||||
);
|
||||
|
||||
if (!tuning_req_status) {
|
||||
dbgWarning(D_ORCHESTRATOR) << "Failed to send tuning notification";
|
||||
} else {
|
||||
dbgDebug(D_ORCHESTRATOR) << "Successfully sent tuning policy update notification";
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user