Merge lp:~ivoks/charms/trusty/contrail-webui/openstack-ssl into lp:~sdn-charmers/charms/trusty/contrail-webui/trunk

Proposed by Ante Karamatić
Status: Merged
Merged at revision: 39
Proposed branch: lp:~ivoks/charms/trusty/contrail-webui/openstack-ssl
Merge into: lp:~sdn-charmers/charms/trusty/contrail-webui/trunk
Diff against target: 210 lines (+139/-2)
7 files modified
charm-helpers-sync.yaml (+1/-0)
config.yaml (+6/-0)
hooks/charmhelpers/contrib/__init__.py (+13/-0)
hooks/charmhelpers/contrib/hahelpers/__init__.py (+13/-0)
hooks/charmhelpers/contrib/hahelpers/apache.py (+95/-0)
hooks/services.py (+10/-1)
templates/config.global.js.j2 (+1/-1)
To merge this branch: bzr merge lp:~ivoks/charms/trusty/contrail-webui/openstack-ssl
Reviewer Review Type Date Requested Status
Robert Ayres (community) Approve
Review via email: mp+316005@code.launchpad.net

Description of the change

This patch allows contrail-webui to connect to OpenStack services using TLS/SSL protocol.

To post a comment you must log in.
Revision history for this message
Robert Ayres (robert-ayres) wrote :

Apologies for the delay. I am actively reviewing/testing some modifications to this patch.

Revision history for this message
Robert Ayres (robert-ayres) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charm-helpers-sync.yaml'
2--- charm-helpers-sync.yaml 2016-10-10 21:00:20 +0000
3+++ charm-helpers-sync.yaml 2017-01-31 13:12:03 +0000
4@@ -3,4 +3,5 @@
5 include:
6 - core
7 - fetch
8+ - contrib.hahelpers.apache
9 - osplatform
10
11=== modified file 'config.yaml'
12--- config.yaml 2015-12-17 20:29:12 +0000
13+++ config.yaml 2017-01-31 13:12:03 +0000
14@@ -50,3 +50,9 @@
15 NOTE: it will get downloaded and cached every time
16 the config is updated. If empty, the default will
17 be used.
18+ ssl_ca:
19+ type: string
20+ default:
21+ description: |
22+ SSL CA used to sign certificates of OpenStack services. It should be
23+ provided in base64 format.
24
25=== added directory 'hooks/charmhelpers/contrib'
26=== added file 'hooks/charmhelpers/contrib/__init__.py'
27--- hooks/charmhelpers/contrib/__init__.py 1970-01-01 00:00:00 +0000
28+++ hooks/charmhelpers/contrib/__init__.py 2017-01-31 13:12:03 +0000
29@@ -0,0 +1,13 @@
30+# Copyright 2014-2015 Canonical Limited.
31+#
32+# Licensed under the Apache License, Version 2.0 (the "License");
33+# you may not use this file except in compliance with the License.
34+# You may obtain a copy of the License at
35+#
36+# http://www.apache.org/licenses/LICENSE-2.0
37+#
38+# Unless required by applicable law or agreed to in writing, software
39+# distributed under the License is distributed on an "AS IS" BASIS,
40+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
41+# See the License for the specific language governing permissions and
42+# limitations under the License.
43
44=== added directory 'hooks/charmhelpers/contrib/hahelpers'
45=== added file 'hooks/charmhelpers/contrib/hahelpers/__init__.py'
46--- hooks/charmhelpers/contrib/hahelpers/__init__.py 1970-01-01 00:00:00 +0000
47+++ hooks/charmhelpers/contrib/hahelpers/__init__.py 2017-01-31 13:12:03 +0000
48@@ -0,0 +1,13 @@
49+# Copyright 2014-2015 Canonical Limited.
50+#
51+# Licensed under the Apache License, Version 2.0 (the "License");
52+# you may not use this file except in compliance with the License.
53+# You may obtain a copy of the License at
54+#
55+# http://www.apache.org/licenses/LICENSE-2.0
56+#
57+# Unless required by applicable law or agreed to in writing, software
58+# distributed under the License is distributed on an "AS IS" BASIS,
59+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
60+# See the License for the specific language governing permissions and
61+# limitations under the License.
62
63=== added file 'hooks/charmhelpers/contrib/hahelpers/apache.py'
64--- hooks/charmhelpers/contrib/hahelpers/apache.py 1970-01-01 00:00:00 +0000
65+++ hooks/charmhelpers/contrib/hahelpers/apache.py 2017-01-31 13:12:03 +0000
66@@ -0,0 +1,95 @@
67+# Copyright 2014-2015 Canonical Limited.
68+#
69+# Licensed under the Apache License, Version 2.0 (the "License");
70+# you may not use this file except in compliance with the License.
71+# You may obtain a copy of the License at
72+#
73+# http://www.apache.org/licenses/LICENSE-2.0
74+#
75+# Unless required by applicable law or agreed to in writing, software
76+# distributed under the License is distributed on an "AS IS" BASIS,
77+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
78+# See the License for the specific language governing permissions and
79+# limitations under the License.
80+
81+#
82+# Copyright 2012 Canonical Ltd.
83+#
84+# This file is sourced from lp:openstack-charm-helpers
85+#
86+# Authors:
87+# James Page <james.page@ubuntu.com>
88+# Adam Gandelman <adamg@ubuntu.com>
89+#
90+
91+import os
92+import subprocess
93+
94+from charmhelpers.core.hookenv import (
95+ config as config_get,
96+ relation_get,
97+ relation_ids,
98+ related_units as relation_list,
99+ log,
100+ INFO,
101+)
102+
103+
104+def get_cert(cn=None):
105+ # TODO: deal with multiple https endpoints via charm config
106+ cert = config_get('ssl_cert')
107+ key = config_get('ssl_key')
108+ if not (cert and key):
109+ log("Inspecting identity-service relations for SSL certificate.",
110+ level=INFO)
111+ cert = key = None
112+ if cn:
113+ ssl_cert_attr = 'ssl_cert_{}'.format(cn)
114+ ssl_key_attr = 'ssl_key_{}'.format(cn)
115+ else:
116+ ssl_cert_attr = 'ssl_cert'
117+ ssl_key_attr = 'ssl_key'
118+ for r_id in relation_ids('identity-service'):
119+ for unit in relation_list(r_id):
120+ if not cert:
121+ cert = relation_get(ssl_cert_attr,
122+ rid=r_id, unit=unit)
123+ if not key:
124+ key = relation_get(ssl_key_attr,
125+ rid=r_id, unit=unit)
126+ return (cert, key)
127+
128+
129+def get_ca_cert():
130+ ca_cert = config_get('ssl_ca')
131+ if ca_cert is None:
132+ log("Inspecting identity-service relations for CA SSL certificate.",
133+ level=INFO)
134+ for r_id in relation_ids('identity-service'):
135+ for unit in relation_list(r_id):
136+ if ca_cert is None:
137+ ca_cert = relation_get('ca_cert',
138+ rid=r_id, unit=unit)
139+ return ca_cert
140+
141+
142+def retrieve_ca_cert(cert_file):
143+ cert = None
144+ if os.path.isfile(cert_file):
145+ with open(cert_file, 'r') as crt:
146+ cert = crt.read()
147+ return cert
148+
149+
150+def install_ca_cert(ca_cert):
151+ if ca_cert:
152+ cert_file = ('/usr/local/share/ca-certificates/'
153+ 'keystone_juju_ca_cert.crt')
154+ old_cert = retrieve_ca_cert(cert_file)
155+ if old_cert and old_cert == ca_cert:
156+ log("CA cert is the same as installed version", level=INFO)
157+ else:
158+ log("Installing new CA cert", level=INFO)
159+ with open(cert_file, 'w') as crt:
160+ crt.write(ca_cert)
161+ subprocess.check_call(['update-ca-certificates', '--fresh'])
162
163=== modified file 'hooks/services.py'
164--- hooks/services.py 2016-11-14 20:48:45 +0000
165+++ hooks/services.py 2017-01-31 13:12:03 +0000
166@@ -6,6 +6,12 @@
167 import yaml
168
169 import actions
170+
171+from charmhelpers.contrib.hahelpers.apache import (
172+ get_ca_cert,
173+ install_ca_cert
174+)
175+
176 from charmhelpers.core import hookenv
177 from charmhelpers.core import services
178 from charmhelpers.core import templating
179@@ -43,7 +49,7 @@
180 name = 'identity_admin'
181 interface = 'keystone-admin'
182 required_keys = ['service_hostname', 'service_port', 'service_username',
183- 'service_tenant_name', 'service_password']
184+ 'service_tenant_name', 'service_password', 'service_protocol']
185
186
187 class RedisRelation(services.RelationContext):
188@@ -150,6 +156,9 @@
189
190 class SSLConfig(services.ManagerCallback):
191 def __call__(self, manager, service_name, event_name):
192+ CAcert = get_ca_cert()
193+ if CAcert is not None:
194+ install_ca_cert(CAcert)
195 if hookenv.is_leader():
196 config = hookenv.config()
197 cert = config.get('ssl-cert')
198
199=== modified file 'templates/config.global.js.j2'
200--- templates/config.global.js.j2 2016-11-14 20:48:45 +0000
201+++ templates/config.global.js.j2 2017-01-31 13:12:03 +0000
202@@ -28,7 +28,7 @@
203 config.identityManager = {};
204 config.identityManager.ip = '{{ identity_admin[0]['service_hostname'] }}';
205 config.identityManager.port = '{{ identity_admin[0]['service_port'] }}';
206-config.identityManager.authProtocol = 'http';
207+config.identityManager.authProtocol = '{{ identity_admin[0]['service_protocol'] }}';
208 config.identityManager.apiVersion = ['v2.0'];
209 config.identityManager.strictSSL = false;
210 config.identityManager.ca = '';

Subscribers

People subscribed via source and target branches