-
Notifications
You must be signed in to change notification settings - Fork 3
/
commands.txt
139 lines (118 loc) · 2.96 KB
/
commands.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
mongosh "mongodb://mongoadmin:passwordone@csfle-mongodb-<PETNAME>.mdbtraining.net:27017/?replicaSet=rs0" --tls --tlsCAFile /etc/pki/tls/certs/ca.cert
// Create Index
db.getSiblingDB("__encryption").getCollection("__keyVault").createIndex(
{
keyAltNames: 1
},
{
unique: true,
partialFilterExpression: {
"keyAltNames": {
"$exists": true
}
}
}
);
// Create DEK
const provider = {
"kmip": { // <-- KMS provider name
"endpoint": "csfle-kmip-<PETNAME>.mdbtraining.net"
}
};
const tlsOptions = {
kmip: {
tlsCAFile: "/etc/pki/tls/certs/ca.cert",
tlsCertificateKeyFile: "/home/ec2-user/server.pem"
}
};
const autoEncryptionOpts = {
kmsProviders : provider,
schemaMap: {}, //no schema map
keyVaultNamespace: "__encryption.__keyVault",
tlsOptions: tlsOptions
};
encryptedClient = Mongo("mongodb://mongoadmin:passwordone@csfle-mongodb-<PETNAME>.mdbtraining.net:27017/?replicaSet=rs0&tls=true&tlsCAFile=%2Fetc%2Fpki%2Ftls%2Fcerts%2Fca.cert", autoEncryptionOpts);
keyVault = encryptedClient.getKeyVault();
keyVault.createKey(
"kmip", // <-- KMS provider name
{
"keyId": "1"
}, // <-- CMK info (specific to AWS in this case)
["dataKey1"] // <-- Key alternative name
);
// Retrieve all the keys
keyVault.getKeys()
// Create User and Role
use admin;
db.createRole({
"role": "cryptoClient",
"privileges": [
{
resource: {
db: "__encryption",
collection: "__keyVault"
},
actions: [ "find" ]
}
],
"roles": [ ]
});
use admin;
db.createUser({
"user": "app_user",
"pwd": "password123",
"roles": ["cryptoClient", {'role': "readWrite", 'db': 'companyData'} ]
});
// Modify collection
use companyData;
db.runCommand({
collMod: "employee",
validator: {
$jsonSchema: <SCHEMA_MAP_GOES_HERE>
}
}
)
// Modify role
use admin;
db.grantPrivilegesToRole(
"cryptoClient",
[
{
"resource": {"db": "__encryption", "collection": "__keyVault"},
"actions": [ "find", "insert", "remove" ]
}
]
)
// CMK Rotation
// start mongosh with `mongosh --nodb`
const provider = {
"kmip": { // <-- KMS provider name
"endpoint": "csfle-kmip-<PETNAME>.mdbtraining.net"
}
}
const tlsOptions = {
kmip: {
tlsCAFile: "/etc/pki/tls/certs/ca.cert",
tlsCertificateKeyFile: "/home/ec2-user/server.pem"
}
}
const autoEncryptionOpts = {
kmsProviders : provider,
schemaMap: {}, //no schema map
keyVaultNamespace: "__encryption.__keyVault",
tlsOptions: tlsOptions
}
encryptedClient = Mongo("mongodb://mongoadmin:passwordone@csfle-mongodb-<PETNAME>.mdbtraining.net:27017/?replicaSet=rs0&tls=true&tlsCAFile=%2Fetc%2Fpki%2Ftls%2Fcerts%2Fca.cert", autoEncryptionOpts)
keyVault = encryptedClient.getKeyVault()
keyVault.rewrapManyDataKey(
{
"masterKey.keyId": "<ID_OF_CMK>"} // <-- example filter
},
{
"provider": "kmip", // <-- new key provider name
"masterKey": { // <-- CMK info (specific to KMIP in this case)
"keyId": "<ID_OF_KEY>",
"endpoint": "<KMIP_ENDPOINT>"
}
}
)