Skip to content

Commit 8ef036e

Browse files
UI for API Key Pair Management (#13225)
Co-authored-by: Fabricio Duarte <fabricio.duarte.jr@gmail.com>
1 parent ce2d890 commit 8ef036e

15 files changed

Lines changed: 1384 additions & 64 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/command/admin/user/RegisterUserKeysCmd.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class RegisterUserKeysCmd extends BaseAsyncCmd {
5050
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "API key pair name.")
5151
private String name;
5252

53-
@Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "API key pair description.")
53+
@Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "API key pair description.", length = 1024)
5454
private String description;
5555

5656
@Parameter(name = ApiConstants.START_DATE, type = CommandType.DATE, description = "Start date of the API key pair. " +
@@ -138,6 +138,9 @@ public List<Map<String, Object>> getRules() {
138138

139139
String description = detail.get(ApiConstants.DESCRIPTION);
140140
if (StringUtils.isNotEmpty(description)) {
141+
if (description.length() > 255) {
142+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Rule description cannot be longer than 255 characters.");
143+
}
141144
ruleDetails.put(ApiConstants.DESCRIPTION, description);
142145
}
143146

engine/schema/src/main/java/org/apache/cloudstack/acl/ApiKeyPairVO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class ApiKeyPairVO implements ApiKeyPair {
7070
@Temporal(value = TemporalType.TIMESTAMP)
7171
private Date created = Date.from(Instant.now());
7272

73-
@Column(name = "description")
73+
@Column(name = "description", length = 1024)
7474
private String description = "";
7575

7676
@Column(name = "api_key", nullable = false)

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ CREATE TABLE IF NOT EXISTS `cloud`.`api_keypair` (
7373
`user_id` bigint(20) unsigned NOT NULL,
7474
`start_date` datetime,
7575
`end_date` datetime,
76-
`description` varchar(100),
76+
`description` varchar(1024),
7777
`api_key` varchar(255) NOT NULL,
7878
`secret_key` varchar(255) NOT NULL,
7979
`created` datetime NOT NULL,
@@ -107,11 +107,15 @@ WHERE user.api_key IS NOT NULL AND user.secret_key IS NOT NULL;
107107
-- Drop API keys from user table
108108
ALTER TABLE `cloud`.`user` DROP COLUMN api_key, DROP COLUMN secret_key;
109109

110-
-- Grant access to the "deleteUserKeys" API to the "User", "Domain Admin" and "Resource Admin" roles, similarly to the "registerUserKeys" API
110+
-- Grant access to the "deleteUserKeys" and "listUserKeyRules" APIs to the "User", "Domain Admin" and "Resource Admin" roles, similarly to the "registerUserKeys" API
111111
CALL `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION`('User', 'deleteUserKeys', 'ALLOW');
112112
CALL `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION`('Domain Admin', 'deleteUserKeys', 'ALLOW');
113113
CALL `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION`('Resource Admin', 'deleteUserKeys', 'ALLOW');
114114

115+
CALL `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION`('User', 'listUserKeyRules', 'ALLOW');
116+
CALL `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION`('Domain Admin', 'listUserKeyRules', 'ALLOW');
117+
CALL `cloud`.`IDEMPOTENT_UPDATE_API_PERMISSION`('Resource Admin', 'listUserKeyRules', 'ALLOW');
118+
115119
-- Add conserve mode for VPC offerings
116120
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vpc_offerings','conserve_mode', 'tinyint(1) unsigned NULL DEFAULT 0 COMMENT ''True if the VPC offering is IP conserve mode enabled, allowing public IP services to be used across multiple VPC tiers'' ');
117121

ui/public/locales/en.json

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"label.action.attach.disk": "Attach Disk",
6363
"label.action.attach.iso": "Attach ISO",
6464
"label.action.attach.to.instance": "Attach to Instance",
65+
"label.action.bulk.delete.api.keys": "Bulk delete API key pairs",
6566
"label.action.bulk.delete.egress.firewall.rules": "Bulk delete egress firewall rules",
6667
"label.action.bulk.delete.firewall.rules": "Bulk delete firewall rules",
6768
"label.action.bulk.delete.ip.v6.firewall.rules": "Bulk remove IPv6 firewall rules",
@@ -82,6 +83,7 @@
8283
"label.action.copy.iso": "Copy ISO",
8384
"label.action.copy.snapshot": "Copy Snapshot",
8485
"label.action.copy.template": "Copy Template",
86+
"label.action.create.api.key": "Create API key pair for user",
8587
"label.action.create.backup.schedule": "Create Backup Schedule",
8688
"label.action.create.recurring.snapshot": "Create Recurring Snapshot",
8789
"label.action.create.snapshot.from.vmsnapshot": "Create Snapshot from Instance Snapshot",
@@ -116,6 +118,7 @@
116118
"label.action.delete.snapshot": "Delete Snapshot",
117119
"label.action.delete.template": "Delete Template",
118120
"label.action.delete.tungsten.router.table": "Remove Tungsten Fabric route table from Network",
121+
"label.action.delete.keypair": "Delete API key pair",
119122
"label.action.delete.user": "Delete User",
120123
"label.action.delete.vgpu.profile": "Delete vGPU profile",
121124
"label.action.delete.volume": "Delete Volume",
@@ -409,6 +412,11 @@
409412
"label.api.docs.count": "APIs available for your account",
410413
"label.api.version": "API version",
411414
"label.apikey": "API key",
415+
"label.apikeypairs": "API Key Pairs",
416+
"label.apikeypair.description": "Description of the API key pair",
417+
"label.apikeypair.name": "Name of the API key pair",
418+
"label.apikeypair.startdate": "API key pair valid from",
419+
"label.apikeypair.enddate": "API key pair valid until",
412420
"label.app.cookie": "AppCookie",
413421
"label.app.name": "CloudStack",
414422
"label.application.policy.set": "Application Policy Set",
@@ -624,6 +632,7 @@
624632
"label.configure.ldap": "Configure LDAP",
625633
"label.configure.ovs": "Configure Ovs",
626634
"label.configure.sticky.policy": "Configure sticky policy",
635+
"label.confirm.delete.api.keys": "Please confirm you wish to delete the selected API key pairs",
627636
"label.confirm.delete.egress.firewall.rules": "Please confirm you wish to delete the selected egress firewall rules.",
628637
"label.confirm.delete.firewall.rules": "Please confirm you wish to delete the selected firewall rules.",
629638
"label.confirm.delete.ip.v6.firewall.rules": "Please confirm you wish to delete the selected IPv6 firewall rules",
@@ -786,6 +795,7 @@
786795
"label.delete.alerts": "Delete alerts",
787796
"label.delete.asnrange": "Delete AS Range",
788797
"label.delete.autoscale.vmgroup": "Delete AutoScaling Group",
798+
"label.delete.all.rules": "Delete all API key pair rules",
789799
"label.delete.backup": "Delete backup",
790800
"label.delete.backup.schedule": "Delete backup schedule",
791801
"label.delete.bgp.peer": "Delete BGP peer",
@@ -843,6 +853,7 @@
843853
"label.deleting": "Deleting",
844854
"label.deleting.failed": "Deleting failed",
845855
"label.deleting.iso": "Deleting ISO",
856+
"label.deleting.keypair": "Deleting API key pair",
846857
"label.deleting.snapshot": "Deleting Snapshot",
847858
"label.deleting.template": "Deleting Template",
848859
"label.deleteprotection": "Delete protection",
@@ -1643,6 +1654,7 @@
16431654
"message.memory.usage.info.hypervisor.additionals": "The data shown may not reflect the actual memory usage if the Instance does not have the additional hypervisor tools installed",
16441655
"message.memory.usage.info.negative.value": "If the Instance's memory usage cannot be obtained from the hypervisor, the lines for free memory in the raw data graph and memory usage in the percentage graph will be disabled",
16451656
"message.migrate.volume.tooltip": "Volume can be migrated to any suitable storage pool. Admin has to choose the appropriate disk offering to replace, that supports the new storage pool",
1657+
"message.register.keypair.failed": "Failed to register API key pair",
16461658
"label.migrate.with.storage": "Migrate with storage",
16471659
"label.migrating": "Migrating",
16481660
"label.migrating.data": "Migrating data",
@@ -2083,12 +2095,14 @@
20832095
"label.redundantvpcrouter": "Redundant VPC",
20842096
"label.refresh": "Refresh",
20852097
"label.region": "Region",
2098+
"label.register.api.key": "Register API key pair",
20862099
"label.register.extension": "Register Extension",
20872100
"label.register.oauth": "Register OAuth",
20882101
"label.register.template": "Register Template",
20892102
"label.register.user.data": "Register User Data",
20902103
"label.register.cni.config": "Register CNI Configuration",
20912104
"label.register.user.data.details": "Enter the User Data in plain text or in Base64 encoding. Up to 32KB of Base64 encoded User Data can be sent by default. The setting vm.userdata.max.length can be used to increase the limit to upto 1MB.",
2105+
"label.registering.keypair": "Registering API key pair for user \"{user}\"",
20922106
"label.reinstall.vm": "Reinstall Instance",
20932107
"label.reject": "Reject",
20942108
"label.related": "Related",
@@ -2403,6 +2417,7 @@
24032417
"label.unregister.extension": "Unregister Extension",
24042418
"label.usediops": "IOPS used",
24052419
"label.userdata": "User Data",
2420+
"label.user.api.key.rules": "API key pair rules",
24062421
"label.user.data.id": "User Data ID",
24072422
"label.user.data.name": "User Data name",
24082423
"label.user.data.details": "User Data details",
@@ -2936,7 +2951,7 @@
29362951
"label.versioning": "Versioning",
29372952
"label.objectlocking": "Object Lock",
29382953
"label.bucket.policy": "Bucket Policy",
2939-
"label.usersecretkey": "Secret Key",
2954+
"label.usersecretkey": "API Secret Key",
29402955
"label.create.bucket": "Create Bucket",
29412956
"label.cniconfiguration": "CNI Configuration",
29422957
"label.cniconfigname": "Associated CNI Configuration",
@@ -3350,6 +3365,8 @@
33503365
"message.delete.failed": "Delete fail",
33513366
"message.delete.gateway": "Please confirm you want to delete the gateway.",
33523367
"message.delete.ip.v6.prefix.processing": "Deleting IPv6 prefix...",
3368+
"message.delete.keypair": "Please confirm that you would like to delete this API key pair.",
3369+
"message.delete.keypair.failed": "Failed to delete API key pair",
33533370
"message.delete.port.forward.processing": "Deleting port forwarding rule...",
33543371
"message.delete.project": "Are you sure you want to delete this project?",
33553372
"message.delete.rule.processing": "Deleting rule...",
@@ -3755,6 +3772,8 @@
37553772
"message.new.version.available": "A new version of CloudStack is available. Click here to check the details",
37563773
"message.no.data.to.show.for.period": "No data to show for the selected period.",
37573774
"message.no.description": "No description entered.",
3775+
"message.note.about.keypair.permissions.title": "Note about API key pair rule permissions",
3776+
"message.note.about.keypair.permissions.body": "During the creation of API key pairs, it is possible to define a corresponding set of rule permissions. If a rule set is defined, the API key pair will only have access to APIs for which access has been explicitly granted (i.e., APIs whose corresponding rules are marked as allowed). On the other hand, if no rule set is specified, the API key pair permissions will follow and adapt to the permission set of the user's account role.",
37583777
"message.offering.internet.protocol.warning": "WARNING: IPv6 supported Networks use static routing and will require upstream routes to be configured manually.",
37593778
"message.offering.ipv6.warning": "Please refer documentation for creating IPv6 enabled Network/VPC offering <a href='http://docs.cloudstack.apache.org/en/latest/plugins/ipv6.html#isolated-network-and-vpc-tier'>IPv6 support in CloudStack - Isolated Networks and VPC Network Tiers</a>",
37603779
"message.oobm.configured": "Successfully configured out-of-band management for host",
@@ -3963,6 +3982,7 @@
39633982
"message.success.delete.gpu.devices": "Successfully deleted GPU device(s)",
39643983
"message.success.delete.icon": "Successfully deleted icon of",
39653984
"message.success.delete.interface.static.route": "Successfully removed interface Static Route",
3985+
"message.success.delete.keypair": "Success deleting API key pair",
39663986
"message.success.delete.ipv4.subnet": "Successfully removed IPv4 subnet",
39673987
"message.success.delete.network.static.route": "Successfully removed Network Static Route",
39683988
"message.success.delete.node": "Successfully deleted node",
@@ -3994,6 +4014,7 @@
39944014
"message.success.register.keypair": "Successfully registered SSH key pair",
39954015
"message.success.register.template": "Successfully registered Template",
39964016
"message.success.register.user.data": "Successfully registered User Data",
4017+
"message.success.register.user.keypair": "Successfully registered API key pair for user \"{user}\"",
39974018
"message.success.release.ip": "Successfully released IP",
39984019
"message.success.release.dedicated.bgp.peer": "Successfully released dedicated BGP peer",
39994020
"message.success.release.dedicated.ipv4.subnet": "Successfully released dedicated IPv4 subnet",

0 commit comments

Comments
 (0)