Skip to content

Commit a755e5d

Browse files
committed
api: Drop generating a keypair and add special chars to naming
As agreed in the spec, we will both drop the generation support for a keypair but we'll also accept @ (at) and . (dot) chars in the keyname, all of them in the same API microversion. Rebased the work from I5de15935e83823afa545a250cf84f6a7a37036b4 APIImpact Implements: blueprint keypair-generation-removal Co-Authored-By: Nicolas Parquet <[email protected]> Change-Id: I6a7c71fb4385348c87067543d0454f302907395e
1 parent 09239fc commit a755e5d

File tree

22 files changed

+344
-60
lines changed

22 files changed

+344
-60
lines changed

api-ref/source/os-keypairs.inc

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,16 @@ Response
4444
.. literalinclude:: ../../doc/api_samples/os-keypairs/v2.35/keypairs-list-resp.json
4545
:language: javascript
4646

47-
Create Or Import Keypair
48-
========================
47+
Import (or create) Keypair
48+
==========================
4949

5050
.. rest_method:: POST /os-keypairs
5151

52-
Generates or imports a keypair.
52+
Imports (or generates) a keypair.
53+
54+
.. warning::
55+
56+
Generating a keypair is no longer possible starting from version 2.92.
5357

5458
Normal response codes: 200, 201
5559

@@ -65,7 +69,7 @@ Request
6569
.. rest_parameters:: parameters.yaml
6670

6771
- keypair: keypair
68-
- name: keypair_name
72+
- name: keypair_name_in
6973
- public_key: keypair_public_key_in
7074
- type: keypair_type_in
7175
- user_id: keypair_userid_in
@@ -75,6 +79,11 @@ Request
7579
.. literalinclude:: ../../doc/api_samples/os-keypairs/v2.10/keypairs-import-post-req.json
7680
:language: javascript
7781

82+
**Example Import Keypair (v2.92): JSON request**
83+
84+
.. literalinclude:: ../../doc/api_samples/os-keypairs/v2.92/keypairs-import-post-req.json
85+
:language: javascript
86+
7887
Response
7988
--------
8089

@@ -93,6 +102,11 @@ Response
93102
.. literalinclude:: ../../doc/api_samples/os-keypairs/v2.10/keypairs-import-post-resp.json
94103
:language: javascript
95104

105+
**Example Import Keypair (v2.92): JSON response**
106+
107+
.. literalinclude:: ../../doc/api_samples/os-keypairs/v2.92/keypairs-import-post-resp.json
108+
:language: javascript
109+
96110
Show Keypair Details
97111
====================
98112

api-ref/source/parameters.yaml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4410,11 +4410,23 @@ keypair_links:
44104410
required: false
44114411
min_version: 2.35
44124412
keypair_name:
4413+
in: body
4414+
required: true
4415+
type: string
4416+
description: |
4417+
The name for the keypair.
4418+
keypair_name_in:
44134419
in: body
44144420
required: true
44154421
type: string
44164422
description: |
44174423
A name for the keypair which will be used to reference it later.
4424+
4425+
.. note::
4426+
4427+
Since microversion 2.92, allowed characters are ASCII letters
4428+
``[a-zA-Z]``, digits ``[0-9]`` and the following special
4429+
characters: ``[@._- ]``.
44184430
keypair_private_key:
44194431
description: |
44204432
If you do not provide a public key on create, a new keypair will
@@ -4424,6 +4436,7 @@ keypair_private_key:
44244436
in: body
44254437
required: false
44264438
type: string
4439+
max_version: 2.91
44274440
keypair_public_key:
44284441
description: |
44294442
The keypair public key.
@@ -4432,10 +4445,11 @@ keypair_public_key:
44324445
type: string
44334446
keypair_public_key_in:
44344447
description: |
4435-
The public ssh key to import. If you omit this value, a keypair is
4436-
generated for you.
4448+
The public ssh key to import.
4449+
Was optional before microversion 2.92 : if you were omitting this value, a
4450+
keypair was generated for you.
44374451
in: body
4438-
required: false
4452+
required: true
44394453
type: string
44404454
keypair_type:
44414455
in: body
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"keypair": {
3+
"name": "[email protected] mooh.",
4+
"type": "ssh",
5+
"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDx8nkQv/zgGgB4rMYmIf+6A4l6Rr+o/6lHBQdW5aYd44bd8JttDCE/F/pNRr0lRE+PiqSPO8nDPHw0010JeMH9gYgnnFlyY3/OcJ02RhIPyyxYpv9FhY+2YiUkpwFOcLImyrxEsYXpD/0d3ac30bNH6Sw9JD9UZHYcpSxsIbECHw== Generated-by-Nova",
6+
"user_id": "fake"
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"keypair": {
3+
"fingerprint": "1e:2c:9b:56:79:4b:45:77:f9:ca:7a:98:2c:b0:d5:3c",
4+
"name": "[email protected] mooh.",
5+
"type": "ssh",
6+
"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDx8nkQv/zgGgB4rMYmIf+6A4l6Rr+o/6lHBQdW5aYd44bd8JttDCE/F/pNRr0lRE+PiqSPO8nDPHw0010JeMH9gYgnnFlyY3/OcJ02RhIPyyxYpv9FhY+2YiUkpwFOcLImyrxEsYXpD/0d3ac30bNH6Sw9JD9UZHYcpSxsIbECHw== Generated-by-Nova",
7+
"user_id": "fake"
8+
}
9+
}

doc/api_samples/versions/v21-version-get-resp.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020
],
2121
"status": "CURRENT",
22-
"version": "2.91",
22+
"version": "2.92",
2323
"min_version": "2.1",
2424
"updated": "2013-07-23T11:33:21Z"
2525
}

doc/api_samples/versions/versions-get-resp.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
}
2323
],
2424
"status": "CURRENT",
25-
"version": "2.91",
25+
"version": "2.92",
2626
"min_version": "2.1",
2727
"updated": "2013-07-23T11:33:21Z"
2828
}

nova/api/openstack/api_version_request.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@
249249
server responses regardless of policy configuration.
250250
* 2.91 - Add support to unshelve instance to a specific host and
251251
to pin/unpin AZ.
252+
* 2.92 - Drop generation of keypair, add keypair name validation on
253+
``POST /os-keypairs`` and allow including @ and dot (.) characters
254+
in keypair name.
252255
"""
253256

254257
# The minimum and maximum versions of the API supported
@@ -257,7 +260,7 @@
257260
# Note(cyeoh): This only applies for the v2.1 API once microversions
258261
# support is fully merged. It does not affect the V2 API.
259262
_MIN_API_VERSION = '2.1'
260-
_MAX_API_VERSION = '2.91'
263+
_MAX_API_VERSION = '2.92'
261264
DEFAULT_API_VERSION = _MIN_API_VERSION
262265

263266
# Almost all proxy APIs which are related to network, images and baremetal

nova/api/openstack/compute/keypairs.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,19 @@ def __init__(self):
4343
@wsgi.Controller.api_version("2.10")
4444
@wsgi.response(201)
4545
@wsgi.expected_errors((400, 403, 409))
46-
@validation.schema(keypairs.create_v210)
46+
@validation.schema(keypairs.create_v210, "2.10", "2.91")
47+
@validation.schema(keypairs.create_v292, "2.92")
4748
def create(self, req, body):
4849
"""Create or import keypair.
4950
51+
Keypair generations are allowed until version 2.91.
52+
Afterwards, only imports are allowed.
53+
5054
A policy check restricts users from creating keys for other users
5155
5256
params: keypair object with:
5357
name (required) - string
54-
public_key (optional) - string
58+
public_key (optional or required if >=2.92) - string
5559
type (optional) - string
5660
user_id (optional) - string
5761
"""
@@ -114,6 +118,8 @@ def _create(self, req, body, user_id=None, key_type=False):
114118
context, user_id, name, params['public_key'],
115119
key_type_value)
116120
else:
121+
# public_key is a required field starting with 2.92 so this
122+
# generation should only happen with older versions.
117123
keypair, private_key = self.api.create_key_pair(
118124
context, user_id, name, key_type_value)
119125
keypair['private_key'] = private_key

nova/api/openstack/compute/rest_api_version_history.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,3 +1211,11 @@ responses is now visible to all users. Previously this was an admin-only field.
12111211
Add support to unshelve instance to a specific host.
12121212

12131213
Add support to pin a server to an availability zone or unpin a server from any availability zone.
1214+
1215+
.. _microversion 2.92:
1216+
1217+
2.92
1218+
----
1219+
1220+
The ``POST /os-keypairs`` API now forbids to generate a keypair and allows new
1221+
safe characters, specifically '@' and '.' (dot character).

nova/api/openstack/compute/schemas/keypairs.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
'keypair': {
2424
'type': 'object',
2525
'properties': {
26-
'name': parameter_types.name,
26+
'name': parameter_types.keypair_name_special_chars,
2727
'public_key': {'type': 'string'},
2828
},
2929
'required': ['name'],
@@ -46,7 +46,7 @@
4646
'keypair': {
4747
'type': 'object',
4848
'properties': {
49-
'name': parameter_types.name,
49+
'name': parameter_types.keypair_name_special_chars,
5050
'type': {
5151
'type': 'string',
5252
'enum': ['ssh', 'x509']
@@ -67,7 +67,7 @@
6767
'keypair': {
6868
'type': 'object',
6969
'properties': {
70-
'name': parameter_types.name,
70+
'name': parameter_types.keypair_name_special_chars,
7171
'type': {
7272
'type': 'string',
7373
'enum': ['ssh', 'x509']
@@ -83,6 +83,11 @@
8383
'additionalProperties': False,
8484
}
8585

86+
create_v292 = copy.deepcopy(create_v210)
87+
create_v292['properties']['keypair']['properties']['name'] = (parameter_types.
88+
keypair_name_special_chars_292)
89+
create_v292['properties']['keypair']['required'] = ['name', 'public_key']
90+
8691
index_query_schema_v20 = {
8792
'type': 'object',
8893
'properties': {},

0 commit comments

Comments
 (0)