KILL USER SESSIONS ' '
(
state: &SharedState,
identity: &AuthenticatedIdentity,
parts: &[&str],
)
| 174 | |
| 175 | /// KILL USER SESSIONS '<auth_user_id>' |
| 176 | pub fn kill_user_sessions( |
| 177 | state: &SharedState, |
| 178 | identity: &AuthenticatedIdentity, |
| 179 | parts: &[&str], |
| 180 | ) -> PgWireResult<Vec<Response>> { |
| 181 | if !identity.is_superuser { |
| 182 | return Err(sqlstate_error( |
| 183 | "42501", |
| 184 | "permission denied: requires superuser", |
| 185 | )); |
| 186 | } |
| 187 | if parts.len() < 4 { |
| 188 | return Err(sqlstate_error( |
| 189 | "42601", |
| 190 | "syntax: KILL USER SESSIONS '<auth_user_id>'", |
| 191 | )); |
| 192 | } |
| 193 | let user_id_str = parts[3].trim_matches('\''); |
| 194 | let user_id: u64 = user_id_str.parse().map_err(|_| { |
| 195 | sqlstate_error( |
| 196 | "22003", |
| 197 | &format!("invalid user_id '{user_id_str}': must be numeric"), |
| 198 | ) |
| 199 | })?; |
| 200 | |
| 201 | let killed = state.session_registry.kill_sessions_for_user( |
| 202 | user_id, |
| 203 | crate::control::security::sessions::KillReason::AdminKill, |
| 204 | ); |
| 205 | |
| 206 | state.audit_record( |
| 207 | crate::control::security::audit::AuditEvent::AdminAction, |
| 208 | Some(identity.tenant_id), |
| 209 | &identity.username, |
| 210 | &format!("killed {killed} sessions for user_id={user_id}"), |
| 211 | ); |
| 212 | |
| 213 | Ok(vec![Response::Execution(Tag::new(&format!( |
| 214 | "KILL {killed}" |
| 215 | )))]) |
| 216 | } |
| 217 | |
| 218 | /// VERIFY AUDIT CHAIN |
| 219 | pub fn verify_audit_chain( |
no test coverage detected