mirror of
https://github.com/openappsec/openappsec.git
synced 2025-09-29 19:24:26 +03:00
Feb 22nd 2023 update
This commit is contained in:
@@ -41,7 +41,11 @@ public:
|
||||
|
||||
virtual std::chrono::microseconds getTimeoutVal() const = 0;
|
||||
|
||||
virtual std::string getProfileId(const std::string &tenant_id, const std::string ®ion) const = 0;
|
||||
virtual std::vector<std::string> getProfileId(
|
||||
const std::string &tenant_id,
|
||||
const std::string ®ion,
|
||||
const std::string &account_id = ""
|
||||
) const = 0;
|
||||
|
||||
private:
|
||||
friend class LoadNewTenants;
|
||||
|
@@ -25,7 +25,10 @@ public:
|
||||
MOCK_CONST_METHOD2(areTenantAndProfileActive, bool(const std::string &, const std::string &));
|
||||
MOCK_METHOD2(addActiveTenantAndProfile, void(const std::string &, const std::string &));
|
||||
MOCK_METHOD2(deactivateTenant, void(const std::string &, const std::string &));
|
||||
MOCK_CONST_METHOD2(getProfileId, std::string(const std::string &, const std::string &));
|
||||
MOCK_CONST_METHOD3(
|
||||
getProfileId,
|
||||
std::vector<std::string>(const std::string &, const std::string &, const std::string &)
|
||||
);
|
||||
|
||||
MOCK_CONST_METHOD0(getTimeoutVal, std::chrono::microseconds());
|
||||
|
||||
|
@@ -69,6 +69,7 @@ enum class AudienceTeam
|
||||
AGENT_INTELLIGENCE,
|
||||
CPVIEW_MONITORING,
|
||||
SIGNATURE_DEVELOPERS,
|
||||
FILE_UPLOAD,
|
||||
IDENTITY_AWARENESS,
|
||||
NONE,
|
||||
|
||||
@@ -140,6 +141,7 @@ enum class IssuingEngine {
|
||||
AGENT_CORE,
|
||||
IOT_NEXT,
|
||||
SDWAN,
|
||||
FILE_UPLOAD,
|
||||
IDA_NEXT
|
||||
};
|
||||
|
||||
|
@@ -257,6 +257,7 @@ TagAndEnumManagement::convertToString(const IssuingEngine &issuing_engine)
|
||||
case IssuingEngine::AGENT_CORE: return "Agent Core";
|
||||
case IssuingEngine::IOT_NEXT: return "iotNext";
|
||||
case IssuingEngine::SDWAN: return "sdwanGwSharing";
|
||||
case IssuingEngine::FILE_UPLOAD: return "fileUpload";
|
||||
case IssuingEngine::IDA_NEXT: return "quantumMetaNotifyIdn";
|
||||
}
|
||||
|
||||
|
@@ -27,6 +27,46 @@ using namespace std;
|
||||
|
||||
USE_DEBUG_FLAG(D_TENANT_MANAGER);
|
||||
|
||||
class AccountRegionPair
|
||||
{
|
||||
public:
|
||||
void
|
||||
load(cereal::JSONInputArchive &ar)
|
||||
{
|
||||
ar(
|
||||
cereal::make_nvp("accountId", accountID),
|
||||
cereal::make_nvp("regionName", regionName)
|
||||
);
|
||||
}
|
||||
|
||||
bool
|
||||
operator<(const AccountRegionPair &other) const {
|
||||
return accountID < other.getAccountID() && regionName < other.getRegion();
|
||||
}
|
||||
|
||||
const string & getAccountID() const { return accountID; }
|
||||
const string & getRegion() const { return regionName; }
|
||||
|
||||
private:
|
||||
string accountID;
|
||||
string regionName;
|
||||
};
|
||||
|
||||
class AccountRegionSet
|
||||
{
|
||||
public:
|
||||
void
|
||||
load(cereal::JSONInputArchive &ar)
|
||||
{
|
||||
cereal::load(ar, account_region_map);
|
||||
}
|
||||
|
||||
const set<AccountRegionPair> & getAccoutRegionPairs() const { return account_region_map; }
|
||||
|
||||
private:
|
||||
set<AccountRegionPair> account_region_map;
|
||||
};
|
||||
|
||||
class TenantManager::Impl
|
||||
:
|
||||
Singleton::Provide<I_TenantManager>::From<TenantManager>
|
||||
@@ -49,7 +89,7 @@ public:
|
||||
|
||||
chrono::microseconds getTimeoutVal() const override;
|
||||
|
||||
string getProfileId(const string &tenant_id, const string ®ion) const override;
|
||||
vector<string> getProfileId(const string &tenant_id, const string ®ion, const string &account) const override;
|
||||
|
||||
void
|
||||
addInstance(const string &tenant_id, const string &profile_id, const string &instace_id)
|
||||
@@ -338,12 +378,13 @@ TenantManager::Impl::getProfileIds(const string &_tenant_id) const
|
||||
return tenant_id.profile_ids.get();
|
||||
}
|
||||
|
||||
string
|
||||
TenantManager::Impl::getProfileId(const string &tenant_id, const string ®ion) const
|
||||
|
||||
vector<string>
|
||||
TenantManager::Impl::getProfileId(const string &tenant_id, const string ®ion, const string &account_id = "") const
|
||||
{
|
||||
if (region.empty()) {
|
||||
dbgWarning(D_TENANT_MANAGER) << "Can't find the profile ID. Region is empty";
|
||||
return "";
|
||||
return vector<string>();
|
||||
}
|
||||
|
||||
vector<string> profile_ids = fetchProfileIds(tenant_id);
|
||||
@@ -352,36 +393,56 @@ TenantManager::Impl::getProfileId(const string &tenant_id, const string ®ion)
|
||||
|
||||
auto i_env = Singleton::Consume<I_Environment>::by<TenantManager>();
|
||||
auto unset_tenant_on_exit = make_scope_exit([&]() { i_env->unsetActiveTenantAndProfile(); });
|
||||
|
||||
vector<string> profiles_to_return;
|
||||
for (const string &profile_id : profile_ids) {
|
||||
string account_dbg = account_id.empty() ? "" : (" in the account " + account_id);
|
||||
dbgDebug(D_TENANT_MANAGER)
|
||||
<< "Checking if the profile ID: "
|
||||
<< profile_id
|
||||
<< " corresponds to the tenant ID: "
|
||||
<< tenant_id
|
||||
<< " and the region "
|
||||
<< region;
|
||||
<< region
|
||||
<< account_dbg;
|
||||
|
||||
i_env->setActiveTenantAndProfile(tenant_id, profile_id);
|
||||
|
||||
auto maybe_region = getSetting<string>("region");
|
||||
if (maybe_region.ok() && region == maybe_region.unpack()) {
|
||||
dbgDebug(D_TENANT_MANAGER) << "The region corresponds to profile ID " << profile_id;
|
||||
return profile_id;
|
||||
auto maybe_account_region_set = getSetting<AccountRegionSet>("accountRegionSet");
|
||||
if (maybe_account_region_set.ok()) {
|
||||
for (const AccountRegionPair &account : maybe_account_region_set.unpack().getAccoutRegionPairs()) {
|
||||
if (region == account.getRegion() && (account_id.empty() || account_id == account.getAccountID())) {
|
||||
dbgTrace(D_TENANT_MANAGER) << "Found a corresponding profile ID: " << profile_id;
|
||||
profiles_to_return.push_back(profile_id);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (maybe_region.ok()) {
|
||||
dbgTrace(D_TENANT_MANAGER)
|
||||
<< "The region does not corresponds to profile ID "
|
||||
<< profile_id
|
||||
<< " region "
|
||||
<< *maybe_region;
|
||||
auto maybe_region = getSetting<string>("region");
|
||||
if (maybe_region.ok() && region == maybe_region.unpack()) {
|
||||
dbgDebug(D_TENANT_MANAGER) << "The region corresponds to profile ID " << profile_id;
|
||||
profiles_to_return.push_back(profile_id);
|
||||
return profiles_to_return;
|
||||
} else {
|
||||
dbgDebug(D_TENANT_MANAGER) << "Failed to get region for profile ID " << profile_id;
|
||||
if (maybe_region.ok()) {
|
||||
dbgTrace(D_TENANT_MANAGER)
|
||||
<< "The region does not corresponds to profile ID "
|
||||
<< profile_id
|
||||
<< " region "
|
||||
<< *maybe_region;
|
||||
} else {
|
||||
dbgDebug(D_TENANT_MANAGER) << "Failed to match profile ID by accountRegionSet or region";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dbgWarning(D_TENANT_MANAGER) << "Found no profile ID for tenant " << tenant_id << " and region " << region;
|
||||
return "";
|
||||
if (!profiles_to_return.empty()) {
|
||||
dbgDebug(D_TENANT_MANAGER) << "Found " << profiles_to_return.size() << " profiles that correspond";
|
||||
return profiles_to_return;
|
||||
}
|
||||
|
||||
dbgWarning(D_TENANT_MANAGER) << "Found no corresponding profile ID";
|
||||
return vector<string>();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -520,5 +581,6 @@ TenantManager::preload()
|
||||
{
|
||||
registerExpectedConfiguration<uint32_t>("Tenant Manager", "Tenant timeout");
|
||||
registerExpectedConfiguration<string>("Tenant Manager", "Tenant manager type");
|
||||
registerExpectedSetting<AccountRegionSet>("accountRegionSet");
|
||||
registerExpectedSetting<string>("region");
|
||||
}
|
||||
|
Reference in New Issue
Block a user