Skip to content

Commit aa954f9

Browse files
jackhodgkissmnasiadka
authored andcommitted
certs: add subject key identifier extension
Add the subject key identifier extension to the certificate generated by Magnum. Which should permit Kubernetes clusters to have certificates that include authority key identifier extension which appears to be a requirement in Python 3.13 and newer. Closes-Bug: #2097094 Change-Id: I13bbb97c8b17fbba2f5f1acfac9d597f12925818 (cherry picked from commit 89f185b) Signed-off-by: Michal Nasiadka <[email protected]>
1 parent c73ef05 commit aa954f9

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

magnum/common/x509/operations.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ def sign(csr, issuer_name, ca_key, ca_key_password=None,
223223
builder = builder.add_extension(extention.value,
224224
critical=extention.critical)
225225

226+
subject_key_identifier = x509.SubjectKeyIdentifier.from_public_key(
227+
csr.public_key())
228+
builder = builder.add_extension(
229+
subject_key_identifier, critical=False
230+
)
231+
226232
certificate = builder.sign(
227233
private_key=ca_key, algorithm=hashes.SHA256(),
228234
).public_bytes(serialization.Encoding.PEM).strip()

magnum/tests/unit/common/x509/test_sign.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,26 @@ def test_sign_empty_chars(self, mock_load_pem):
233233
self.assertEqual(certificate,
234234
certificate.strip())
235235

236+
# If a subject key identifier is given in the CSR, ensure it is added
237+
@mock.patch('cryptography.x509.load_pem_x509_csr')
238+
def test_sign_subject_key_identifier(self, mock_load_pem):
239+
ca_key = self._generate_private_key()
240+
private_key = self._generate_private_key()
241+
csr_obj = self._build_csr(private_key)
242+
csr = csr_obj.public_bytes(serialization.Encoding.PEM)
243+
csr = csr.decode('utf-8')
244+
245+
mock_load_pem.return_value = csr_obj
246+
certificate = operations.sign(csr, self.issuer_name,
247+
ca_key, skip_validation=True)
248+
249+
# Ensure the Subject Key Identifier extension is present
250+
cert = c_x509.load_pem_x509_certificate(certificate)
251+
ext_ski = [ext for ext in cert.extensions
252+
if cert.extensions[0].oid ==
253+
c_x509.oid.ExtensionOID.SUBJECT_KEY_IDENTIFIER]
254+
self.assertEqual(len(ext_ski), 1)
255+
236256
def test_sign_with_invalid_csr(self):
237257
ca_key = self._generate_private_key()
238258
csr = 'test'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
features:
3+
- |
4+
Add subject key identifier extension to x509 operations
5+
signing function. Allows for magnum Kubernetes clusters
6+
to generate certificates with authority key
7+
identifier extension.

0 commit comments

Comments
 (0)