Skip to content

Commit f50130b

Browse files
authored
Merge pull request #19 from nathanjrobertson/unix_socket_docs
Add documentation for UNIX socket connections
2 parents 74faf9f + d4efc2e commit f50130b

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

docs/sql.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Options
3838
Writing a Query / Queries
3939
-------------------------
4040

41-
A `query` can be either a single string with an SQL statement, or an array of queries, run in order. That single string (or the first query in the array) is the "authentication query" - the parameters `:username` and `:password` are available and should be evaluated by the query for authenticaion purposes. If the username/password is incorrect, the "authentication query" should return no rows. The rows returned represent attributes to be returned.
41+
A `query` can be either a single string with an SQL statement, or an array of queries, run in order. That single string (or the first query in the array) is the "authentication query" - the parameters `:username` and `:password` are available and should be evaluated by the query for authentication purposes. If the username/password is incorrect, the "authentication query" should return no rows. The rows returned represent attributes to be returned.
4242

4343
Taking this example schema:
4444

@@ -180,6 +180,37 @@ Example query - SHA512 of salt + password, stored as salt (32 bytes) + sha256(sa
180180
)
181181
```
182182

183+
Connecting with UNIX Domain Sockets (Local Sockets)
184+
---------------------------------------------------
185+
186+
When on a UNIX-like platform (Linux, *BSD, etc), and when your SQL database server is running on the same host as the web server
187+
hosting SimpleSAMLphp, it is possible to use UNIX domain sockets instead of TCP sockets for the database connection. This
188+
configuration should result in marginally better performance and security (when configured correctly).
189+
190+
Here is an example using PostgreSQL:
191+
192+
```php
193+
'example-unix-socket-sql' => [
194+
'sqlauth:SQL',
195+
'dsn' => 'pgsql:host=/var/run/postgresql;dbname=simplesaml',
196+
'username' => 'www-data',
197+
'password' => 'this-is-ignored',
198+
'query' => 'SELECT uid, givenName, email, eduPersonPrincipalName FROM users WHERE uid = :username ' .
199+
'AND password = SHA2(CONCAT((SELECT salt FROM users WHERE uid = :username), :password), 256);',
200+
],
201+
```
202+
203+
Configuration is largely the same as TCP sockets (documented above), with the differences being:
204+
205+
`dsn`
206+
: The key difference is that the `host` parameter. This needs to be the **directory** that contains the socket file used to connect to the PostgreSQL server. For example, actual socket file might be `/var/run/postgresql/.s.PGSQL.5432`, so `host=/var/run/postgresql` is the parameter that you need. If you're struggling to find where the socket is, the `unix_socket_directories` parameter in the server `postgresql.conf` is where that location is configured.
207+
208+
`username`
209+
: The UNIX username of the user running SimpleSAMLphp (ie. the web server user or the php-fpm user, depending on your setup).
210+
211+
`password`
212+
: Required, but the value you specify is ignored (so you can put any placeholder string value in there). All authentication for UNIX domain sockets are done by the operating system kernel.
213+
183214
Security considerations
184215
-----------------------
185216

0 commit comments

Comments
 (0)