Skip to content

Commit 828e49f

Browse files
authored
Rename [database].ssl* options to [database].tls* to support pymongo 4 (#6250)
2 parents 5a833f2 + 059bca3 commit 828e49f

File tree

12 files changed

+399
-190
lines changed

12 files changed

+399
-190
lines changed

CHANGELOG.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ in development
66

77
Python 3.6 is no longer supported; Stackstorm requires at least Python 3.8.
88

9+
Several st2.conf database options have been renamed or deprecated. Most of the options will continue to work using their old name.
10+
However, if you use `[database].ssl_keyfile` and/or `[database].ssl_certfile`, you MUST migrate to `[database].tls_certificate_key_file`.
11+
This new option expects the key and certificate in the same file. Use something like the following to create that file from your old files:
12+
13+
```
14+
cat path/to/ssl_keyfile path/to/ssl_certfile > path/to/tls_certificate_key_file
15+
```
16+
17+
Other options that were renamed under `[database]` are (more details available in `st2.conf.sample`):
18+
19+
* `ssl` -> `tls`
20+
* `ssl_cert_reqs` -> `tls_allow_invalid_certificates` (opt type change: string -> boolean)
21+
* `ssl_ca_certs` -> `tls_ca_file`
22+
* `ssl_match_hostnames` -> `tls_allow_invalid_hostnames` (meaning is inverted: the new option is the opposite of the old)
23+
924
Fixed
1025
~~~~~
1126
* Fixed #6021 and #5327 by adding max_page_size to api_opts and added limit and offset to list_values() methods of
@@ -31,6 +46,11 @@ Changed
3146
* Updated unit tests to use redis for coordination instead of the NoOp driver. This will hopefully make CI more stable. #6245
3247
Contributed by @FileMagic, @guzzijones, and @cognifloyd
3348

49+
* Renamed `[database].ssl*` options to support pymongo 4, which we have to update to support newer MongoDB servers.
50+
Please see the note above about migrating to the newer options, especially if you use `[database].ssl_keyfile`
51+
and/or `[database].ssl_certfile`, as those options are ignored in StackStorm 3.9.0. #6250
52+
Contributed by @cognifloyd
53+
3454
Added
3555
~~~~~
3656
* Continue introducing `pants <https://www.pantsbuild.org/docs>`_ to improve DX (Developer Experience)

conf/st2.conf.sample

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ logging = /etc/st2/logging.actionrunner.conf
1919
# List of pip options to be passed to "pip install" command when installing pack dependencies into pack virtual environment.
2020
pip_opts = # comma separated list allowed here.
2121
# Python binary which will be used by Python actions.
22-
python_binary = /usr/bin/python
22+
python_binary = /usr/bin/python3
2323
# Default log level to use for Python runner actions. Can be overriden on invocation basis using "log_level" runner parameter.
2424
python_runner_log_level = DEBUG
2525
# Time interval between subsequent queries to check running executions.
@@ -106,11 +106,13 @@ index_url = https://index.stackstorm.org/v1/index.json # comma separated list al
106106
pack_group = st2packs
107107
# Paths which will be searched for integration packs.
108108
packs_base_paths = None
109-
# Paths which will be searched for runners. NOTE: This option has been deprecated and it's unused since StackStorm v3.0.0
109+
# Paths which will be searched for runners.
110+
# DEPRECATED FOR REMOVAL since 3.0.0: Option unused since StackStorm v3.0.0
110111
runners_base_paths = None
111112
# Path to the directory which contains system packs.
112113
system_packs_base_path = /opt/stackstorm/packs
113-
# Path to the directory which contains system runners. NOTE: This option has been deprecated and it's unused since StackStorm v3.0.0
114+
# Path to the directory which contains system runners.
115+
# DEPRECATED FOR REMOVAL since 3.0.0: Option unused since StackStorm v3.0.0
114116
system_runners_base_path = /opt/stackstorm/runners
115117

116118
[coordination]
@@ -142,19 +144,33 @@ host = 127.0.0.1
142144
password = None
143145
# port of db server
144146
port = 27017
145-
# Create the connection to mongodb using SSL
146-
ssl = False
147-
# ca_certs file contains a set of concatenated CA certificates, which are used to validate certificates passed from MongoDB.
148-
ssl_ca_certs = None
149147
# Specifies whether a certificate is required from the other side of the connection, and whether it will be validated if provided
148+
# DEPRECATED FOR REMOVAL since 3.9.0: Use tls_allow_invalid_certificates with the following: The 'optional' and 'required' values are equivalent to tls_allow_invalid_certificates=False. The 'none' value is equivalent to tls_allow_invalid_certificates=True. This option is a needlessly more complex version of tls_allow_invalid_certificates.
150149
# Valid values: none, optional, required
151150
ssl_cert_reqs = None
152151
# Certificate file used to identify the localconnection
152+
# DEPRECATED FOR REMOVAL since 3.9.0: Use tls_certificate_key_file with a path to a file containing the concatenation of the files from ssl_keyfile and ssl_certfile. This option is ignored by pymongo.
153153
ssl_certfile = None
154154
# Private keyfile used to identify the local connection against MongoDB.
155+
# DEPRECATED FOR REMOVAL since 3.9.0: Use tls_certificate_key_file with a path to a file containing the concatenation of the files from ssl_keyfile and ssl_certfile. This option is ignored by pymongo.
155156
ssl_keyfile = None
156157
# If True and `ssl_cert_reqs` is not None, enables hostname verification
158+
# DEPRECATED FOR REMOVAL since 3.9.0: Use tls_allow_invalid_hostnames with the opposite value from this option.
157159
ssl_match_hostname = True
160+
# Create the connection to mongodb using TLS.
161+
# This option has a deprecated alias: ssl
162+
tls = False
163+
# Specifies whether MongoDB is allowed to pass an invalid certificate. This defaults to False to have security by default. Only temporarily set to True if you need to debug the connection.
164+
tls_allow_invalid_certificates = False
165+
# If True and `tlsAllowInvalidCertificates` is True, disables hostname verification. This defaults to False to have security by default. Only temporarily set to True if you need to debug the connection.
166+
tls_allow_invalid_hostnames = False
167+
# ca_certs file contains a set of concatenated CA certificates, which are used to validate certificates passed from MongoDB.
168+
# This option has a deprecated alias: ssl_ca_certs
169+
tls_ca_file = None
170+
# Client certificate used to identify the local connection against MongoDB. The certificate file must contain one or both of private key and certificate. Supplying separate files for private key (ssl_keyfile) and certificate (ssl_certfile) is no longer supported. If encrypted, pass the password or passphrase in tls_certificate_key_file_password.
171+
tls_certificate_key_file = None
172+
# The password or passphrase to decrypt the file in tls_certificate_key_file. Only set this if tls_certificate_key_file is encrypted.
173+
tls_certificate_key_file_password = None
158174
# username for db login
159175
username = None
160176
# Compression level when compressors is set to zlib. Valid values are -1 to 9. Defaults to 6.

contrib/packs/actions/pack_mgmt/unload.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ def initialize(self):
5959
cfg.CONF.database.port,
6060
username=username,
6161
password=password,
62-
ssl=cfg.CONF.database.ssl,
63-
ssl_keyfile=cfg.CONF.database.ssl_keyfile,
64-
ssl_certfile=cfg.CONF.database.ssl_certfile,
65-
ssl_cert_reqs=cfg.CONF.database.ssl_cert_reqs,
66-
ssl_ca_certs=cfg.CONF.database.ssl_ca_certs,
62+
tls=cfg.CONF.database.tls,
63+
tls_certificate_key_file=cfg.CONF.database.tls_certificate_key_file,
64+
tls_certificate_key_file_password=cfg.CONF.database.tls_certificate_key_file_password,
65+
tls_allow_invalid_certificates=cfg.CONF.database.tls_allow_invalid_certificates,
66+
tls_ca_file=cfg.CONF.database.tls_ca_file,
67+
ssl_cert_reqs=cfg.CONF.database.ssl_cert_reqs, # deprecated
6768
authentication_mechanism=cfg.CONF.database.authentication_mechanism,
6869
ssl_match_hostname=cfg.CONF.database.ssl_match_hostname,
6970
)

pants-plugins/sample_conf/rules.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
FileContent,
2828
Snapshot,
2929
)
30-
from pants.engine.process import FallibleProcessResult
30+
from pants.engine.process import ProcessResult
3131
from pants.engine.rules import Get, collect_rules, rule
3232
from pants.engine.target import FieldSet
3333
from pants.util.logging import LogLevel
@@ -64,7 +64,7 @@ async def generate_sample_conf_via_fmt(
6464
pex = await Get(VenvPex, PexFromTargetsRequest, subsystem.pex_request())
6565

6666
result = await Get(
67-
FallibleProcessResult,
67+
ProcessResult,
6868
VenvPexProcess(
6969
pex,
7070
description="Regenerating st2.conf.sample",

st2common/st2common/config.py

Lines changed: 91 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ def register_opts(ignore_errors=False):
143143
cfg.StrOpt(
144144
"system_runners_base_path",
145145
default=system_runners_base_path,
146-
help="Path to the directory which contains system runners. "
147-
"NOTE: This option has been deprecated and it's unused since StackStorm v3.0.0",
146+
help="Path to the directory which contains system runners.",
147+
deprecated_for_removal=True,
148+
deprecated_reason="Option unused since StackStorm v3.0.0",
149+
deprecated_since="3.0.0",
148150
),
149151
cfg.StrOpt(
150152
"packs_base_paths",
@@ -154,8 +156,10 @@ def register_opts(ignore_errors=False):
154156
cfg.StrOpt(
155157
"runners_base_paths",
156158
default=None,
157-
help="Paths which will be searched for runners. "
158-
"NOTE: This option has been deprecated and it's unused since StackStorm v3.0.0",
159+
help="Paths which will be searched for runners.",
160+
deprecated_for_removal=True,
161+
deprecated_reason="Option unused since StackStorm v3.0.0",
162+
deprecated_since="3.0.0",
159163
),
160164
cfg.ListOpt(
161165
"index_url",
@@ -172,6 +176,7 @@ def register_opts(ignore_errors=False):
172176
cfg.StrOpt(
173177
"webui_base_url",
174178
default="https://%s" % socket.getfqdn(),
179+
sample_default="https://localhost",
175180
help="Base https URL to access st2 Web UI. This is used to construct history URLs "
176181
"that are sent out when chatops is used to kick off executions.",
177182
)
@@ -184,7 +189,7 @@ def register_opts(ignore_errors=False):
184189
cfg.IntOpt("port", default=27017, help="port of db server"),
185190
cfg.StrOpt("db_name", default="st2", help="name of database"),
186191
cfg.StrOpt("username", help="username for db login"),
187-
cfg.StrOpt("password", help="password for db login"),
192+
cfg.StrOpt("password", help="password for db login", secret=True),
188193
cfg.IntOpt(
189194
"connection_timeout",
190195
default=3 * 1000,
@@ -206,35 +211,108 @@ def register_opts(ignore_errors=False):
206211
help="Backoff multiplier (seconds).",
207212
),
208213
cfg.BoolOpt(
209-
"ssl", default=False, help="Create the connection to mongodb using SSL"
214+
"tls",
215+
deprecated_name="ssl",
216+
default=False,
217+
help="Create the connection to mongodb using TLS.",
218+
),
219+
cfg.StrOpt(
220+
"tls_certificate_key_file",
221+
default=None,
222+
help=(
223+
"Client certificate used to identify the local connection against MongoDB. "
224+
"The certificate file must contain one or both of private key and certificate. "
225+
"Supplying separate files for private key (ssl_keyfile) and certificate (ssl_certfile) "
226+
"is no longer supported. "
227+
"If encrypted, pass the password or passphrase in tls_certificate_key_file_password."
228+
),
229+
),
230+
cfg.StrOpt(
231+
"tls_certificate_key_file_password",
232+
default=None,
233+
help=(
234+
"The password or passphrase to decrypt the file in tls_certificate_key_file. "
235+
"Only set this if tls_certificate_key_file is encrypted."
236+
),
237+
secret=True,
210238
),
211239
cfg.StrOpt(
212240
"ssl_keyfile",
213241
default=None,
214242
help="Private keyfile used to identify the local connection against MongoDB.",
243+
deprecated_for_removal=True,
244+
deprecated_reason=(
245+
"Use tls_certificate_key_file with a path to a file containing "
246+
"the concatenation of the files from ssl_keyfile and ssl_certfile. "
247+
"This option is ignored by pymongo."
248+
),
249+
deprecated_since="3.9.0",
215250
),
216251
cfg.StrOpt(
217252
"ssl_certfile",
218253
default=None,
219254
help="Certificate file used to identify the localconnection",
255+
deprecated_for_removal=True,
256+
deprecated_reason=(
257+
"Use tls_certificate_key_file with a path to a file containing "
258+
"the concatenation of the files from ssl_keyfile and ssl_certfile. "
259+
"This option is ignored by pymongo. "
260+
),
261+
deprecated_since="3.9.0",
262+
),
263+
cfg.BoolOpt(
264+
"tls_allow_invalid_certificates",
265+
default=None,
266+
sample_default=False,
267+
help=(
268+
"Specifies whether MongoDB is allowed to pass an invalid certificate. "
269+
"This defaults to False to have security by default. "
270+
"Only temporarily set to True if you need to debug the connection."
271+
),
220272
),
221273
cfg.StrOpt(
222274
"ssl_cert_reqs",
223275
default=None,
224276
choices=["none", "optional", "required"],
225-
help="Specifies whether a certificate is required from the other side of the "
226-
"connection, and whether it will be validated if provided",
277+
help=(
278+
"Specifies whether a certificate is required from the other side of the "
279+
"connection, and whether it will be validated if provided"
280+
),
281+
deprecated_for_removal=True,
282+
deprecated_reason=(
283+
"Use tls_allow_invalid_certificates with the following: "
284+
"The 'optional' and 'required' values are equivalent to tls_allow_invalid_certificates=False. "
285+
"The 'none' value is equivalent to tls_allow_invalid_certificates=True. "
286+
"This option is a needlessly more complex version of tls_allow_invalid_certificates."
287+
),
288+
deprecated_since="3.9.0",
227289
),
228290
cfg.StrOpt(
229-
"ssl_ca_certs",
291+
"tls_ca_file",
292+
deprecated_name="ssl_ca_certs",
230293
default=None,
231-
help="ca_certs file contains a set of concatenated CA certificates, which are "
232-
"used to validate certificates passed from MongoDB.",
294+
help=(
295+
"ca_certs file contains a set of concatenated CA certificates, which are "
296+
"used to validate certificates passed from MongoDB."
297+
),
298+
),
299+
cfg.BoolOpt(
300+
"tls_allow_invalid_hostnames",
301+
default=None,
302+
sample_default=False,
303+
help=(
304+
"If True and `tlsAllowInvalidCertificates` is True, disables hostname verification. "
305+
"This defaults to False to have security by default. "
306+
"Only temporarily set to True if you need to debug the connection."
307+
),
233308
),
234309
cfg.BoolOpt(
235310
"ssl_match_hostname",
236311
default=True,
237312
help="If True and `ssl_cert_reqs` is not None, enables hostname verification",
313+
deprecated_for_removal=True,
314+
deprecated_reason="Use tls_allow_invalid_hostnames with the opposite value from this option.",
315+
deprecated_since="3.9.0",
238316
),
239317
cfg.StrOpt(
240318
"authentication_mechanism",
@@ -460,11 +538,13 @@ def register_opts(ignore_errors=False):
460538
cfg.StrOpt(
461539
"python_binary",
462540
default=default_python_bin_path,
541+
sample_default="/usr/bin/python3",
463542
help="Python binary which will be used by Python actions.",
464543
),
465544
cfg.StrOpt(
466545
"virtualenv_binary",
467546
default=default_virtualenv_bin_path,
547+
sample_default="/usr/bin/virtualenv",
468548
help="Virtualenv binary which should be used to create pack virtualenvs.",
469549
),
470550
cfg.StrOpt(

st2common/st2common/database_setup.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ def db_config():
3636
"db_port": cfg.CONF.database.port,
3737
"username": username,
3838
"password": password,
39-
"ssl": cfg.CONF.database.ssl,
40-
"ssl_keyfile": cfg.CONF.database.ssl_keyfile,
41-
"ssl_certfile": cfg.CONF.database.ssl_certfile,
42-
"ssl_cert_reqs": cfg.CONF.database.ssl_cert_reqs,
43-
"ssl_ca_certs": cfg.CONF.database.ssl_ca_certs,
39+
"tls": cfg.CONF.database.tls,
40+
"tls_certificate_key_file": cfg.CONF.database.tls_certificate_key_file,
41+
"tls_certificate_key_file_password": cfg.CONF.database.tls_certificate_key_file_password,
42+
"tls_allow_invalid_certificates": cfg.CONF.database.tls_allow_invalid_certificates,
43+
"tls_ca_file": cfg.CONF.database.tls_ca_file,
44+
"tls_allow_invalid_hostnames": cfg.CONF.database.tls_allow_invalid_hostnames,
45+
"ssl_cert_reqs": cfg.CONF.database.ssl_cert_reqs, # deprecated
4446
"authentication_mechanism": cfg.CONF.database.authentication_mechanism,
45-
"ssl_match_hostname": cfg.CONF.database.ssl_match_hostname,
47+
"ssl_match_hostname": cfg.CONF.database.ssl_match_hostname, # deprecated
4648
}
4749

4850

0 commit comments

Comments
 (0)