Docs Menu
Docs Home
/
MongoDB ๋งค๋‰ด์–ผ
/ / / / /

์•”ํ˜ธํ™” ์Šคํ‚ค๋งˆ

์ด ํŽ˜์ด์ง€์˜ ๋‚ด์šฉ

  • ๊ฐœ์š”
  • ์•”ํ˜ธํ™” ์Šคํ‚ค๋งˆ
  • ์•”ํ˜ธํ™” ํ‚ค์›Œ๋“œ
  • ์•”ํ˜ธํ™” ๋ฉ”ํƒ€๋ฐ์ดํ„ฐ ํ‚ค์›Œ๋“œ
  • patternProperties ํ‚ค์›Œ๋“œ
  • ์˜ˆ์‹œ
  • ๋„ค์ž„์ŠคํŽ˜์ด์Šค ์ง€์ •
  • ๋ฐ์ดํ„ฐ ์•”ํ˜ธํ™” ํ‚ค ์ง€์ •
  • ์•”ํ˜ธํ™” ๊ทœ์น™ ์„ ํƒ
  • ์•”ํ˜ธํ™” ๊ทœ์น™ ์ง€์ •
  • ์ „์ฒด ์Šคํ‚ค๋งˆ ๋ณด๊ธฐ
  • ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

์ด ํŽ˜์ด์ง€์—์„œ๋Š” ์ž๋™ CSFLE(ํด๋ผ์ด์–ธํŠธ ์ธก ํ•„๋“œ ๋ ˆ๋ฒจ ์•”ํ˜ธํ™”)๋ฅผ ์œ„ํ•œ ์•”ํ˜ธํ™” ์Šคํ‚ค๋งˆ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•๊ณผ CSFLE ๋น ๋ฅธ ์‹œ์ž‘์—์„œ ์‚ฌ์šฉ๋˜๋Š” ์•”ํ˜ธํ™” ์Šคํ‚ค๋งˆ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ์ž์„ธํ•œ ์˜ˆ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

JSON schema 4 ์•”ํ˜ธํ™” ์Šคํ‚ค๋งˆ๋Š” JSON ์ดˆ์•ˆ ํ‘œ์ค€ ๊ตฌ๋ฌธ ์˜ ์—„๊ฒฉํ•œ ํ•˜์œ„ ์ง‘ํ•ฉ์„ ์‚ฌ์šฉํ•˜๋Š” encrypt encryptMetadata ๊ฐ์ฒด์ž…๋‹ˆ๋‹ค. ๋ฐ ํ‚ค์›Œ๋“œ์™€ ํ•จ๊ป˜ CSFLE ์ง€์› ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋ฌธ์„œ๋ฅผ ์•”ํ˜ธํ™”ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ง€์ •ํ•˜๋Š” ์•”ํ˜ธํ™” ๊ทœ์น™ ์„ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.

์•”ํ˜ธํ™” ๊ทœ์น™์€ ํด๋ผ์ด์–ธํŠธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ํ•„๋“œ๋ฅผ ์•”ํ˜ธํ™”ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ •์˜ํ•˜๋Š” JSON ํ‚ค-๊ฐ’ ์Œ์ž…๋‹ˆ๋‹ค. ์•”ํ˜ธํ™” ๊ทœ์น™์—์„œ ๋‹ค์Œ ์ •๋ณด๋ฅผ ์ง€์ •ํ•˜๊ฑฐ๋‚˜ ์ƒ์†ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  • ํ•„๋“œ๋ฅผ ์•”ํ˜ธํ™”ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜

  • ํด๋ผ์ด์–ธํŠธ๊ฐ€ ํ•„๋“œ๋ฅผ ์•”ํ˜ธํ™”ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉํ•˜๋Š” DEK(๋ฐ์ดํ„ฐ ์•”ํ˜ธํ™” ํ‚ค)

  • ํ•„๋“œ์˜ BSON ์œ ํ˜•

์•”ํ˜ธํ™” ๊ทœ์น™์—๋Š” encrypt ๋˜๋Š” encryptMetadata ํ‚ค์›Œ๋“œ๊ฐ€ ํฌํ•จ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์•”ํ˜ธํ™” ์Šคํ‚ค๋งˆ์—์„œ ์ •์˜ํ•  ์ˆ˜ ์žˆ๋Š” ์•”ํ˜ธํ™” ์•Œ๊ณ ๋ฆฌ์ฆ˜์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๋ ค๋ฉด ํ•„๋“œ ๋ฐ ์•”ํ˜ธํ™” ์œ ํ˜•์„ ์ฐธ์กฐํ•˜์„ธ์š”.

๋ฐ์ดํ„ฐ ์•”ํ˜ธํ™” ํ‚ค์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๋ ค๋ฉด ํ‚ค ๋ฐ ํ‚ค ๋ณผํŠธ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

encrypt ํ‚ค์›Œ๋“œ๋Š” BSON ๋ฌธ์„œ์˜ ๋‹จ์ผ ํ•„๋“œ์— ๋Œ€ํ•œ ์•”ํ˜ธํ™” ๊ทœ์น™์„ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. encrypt ํ‚ค์›Œ๋“œ๊ฐ€ ํฌํ•จ๋œ ์•”ํ˜ธํ™” ๊ทœ์น™์˜ ๊ตฌ์กฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

"<field-name-to-encrypt>": {
"encrypt": {
"algorithm": "<encryption algorithm to use>",
"bsonType": "<bson type of field>",
"keyId": [UUID("<_id of your Data Encryption Key>" )]
}
}

encryptMetadata ํ‚ค์›Œ๋“œ๋Š” ํ˜•์ œ properties ํƒœ๊ทธ์˜ ํ•˜์œ„ ์š”์†Œ๊ฐ€ ์ƒ์†ํ•˜๋Š” ์•”ํ˜ธํ™” ๊ทœ์น™์„ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. encryptMetadata ๋ฅผ ํฌํ•จํ•˜๋Š” ์•”ํ˜ธํ™” ๊ทœ์น™์˜ ๊ตฌ์กฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

"bsonType": "object",
"encryptMetadata": {
"algorithm": "<encryption algorithm inherited by children of properties field>",
"keyId": [UUID("<_id of your Data Encryption Key>" )]
},
"properties": { <object to inherit encryptMetadata values> }

์•”ํ˜ธํ™” ์Šคํ‚ค๋งˆ์—์„œ patternProperties ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ •๊ทœ ํ‘œํ˜„์‹๊ณผ ์ผ์น˜ํ•˜๋Š” ์ด๋ฆ„์„ ๊ฐ€์ง„ ๋ชจ๋“  ํ•„๋“œ์— ๋Œ€ํ•œ ์•”ํ˜ธํ™” ๊ทœ์น™์„ ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ๋‹จ์ผ ์ •๊ทœ ํ‘œํ˜„์‹์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์•”ํ˜ธํ™”ํ•  ํ•„๋“œ๋ฅผ ์—ฌ๋Ÿฌ ๊ฐœ ์ง€์ •ํ•˜๊ฑฐ๋‚˜ ํ•„๋“œ ์ด๋ฆ„์˜ ์ผ๋ถ€๋งŒ ์‚ฌ์šฉํ•˜์—ฌ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. patternProperties ํ‚ค์›Œ๋“œ๋Š” ์•”ํ˜ธํ™” ์Šคํ‚ค๋งˆ์—์„œ properties ์„(๋ฅผ) ๋Œ€์ฒดํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ ๊ตฌ์กฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ patternProperties ๋กœ ์•”ํ˜ธํ™” ๊ทœ์น™์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

"bsonType": "object",
"patternProperties": {
"<regular expression to match>": {
"encrypt": {
"algorithm": "<encryption algorithm to use>",
"bsonType": "<bson type of field>",
"keyId": [UUID("<_id of your Data Encryption Key>" )]
}
}

patternProperties ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์˜ ์˜ˆ๋Š” ์•”ํ˜ธํ™” ์Šคํ‚ค๋งˆ - ํŒจํ„ด ์†์„ฑ์„ ์‚ฌ์šฉํ•œ ์•”ํ˜ธํ™”๋ฅผ์ฐธ์กฐํ•˜์„ธ์š”.

์ด ์˜ˆ์—์„œ๋Š” CSFLE ๋น ๋ฅธ ์‹œ์ž‘ ์˜ ๋ฌธ์„œ์— ๋Œ€ํ•œ ์•”ํ˜ธํ™” ์Šคํ‚ค๋งˆ ์ƒ์„ฑ ๋‹จ๊ณ„์—์„œ ์‚ฌ์šฉ๋˜๋Š” ์•”ํ˜ธํ™” ์Šคํ‚ค๋งˆ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

๋น ๋ฅธ ์‹œ์ž‘์—์„œ๋Š” ๋‹ค์Œ ๊ตฌ์กฐ์˜ ๋ฌธ์„œ๋ฅผ medicalRecords ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ patients collection์— ์‚ฝ์ž…ํ•ฉ๋‹ˆ๋‹ค.

{
"_id": { "$oid": "<_id of your document>" },
"name": "<name of patient>",
"ssn": <integer>,
"bloodType": "<blood type>",
"medicalRecords": [
{ "weight": <integer>, "bloodPressure": "<blood pressure>" }
],
"insurance": {
"provider": "<provider name>",
"policyNumber": <integer>
}
}

์•”ํ˜ธํ™” ์Šคํ‚ค๋งˆ์˜ ๋ฃจํŠธ์—์„œ ์•”ํ˜ธํ™” ์Šคํ‚ค๋งˆ๊ฐ€ ์ ์šฉ๋˜๋Š” ๋„ค์ž„์ŠคํŽ˜์ด์Šค๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค. medicalRecords ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ patients collection์— ์žˆ๋Š” ๋ฌธ์„œ๋ฅผ ์•”ํ˜ธํ™”ํ•˜๊ณ  ํ•ด๋…ํ•˜๋ ค๋ฉด ๋‹ค์Œ์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

{
"medicalRecords.patients": {
<the schema created in the following steps of this example>
}
}

์ด ๋น ๋ฅธ ์‹œ์ž‘์—์„œ๋Š” ๋‹จ์ผ DEK(๋ฐ์ดํ„ฐ ์•”ํ˜ธํ™” ํ‚ค)๋กœ ๋ฌธ์„œ์˜ ๋ชจ๋“  ํ•„๋“œ๋ฅผ ์•”ํ˜ธํ™”ํ•ฉ๋‹ˆ๋‹ค. ์•”ํ˜ธํ™” ๋ฐ ์•”ํ˜ธ ํ•ด๋…์— ๋‹จ์ผ DEK๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ๋ฌธ์„œ์˜ ๋ชจ๋“  ํ•„๋“œ๋ฅผ ๊ตฌ์„ฑํ•˜๋ ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์•”ํ˜ธํ™” ์Šคํ‚ค๋งˆ์˜ ๋ฃจํŠธ์—์„œ encryptMetadata ํ‚ค์›Œ๋“œ์™€ ํ•จ๊ป˜ DEK์˜ _id ๋ฅผ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

{
"medicalRecords.patients": {
"bsonType": "object",
"encryptMetadata": {
"keyId": [UUID("<_id of your Data Encryption Key>" )]
},
"properties": {
<the schema created in the following steps of this example>
}
}
}

๋‹ค์Œ ์•”ํ˜ธํ™” ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•˜์—ฌ ๋‹ค์Œ ํ•„๋“œ๋ฅผ ์•”ํ˜ธํ™”ํ•˜๊ธฐ๋กœ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค.

ํ•„๋“œ ์ด๋ฆ„
์•”ํ˜ธํ™” ์•Œ๊ณ ๋ฆฌ์ฆ˜
BSON ์œ ํ˜•

ssn

๊ฒฐ์ •๋ก ์ 

Int

bloodType

๋žœ๋ค

๋ฌธ์ž์—ด

medicalRecords

๋žœ๋ค

๋ฐฐ์—ด

insurance.policyNumber

๊ฒฐ์ •๋ก ์ 

Int

๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ด์œ ๋กœ ๊ฒฐ์ •๋ก ์  ์•”ํ˜ธํ™”๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ssn ๋ฐ insurance.policyNumber ํ•„๋“œ๋ฅผ ์•”ํ˜ธํ™”ํ•˜๊ธฐ๋กœ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

  • ์ด๋Ÿฌํ•œ ํ•„๋“œ์— ๋Œ€ํ•ด ์ฟผ๋ฆฌํ•  ์ˆ˜ ์žˆ๊ธฐ๋ฅผ ์›ํ•ฉ๋‹ˆ๋‹ค.

  • ์ด๋Ÿฌํ•œ ํ•„๋“œ์˜ ๊ฐ’์€ ์นด๋””๋„๋ฆฌํ‹ฐ๊ฐ€ ๋†’์œผ๋ฏ€๋กœ ์ด ๋ฐ์ดํ„ฐ๋Š” ๋นˆ๋„ ๋ถ„์„ ๊ณต๊ฒฉ์— ์ทจ์•ฝํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ด์œ ๋กœ ๋ฌด์ž‘์œ„ ์•”ํ˜ธํ™”๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ bloodType ํ•„๋“œ๋ฅผ ์•”ํ˜ธํ™”ํ•˜๊ธฐ๋กœ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

  • ์ด ํ•„๋“œ์— ๋Œ€ํ•ด ์ฟผ๋ฆฌํ•  ๊ณ„ํš์ด ์—†์Šต๋‹ˆ๋‹ค.

  • ์ด ํ•„๋“œ์˜ ๊ฐ’์€ ์นด๋””๋„๋ฆฌํ‹ฐ๊ฐ€ ๋‚ฎ๊ธฐ ๋•Œ๋ฌธ์— ๊ฒฐ์ •๋ก ์ ์œผ๋กœ ์•”ํ˜ธํ™”ํ•œ ๊ฒฝ์šฐ ๋นˆ๋„ ๋ถ„์„ ๊ณต๊ฒฉ์— ์ทจ์•ฝํ•ฉ๋‹ˆ๋‹ค.

CSFLE๋Š” array ์œ ํ˜•์˜ ํ•„๋“œ์— ๋Œ€ํ•œ ๊ฒฐ์ •๋ก ์  ์•”ํ˜ธํ™”๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ ๋ฌด์ž‘์œ„ ์•”ํ˜ธํ™”๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ medicalRecords ํ•„๋“œ๋ฅผ ์•”ํ˜ธํ™”ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

ํŒ

์ง€์›๋˜๋Š” ์ž๋™ ์•”ํ˜ธํ™” ์ž‘์—…๊ณผ ์ง€์›๋˜์ง€ ์•Š๋Š” ์ž๋™ ์•”ํ˜ธํ™” ์ž‘์—…์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๋ ค๋ฉด ์ž๋™ ์•”ํ˜ธํ™”์— ์ง€์›๋˜๋Š” ์ž‘์—…์„ ์ฐธ์กฐํ•˜์„ธ์š”.

๊ฒฐ์ •๋ก ์  ์•”ํ˜ธํ™”๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ssn ํ•„๋“œ๋ฅผ ์•”ํ˜ธํ™”ํ•˜๋ ค๋ฉด ์•”ํ˜ธํ™” ์Šคํ‚ค๋งˆ์— ๋‹ค์Œ์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

"ssn": {
"encrypt": {
"bsonType": "int",
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
}
}

๋ฌด์ž‘์œ„ ์•”ํ˜ธํ™”๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ bloodType ํ•„๋“œ๋ฅผ ์•”ํ˜ธํ™”ํ•˜๋ ค๋ฉด ์•”ํ˜ธํ™” ์Šคํ‚ค๋งˆ์—์„œ ๋‹ค์Œ์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

"bloodType": {
"encrypt": {
"bsonType": "string",
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random"
}
}

๋ฌด์ž‘์œ„ ์•”ํ˜ธํ™”๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ medicalRecords ํ•„๋“œ๋ฅผ ์•”ํ˜ธํ™”ํ•˜๋ ค๋ฉด ์•”ํ˜ธํ™” ์Šคํ‚ค๋งˆ์—์„œ ๋‹ค์Œ์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

"medicalRecords": {
"encrypt": {
"bsonType": "array",
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random"
}
}

๊ฒฐ์ •๋ก ์  ์•”ํ˜ธํ™”๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ insurance.policyNumber ํ•„๋“œ๋ฅผ ์•”ํ˜ธํ™”ํ•˜๋ ค๋ฉด ์•”ํ˜ธํ™” ์Šคํ‚ค๋งˆ์— ๋‹ค์Œ์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

"insurance": {
"bsonType": "object",
"properties": {
"policyNumber": {
"encrypt": {
"bsonType": "int",
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
}
}
}
}

์ด Quick Start์˜ ์ „์ฒด ์•”ํ˜ธํ™” ์Šคํ‚ค๋งˆ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:

{
"medicalRecords.patients": {
"bsonType": "object",
"encryptMetadata": {
"keyId": [UUID("<_id of your Data Encryption Key>" )]
},
"properties": {
"insurance": {
"bsonType": "object",
"properties": {
"policyNumber": {
"encrypt": {
"bsonType": "int",
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
}
}
}
},
"medicalRecords": {
"encrypt": {
"bsonType": "array",
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random"
}
},
"bloodType": {
"encrypt": {
"bsonType": "string",
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random"
}
},
"ssn": {
"encrypt": {
"bsonType": "int",
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
}
}
}
}
}

์•”ํ˜ธํ™” ์Šคํ‚ค๋งˆ์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๋ ค๋ฉด CSFLE ์•”ํ˜ธํ™” ์Šคํ‚ค๋งˆ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

์ž๋™ ์•”ํ˜ธํ™”์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๋ ค๋ฉด ์ž๋™ ์•”ํ˜ธํ™”๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š” .

๋น ๋ฅธ ์‹œ์ž‘์„ ๋ณด๋ ค๋ฉด ๋น ๋ฅธ ์‹œ์ž‘์„ ์ฐธ์กฐํ•˜์„ธ์š”.

๋Œ์•„๊ฐ€๊ธฐ

๋ช…์‹œ์  ์•”ํ˜ธํ™”