MySQL

Setting the Service mode to MYSQL enables it to operate in application-layer aware MySQL mode. This mode enables you to provide secret-less access for Users to the protected upstream MySQL-based server without having to share the upstream's password. This mode also provides you with clear application-layer aware visibility where your MySQL sessions and queries are logged and audited in real-time.

Secret-less Access

You can simply provide your database configuration (i.e. user, database and password) to provide secret-less access for your Users as follows:

1
kind: Service
2
metadata:
3
name: mysql-db-01
4
spec:
5
# Set the mode to MYSQL
6
mode: MYSQL
7
port: 1234
8
config:
9
upstream:
10
url: mysql://address-to-db
11
mysql:
12
# RECOMMENDED. Override the DB user. If not set, then the value from the downstream is used.
13
user: user01
14
# RECOMMENDED. Override the DB name. If not set, then the value from the downstream is used.
15
database: db01
16
# RECOMMENDED. Set the password of the user.
17
auth:
18
password:
19
fromSecret: <SECRET_NAME>
20
# Set isTLS to true if the MySQL server is running over TLS
21
isTLS: true

Access Control

You can control access based on the MySQL request information. Such information are stored in ctx.request.mysql where it contains the username and database. Here is a detailed example of a inline Policy that controls access based on MySQL-specific information:

1
kind: Service
2
metadata:
3
name: svc1
4
spec:
5
mode: MYSQL
6
port: 1234
7
config:
8
upstream:
9
url: mysql://address-to-db
10
# rest of the config
11
authorization:
12
inlinePolicies:
13
- spec:
14
rules:
15
- effect: ALLOW
16
condition:
17
any:
18
of:
19
- match: ctx.request.mysql.connect.user == "db-user-1"
20
- match: ctx.request.mysql.connect.database == "db-01"
NOTE

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

Dynamic Configuration

You can use dynamic configuration in order to, for example, route to different upstreams and/or setting different users, databases and passwords depending on the request's context (read more about dynamic configuration here). Here is an example:

1
metadata:
2
name: example-svc
3
spec:
4
mode: MYSQL
5
dynamicConfig:
6
configs:
7
- name: prod
8
upstream:
9
url: mysql://address
10
mysql:
11
user: prod
12
database: prod-db
13
auth:
14
password:
15
fromSecret: prod-password
16
- name: dev
17
upstream:
18
url: mysql://address
19
mysql:
20
user: dev
21
database: dev-db
22
auth:
23
password:
24
fromSecret: dev-password
25
rules:
26
- condition:
27
match: '"prod" in ctx.user.spec.groups'
28
configName: prod
29
- condition:
30
matchAny: true
31
configName: dev

Visibility

The Service emits access logs in real time to the audit collector. Each log provides MySQL application-layer aware information about the request such as the command type, the query details, etc.... Here is an example:

1
{
2
"apiVersion": "core/v1",
3
"kind": "Log",
4
"metadata": {
5
// Omitted for the sake of brevity of the example
6
},
7
"entry": {
8
"service": {
9
"info": {
10
"common": {
11
"status": "ALLOWED"
12
// Omitted for the sake of brevity of the example
13
},
14
"mysql": {
15
"query": {
16
"query": "CREATE DATABASE db01;"
17
},
18
"type": "QUERY"
19
}
20
}
21
// Omitted for the sake of brevity of the example
22
}
23
}
24
}

As you can see in the above example, the type of this MYSQL access Log is a QUERY. The MYSQL 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.

© 2025 octelium.comOctelium Labs, LLCAll rights reserved
Octelium and Octelium logo are trademarks of Octelium Labs, LLC.
WireGuard is a registered trademark of Jason A. Donenfeld