Closed AurimasNav closed 2 years ago
Try url-encoding it, so password_with_special_symbols_%23%21%26%2B%7B%7D%3C%3E%3A
, see https://stackoverflow.com/questions/6718471/escaping-username-characters-in-basic-auth-urls
I think kratos/keto should provide a mechanism that allows for providing database credentials (passwords) with special characters.
Our usecase is that we run Kratos and keto in AWS ECS which provides databasae credentials via a secret stored in secret manager. This password is autogenerated and can possibly contain illegal url characters.
I solved this by adding an entrypoint script which encodes the password before sending it to kratos/keto. but imo the encoding should be handled by kratos/keto. I'd prefer to specify database name, password, username etc. as seperate env vars.
#!/bin/sh
url_encode() (
string=${*:-$(
cat -
printf x
)}
[ -n "$*" ] || string=${string%x}
# Zero index, + 1 to start from 1 since sed starts from 1
lines=$(($(printf %s "$string" | wc -l) + 1))
lineno=1
while [ $lineno -le $lines ]; do
currline=$(printf %s "$string" | sed "${lineno}q;d")
pos=1
chars=$(printf %s "$currline" | wc -c)
while [ $pos -le "$chars" ]; do
c=$(printf %s "$currline" | cut -b$pos)
case $c in
[-_.~a-zA-Z0-9]) printf %c "$c" ;;
*) printf %%%02X "'${c:-\n}'" ;;
esac
pos=$((pos + 1))
done
[ $lineno -eq $lines ] || printf %%0A
lineno=$((lineno + 1))
done
)
DSN="postgres://$DATABASE_USERNAME:$(url_encode "$DATABASE_PASSWORD")@$DATABASE_HOST:$DATABASE_PORT/$DATABASE_NAME?sslmode=verify-full&sslrootcert=$(url_encode "/home/ory/.postgresql/root.crt")"
export DSN
/usr/bin/keto "$@"
Preflight checklist
Describe the bug
automigrate container fails due to failed parsing of postgres address as URL.
Reproducing the bug
#!$%&+{}<>:
Relevant log output
Relevant configuration
Version
v0.8.0-alpha.3
On which operating system are you observing this issue?
Linux
In which environment are you deploying?
Kubernetes with Helm
Additional Context
Not sure if qualifies as a bug, if not then it would be nice if in the configuration docs it would be mentioned that symbols in dsn need to be percent-encoded for url parsing.