Reputation: 21
We have an application with a script that create a conceptual model and a login role in a PostgreSQL database. This login role will be used by the application for everything, independent of the logged application user.
How can we protect this login role password inside the application code?
Upvotes: 1
Views: 154
Reputation: 149155
You cannot.
If the user has a direct access to the application (they can directly launch it) everything that is hardcoded in the application should be seen as accessible to the user. Whatever obfuscation you can use, a determinated attacker will be able to find it (through decompilers an debuggers).
If a break point exist, all is different:
front end application back end application
launched by user --/--> launched with a sytem user
local machine local or remote machine
This is typically the use case for web applications: the user has no access to the application code, and does not launch it, so the database password can lie in a configuration file - it will always be accessible to administrators. Even when all runs on the same machine, decent OS allows for access protection to prevent unprivileged users any access to the backend program. For that latter case, the front end and backend can communicate through sockets, named pipes, messages or almost any other IPC mechanism.
TL/DR: only secure way:
Upvotes: 0
Reputation: 249582
The main three authentication mechanisms you could use, roughly in order of popularity, are:
kinit
, or loading a credential file).Of these, my personal preference would be Kerberos if that service is supported on the network in question. Second best would be LDAP, because it allows centralized control over things like password changes and revocation. And third would be the regular password mechanism, which works in any environment.
Details on all of the available mechanisms are here: https://www.postgresql.org/docs/10/static/auth-methods.html
Upvotes: 0
Reputation: 19663
Consider using a yaml file
to store your credentials or alternatively place them in a .pgpass file
.
Upvotes: 1