Skip to content

Commit cfb1fde

Browse files
committed
add more logger event types
1 parent 1ca7375 commit cfb1fde

File tree

2 files changed

+181
-7
lines changed

2 files changed

+181
-7
lines changed

src/db/models/audit_log.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,32 @@ pub enum AuditModule {
1515
Enrollment,
1616
}
1717

18+
/// Represents audit event type as it's stored in the DB
19+
///
20+
/// To make searching and exporting the type is stored as text and not a custom Postgres enum.
21+
/// Variant names are renamed to `snake_case` so `UserLogin` becomes `user_login` in the DB table.
1822
#[derive(Clone, Debug, Deserialize, Serialize, Type)]
1923
#[sqlx(type_name = "text", rename_all = "snake_case")]
2024
#[serde(rename_all = "snake_case")]
2125
pub enum EventType {
26+
// user management
2227
UserLogin,
2328
UserLogout,
29+
UserAdded,
30+
UserRemoved,
31+
UserModified,
32+
// device management
2433
DeviceAdded,
2534
DeviceRemoved,
2635
DeviceModified,
36+
// OpenID app management
37+
OpenIdAppAdded,
38+
OpenIdAppRemoved,
39+
OpenIdAppModified,
40+
// VPN location management
41+
VpnLocationAdded,
42+
VpnLocationRemoved,
43+
VpnLocationModified,
2744
}
2845

2946
#[derive(Model, FromRow)]

src/event_logger/message.rs

Lines changed: 164 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use chrono::NaiveDateTime;
22
use ipnetwork::IpNetwork;
33

4-
use crate::db::Id;
4+
use crate::{
5+
db::{models::authentication_key::AuthenticationKeyType, Id},
6+
grpc::proto::proxy::MfaMethod,
7+
};
58

69
/// Messages that can be sent to the event logger
710
pub struct EventLoggerMessage {
@@ -32,20 +35,174 @@ pub struct EventContext {
3235
pub device: String,
3336
}
3437

35-
/// Represents audit events related to Web UI
38+
/// Represents audit events related to actions performed in Web UI
3639
pub enum DefguardEvent {
40+
// authentication
3741
UserLogin,
3842
UserLogout,
39-
DeviceAdded { device_name: String },
40-
DeviceRemoved { device_name: String },
41-
DeviceModified { device_name: String },
43+
RecoveryCodeUsed,
44+
PasswordChanged,
45+
MfaFailed,
46+
// user MFA management
47+
MfaDisabled,
48+
MfaDefaultChanged {
49+
mfa_method: MfaMethod,
50+
},
51+
MfaTotpEnabled,
52+
MfaTotpDisabled,
53+
MfaEmailEnabled,
54+
MfaEmailDisabled,
55+
MfaSecurityKeyAdded {
56+
key_id: Id,
57+
key_name: String,
58+
},
59+
MfaSecurityKeyRemoved {
60+
key_id: Id,
61+
key_name: String,
62+
},
63+
// authentication key management
64+
AuthenticationKeyAdded {
65+
key_id: Id,
66+
key_name: String,
67+
key_type: AuthenticationKeyType,
68+
},
69+
AuthenticationKeyRemoved {
70+
key_id: Id,
71+
key_name: String,
72+
key_type: AuthenticationKeyType,
73+
},
74+
AuthenticationKeyRenamed {
75+
key_id: Id,
76+
key_name: String,
77+
key_type: AuthenticationKeyType,
78+
},
79+
// API token management
80+
ApiTokenAdded {
81+
token_id: Id,
82+
token_name: String,
83+
},
84+
ApiTokenRemoved {
85+
token_id: Id,
86+
token_name: String,
87+
},
88+
ApiTokenRenamed {
89+
token_id: Id,
90+
token_name: String,
91+
},
92+
// user management
93+
UserAdded {
94+
username: String,
95+
enrollment: bool,
96+
},
97+
UserRemoved {
98+
username: String,
99+
},
100+
UserModified {
101+
username: String,
102+
},
103+
UserDisabled {
104+
username: String,
105+
},
106+
// device management
107+
UserDeviceAdded {
108+
device_id: Id,
109+
device_name: String,
110+
user: String,
111+
},
112+
UserDeviceRemoved {
113+
device_id: Id,
114+
device_name: String,
115+
user: String,
116+
},
117+
UserDeviceModified {
118+
device_id: Id,
119+
device_name: String,
120+
user: String,
121+
},
122+
NetworkDeviceAdded {
123+
device_id: Id,
124+
device_name: String,
125+
location_id: Id,
126+
location: String,
127+
},
128+
NetworkDeviceRemoved {
129+
device_id: Id,
130+
device_name: String,
131+
location_id: Id,
132+
location: String,
133+
},
134+
NetworkDeviceModified {
135+
device_id: Id,
136+
device_name: String,
137+
location_id: Id,
138+
location: String,
139+
},
140+
// VPN location management
141+
VpnLocationAdded {
142+
location_id: Id,
143+
location_name: String,
144+
},
145+
VpnLocationRemoved {
146+
location_id: Id,
147+
location_name: String,
148+
},
149+
VpnLocationModified {
150+
location_id: Id,
151+
location_name: String,
152+
},
153+
// OpenID app management
154+
OpenIdAppAdded {
155+
app_id: Id,
156+
app_name: String,
157+
},
158+
OpenIdAppRemoved {
159+
app_id: Id,
160+
app_name: String,
161+
},
162+
OpenIdAppModified {
163+
app_id: Id,
164+
app_name: String,
165+
},
166+
OpenIdAppDisabled {
167+
app_id: Id,
168+
app_name: String,
169+
},
170+
// OpenID provider management
171+
OpenIdProviderAdded {
172+
provider_id: Id,
173+
provider_name: String,
174+
},
175+
OpenIdProviderRemoved {
176+
provider_id: Id,
177+
provider_name: String,
178+
},
179+
// settings management
180+
SettingsUpdated,
181+
SettingsUpdatedPartial,
182+
SettingsDefaultBrandingRestored,
42183
}
43184

44185
/// Represents audit events related to client applications
45-
pub enum ClientEvent {}
186+
pub enum ClientEvent {
187+
DesktopClientActivated { device_id: Id, device_name: String },
188+
DesktopClientUpdated { device_id: Id, device_name: String },
189+
}
46190

47191
/// Represents audit events related to VPN
48-
pub enum VpnEvent {}
192+
pub enum VpnEvent {
193+
ConnectedToMfaLocation {
194+
location_id: Id,
195+
location_name: String,
196+
},
197+
DisconnectedFromMfaLocation {
198+
location_id: Id,
199+
location_name: String,
200+
},
201+
MfaFailed {
202+
location_id: Id,
203+
location_name: String,
204+
},
205+
}
49206
///
50207
/// Represents audit events related to enrollment process
51208
pub enum EnrollmentEvent {}

0 commit comments

Comments
 (0)