PostgreSQL - storing db credentials in Apache2 httpd.conf - postgresql

I have a PHP application that needs to connect to a Postgres database and I don't want to store the credentials in a config file outside the web tree, if I can help it. I installed the pgsql module.
I read this SO post and like the idea of putting them in httpd.conf
I was wondering if anyone has figured out a way to store PostgreSQL db credentials in httpd.conf.
There are no predefined php.ini directives for PostgreSQL PHP module like there are for MySQL PHP module, as far as I can tell:
http://php.net/manual/en/ini.list.php
php_value mysql.default.user myusername
php_value mysql.default.password mypassword
php_value mysql.default.host server
Thanks

You have a few options here.
The best option, if you can do it, is to use certificate auth and a client certificate.
The second best option if you can is to use a .pgpass file, which would store this in the home directory of the user that Apache runs as.
Your third option is you could use mod_rewrite to set the PGUSER and PGPASSWORD environment variables. Note that this is pretty dangerous because anyone on the server could access the environment and learn the username and password.

Related

Can't create Keycloak 17.0.0 admin user

I installed Keycloak 17.0.0 but not able to create admin user. I followed this document.
When I access Keycloak page, it is showing "you need local access to create the initial admin user". Screenshot is here - Keycloak. Also I didn't find the add-user-keycloak script in Keycloak 17.0.0. I am quite new to this. Can anyone help on how to create the initial admin user?
Thanks in advance.
I to have been trying to play around with Keycloak 17, and have found it far from easy to get it to work as I expected.
I am trying to get it work on remote server,where its impossible to login on localhost. To create the admin user I followed the information in the Keycloak document at KeyCloak documents, see the section called Creating the first administrator
You set the following envronmental variables
export KEYCLOAK_ADMIN='username'
export KEYCLOAK_ADMIN_PASSWORD='password'
bin/kc.[sh|bat] start
Were username and password are strings for username and password.
Another problem I had was getting Keycloak to work on my server haggis on port 8085. My solution was to invoke it as follows.
./kc.sh start-dev --http-port=8085 --http-host=haggis --db-url-host=haggis --db-username=kc --hostname=haggis:8085 --hostname-admin=haggis:8085 --hostname-strict-backchannel=true --db-url-database=postgresql --db-username='kcuser'
This command line instructs Keycloak to start up on the server haggis, at port 8085, using a postgres database with a database user called kcuser in development mode.
My largest problem was working out that you had to include the port number in the hostname style arguments.
Once everything is working you can invoke it as
http://haggis:8085/admin/master/console/#/realms/master
Ok, someone far cleverer than I figured this out:
export KEYCLOAK_ADMIN=admin
export KEYCLOAK_ADMIN_PASSWORD=admin
sudo -E bin/kc.sh start-dev
https://github.com/keycloak/keycloak/discussions/10262
But don't use admin/admin of course...

How does the Cloud SQL socket know what domain to connect to?

I don't have a lot of experience with sockets, especially google cloud ones. The Cloud SQL uses a format: mysql:unix_socket=/cloudsql/INSTANCE_CONNECTION_NAME;dbname=DATABASE
How does this get translated into making a real connection? To me it seems like it is missing a domain name.
https://cloud.google.com/appengine/docs/standard/php/cloud-sql/using-cloud-sql-mysql
env_variables:
# Replace USER, PASSWORD, DATABASE, and CONNECTION_NAME with the
# values obtained when configuring your Cloud SQL instance.
MYSQL_DSN: mysql:unix_socket=/cloudsql/INSTANCE_CONNECTION_NAME;dbname=DATABASE
MYSQL_USER: USER
MYSQL_PASSWORD: PASSWORD
Sockets on Linux are just folders that are CHMOD 777
In this case you need to create a directory /cloudsql and CHMOD 777.
Better documentation found for this by visiting https://cloud.google.com/appengine/docs/flexible/php/using-cloud-sql and clicking UNIX Sockets as the doc option.
Also you need to download the cloud sql proxy app, these are all just settings for it.

PostgreSQL : .pcppass file not found, tried other links

I am working on installing PgPoolAdmin on my local ubuntu system for installing it on server later. Currently, I am able to login but I keep getting an error Could not read .pcppass fileFile not found. I have tried this and many other resources, but no luck. Where is it looking for this file?
The username and passowrd in pcp.conf is same as here, just its in plain text in .pcppass and md5 in pcp.conf. Is that correct?
pcp.conf I have on 2 location /var/www/html and /var/www/html/admin-tool/
Its contents :
#insert:hostname:port:username:password
*:*:akshay:PASSWORD
*:*:postgres:PASSWORD
Thank you.
.pcppass needs to accessible by the user that runs your web server. For example, if you are serving pgpoolAdmin through apache2 with default paths and users. The following should solve the issue.
cp ~/.pcpass /var/www/.pcppass
chown www-data:www-data /var/www/.pcppass
chmod 600 /var/www/.pcppass
By default a .pcppass file should be located in the user's $HOME directory. If you have created it elsewhere, then initialize the $PCPPASSFILE environment variable with the filepath. Make sure the file is in this format:hostname:port:username:password. Then you should be able to access the database.
Note: You cannot use wildcards in the password files, as it will give error sometimes. It is better to use exact host/port values for better security.

OwnCloud does not use alternative config directory

I'd like to run an OwnCloud instance with an alternative configuration directory. The client version is 1.6.2. I use the following command:
owncloud --confdir /path/to/owncloud.cfg
The always tries to take the default directory to get the configuration and if this is empty it ask me for server address, user name and password and so on and creates a new owncloud.cfg again.
I found some descriptions on the internet where this seems to work, but not on my machine. Does somebody has an idea?

How do I get started if I want to use PostgreSQL for local use?

Good day,
Currently I use MS Access at home for several Databases (for personal use).
At work, I use PostgreSQL, which is infinity times better. I want to start using postgres for my personally used databases, but I don't know where to start.
I've tried reading the documentation, but still don't know how to start. I don't have a server at home; is it possible I can just make a local database/tablespace? Or would I have to host a virtual server?
Note that I am willing to use other open source databases if there is an easy option out there - MS access is just so... terrible.
Thanks,
So, it seems you have Windows at home. You just need to download full installer for PostgreSQL:
http://www.postgresql.org/download/windows/
After installation it will automatically add starting postgres server as a service on local machine. That means, server will always run in background, but you can disable that later, or just uninstall.
After that, you can use pgAdmin (included in default installation package) or other client tools to access the DB engine.
UPD in pgadmin, create connection with this settings:
'localhost' as hostname;
port - 5432;
user, database - postgres (for testing purpose only - you should create your own user and tables with restricted rights later).
Password for postgres (that is DB admin user) must be entered during installation process.
Server settings are stored somewhere here:
"C:\Program Files\PostgreSQL\9.3\data"
pg_hba.conf - Client Authentication Configuration File
postgresql.conf - Configuration File