The existing logic for bucket encryption was incomplete. This adds the
rest of the changes necessary to support sse-kms with default bucket
encryption.
The new logic has these changes:
on input: SSEAlgorithm is now optional.
On output: emit xmlns attribute at top level.
also output
BucketKeyEnabled and KMSMasterKeyID.
Hnadle "empty rule" case.
for testing and diagnostics:
support RGWBucketEncryptionConfig in ceph-dencoder
Signed-off-by: Marcus Watts <mwatts@redhat.com>
src/rgw/rgw_bucket_encryption.cc
src/rgw/rgw_bucket_encryption.h
src/rgw/rgw_crypt.cc
src/rgw/rgw_dencoder.cc
src/rgw/rgw_json_enc.cc
src/rgw/rgw_rest_s3.cc
src/tools/ceph-dencoder/rgw_types.h
(cherry picked from commit
bd9ff0f7b10b1271c0956e7d6ce6e834c3aa0049)
//
#include "rgw_bucket_encryption.h"
#include "rgw_xml.h"
+#include "common/ceph_json.h"
void ApplyServerSideEncryptionByDefault::decode_xml(XMLObj *obj) {
RGWXMLDecoder::decode_xml("KMSMasterKeyID", kmsMasterKeyID, obj, false);
void ApplyServerSideEncryptionByDefault::dump_xml(Formatter *f) const {
encode_xml("SSEAlgorithm", sseAlgorithm, f);
+ if (kmsMasterKeyID != "") {
+ encode_xml("KMSMasterKeyID", kmsMasterKeyID, f);
+ }
}
void ServerSideEncryptionConfiguration::decode_xml(XMLObj *obj) {
- RGWXMLDecoder::decode_xml("ApplyServerSideEncryptionByDefault", applyServerSideEncryptionByDefault, obj, true);
+ RGWXMLDecoder::decode_xml("ApplyServerSideEncryptionByDefault", applyServerSideEncryptionByDefault, obj, false);
RGWXMLDecoder::decode_xml("BucketKeyEnabled", bucketKeyEnabled, obj, false);
}
void ServerSideEncryptionConfiguration::dump_xml(Formatter *f) const {
encode_xml("ApplyServerSideEncryptionByDefault", applyServerSideEncryptionByDefault, f);
+ if (bucketKeyEnabled) {
+ encode_xml("BucketKeyEnabled", true, f);
+ }
}
void RGWBucketEncryptionConfig::decode_xml(XMLObj *obj) {
}
void RGWBucketEncryptionConfig::dump_xml(Formatter *f) const {
- encode_xml("Rule", rule, f);
+ if (rule_exist) {
+ encode_xml("Rule", rule, f);
+ }
+}
+
+void RGWBucketEncryptionConfig::dump(Formatter *f) const {
+ encode_json("rule_exist", has_rule(), f);
+ if (has_rule()) {
+ encode_json("sse_algorithm", sse_algorithm(), f);
+ encode_json("kms_master_key_id", kms_master_key_id(), f);
+ encode_json("bucket_key_enabled", bucket_key_enabled(), f);
+ }
}
std::string sseAlgorithm;
public:
- ApplyServerSideEncryptionByDefault(): kmsMasterKeyID(""), sseAlgorithm("") {};
+ ApplyServerSideEncryptionByDefault() {};
+ ApplyServerSideEncryptionByDefault(const std::string &algorithm,
+ const std::string &key_id)
+ : kmsMasterKeyID(key_id), sseAlgorithm(algorithm) {};
const std::string& kms_master_key_id() const {
return kmsMasterKeyID;
public:
ServerSideEncryptionConfiguration(): bucketKeyEnabled(false) {};
+ ServerSideEncryptionConfiguration(const std::string &algorithm,
+ const std::string &keyid="", bool enabled = false)
+ : applyServerSideEncryptionByDefault(algorithm, keyid),
+ bucketKeyEnabled(enabled) {}
const std::string& kms_master_key_id() const {
return applyServerSideEncryptionByDefault.kms_master_key_id();
public:
RGWBucketEncryptionConfig(): rule_exist(false) {}
+ RGWBucketEncryptionConfig(const std::string &algorithm,
+ const std::string &keyid = "", bool enabled = false)
+ : rule_exist(true), rule(algorithm, keyid, enabled) {}
const std::string& kms_master_key_id() const {
return rule.kms_master_key_id();
void decode_xml(XMLObj *obj);
void dump_xml(Formatter *f) const;
+ void dump(Formatter *f) const;
+ static void generate_test_instances(std::list<RGWBucketEncryptionConfig*>& o);
};
WRITE_CLASS_ENCODER(RGWBucketEncryptionConfig)
#include "rgw_meta_sync_status.h"
#include "rgw_data_sync.h"
#include "rgw_multi.h"
+#include "rgw_bucket_encryption.h"
#include "common/Formatter.h"
o.push_back(v);
o.push_back(new obj_version);
}
+
+void RGWBucketEncryptionConfig::generate_test_instances(std::list<RGWBucketEncryptionConfig*>& o)
+{
+ auto *bc = new RGWBucketEncryptionConfig("aws:kms", "some:key", true);
+ o.push_back(bc);
+
+ bc = new RGWBucketEncryptionConfig("AES256");
+ o.push_back(bc);
+
+ o.push_back(new RGWBucketEncryptionConfig);
+}
dump_start(s);
if (!op_ret) {
- encode_xml("ServerSideEncryptionConfiguration", bucket_encryption_conf, s->formatter);
+ encode_xml("ServerSideEncryptionConfiguration", XMLNS_AWS_S3,
+ bucket_encryption_conf, s->formatter);
rgw_flush_formatter_and_reset(s, s->formatter);
}
}
TYPE(rgw_data_sync_marker)
TYPE(rgw_data_sync_status)
+#include "rgw/rgw_bucket_encryption.h"
+TYPE(RGWBucketEncryptionConfig)
+
#endif