Octelium documentation · Latest
PostgreSQL
Setting the Service mode to POSTGRES enables it to operate in application-layer aware PostgreSQL mode. This mode enables you to provide secretless access for Users to the protected upstream PostgreSQL-based server without having to share the upstream's password. This mode also provides you with clear application-layer aware visibility where your Postgres sessions and queries are logged and audited in real-time.
Secretless Access
Secretless access enables you to provide secretless access for authorized Users to POSTGRES-based Service by automatically injecting passwords to authenticate to the upstream PostgreSQL database, and force the User to connect to the upstream as a specific user, possibly with a certain role corresponding to specific permissions, to a specific database.
First, you need to create a Secret to store the password of your upstream SSH server (read more here) as follows:
Now, you define your Service as follows:
Now, the above configuration forces the User to authenticate as postgres with the password value set in the Secret pg-password and connect to the db01 database regardless of the information supplied by the downstream.
For internal/private PostgreSQL upstreams behind NAT, you need to remotely serve them via a connected octelium client or container as discussed here.
SSL Mode
By default, the Service attempts to use prefer ssl mode (read more here). You can, however, override that default behavior via the sslMode field and explicitly set it to one of the following modes:
DISABLEdisables using TLS.REQUIREforces using TLS without verifying the upstream's certificate at all.VERIFY_CAforces using TLS and additionally verifies that the upstream's certificate chains up to a trusted CA without verifying the upstream's hostname.VERIFY_FULLforces using TLS and additionally verifies both the upstream's certificate chain and its hostname. This is the recommended mode for upstreams that are listening over TLS.
Here is an example:
For the VERIFY_CA and VERIFY_FULL modes, the upstream's certificate is verified against the system's default trusted CAs. If the upstream is using a certificate that is signed by a private CA, you can set your own trusted CAs via the tls field (read more here). Here is an example:
Access Control
You can control access based on the Postgres request information. Such information are stored in ctx.request.postgres where it contains the username and database. Here is a detailed example of a inline Policy that controls access based on Postgres-specific information:
You do not actually need to control access by checking against the database user since you already override the database user in your Service configuration as illustrated above regardless of the database user value provided by the User. You can also use dynamic configuration in order to map different databases and/or database users to different Users under different conditions. You can read more about dynamic configuration here
By default, the Service enforces authorization only at the beginning of the connection. You can, however, enforce authorization for every PostgreSQL command by setting the authorization.mode field to ALL. In such case, the SQL statement of simple queries is stored in ctx.request.postgres.query.query while the name and SQL statement of extended query protocol parse requests are stored in ctx.request.postgres.parse.name and ctx.request.postgres.parse.query respectively. Here is an example:
A denied command is not proxied to the upstream and the downstream receives an error instead. Note that fast-path function calls are always denied in this mode.
Dynamic Configuration
You can use dynamic configuration (read more about dynamic configuration here) to, for example, route to different upstreams or different database users with different privileges and roles (e.g. more privileged Users can automatically delete tables or databases while other Users cannot do so) based on identity and/or context. Here is an example:
Visibility
The Service emits access logs in real time to the audit collector. Each log provides PostgreSQL application-layer aware information about the request such as the command type, the query details, etc.... Here is an example:
As you can see in the above example, the type of this POSTGRES access Log is a QUERY. The POSTGRES mode has currently 8 Log types: SESSION_START, SESSION_END, QUERY, PARSE, CLOSE, EXECUTE, BIND, FUNCTION_CALL and some of these types include different detailed information according to their type. You can read more in the API reference.
You can also disable recording the statement text of the query and parse messages in the access logs via the visibility.disableQuery field. The access logs themselves are still recorded without the statement text. This is recommended for databases whose statements routinely embed credentials or other sensitive values. Here is an example: