Skip to content

Commit 8cb818b

Browse files
authored
Merge pull request #164 from grycap/devel
Hide sensitive data from template
2 parents 43c4e1e + 720ad91 commit 8cb818b

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

app/__init__.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,28 @@ def infrastructure_state():
383383
app.logger.error("Error getting infrastructure state: %s" % exs)
384384
return {"state": "error", "vm_states": {}}
385385

386+
def hide_sensitive_data(template):
387+
"""Remove/Hide sensitive data (passwords, credentials)."""
388+
data = yaml.full_load(template)
389+
390+
for node in list(data['topology_template']['node_templates'].values()):
391+
if node["type"] == "tosca.nodes.ec3.DNSRegistry":
392+
try:
393+
node["properties"]["dns_service_credentials"]["token"] = "AK:SK"
394+
except KeyError:
395+
pass
396+
397+
if node["type"] == "tosca.nodes.ec3.ElasticCluster":
398+
if "im_auth" in node["properties"]:
399+
node["properties"]["im_auth"] = "protected"
400+
try:
401+
node["interfaces"]["Standard"]["configure"]["inputs"]["CLIENT_ID"] = "client_id"
402+
node["interfaces"]["Standard"]["configure"]["inputs"]["CLIENT_SECRET"] = "client_secret"
403+
except KeyError:
404+
pass
405+
406+
return yaml.dump(data, default_flow_style=False, sort_keys=False)
407+
386408
@app.route('/template/<infid>')
387409
@authorized_with_valid_token
388410
def template(infid=None):
@@ -393,7 +415,7 @@ def template(infid=None):
393415
response = im.get_inf_property(infid, 'tosca', auth_data)
394416
if not response.ok:
395417
raise Exception(response.text)
396-
template = response.text
418+
template = hide_sensitive_data(response.text)
397419
except Exception as ex:
398420
flash("Error getting template: \n%s" % ex, "error")
399421

@@ -644,7 +666,6 @@ def createdep():
644666

645667
with io.open(settings.toscaDir + request.args.get('template')) as stream:
646668
template = yaml.full_load(stream)
647-
template = add_image_to_template(template, image)
648669

649670
template = add_image_to_template(template, image)
650671

app/tests/test_app.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ def get_response(url, params=None, **kwargs):
5757
elif url == "/im/infrastructures/infid/tosca":
5858
resp.ok = True
5959
resp.status_code = 200
60-
resp.text = "TOSCA"
60+
resp.text = """topology_template:
61+
node_templates:
62+
simple_node:
63+
type: tosca.nodes.indigo.Compute"""
6164
elif url == "/im/infrastructures/infid/contmsg":
6265
resp.ok = True
6366
resp.status_code = 200
@@ -263,7 +266,8 @@ def test_template(self, avatar, get, user_data):
263266
self.login(avatar)
264267
res = self.client.get('/template/infid')
265268
self.assertEqual(200, res.status_code)
266-
self.assertIn(b'TOSCA', res.data)
269+
expected = b"topology_template:\n node_templates:\n simple_node:\n type: tosca.nodes.indigo.Compute"
270+
self.assertIn(expected, res.data)
267271

268272
@patch("app.utils.getUserAuthData")
269273
@patch('requests.get')

0 commit comments

Comments
 (0)