Skip to content

Commit cb9c979

Browse files
Encryption changes in status json (#12657)
* EncryptionBackup: Log encryption key file access failures at SevError severity (#12629) * Change the error to Sev40 * Fix formatting error * Display Encryption Key Info in status json (#12649) * Encryption in json * Addressed comments * Use unordered_set * Addressed comments for ctest
1 parent 431e7c9 commit cb9c979

File tree

7 files changed

+57
-7
lines changed

7 files changed

+57
-7
lines changed

fdbbackup/backup.actor.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "fdbclient/S3BlobStore.h"
5151
#include "fdbclient/SystemData.h"
5252
#include "fdbclient/json_spirit/json_spirit_writer_template.h"
53+
#include "fdbclient/BackupContainer.h"
5354

5455
#include "flow/Platform.h"
5556

@@ -1612,6 +1613,32 @@ ACTOR Future<std::string> getLayerStatus(Reference<ReadYourWritesTransaction> tr
16121613
wait(waitForAll(tagLastRestorableVersions) && waitForAll(tagStates) && waitForAll(tagContainers) &&
16131614
waitForAll(tagRangeBytes) && waitForAll(tagLogBytes) && success(fBackupPaused));
16141615

1616+
state std::vector<Future<Void>> encryptionSetupResults;
1617+
state std::vector<int> encryptionContainerIndices;
1618+
1619+
for (int i = 0; i < tagContainers.size(); i++) {
1620+
if (tagContainers[i].get()->getEncryptionKeyFileName().present()) {
1621+
encryptionSetupResults.push_back(tagContainers[i].get()->encryptionSetupComplete());
1622+
encryptionContainerIndices.push_back(i);
1623+
}
1624+
}
1625+
wait(waitForAllReady(encryptionSetupResults));
1626+
json_spirit::mArray keysArr;
1627+
std::unordered_set<std::string> seenKeyPaths;
1628+
for (int j = 0; j < encryptionContainerIndices.size() && j < 1e6; j++) {
1629+
int i = encryptionContainerIndices[j];
1630+
std::string keyPath = tagContainers[i].get()->getEncryptionKeyFileName().get();
1631+
1632+
if (seenKeyPaths.find(keyPath) == seenKeyPaths.end()) {
1633+
seenKeyPaths.insert(keyPath);
1634+
json_spirit::mObject keyObj;
1635+
keyObj["path"] = tagContainers[i].get()->getEncryptionKeyFileName().get();
1636+
keyObj["success"] = !encryptionSetupResults[j].isError();
1637+
keysArr.push_back(keyObj);
1638+
}
1639+
}
1640+
o.create("encryption_keys") = keysArr;
1641+
16151642
JSONDoc tagsRoot = layerRoot.subDoc("tags.$latest");
16161643
layerRoot.create("tags.timestamp") = now();
16171644
layerRoot.create("total_workers.$sum") =
@@ -1640,7 +1667,11 @@ ACTOR Future<std::string> getLayerStatus(Reference<ReadYourWritesTransaction> tr
16401667
tagRoot.create("range_bytes_written") = tagRangeBytes[j].get();
16411668
tagRoot.create("mutation_log_bytes_written") = tagLogBytes[j].get();
16421669
tagRoot.create("mutation_stream_id") = backupTagUids[j].toString();
1643-
1670+
tagRoot.create("file_level_encryption") =
1671+
tagContainers[j].get()->getEncryptionKeyFileName().present() ? true : false;
1672+
if (tagContainers[j].get()->getEncryptionKeyFileName().present()) {
1673+
tagRoot.create("encryption_key_file") = tagContainers[j].get()->getEncryptionKeyFileName().get();
1674+
}
16441675
j++;
16451676
}
16461677
} else if (exe == ProgramExe::DR_AGENT) {

fdbbackup/tests/dir_backup_test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ function test_dir_backup_and_restore {
104104
err "Failed backup"
105105
return 1
106106
fi
107+
108+
test_fdbcli_status_json_for_bkup "${local_build_dir}" "${scratch_dir}"
109+
107110
log "Clear fdb data"
108111
if ! clear_data "${local_build_dir}" "${scratch_dir}"; then
109112
err "Failed clear data in fdb"

fdbbackup/tests/s3_backup_test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ function test_s3_backup_and_restore {
132132
err "Failed backup"
133133
return 1
134134
fi
135+
136+
test_fdbcli_status_json_for_bkup "${local_build_dir}" "${local_scratch_dir}"
137+
135138
log "Clear fdb data"
136139
if ! clear_data "${local_build_dir}" "${local_scratch_dir}"; then
137140
err "Failed clear data in fdb"

fdbclient/BackupContainerFileSystem.actor.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,16 +1307,15 @@ class BackupContainerFileSystemImpl {
13071307
0400));
13081308
keyFile = _keyFile;
13091309
} catch (Error& e) {
1310-
TraceEvent(SevWarnAlways, "FailedToOpenEncryptionKeyFile")
1311-
.error(e)
1312-
.detail("FileName", encryptionKeyFileName);
1310+
TraceEvent(SevError, "FailedToOpenEncryptionKeyFile").error(e).detail("FileName", encryptionKeyFileName);
13131311
throw e;
13141312
}
13151313
int bytesRead = wait(keyFile->read(cipherKey->data(), cipherKey->size(), 0));
13161314
if (bytesRead != cipherKey->size()) {
1317-
TraceEvent(SevWarnAlways, "InvalidEncryptionKeyFileSize")
1315+
TraceEvent(SevError, "InvalidEncryptionKeyFileSize")
13181316
.detail("ExpectedSize", cipherKey->size())
1319-
.detail("ActualSize", bytesRead);
1317+
.detail("ActualSize", bytesRead)
1318+
.detail("FileName", encryptionKeyFileName);
13201319
throw invalid_encryption_key_file();
13211320
}
13221321
ASSERT_EQ(bytesRead, cipherKey->size());

fdbclient/include/fdbclient/BackupContainer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ class IBackupContainer {
316316

317317
static std::string lastOpenError;
318318

319+
virtual Future<Void> encryptionSetupComplete() const = 0;
320+
319321
// TODO: change the following back to `private` once blob obj access is refactored
320322
protected:
321323
std::string URL;

fdbclient/include/fdbclient/BackupContainerFileSystem.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,14 @@ class BackupContainerFileSystem : public IBackupContainer {
165165

166166
Future<Void> writeEncryptionMetadata() override;
167167

168+
// Waits for encryption initialization to complete by reading encryption key file during container opening.
169+
Future<Void> encryptionSetupComplete() const override;
170+
168171
protected:
172+
// Returns true if an encryption key file was provided.
169173
bool usesEncryption() const;
174+
170175
void setEncryptionKey(Optional<std::string> const& encryptionKeyFileName);
171-
Future<Void> encryptionSetupComplete() const;
172176

173177
Future<Void> writeEntireFileFallback(const std::string& fileName, const std::string& fileContents);
174178

fdbclient/tests/tests_common.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,11 @@ function grep_for_severity40 {
176176
return 1
177177
fi
178178
}
179+
180+
function test_fdbcli_status_json_for_bkup {
181+
local local_build_dir="${1}"
182+
local local_scratch_dir="${2}"
183+
# Give backup agent time to write status
184+
sleep 5
185+
"${local_build_dir}"/bin/fdbcli -C "${local_scratch_dir}/loopback_cluster/fdb.cluster" --exec 'status json' | jq '.cluster.layers'
186+
}

0 commit comments

Comments
 (0)