diff --git a/endpoints/api/superuser.py b/endpoints/api/superuser.py index 9a1da3dea..953c30960 100644 --- a/endpoints/api/superuser.py +++ b/endpoints/api/superuser.py @@ -3,6 +3,7 @@ import logging import os import string +import subprocess import pathvalidate @@ -894,9 +895,27 @@ class SuperUserCustomCertificate(ApiResource): if not uploaded_file: abort(400) + # Save the certificate. certpath = pathvalidate.sanitize_filename(certpath) + if not certpath.endswith('.crt'): + abort(400) + cert_full_path = os.path.join(EXTRA_CA_DIRECTORY, certpath) config_provider.save_volume_file(cert_full_path, uploaded_file) + + # Validate the certificate. + try: + with config_provider.get_volume_file(cert_full_path) as f: + load_certificate(f.read()) + + # Call the update script to install the certificate immediately. + if not app.config['TESTING']: + subprocess.check_call(['/conf/init/certs_install.sh']) + except CertInvalidException: + pass + except IOError: + pass + return '', 204 abort(403) diff --git a/static/directives/config/config-certificates-field.html b/static/directives/config/config-certificates-field.html index 502475672..f20e4c459 100644 --- a/static/directives/config/config-certificates-field.html +++ b/static/directives/config/config-certificates-field.html @@ -12,6 +12,7 @@
Custom certificates are typically used in place of publicly signed certificates for corporate-internal services.
+Please make sure that all custom names used for downstream services (such as Clair) are listed in the certificates below.
Upload certificates: | + reset="resetUpload" + extensions="['.crt']"> |