Skip to content

Commit a45a669

Browse files
committed
tls: add db_* commands for tls_mgm provisioning
The tls module could only write certificates to files, leaving the tls_mgm table to be provisioned by hand. Add CRUD commands over it: tls db_add <domain> [type] column=value ... tls db_update <domain> [type] column=value ... tls db_show <domain> [type] tls db_delete <domain> [type] tls db_list A domain is identified by its name and its type (server or client), matching the UNIQUE (domain, type) constraint of the table. Every settable column is passed as 'column=value', so the whole schema is reachable, not just the certificate and the key. The columns holding PEM content take the path of the file holding it, which is read and stored as a BLOB; every other column is stored as given. Unknown columns, unreadable files and files that do not hold PEM are rejected before the database is touched. After every change the tls_reload MI command is issued, so a running OpenSIPS picks up the domains without a restart.
1 parent 8cd8a50 commit a45a669

2 files changed

Lines changed: 392 additions & 1 deletion

File tree

‎docs/modules/tls.md‎

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,51 @@
22

33
Using the `tls` module, you can generate TLS certificates and private keys.
44

5-
The module has two subcommands:
5+
The module has the following subcommands:
66
* `rootCA` - generates a CA (certification authority) self signed certificate
77
and private key pair. These are to be used by a TLS server.
88
* `userCERT` - generates a certificate signed by a given CA, a private key and
99
a CA list (chain of trust) file. These are to be used by TLS clients (users).
10+
* `db_add` - adds a new TLS domain to the `tls_mgm` table.
11+
* `db_update` - changes the columns of an existing TLS domain.
12+
* `db_list` - lists the TLS domains provisioned in the `tls_mgm` table.
13+
* `db_show` - prints the columns of a TLS domain.
14+
* `db_delete` - removes a TLS domain from the `tls_mgm` table.
15+
16+
The `db_*` subcommands provision the `tls_mgm` module over the database, where
17+
the certificate, private key and CA list are stored as BLOB values rather than
18+
as paths to files. A TLS domain is identified by its name and its type
19+
(`server` or `client`), both passed as arguments:
20+
```
21+
opensips-cli -x tls db_delete a.example.org server
22+
```
23+
24+
`db_add` and `db_update` take the remaining `tls_mgm` columns as `column=value`
25+
arguments, in any order and after the domain and the type:
26+
```
27+
opensips-cli -x tls db_add a.example.org server method=TLSv1_2 verify_cert=1
28+
```
29+
The settable columns are `match_ip_address`, `match_sip_domain`, `method`,
30+
`verify_cert`, `require_cert`, `certificate`, `private_key`, `crl_check_all`,
31+
`crl_dir`, `ca_list`, `ca_dir`, `cipher_list`, `dh_params` and `ec_curve`. A
32+
column that is not given is left to its default in the database schema;
33+
`db_update` only changes the columns it is given.
34+
35+
The `certificate`, `private_key`, `ca_list` and `dh_params` columns hold PEM
36+
content, so their value is the path of the file holding it, and that file is
37+
read and stored in the table:
38+
```
39+
opensips-cli -x tls db_add a.example.org server \
40+
certificate=/etc/opensips/tls/user/user-cert.pem \
41+
private_key=/etc/opensips/tls/user/user-privkey.pem
42+
```
43+
Every other column is stored as the value it is given, paths included: for
44+
example, `ca_list` reads the file it points to, while `ca_dir` and `crl_dir`
45+
keep the directory as such, which is what `tls_mgm` expects of them.
46+
47+
After every change, the `tls_reload` MI command is issued so that a running
48+
OpenSIPS picks up the new domains. If OpenSIPS cannot be reached, a warning is
49+
logged and the domains are loaded at the next restart.
1050

1151
## Configuration
1252

@@ -47,6 +87,14 @@ List of `opensips-cli.cfg` settings for configuring user certificates:
4787
* tls_user_key_size - the size of the RSA key, in bits (e.g. 4096)
4888
* tls_user_md - the digest algorithm to use for signing (e.g. SHA256)
4989

90+
List of `opensips-cli.cfg` settings for the `db_*` subcommands:
91+
92+
* database_tls_url - URL of the database holding the `tls_mgm` table; falls
93+
back to `database_url`
94+
* database_tls_name - name of the database; falls back to `database_name`
95+
* tls_db_type - the default TLS domain type ("server" or "client"), used when
96+
no type is passed as an argument
97+
5098

5199
## Examples
52100

@@ -97,3 +145,39 @@ tls_user_notafter: 315360000
97145
tls_user_key_size: 4096
98146
tls_user_md: SHA256
99147
```
148+
149+
To provision the certificate generated above as a TLS domain in the database:
150+
```
151+
opensips-cli -x tls db_add a.example.org server \
152+
certificate=/etc/opensips/tls/user/user-cert.pem \
153+
private_key=/etc/opensips/tls/user/user-privkey.pem \
154+
ca_list=/etc/opensips/tls/user/user-calist.pem
155+
```
156+
Certificates issued by a public CA are provisioned the same way:
157+
```
158+
opensips-cli -x tls db_add a.example.org server \
159+
certificate=/etc/letsencrypt/live/a.example.org/fullchain.pem \
160+
private_key=/etc/letsencrypt/live/a.example.org/privkey.pem
161+
```
162+
Configuration file example for the `db_*` subcommands:
163+
```
164+
[default]
165+
database_url: mysql://opensips:opensipsrw@localhost
166+
database_name: opensips
167+
tls_db_type: server
168+
```
169+
170+
To renew the certificate of a domain, or to change any of its other columns:
171+
```
172+
opensips-cli -x tls db_update a.example.org server \
173+
certificate=/etc/letsencrypt/live/a.example.org/fullchain.pem \
174+
private_key=/etc/letsencrypt/live/a.example.org/privkey.pem
175+
opensips-cli -x tls db_update a.example.org server cipher_list=HIGH
176+
```
177+
178+
To inspect and remove the provisioned domains:
179+
```
180+
opensips-cli -x tls db_list
181+
opensips-cli -x tls db_show a.example.org server
182+
opensips-cli -x tls db_delete a.example.org server
183+
```

0 commit comments

Comments
 (0)