Skip to content

Commit 323b8a0

Browse files
romanetarsmarcet
authored andcommitted
feat: add action_by and environment to privilege escalation email (#89)
Signed-off-by: romanetar <roman_ag@hotmail.com>
1 parent 0678685 commit 323b8a0

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

app/Mail/MonitoredSecurityGroupNotificationEmail.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ final class MonitoredSecurityGroupNotificationEmail extends Mailable
3434
*/
3535
public $action;
3636

37+
/**
38+
* @var string
39+
*/
40+
public $action_by;
41+
3742
/**
3843
* @var int
3944
*/
@@ -76,9 +81,17 @@ final class MonitoredSecurityGroupNotificationEmail extends Mailable
7681
*/
7782
public $subject;
7883

84+
/**
85+
* @var string
86+
*/
87+
public $env;
88+
89+
public $action_by_phrase;
90+
7991
/**
8092
* @param string $email
8193
* @param string $action
94+
* @param string $action_by
8295
* @param int $user_id
8396
* @param string $user_email
8497
* @param string $user_name
@@ -90,6 +103,7 @@ public function __construct
90103
(
91104
string $email,
92105
string $action,
106+
string $action_by,
93107
int $user_id,
94108
string $user_email,
95109
string $user_name,
@@ -100,20 +114,23 @@ public function __construct
100114
{
101115
$this->email = $email;
102116
$this->action = $action;
117+
$this->action_by = $action_by;
103118
$this->user_id = $user_id;
104119
$this->user_email = $user_email;
105120
$this->user_name = $user_name;
106121
$this->group_id = $group_id;
107122
$this->group_name = $group_name;
108123
$this->group_slug = $group_slug;
109-
124+
$this->env = Config::get('app.env');
125+
$this->action_by_phrase = $this->action_by ? " by $this->action_by" : "";
110126
Log::debug
111127
(
112128
sprintf
113129
(
114-
"MonitoredSecurityGroupNotificationEmail::constructor email %s action %s user_id %s user_email %s user_name %s group_id %s group_name %s group_slug %s",
130+
"MonitoredSecurityGroupNotificationEmail::constructor email %s action %s action_by %s user_id %s user_email %s user_name %s group_id %s group_name %s group_slug %s",
115131
$email,
116132
$action,
133+
$action_by,
117134
$user_id,
118135
$user_email,
119136
$user_name,
@@ -126,15 +143,19 @@ public function __construct
126143

127144
public function build()
128145
{
146+
147+
129148
$this->subject = sprintf
130149
(
131-
"[%s] Monitored Security Groups - User %s (%s) has been %s - Group %s (%s)"
150+
"[%s] Monitored Security Groups - User %s (%s) has been %s%s - Group %s (%s) - Environment: %s"
132151
,Config::get('app.app_name')
133152
,$this->user_name
134153
,$this->user_email
135154
,$this->action
155+
,$this->action_by_phrase
136156
,$this->group_name
137157
,$this->group_id
158+
,$this->env
138159
);
139160
Log::debug(sprintf("MonitoredSecurityGroupNotificationEmail::build to %s", $this->email));
140161
return $this->from(Config::get("mail.from"))

app/Services/OpenId/UserService.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
use Illuminate\Support\Facades\Storage;
3838
use models\exceptions\EntityNotFoundException;
3939
use models\exceptions\ValidationException;
40-
use Models\OAuth2\Client;
4140
use models\utils\IEntity;
4241
use OAuth2\IResourceServerContext;
4342
use OAuth2\Models\IClient;
@@ -483,6 +482,13 @@ public function notifyMonitoredSecurityGroupActivity(string $action, int $user_i
483482
return;
484483
}
485484

485+
$action_by = '';
486+
$current_user = Auth::user();
487+
488+
if($current_user instanceof User){
489+
$action_by = sprintf("%s ( %s )", $current_user->getFullName(), $current_user->getEmail());
490+
}
491+
486492
$notified_users = [];
487493
foreach ($watcher_groups as $watcher_group_slug) {
488494
Log::debug(sprintf("UserService::notifyMonitoredSecurityGroupActivity processing %s", $watcher_group_slug));
@@ -497,13 +503,15 @@ public function notifyMonitoredSecurityGroupActivity(string $action, int $user_i
497503
continue;
498504
}
499505
$notified_users[] = $user->getId();
506+
500507
Log::debug(sprintf("UserService::notifyMonitoredSecurityGroupActivity processing user %s", $user->getId()));
501508
Mail::queue
502509
(
503510
new MonitoredSecurityGroupNotificationEmail
504511
(
505512
$user->getEmail(),
506513
$action,
514+
$action_by,
507515
$user_id,
508516
$user_email,
509517
$user_name,
@@ -514,6 +522,5 @@ public function notifyMonitoredSecurityGroupActivity(string $action, int $user_i
514522
);
515523
}
516524
}
517-
518525
}
519526
}

resources/views/emails/audit/monitored_security_group_notification.blade.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@
1515
<td align="center" style="font-size:0px;padding:10px 25px;word-break:break-word;">
1616
<div style="font-family:open Sans Helvetica, Arial, sans-serif;font-size:16px;line-height:1;text-align:center;color:#000000;">
1717
<p>
18-
User {!! $user_name !!} (Email: {!! $user_email !!}) has been <b>{!! $action !!}</b>
18+
User {!! $user_name !!} (Email: {!! $user_email !!}) has been <b>{!! $action !!}</b> {!! $action_by_phrase !!} }
1919
</p>
2020
</div>
2121
</td>
2222
</tr>
2323
<tr>
2424
<td align="center" style="font-size:0px;padding:10px 25px;padding-right:25px;padding-left:25px;word-break:break-word;">
2525
<div style="font-family:open Sans Helvetica, Arial, sans-serif;font-size:16px;line-height:1;text-align:center;color:#000000;">Thanks! <br/><br/>{{Config::get('app.tenant_name')}} Support Team</div>
26+
<div style="font-family:open Sans Helvetica, Arial, sans-serif;font-size:16px;line-height:1;text-align:center;color:#000000;">
27+
<b>{!! $env !!} ENVIRONMENT</b>
28+
</div>
2629
</td>
2730
</tr>
2831
</tbody>

0 commit comments

Comments
 (0)