Skip to content
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

Scram auth #667

Merged
merged 2 commits into from
Aug 14, 2024
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
59 changes: 8 additions & 51 deletions config-examples/odyssey-aq.conf
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ storage "postgres_server" {

database default {
user default {
authentication "md5"
authentication "scram-sha-256"
auth_query "SELECT usename, passwd FROM pg_shadow WHERE usename=$1"
auth_query_user "admin"
auth_query_db "postgres"
storage_password "passwd"
storage_password "odyssey"
storage_user "odyssey"

storage "postgres_server"
pool "session"
Expand All @@ -85,61 +86,17 @@ database default {
server_lifetime 1901
log_debug no

quantiles "0.99,0.95,0.5"
client_max 107
}
}

database "postgres" {
user "user_aq" {
authentication "none"

storage "postgres_server"

pool "session"
storage_user "admin"
storage_db "postgres"

log_debug yes
pool_discard yes
pool_size 20
pool_routing "internal"

quantiles "0.99,0.95,0.5"
client_max 107
}


user "user_aq" {
authentication "md5"
auth_query "SELECT usename, passwd FROM pg_shadow WHERE usename=$1"
auth_query_user "admin"
auth_query_db "postgres"
storage_password "passwd"

storage "postgres_server"
storage_password "1"
pool "statement"
pool_size 1

pool_timeout 0
pool_ttl 60
pool_discard no
pool_cancel yes
pool_rollback yes

client_fwd_error yes
# add this options to backend-startup package
backend_startup_options {
"_pq_.service_auth_role" "odyssey"
}

application_name_add_host yes
reserve_session_server_connection no
server_lifetime 3600
log_debug no

quantiles "0.99,0.95,0.5"
client_max 107
}

}

storage "local" {
type "local"
}
Expand Down
6 changes: 3 additions & 3 deletions sources/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,15 +951,15 @@ static inline int od_auth_backend_sasl_continue(od_server_t *server,
/* use storage or user password */
char *password;

if (client != NULL && client->password.password != NULL) {
if (route->rule->storage_password) {
password = route->rule->storage_password;
} else if (client != NULL && client->password.password != NULL) {
od_error(
&instance->logger, "auth", NULL, server,
"cannot authenticate with SCRAM secret from auth_query",
route->rule->db_name, route->rule->user_name);

return -1;
} else if (route->rule->storage_password) {
password = route->rule->storage_password;
} else if (route->rule->password) {
password = route->rule->password;
} else if (client->received_password.password) {
Expand Down
2 changes: 2 additions & 0 deletions sources/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,7 @@ int od_rules_autogenerate_defaults(od_rules_t *rules, od_logger_t *logger)
if (!default_rule->storage_password) {
od_log(logger, "config", NULL, NULL,
"skipping default internal rule auto-generation: default rule storage password not set");

return OK_RESPONSE;
}

Expand All @@ -1380,6 +1381,7 @@ int od_rules_autogenerate_defaults(od_rules_t *rules, od_logger_t *logger)

/* force several default settings */
#define OD_DEFAULT_INTERNAL_POLL_SZ 0

rule->pool->type = strdup("transaction");
if (rule->pool->type == NULL)
return NOT_OK_RESPONSE;
Expand Down
Loading