MongoDB는 구성 파일에서 확장 지시문을 사용하여 외부 소스 값을 로드하는 기능을 지원합니다. 확장 지시문은 특정 구성 파일 옵션의 값을 로드하거나 또는 전체 구성 파일을 로드할 수 있습니다. 확장 지시문은 보안 인증서와 비밀번호와 같은 기밀 정보를 가리는 데 도움이 됩니다.
storage: dbPath: "/var/lib/mongo" systemLog: destination: file path: "/var/log/mongodb/mongod.log" net: bindIp: __exec: "python /home/user/getIPAddresses.py" type: "string" trim: "whitespace" digest: 85fed8997aac3f558e779625f2e51b4d142dff11184308dc6aca06cff26ee9ad digest_key: 68656c6c30303030307365637265746d796f6c64667269656e64 tls: mode: requireTLS certificateKeyFile: "/etc/tls/mongod.pem" certificateKeyFilePassword: __rest: "https://myrestserver.example.net/api/config/myCertKeyFilePassword" type: "string" digest: b08519162ba332985ac18204851949611ef73835ec99067b85723e10113f5c26 digest_key: 6d795365637265744b65795374756666
확장 지시문을 사용하려면 사용된 확장 지시문의 전체 목록과 함께 --configExpand 명령줄 옵션을 지정해야 합니다.
mongod --config "/path/to/config/mongod.conf" --configExpand "rest,exec"
If you omit the --configExpand option or if you do not specify the complete list of expansion directives used in the configuration file, the mongod returns an error and terminates. You can only specify the --configExpand option on the command line.
__rest 확장 지시문 사용
The __rest expansion directive loads configuration file values from a REST endpoint. __rest supports loading specific values in the configuration file or loading the entire configuration file.
The following configuration file uses the __rest expansion directive to load the setting net.tls.certificateKeyFilePassword value from an external REST endpoint:
storage: dbPath: "/var/lib/mongo" systemLog: destination: file path: "/var/log/mongodb/mongod.log" net: bindIp: 192.51.100.24,127.0.0.1 tls: mode: requireTLS certificateKeyFile: "/etc/tls/mongod.pem" certificateKeyFilePassword: __rest: "https://myrestserver.example.net/api/config/myCertKeyFilePassword" type: "string"
- 파일 권한
If the configuration file includes the
__restexpansion, on Linux/macOS, the read access to the configuration file must be limited to the user running themongod/mongosprocess only.- 확장 구문 분석
To parse the
__restblocks, start themongodwith the--configExpand "rest"option.The
mongodissues aGETrequest against specified URL. If successful, themongodreplaces the value ofcertificateKeyFilePasswordwith the returned value. If the URL fails to resolve or if theRESTendpoint returns an invalid value, themongodthrows an error and terminates.
The following configuration file uses the __rest expansion directive to load the configuration file from an external REST endpoint. The expansion directive and its options must be the only values specified in the configuration file.
__rest: "https://myrestserver.example.net/api/config/fullConfig" type: "yaml"
- 파일 권한
If the configuration file includes the
__restexpansion, on Linux/macOS, the read access to the configuration file must be limited to the user running themongod/mongosprocess only.- 확장 구문 분석
To parse the
__restblocks, start themongodwith the--configExpand "rest"option.The
mongodissues aGETrequest against the specified URL. If successful, themongodparses the returned configurationyamlfile and uses it during startup. If the URL fails to resolve or return a properly formattedyamlfile, themongodthrows an error and terminates.
중요
The value returned by the specified REST endpoint cannot include any additional expansion directives. The mongod does not perform additional processing on the returned data and will terminate with an error code if the returned data includes additional expansion directives.
__exec 확장 지시문 사용
The __exec expansion directive loads configuration file values from a shell or terminal command. __exec supports loading specific values in the configuration file or loading the entire configuration file.
The following example configuration file uses the __exec expansion directive to to load the setting net.tls.certificateKeyFilePassword value from the output of a shell or terminal command:
storage: dbPath: "/var/lib/mongo" systemLog: destination: file path: "/var/log/mongodb/mongod.log" net: bindIp: 192.51.100.24,127.0.0.1 tls: mode: requireTLS certificateKeyFile: "/etc/tls/mongod.pem" certificateKeyFilePassword: __exec: "python /home/myUserName/getPEMPassword.py" type: "string"
- 파일 권한
If the configuration file includes the
__execexpansion, on Linux/macOS, the write access to the configuration file must be limited to the user running themongod/mongosprocess only.- 확장 구문 분석
To parse the
__execblocks, start themongodwith the--configExpand "exec"option.The
mongodattempts to execute the specified operation. If the command executes successfully, themongodreplaces the value ofcertificateKeyFilePasswordwith the returned value. If the command fails or returns an invalid value for the configuration file setting, themongodthrows an error and terminates.
The following example configuration file uses the __exec expansion directive to load the configuration file from the output of a shell or terminal command. The __exec expansion directive and its options must be the only values specified in the configuration file.
__exec: "python /home/myUserName/getFullConfig.py" type: "yaml"
- 파일 권한
If the configuration file includes the
__execexpansion, on Linux/macOS, the write access to the configuration file must be limited to the user running themongod/mongosprocess only.- 확장 구문 분석
To parse the
__execblocks, start themongodwith the--configExpand "rest"option.If the command executes successfully, the
mongodparses the returned configurationyamlfile and uses it during startup. If the command fails or returns an invalidyamlfile, themongodthrows an error and terminates.
중요
The data returned by executing the specified __exec string cannot include any additional expansion directives. The mongod does not perform additional processing on the returned data and will terminate with an error code if the returned data includes additional expansion directives.
확장 지시문 참조
__restThe
__restexpansion directive loads configuration file values from aRESTendpoint.__restsupports loading specific values in the configuration file or loading the entire configuration file. Themongodthen starts using the externally sourced values as part of its configuration.The
__restexpansion directive has the following syntax:특정 구성 파일 설정에 대해
REST엔드포인트를 지정하려면 다음을 수행합니다.<some configuration file setting>: __rest: "<string>" type: "string" trim: "none|whitespace" digest: "<string>" digest_key: "<string>" 전체 구성 파일에 대해
REST엔드포인트를 지정하려면 다음 안내를 따르세요.__rest: "<string>" type: "yaml" trim: "none|whitespace" REST엔드포인트를 통해 전체 구성 파일을 지정하는 경우 반드시 확장 지시문과 해당 옵션이 구성 파일에 지정된 유일한 값이어야 합니다.
__rest은(는) 다음 필드를 사용합니다.필드유형설명문자열
Required The URL against which the
mongodissues aGETrequest to retrieve the externally sourced value.로컬 호스트가 아닌 엔드포인트(예: 원격 서버
REST에서 호스팅되는REST엔드포인트)의 경우 에는__rest호스팅하다https://시스템과 원격 서버 모두 TLS 를 지원 암호화됨 () URL이 1 필요합니다.1 이상입니다.URL 에 지정된 엔드포인트에 인증 필요한 경우
REST표준 RFC 3986 사용자 정보 형식을 사용하여 자격 증명 URL 에 인코딩합니다.For localhost
RESTendpoints (e.g. aRESTendpoint listening on the host machine),__restallows unencrypted (http://) URLs.IMPORTANT: The value returned by the specified
RESTendpoint cannot include any additional expansion directives. Themongoddoes not perform additional processing on the returned data and will terminate with an error code if the returned data includes additional expansion directives.type문자열
trim문자열
Optional Specify
whitespaceto direct__restto trim any leading or trailing whitespace, specifically occurrences of" ","\r","\n","\t","\v", and"\f". Defaults tonone, or no trimming.문자열
선택 사항. 확장 결과의 HMAC-SHA256 출력은
HMAC-SHA256(digest_key, message)로 계산되며, 여기서message는 조회할 구성 설정의 값입니다.명시된 경우 digest_key도 지정해야 합니다.
문자열
선택 사항.64 32256 확장 결과의 HMAC-SHA 다이제스트를 계산하는 데 사용되는 바이트 키의 문자 16진수 문자열 표현입니다.
명시된 경우 다이제스트도 지정해야 합니다.
예를 들어
certificateKeyFilePassword이 "superSecret123"이라고 가정해 봅시다. REST 요청 또는 exec 서비스 호출을 사용하여 이 비밀번호를 조회하려면 다이제스트 키를 생성하고 이 키를 사용하여 비밀번호의 다이제스트를 계산해야 합니다.터미널에서 다음 코드를 실행하여 32바이트 다이젬트 키를 생성합니다.
openssl rand -hex 32 다이젬트 키를 생성한 후에 이 키를 사용하여 암호의 다이젬트를 계산할 수 있습니다.
echo -ne "superSecret123" | openssl dgst -sha256 -mac hmac -macopt hexkey:f38d0d5adfcf1a0575f9fa9051c70a2f88b1bb7562513c9efd7686e9c21ad304 참고
To enable parsing of the
__restexpansion directive, start themongodwith the--configExpand "rest"option.
For examples, see Use the
__restExpansion Directive.
__execThe
__execexpansion directive loads configuration file values from the output of a shell or terminal command.__execsupports loading specific values in the configuration file or loading the entire configuration file. Themongodthen starts using the externally sourced values as part of its configuration.The
__execexpansion directive has the following syntax:특정 구성 파일 설정 또는 설정에 대한 셸 또는 터미널 명령을 지정하려면 다음을 수행합니다.
<some configuration file setting>: __exec: "<string>" type: "string" trim: "none|whitespace" 전체 구성 파일에 대해 shell 또는 터미널 명령을 지정하려면 다음을 수행합니다.
__exec: "<string>" type: "yaml" trim: "none|whitespace" 터미널 또는 shell 명령을 통해 전체 구성 파일을 지정하는 경우 확장 지시어와 해당 옵션은 반드시 구성 파일에 지정된 유일한 값이어야 합니다.
__exec은(는) 다음 필드를 사용합니다.필드유형설명__exec문자열
Required The string which the
mongodexecutes on the terminal or shell to retrieve the externally sourced value.Linux 및 OSX 호스트에서 실행은 POSIX
popen()을 통해 처리됩니다. Windows 호스트에서 실행은 프로세스 제어 API를 통해 처리됩니다.__exec는mongod또는mongos를 시작한 사용자와 동일한 사용자로 읽기 전용 파이프를 엽니다.IMPORTANT: The data returned by executing the specified command cannot include any additional expansion directives. The
mongoddoes not perform additional processing on the returned data and will terminate with an error code if the returned data includes additional expansion directives.type문자열
trim문자열
Optional Specify
whitespaceto direct__execto trim any leading or trailing whitespace, specifically occurrences of" ","\r","\n","\t","\v", and"\f". Defaults tonone, or no trimming.문자열
선택 사항. 확장 결과의 HMAC-SHA256 출력은
HMAC-SHA256(digest_key, message)로 계산되며, 여기서message는 조회할 구성 설정의 값입니다.명시된 경우 digest_key도 지정해야 합니다.
문자열
Optional. The 64-character hexadecimal string representation of the 32-byte key used to calculate the HMAC-SHA256 digest of the expansion result.
지정하는 경우 다이제스트도 지정해야 합니다.
예를 들어
certificateKeyFilePassword이 "superSecret123"이라고 가정해 봅시다. REST 요청 또는 exec 서비스 호출을 사용하여 이 비밀번호를 조회하려면 다이제스트 키를 생성하고 이 키를 사용하여 비밀번호의 다이제스트를 계산해야 합니다.터미널에서 다음 코드를 실행하여 32바이트 다이젬트 키를 생성합니다.
openssl rand -hex 32 다이젬트 키를 생성한 후에 이 키를 사용하여 암호의 다이젬트를 계산할 수 있습니다.
echo -ne "superSecret123" | openssl dgst -sha256 -mac hmac -macopt hexkey:f38d0d5adfcf1a0575f9fa9051c70a2f88b1bb7562513c9efd7686e9c21ad304 참고
To enable parsing of the
__execexpansion directives, start themongodwith the--configExpand "exec"option.
For examples, see Use the
__execExpansion Directive.
완료된 확장 명령어 값이 있는 구성 파일 출력하기
You can test the final output of a configuration file that specifies one or more expansion directives by starting the mongod with the --outputConfig option. A mongod started with --outputConfig outputs the resolved YAML configuration document to stdout and halts. If any expansion directive specified in the configuration file returns additional expansion directives, the mongod throws an error and terminates.
경고
--outputConfig 옵션은 확장 지시문을 사용하여 모든 필드에 대해 확인된 값을 반환합니다. 여기에는 이전에 구성 옵션에 외부 소스를 사용하여 가려졌던 모든 개인정보 또는 민감한 정보가 포함됩니다.
For example, the following configuration file mongod.conf contains a __rest expansion directive:
storage: dbPath: "/var/lib/mongo" systemLog: destination: file path: "/var/log/mongodb/mongod.log" net: port: __rest: "https://mongoconf.example.net:8080/record/1" type: string
지정된 URL에 기록된 문자열은 다음과 같습니다. 20128
If the configuration file includes the __rest expansion, on Linux/macOS, the read access to the configuration file must be limited to the user running the mongod / mongos process only.
--configExpand "rest" 및 --outputConfig 옵션을 사용하여 mongod를 시작합니다.
mongod -f mongod.conf --configExpand rest --outputConfig
mongod는 종료하기 전에 stdout에 다음을 출력합니다.
config: mongod.conf storage: dbPath: "/var/lib/mongo" systemLog: destination: file path: "/var/log/mongodb/mongod.log" net: port: 20128 outputConfig: true