Skip to content

A couple things #397

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

Merged
merged 3 commits into from
Apr 10, 2023
Merged
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: 1 addition & 1 deletion .circleci/pgcat.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ log_client_connections = false
log_client_disconnections = false

# Reload config automatically if it changes.
autoreload = true
autoreload = 15000

# TLS
tls_certificate = ".circleci/server.cert"
Expand Down
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
root = true

[*]
trim_trailing_whitespace = true
insert_final_newline = true

[*.rs]
indent_style = space
indent_size = 4
max_line_length = 120

[*.toml]
indent_style = space
indent_size = 2
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pgcat"
version = "1.0.0"
version = "1.0.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
3 changes: 0 additions & 3 deletions examples/docker/pgcat.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ log_client_connections = false
# If we should log client disconnections
log_client_disconnections = false

# Reload config automatically if it changes.
autoreload = false

# TLS
# tls_certificate = "server.cert"
# tls_private_key = "server.key"
Expand Down
2 changes: 1 addition & 1 deletion pgcat.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ log_client_connections = false
log_client_disconnections = false

# When set to true, PgCat reloads configs if it detects a change in the config file.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment is outdated, maybe specifying also unit? (milliseconds)

autoreload = false
autoreload = 15000

# Number of worker threads the Runtime will use (4 by default).
worker_threads = 5
Expand Down
48 changes: 35 additions & 13 deletions src/auth_passthrough.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::errors::Error;
use crate::pool::ConnectionPool;
use crate::server::Server;
use log::debug;

Expand Down Expand Up @@ -78,19 +79,25 @@ impl AuthPassthrough {

let user = &address.username;

debug!("Connecting to server to obtain auth hashes.");
debug!("Connecting to server to obtain auth hashes");

let auth_query = self.query.replace("$1", user);

match Server::exec_simple_query(address, &auth_user, &auth_query).await {
Ok(password_data) => {
if password_data.len() == 2 && password_data.first().unwrap() == user {
if let Some(stripped_hash) = password_data.last().unwrap().to_string().strip_prefix("md5") {
Ok(stripped_hash.to_string())
}
else {
Err(Error::AuthPassthroughError(
"Obtained hash from auth_query does not seem to be in md5 format.".to_string(),
))
}
if let Some(stripped_hash) = password_data
.last()
.unwrap()
.to_string()
.strip_prefix("md5") {
Ok(stripped_hash.to_string())
}
else {
Err(Error::AuthPassthroughError(
"Obtained hash from auth_query does not seem to be in md5 format.".to_string(),
))
}
} else {
Err(Error::AuthPassthroughError(
"Data obtained from query does not follow the scheme 'user','hash'."
Expand All @@ -99,10 +106,25 @@ impl AuthPassthrough {
}
}
Err(err) => {
Err(Error::AuthPassthroughError(
format!("Error trying to obtain password from auth_query, ignoring hash for user '{}'. Error: {:?}",
user, err)))
Err(Error::AuthPassthroughError(
format!("Error trying to obtain password from auth_query, ignoring hash for user '{}'. Error: {:?}",
user, err))
)
}
}
}
}
}

pub async fn refetch_auth_hash(pool: &ConnectionPool) -> Result<String, Error> {
let address = pool.address(0, 0);
if let Some(apt) = AuthPassthrough::from_pool_settings(&pool.settings) {
let hash = apt.fetch_hash(address).await?;

return Ok(hash);
}

Err(Error::ClientError(format!(
"Could not obtain hash for {{ username: {:?}, database: {:?} }}. Auth passthrough not enabled.",
address.username, address.database
)))
}
Loading