Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLAT-24956+PLAT-24957: Add support for configuring support access mode + block login when support access not allowed #12902

Open
wants to merge 4 commits into
base: Ursa-21.2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions alpha/apps/kaltura/lib/webservices/APIErrors.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ public static function getMessage($errorString)

const PARTNER_ACCESS_FORBIDDEN = "PARTNER_ACCESS_FORBIDDEN;ACCESSING_PID,ACCESSED_PID;Partner [@ACCESSING_PID@] cannot access partner [@ACCESSED_PID@]";

const PARTNER_LOGIN_FORBIDDEN = "PARTNER_LOGIN_FORBIDDEN;ACCESSING_PID,ACCESSED_PID;Partner [@ACCESSED_PID@] did not allow partner [@ACCESSING_PID@] to access his account ";

const ACCESS_FORBIDDEN_FROM_UNKNOWN_IP = "ACCESS_FORBIDDEN_FROM_UNKNOWN_IP;IP;Access forbidden from unknown ip [@IP@]";

const INVALID_BATCHJOB_ID = "INVALID_BATCHJOB_ID;JOB_ID;[@JOB_ID@]" ;
Expand Down
18 changes: 18 additions & 0 deletions alpha/lib/enums/SupportAccessMode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* @package Core
* @subpackage model.enum
*/
interface SupportAccessMode extends BaseEnum
{
//Access to manage the account is always allowed
const ALLWAYS_ALLOWED = 0;

//Access will be blocked unless security team opens overrides this in case of security/production incidents
const NEVER_ALLOWED = 1;

//Access to manage the account will be opened and the time frame of it will controlled by the account admins
const USER_CONTROLLED = 2;


}
74 changes: 48 additions & 26 deletions alpha/lib/model/Partner.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ class Partner extends BasePartner
const CUSTOM_DATE_MAX_METADATA_INDEX_LENGTH = 'max_metadata_index_length';

const CUSTOM_ANALYTICS_DOMAIN = 'custom_analytics_domain';

const SUPPORT_ACCESS_ALLOWED_UNTIL = 'custom_support_access_allowed_until';

const SUPPORT_ACCESS_MODE = 'custom_support_access_mode';

public function save(PropelPDO $con = null)
{
Expand Down Expand Up @@ -2315,32 +2319,6 @@ public function getSharedStorageProfileId()

return $partnerDedicatedStorage ? $partnerDedicatedStorage->getId() : null;
}

// public function getSharedStorageProfileId()
// {
// $sharedStorageId = null;
// $allSharedStorageIds = kDataCenterMgr::getSharedStorageProfileIds();
//
// $sharedIncludePartnerIds = kConf::get('shared_include_partner_ids', 'cloud_storage', array());
// if (in_array($this->getId(), $sharedIncludePartnerIds) || in_array(self::ALL_PARTNERS_WILD_CHAR, $sharedIncludePartnerIds))
// {
// $sharedStorageId = reset($allSharedStorageIds);
// }
//
// $sharedPartnerPackages = kConf::get('shared_partner_package_types', 'cloud_storage', array());
// if (in_array($this->getPartnerPackage(), $sharedPartnerPackages) || in_array(self::ALL_PARTNERS_WILD_CHAR, $sharedPartnerPackages))
// {
// $sharedStorageId = reset($allSharedStorageIds);
// }
//
// $sharedExcludePartnerIds = kConf::get('shared_exclude_partner_ids', 'cloud_storage', array());
// if (in_array($this->getId(), $sharedExcludePartnerIds) || in_array(self::ALL_PARTNERS_WILD_CHAR, $sharedExcludePartnerIds))
// {
// $sharedStorageId = null;
// }
//
// return $sharedStorageId;
// }

public function setSharedStorageProfileId($v)
{
Expand Down Expand Up @@ -2454,4 +2432,48 @@ public function setAllowedEmailDomainsForAdmins($v)
{
return $this->putInCustomData(self::ALLOWED_EMAIL_DOMAINS_FOR_ADMINS, $v);
}

public function getSupportAccessAllowedUntil()
{
return $this->getFromCustomData(self::SUPPORT_ACCESS_ALLOWED_UNTIL);
}

public function setSupportAccessAllowedUntil($v)
{
return $this->putInCustomData(self::SUPPORT_ACCESS_ALLOWED_UNTIL, $v);
}

public function getSupportAccessMode()
{
return $this->getFromCustomData(self::SUPPORT_ACCESS_MODE, null, SupportAccessMode::ALLWAYS_ALLOWED);
}

public function setSupportAccessMode($v)
{
return $this->putInCustomData(self::SUPPORT_ACCESS_MODE, $v);
}

public function isSupportAccessAllowed()
{
$shouldEnforceSupportAccess = kConf::get('enforce_support_access', kConfMapNames::SECURITY, true);
if(!$shouldEnforceSupportAccess || $this->getSupportAccessMode() == SupportAccessMode::ALLWAYS_ALLOWED)
{
return true;
}

$allowedUntil = $this->getSupportAccessAllowedUntil();
$allowedUntil = $allowedUntil ? $allowedUntil : (time() - 3600);
return (time() < $allowedUntil);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the case you set allowedUntil= time() - 3600 this condition in line 2466 will always be false, is this intended?

}

public function getSupportAccessMaxKsExpiry()
{
$shouldEnforceSupportAccess = kConf::get('enforce_support_access', kConfMapNames::SECURITY, true);
if(!$shouldEnforceSupportAccess || $this->getSupportAccessMode() == SupportAccessMode::ALLWAYS_ALLOWED)
{
return dateUtils::DAY;
}

return $this->getSupportAccessAllowedUntil() - time();
}
}
4 changes: 4 additions & 0 deletions api_v3/lib/KalturaErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,10 @@ class KalturaErrors extends APIErrors
const PROPERTY_IS_NOT_DEFINED = "PROPERTY_IS_NOT_DEFINED;PROP,TYPE;The property \"@PROP@\" is not defined on type \"@TYPE@\"";

const GROUPS_CANNOT_CO_EXIST = "GROUPS_CANNOT_CO_EXIST;userId,group,blockedCoExist;Cannot add user [@userId@] to group [@group@], User is already member of a group with coexistence enforcement [@blockedCoExist@]";

const CAN_ONLY_BE_UPDATED_BY_ACCOUNT_OWNER = "CAN_ONLY_BE_CHANGED_BY_ACCOUNT_OWNER;;Support access mode can only be updated by the account owner";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would chose either changed/updated and use one terminology for all


const SUPPORT_ACCESS_CANNOT_BE_ENABLED = "SUPPORT_ACCESS_CANNOT_BE_ENABLED;;Support access cannot be enabled, please contact you account admin to change support access mode to be set to user_controlled";

/*
* syndication service
Expand Down
9 changes: 9 additions & 0 deletions api_v3/lib/types/enums/KalturaSupportAccessMode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* @package api
* @subpackage enum
*/
class KalturaSupportAccessMode extends KalturaEnum implements SupportAccessMode
{

}
65 changes: 64 additions & 1 deletion api_v3/lib/types/partner/KalturaPartner.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,16 @@ class KalturaPartner extends KalturaObject implements IFilterable
*/
public $allowedEmailDomainsForAdmins;

/**
* @var time
*/
public $supportAccessAllowedUntil;

/**
* @var KalturaSupportAccessMode
*/
public $supportAccessMode;

private static $map_between_objects = array
(
'id' , 'name', 'website' => 'url1' , 'notificationUrl' => 'url2' , 'appearInSearch' , 'createdAt' , 'adminName' , 'adminEmail' , 'useTwoFactorAuthentication', 'useSso', 'blockDirectLogin',
Expand All @@ -520,7 +530,7 @@ class KalturaPartner extends KalturaObject implements IFilterable
'extendedFreeTrail', 'extendedFreeTrailEndsWarning', 'eightyPercentWarning', 'usageLimitWarning', 'lastFreeTrialNotificationDay','monitorUsage', 'additionalParams',
'passwordStructureValidations', 'passReplaceFreq', 'maxLoginAttempts', 'loginBlockPeriod', 'numPrevPassToKeep', 'twoFactorAuthenticationMode', 'isSelfServe', 'allowedDomains',
'excludedAdminRoleName', 'eventPlatformAllowedTemplates', 'verticalClassificationId' => 'verticalClasiffication', 'allowDefaultPasswordRestrictions', 'recycleBinRetentionPeriod',
'customAnalyticsDomain','allowedEmailDomainsForAdmins'
'customAnalyticsDomain','allowedEmailDomainsForAdmins', 'supportAccessAllowedUntil', 'supportAccessMode'
);

public function getMapBetweenObjects ( )
Expand Down Expand Up @@ -615,6 +625,59 @@ public function toPartner()
return $this->toObject($partner);
}

/* (non-PHPdoc)
* @see KalturaObject::validateForInsert()
*/
public function validateForInsert($propertiesToSkip = array())
{
if(isset($this->supportAccessMode) && !$this->isApiDoneByAccountOwner())
{
throw new KalturaAPIException(KalturaErrors::CAN_ONLY_BE_UPDATED_BY_ACCOUNT_OWNER);
}

if(isset($this->supportAccessAllowedUntil) && !kCurrentContext::$is_admin_session)
{
throw new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_ADMIN_PROPERTY, 'supportAccessAllowedUntil');
}

if(isset($this->supportAccessAllowedUntil) && isset($this->supportAccessMode) == KalturaSupportAccessMode::NEVER_ALLOWED)
{
throw new KalturaAPIException(KalturaErrors::SUPPORT_ACCESS_CANNOT_BE_ENABLED);
}

return parent::validateForInsert($propertiesToSkip);
}

/* (non-PHPdoc)
* @see KalturaObject::validateForUpdate()
*/
public function validateForUpdate($sourceObject, $propertiesToSkip = array())
{
if(isset($this->supportAccessMode) && $this->supportAccessMode != $sourceObject->getSupportAccessMode()
&& !$this->isApiDoneByAccountOwner())
{
throw new KalturaAPIException(KalturaErrors::CAN_ONLY_BE_UPDATED_BY_ACCOUNT_OWNER);
}

if(isset($this->supportAccessAllowedUntil) && $this->supportAccessAllowedUntil != $sourceObject->getSupportAccessAllowedUntil()
&& !kCurrentContext::$is_admin_session)
{
throw new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_ADMIN_PROPERTY, 'supportAccessAllowedUntil');
}

if(isset($this->supportAccessAllowedUntil) && $sourceObject->getSupportAccessAllowedUntil() == KalturaSupportAccessMode::NEVER_ALLOWED)
{
throw new KalturaAPIException(KalturaErrors::SUPPORT_ACCESS_CANNOT_BE_ENABLED);
}

return parent::validateForUpdate($sourceObject, $propertiesToSkip);
}

private function isApiDoneByAccountOwner()
{
return kCurrentContext::getCurrentKsKuserId() != $sourceObject->getAccountOwnerKuserId();
}

public function toObject($dbObject = null, $propsToSkip = array())
{
if (!$dbObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ public function getAdminSessionAction($pId, $userId = null)
$userId = $dbPartner->getAdminUserId();
}

if(!$dbPartner->isSupportAccessAllowed()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{ in new line

throw new KalturaAPIException(KalturaErrors::PARTNER_LOGIN_FORBIDDEN, kCurrentContext::getCurrentPartnerId(), $pId);
}

$kuser = kuserPeer::getKuserByPartnerAndUid($pId, $userId);
if (!$kuser) {
throw new KalturaAPIException(KalturaErrors::INVALID_USER_ID, $userId);
Expand All @@ -219,7 +223,7 @@ public function getAdminSessionAction($pId, $userId = null)
}

$ks = "";
kSessionUtils::createKSessionNoValidations($dbPartner->getId(), $userId, $ks, 86400, 2, "", '*,' . ks::PRIVILEGE_DISABLE_ENTITLEMENT);
kSessionUtils::createKSessionNoValidations($dbPartner->getId(), $userId, $ks, $dbPartner->getSupportAccessMaxKsExpiry(), 2, "", '*,' . ks::PRIVILEGE_DISABLE_ENTITLEMENT);
return $ks;
}

Expand Down