(
RunParams {
tls_mode,
adapter_client,
conn,
conn_uuid,
version,
mut params,
frontegg,
oidc,
authenticator_kind,
ac
| 143 | /// the middle of a request. |
| 144 | #[mz_ore::instrument(level = "debug")] |
| 145 | pub async fn run<'a, A, I>( |
| 146 | RunParams { |
| 147 | tls_mode, |
| 148 | adapter_client, |
| 149 | conn, |
| 150 | conn_uuid, |
| 151 | version, |
| 152 | mut params, |
| 153 | frontegg, |
| 154 | oidc, |
| 155 | authenticator_kind, |
| 156 | active_connection_counter, |
| 157 | helm_chart_version, |
| 158 | allowed_roles, |
| 159 | tokio_metrics_intervals, |
| 160 | }: RunParams<'a, A, I>, |
| 161 | ) -> Result<(), io::Error> |
| 162 | where |
| 163 | A: AsyncRead + AsyncWrite + AsyncReady + Send + Sync + Unpin, |
| 164 | I: Iterator<Item = TaskMetrics> + Send, |
| 165 | { |
| 166 | if version != VERSION_3 { |
| 167 | return conn |
| 168 | .send(ErrorResponse::fatal( |
| 169 | SqlState::SQLSERVER_REJECTED_ESTABLISHMENT_OF_SQLCONNECTION, |
| 170 | "server does not support the client's requested protocol version", |
| 171 | )) |
| 172 | .await; |
| 173 | } |
| 174 | |
| 175 | let user = params.remove("user").unwrap_or_else(String::new); |
| 176 | let options = parse_options(params.get("options").unwrap_or(&String::new())); |
| 177 | let authenticator = |
| 178 | get_authenticator(authenticator_kind, frontegg, oidc, adapter_client.clone()); |
| 179 | // TODO move this somewhere it can be shared with HTTP |
| 180 | let is_internal_user = INTERNAL_USER_NAMES.contains(&user); |
| 181 | // this is a superset of internal users |
| 182 | let is_reserved_user = mz_adapter::catalog::is_reserved_role_name(user.as_str()); |
| 183 | let role_allowed = match allowed_roles { |
| 184 | AllowedRoles::Normal => !is_reserved_user, |
| 185 | AllowedRoles::Internal => is_internal_user, |
| 186 | AllowedRoles::NormalAndInternal => !is_reserved_user || is_internal_user, |
| 187 | }; |
| 188 | if !role_allowed { |
| 189 | let msg = format!("unauthorized login to user '{user}'"); |
| 190 | return conn |
| 191 | .send(ErrorResponse::fatal(SqlState::INSUFFICIENT_PRIVILEGE, msg)) |
| 192 | .await; |
| 193 | } |
| 194 | |
| 195 | if let Err(err) = conn.inner().ensure_tls_compatibility(&tls_mode) { |
| 196 | return conn.send(err).await; |
| 197 | } |
| 198 | |
| 199 | let authenticator_kind = authenticator.kind(); |
| 200 | |
| 201 | let (mut session, expired) = match authenticator { |
| 202 | Authenticator::Frontegg(frontegg) => { |
no test coverage detected