@@ -84,6 +84,99 @@ configuration file, :binary:`~bin.mongod` may not start.
84
84
85
85
.. [#yaml-json] YAML is a superset of :term:`JSON`.
86
86
87
+ .. _externally-sourced-values:
88
+
89
+ Externally Sourced Values
90
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
91
+
92
+ .. versionadded:: 4.2
93
+
94
+ Starting in MongoDB 4.2, users can use expansion directives in the
95
+ configuration file to define the value of configuration file options with
96
+ values from an external source. The following expansion directives are
97
+ available:
98
+
99
+ - :configexpansion:`__rest`
100
+
101
+ You must use the :option:`--configExpand <mongod --configExpand>`
102
+ option for the :binary:`~bin.mongod`/:binary:`~bin.mongos` to enable parsing of
103
+ expansion directives. If you specify any expansion directives in the
104
+ configuration file and start the :binary:`~bin.mongod`/:binary:`~bin.mongos`
105
+ without this option, the :binary:`~bin.mongod`/:binary:`~bin.mongos` fails
106
+ to start. This option must be configured on the command line only, and can not
107
+ be expressed in either YAML or INI configuration files.
108
+
109
+ .. configexpansion:: __rest
110
+
111
+ The ``__rest`` expansion directive allows users to use externally sourced
112
+ values in a configuration file. ``__rest`` makes http(s) calls for values
113
+ and can be used two ways.
114
+
115
+ ``__rest`` can fetch field values:
116
+
117
+ .. code-block:: yaml
118
+
119
+ <field> :
120
+ __rest: <string>
121
+ type: string
122
+ trim: < none | whitespace >
123
+
124
+ ``__rest`` can also be used to fetch entire configuration files:
125
+
126
+ .. code-block:: yaml
127
+
128
+ __rest: <string>
129
+ type: yaml
130
+ trim: < none | whitespace >
131
+
132
+ The ``__rest`` expansion directive takes a string representing the url for
133
+ which the mongod or mongos issues a ``GET`` request to retrieve the value.
134
+
135
+ .. note::
136
+
137
+ - ``__rest`` URLs must be HTTPS unless they are referring to
138
+ localhost, in which case they can use unencrypted HTTP URLs.
139
+ - If the REST endpoint requires authentication, encode credentials into the
140
+ URL with standard
141
+ `RFC 3986 User Information <https://tools.ietf.org/html/rfc3986#section-3.2.1>`_
142
+ format.
143
+ - HTTPS requests require TLS 1.1 or later on the client and the host.
144
+
145
+ The following optional fields affect the behavior of the ``__rest``
146
+ expansion directive:
147
+
148
+ .. list-table::
149
+ :header-rows: 1
150
+ :widths: 20 80
151
+
152
+ * - Field
153
+ - Description
154
+
155
+ * - ``type``
156
+
157
+ - Optional. Defaults to ``string``
158
+
159
+ For ``string``, the :binary:`~bin.mongod`/:binary:`~bin.mongos` uses
160
+ the value returned from the endpoint as a literal string. This value
161
+ is not parsed for additional structure beyond what is specific to the
162
+ setting.
163
+
164
+ For ``yaml``, the ``__rest`` directive must be the *only* block in
165
+ the entire configuration file. Users must define their entire
166
+ configuration file within the specified endpoint, and the return type
167
+ must be YAML. See the :ref:`yaml example<rest-yaml-example>`.
168
+
169
+ .. warning::
170
+ Recursive ``__rest`` expansion directives are forbidden. If the
171
+ value returned from a ``__rest`` expansion directive contains an
172
+ expansion directive, the :binary:`~bin.mongod`/
173
+ :binary:`~bin.mongos` throws an error and fails to start.
174
+
175
+ * - ``trim``
176
+
177
+ - Optional. Defaults to ``none``. Specify ``whitespace`` to trim any
178
+ leading or trailing whitespace from the resulting response.
179
+
87
180
Use the Configuration File
88
181
~~~~~~~~~~~~~~~~~~~~~~~~~~
89
182
@@ -114,6 +207,121 @@ If you installed from a package and have started MongoDB using your
114
207
system's :term:`init script`, you are already using a configuration
115
208
file.
116
209
210
+ .. _rest-yaml-example:
211
+
212
+ ``__rest`` Expansion with YAML Example
213
+ ``````````````````````````````````````
214
+
215
+ When using expansion directives, you must include the :option:`--configExpand
216
+ <mongod --configExpand>` command line option when starting the the
217
+ :binary:`~bin.mongod`/:binary:`~bin.mongos`.
218
+
219
+ For example, the configuration file ``mongod.conf`` consists of the following
220
+ ``__rest`` expansion directive.
221
+
222
+ .. code-block:: yaml
223
+
224
+ __rest: "https://mongoconf.example.net:8080/record/1"
225
+ type: yaml
226
+
227
+ .. note::
228
+ When using the ``__rest`` expansion directive with ``type : yaml``, the
229
+ configuration file must include only the expansion directive and its
230
+ related options. All other required configuration options must exist on
231
+ the remote resource specified in ``__rest``.
232
+
233
+ The YAML document recorded at the URL is:
234
+
235
+ .. code-block:: yaml
236
+
237
+ net:
238
+ port: 20128
239
+
240
+ To start :binary:`~bin.mongod` using the configuration, include both the
241
+ configuration file and the :option:`--configExpand <mongod --configExpand>`
242
+ options:
243
+
244
+ .. code-block:: yaml
245
+
246
+ mongod -f mongod.conf --configExpand rest
247
+
248
+ To verify the configuration, you can include the
249
+ :option:`--outputConfig <mongod --outputConfig>` option.
250
+ The :option:`--outputConfig <mongod --outputConfig>` option prints the
251
+ specified configuration, including any resolved values, to ``stdout`` and
252
+ halts the :binary:`~bin.mongod`.
253
+
254
+ .. warning::
255
+
256
+ The :option:`--outputConfig <mongod --outputConfig>` option returns the
257
+ resolved values for any field using an expansion directive. This includes
258
+ any private or sensitive information previously obscured by using an
259
+ external source for configuration.
260
+
261
+ For example:
262
+
263
+ .. code-block:: yaml
264
+
265
+ mongod -f mongod.conf --configExpand rest --outputConfig
266
+
267
+ Will output:
268
+
269
+ .. code-block:: yaml
270
+
271
+ config: mongod.conf
272
+ configExpand: rest
273
+ net:
274
+ port: 20128
275
+ outputConfig: true
276
+
277
+ ``--outputConfig`` with Configuration Files
278
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
279
+
280
+ The :option:`--outputConfig <mongod --outputConfig>` option causes the
281
+ :binary:`~bin.mongod` or :binary:`~bin.mongos` to output its resolved YAML
282
+ configuration document to ``stdout`` and halt. For configuration options using
283
+ externally sourced values, :option:`--outputConfig <mongod --outputConfig>`
284
+ returns the resolved value for those options.
285
+
286
+ .. warning::
287
+
288
+ The :option:`--outputConfig <mongod --outputConfig>` option returns the
289
+ resolved values for any field using an expansion directive. This includes
290
+ any private or sensitive information previously obscured by using an
291
+ external source for configuration.
292
+
293
+ .. example::
294
+
295
+ The following configuration file ``mongod.conf`` contains a ``__rest``
296
+ expansion directive.
297
+
298
+ .. code-block:: yaml
299
+
300
+ net:
301
+ port:
302
+ __rest: "https://mongoconf.example.net:8080/record/1"
303
+
304
+ The string recorded at the URL is:
305
+
306
+ .. code-block:: yaml
307
+
308
+ 20128
309
+
310
+ After starting the :binary:`~bin.mongod` with:
311
+
312
+ .. code-block:: yaml
313
+
314
+ mongod -f mongod.conf --configExpand rest --outputConfig
315
+
316
+ The output is:
317
+
318
+ .. code-block:: yaml
319
+
320
+ config: mongod.conf
321
+ net:
322
+ port: 20128
323
+ outputConfig: true
324
+
117
325
Core Options
118
326
------------
119
327
0 commit comments