Skip to content

Commit 2c49e92

Browse files
committed
Fix test failures
1 parent 30891ee commit 2c49e92

File tree

6 files changed

+170
-210
lines changed

6 files changed

+170
-210
lines changed

engine/schema/src/main/java/org/apache/cloudstack/kms/dao/KMSKeyDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@ public interface KMSKeyDao extends GenericDao<KMSKeyVO, Long> {
3030
List<KMSKeyVO> listByZone(Long zoneId, KeyPurpose purpose, Boolean enabled);
3131

3232
long countByHsmProfileId(Long hsmProfileId);
33+
34+
KMSKeyVO findByNameAndAccountId(String name, long accountId);
3335
}

engine/schema/src/main/java/org/apache/cloudstack/kms/dao/KMSKeyDaoImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class KMSKeyDaoImpl extends GenericDaoBase<KMSKeyVO, Long> implements KMS
3333

3434
public KMSKeyDaoImpl() {
3535
allFieldSearch = createSearchBuilder();
36+
allFieldSearch.and("name", allFieldSearch.entity().getName(), SearchCriteria.Op.EQ);
3637
allFieldSearch.and("kekLabel", allFieldSearch.entity().getKekLabel(), SearchCriteria.Op.EQ);
3738
allFieldSearch.and("domainId", allFieldSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
3839
allFieldSearch.and("accountId", allFieldSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
@@ -71,4 +72,12 @@ public long countByHsmProfileId(Long hsmProfileId) {
7172
Integer count = getCount(sc);
7273
return count != null ? count : 0;
7374
}
75+
76+
@Override
77+
public KMSKeyVO findByNameAndAccountId(String name, long accountId) {
78+
SearchCriteria<KMSKeyVO> sc = allFieldSearch.create();
79+
sc.setParameters("name", name);
80+
sc.setParameters("accountId", accountId);
81+
return findOneBy(sc);
82+
}
7483
}

engine/schema/src/main/resources/META-INF/db/schema-42210to42300.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ CREATE TABLE IF NOT EXISTS `cloud`.`kms_keys` (
164164
`name` VARCHAR(255) NOT NULL COMMENT 'User-friendly name',
165165
`description` VARCHAR(1024) COMMENT 'User description',
166166
`kek_label` VARCHAR(255) NOT NULL COMMENT 'Provider-specific KEK label/ID',
167-
`purpose` VARCHAR(32) NOT NULL COMMENT 'Key purpose (VOLUME_ENCRYPTION, TLS_CERT, CONFIG_SECRET)',
167+
`purpose` VARCHAR(32) NOT NULL COMMENT 'Key purpose (VOLUME_ENCRYPTION, TLS_CERT)',
168168
`account_id` BIGINT UNSIGNED NOT NULL COMMENT 'Owning account',
169169
`domain_id` BIGINT UNSIGNED NOT NULL COMMENT 'Owning domain',
170170
`zone_id` BIGINT UNSIGNED NOT NULL COMMENT 'Zone where key is valid',
@@ -261,7 +261,7 @@ CREATE TABLE IF NOT EXISTS `cloud`.`kms_database_kek_objects` (
261261
`always_sensitive` BOOLEAN NOT NULL DEFAULT TRUE COMMENT 'PKCS#11 CKA_ALWAYS_SENSITIVE - key was always sensitive',
262262
`never_extractable` BOOLEAN NOT NULL DEFAULT TRUE COMMENT 'PKCS#11 CKA_NEVER_EXTRACTABLE - key was never extractable',
263263
-- Key Metadata
264-
`purpose` VARCHAR(32) NOT NULL COMMENT 'Key purpose (VOLUME_ENCRYPTION, TLS_CERT, CONFIG_SECRET)',
264+
`purpose` VARCHAR(32) NOT NULL COMMENT 'Key purpose (VOLUME_ENCRYPTION, TLS_CERT)',
265265
`key_bits` INT NOT NULL COMMENT 'Key size in bits (128, 192, 256)',
266266
`algorithm` VARCHAR(64) NOT NULL DEFAULT 'AES/GCM/NoPadding' COMMENT 'Encryption algorithm',
267267
-- Validity Dates (PKCS#11 CKA_START_DATE, CKA_END_DATE)

server/src/main/java/org/apache/cloudstack/kms/KMSManagerImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,9 @@ KMSKey createUserKMSKey(Long accountId, Long domainId, Long zoneId,
392392
if (profile == null) {
393393
throw KMSException.invalidParameter("HSM Profile not found");
394394
}
395+
if (kmsKeyDao.findByNameAndAccountId(name, accountId) != null) {
396+
throw new InvalidParameterValueException("A KMS key with name " + name + " already exists in this account");
397+
}
395398

396399
KMSKeyVO kmsKey = new KMSKeyVO(name, description, "", purpose,
397400
accountId, domainId, zoneId, "AES/GCM/NoPadding", keyBits);

0 commit comments

Comments
 (0)