Skip to content

Commit 601eac7

Browse files
author
Matthew Fisher
committed
feat(controller): support SAN certificates
This feature allows a user to specify a list of SubjectAltNames (SANs) for a specified certificate. This has the effect of creating multiple certificate entries in the database (one for each SAN), but it gives the user the benefit to revoke the certficate for each custom domain. By default, SANs are **not** added as new entries with `certs:add`. The user will need to explicitly give each subject alt name they wish to add as a certificate. Usage: ``` $ deis certs:add ~/.openssl/star.fishworks.io.cert ~/.openssl/private.key.nopass --subject-alt-name foo.fishworks.io --subject-alt-name bar.fishworks.io Adding SSL endpoint... done *.fishworks.io Adding SSL endpoint foo.fishworks.io...done Adding SSL endpoint bar.fishworks.io...done $ deis certs Common Name Expires ---------------- ---------------------- *.fishworks.io 2015-08-29T08:17:48UTC foo.fishworks.io 2015-08-29T08:17:48UTC bar.fishworks.io 2015-08-29T08:17:48UTC ``` In order for users to update their certificate, they will need to run `deis certs:remove` for each entry, then re-run `deis certs:add`. Docopt does not respect ellipsis when '[options]' is present, so I had to explicitly write out the option in the usage in order for the flag to work. Additionally, a new --common-name flag has also been introduced. This is a temporary workaround for users to add their wildcard certificates to their custom domain endpoints. This acts the same way where a database entry is created for each call to `certs:add`. If users want to update their wildcard certificate, they'll have to update each entry they've added. This is not the optimal solution, but it provides a way for us to support wildcard certificates for custom domains. Usage: ``` $ deis certs:add ~/.openssl/star.fishworks.io.cert ~/.openssl/private.key.nopass --common-name foo.fishworks.io Adding SSL endpoint foo.fishworks.io...done $ deis certs Common Name Expires ---------------- ---------------------- foo.fishworks.io 2015-08-29T08:17:48UTC ```
1 parent d175961 commit 601eac7

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

api/serializers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,9 @@ class Meta:
275275
"""Metadata options for a DomainCertSerializer."""
276276
model = models.Certificate
277277
extra_kwargs = {'certificate': {'write_only': True},
278-
'key': {'write_only': True}}
279-
read_only_fields = ['common_name', 'expires', 'created', 'updated']
278+
'key': {'write_only': True},
279+
'common_name': {'required': False}}
280+
read_only_fields = ['expires', 'created', 'updated']
280281

281282

282283
class PushSerializer(ModelSerializer):

api/tests/test_certificate.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ def test_create_certificate_with_domain(self):
8080
HTTP_AUTHORIZATION='token {}'.format(self.token))
8181
self.assertEqual(response.status_code, 201)
8282

83+
def test_create_certificate_with_different_common_name(self):
84+
"""
85+
In some cases such as with SAN certificates, the certificate can cover more
86+
than a single domain. In that case, we want to be able to specify the common
87+
name for the certificate/key.
88+
"""
89+
body = {'certificate': self.autotest_example_com_cert,
90+
'key': self.key,
91+
'common_name': 'foo.example.com'}
92+
response = self.client.post(self.url, json.dumps(body), content_type='application/json',
93+
HTTP_AUTHORIZATION='token {}'.format(self.token))
94+
self.assertEqual(response.status_code, 201)
95+
self.assertEqual(response.data['common_name'], 'foo.example.com')
96+
8397
def test_get_certificate_screens_data(self):
8498
"""
8599
When a user retrieves a certificate, only the common name and expiry date should be

0 commit comments

Comments
 (0)