]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: set security headers
authorAvan Thakkar <athakkar@redhat.com>
Wed, 10 Feb 2021 22:12:49 +0000 (03:42 +0530)
committerAvan Thakkar <athakkar@redhat.com>
Fri, 19 Feb 2021 07:48:26 +0000 (13:18 +0530)
Fixes: https://tracker.ceph.com/issues/49243
Signed-off-by: Avan Thakkar <athakkar@redhat.com>
qa/tasks/mgr/dashboard/test_requests.py
qa/tasks/mgr/test_prometheus.py
src/pybind/mgr/dashboard/services/auth.py
src/pybind/mgr/prometheus/module.py

index 376f9bba4d19a975cbc0132d2566d39bb724ab90..93b175bfda0ea635248d1a3f921fdc2dc7144684 100644 (file)
@@ -27,5 +27,8 @@ class RequestsTest(DashboardTestCase):
         self._get('/api/summary')
         self.assertHeaders({
             'server': 'Ceph-Dashboard',
-            'Content-Type': 'application/vnd.ceph.api.v{}+json'.format(DEFAULT_VERSION)
+            'Content-Type': 'application/vnd.ceph.api.v{}+json'.format(DEFAULT_VERSION),
+            'Content-Security-Policy': "frame-ancestors 'self';",
+            'X-Content-Type-Options': 'nosniff',
+            'Strict-Transport-Security': 'max-age=63072000; includeSubDomains; preload'
         })
index 63a4abe00dbba0dc82460c1b4912c0b5cf21617e..376556ab30536e925b38d8e2286cc2a2aa7787d6 100644 (file)
@@ -48,6 +48,7 @@ class TestPrometheus(MgrTestCase):
         r = requests.get(original_uri + "metrics", allow_redirects=False)
         self.assertEqual(r.status_code, 200)
         self.assertEqual(r.headers["content-type"], "text/plain;charset=utf-8")
+        self.assertEqual(r.headers["server"], "Ceph-Prometheus")
 
     def test_urls(self):
         self._assign_ports("prometheus", "server_port")
index c44963ca7ed147cd4fa2255856389310bff6ebec..a3f165430014bfd96a700e657583a4d6cd0bff19 100644 (file)
@@ -16,7 +16,10 @@ from .. import mgr
 from .access_control import LocalAuthenticator, UserDoesNotExist
 
 cherrypy.config.update({
-    'response.headers.server': 'Ceph-Dashboard'
+    'response.headers.server': 'Ceph-Dashboard',
+    'response.headers.content-security-policy': "frame-ancestors 'self';",
+    'response.headers.x-content-type-options': 'nosniff',
+    'response.headers.strict-transport-security': 'max-age=63072000; includeSubDomains; preload'
 })
 
 
index ac586684a25c014f6aecad080f38a7db05543420..58c047c13484e2b527aac8e331bdb4b91642cb20 100644 (file)
@@ -50,6 +50,9 @@ os._exit = os_exit_noop
 # it's a dict, the writer doesn't need to declare 'global' for access
 
 _global_instance = None  # type: Optional[Module]
+cherrypy.config.update({
+    'response.headers.server': 'Ceph-Prometheus'
+})
 
 
 def health_status_to_number(status):