Commit a790d6c5 authored by Xavier Thompson's avatar Xavier Thompson

stack/lamp: Generate random password for mariadb

See merge request !1331
parents e3b355ab 457905fe
Pipeline #26130 failed with stage
......@@ -35,7 +35,6 @@ path = ${template-matomo-instance:output}
part-list = matomo-backup.sh matomo-backup-cron
db-name = matomo
db-user = matomo
db-password = 12345678
[template-matomo-instance]
recipe = slapos.recipe.template:jinja2
......
......@@ -52,6 +52,9 @@ class MatomoTestCase(SlapOSInstanceTestCase):
break
self.assertTrue(self.matomo_path,"matomo path not found in %r" % (partition_path_list,))
self.connection_parameters = self.computer_partition.getConnectionParameterDict()
# parse <url> out of ['<url>']
url = self.connection_parameters['mariadb-url-list'][2:-2]
self.db_info = urllib.parse.urlparse(url)
#Check if matomo root directory is empty
def test_matomo_dir(self):
......@@ -83,8 +86,9 @@ class MatomoTestCase(SlapOSInstanceTestCase):
self.assertEqual(
tree.xpath('//input[@name="dbname"]/@value'),
['matomo'])
self.assertTrue(
tree.xpath('//input[@name="password"]/@value')[0])
self.assertEqual(
tree.xpath('//input[@name="password"]/@value'),
[self.db_info.password])
self.assertEqual(
tree.xpath('//input[@name="host"]/@value'),
[f'{self._ipv4_address}:2099']
......
......@@ -39,7 +39,6 @@ path = ${template-nextcloud-instance:output}
part-list = nextcloud-install.sh
db-name = nextcloud
db-user = nextcloud
db-password = insecure
[nc-download-unpacked]
recipe = slapos.recipe.build:download-unpacked
......
......@@ -31,6 +31,8 @@ import json
import glob
import re
from six.moves.urllib.parse import urlparse
from slapos.recipe.librecipe import generateHashFromFiles
from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass
......@@ -63,13 +65,17 @@ class NextCloudTestCase(InstanceTestCase):
self.nextcloud_path,
"Nextcloud path not found in %r" % (partition_path_list,))
# parse database info from mariadb url
d = self.computer_partition.getConnectionParameterDict()
db_url = d['mariadb-url-list'][2:-2] # parse <url> out of "['<url>']"
self._db_info = urlparse(db_url)
def getNextcloudConfig(self, config_dict={}):
data_dict = dict(
datadirectory=self.partition_dir + "/srv/data",
dbhost="%s:2099" % self._ipv4_address,
dbname="nextcloud",
dbpassword="insecure",
dbpassword=self._db_info.password,
dbport="",
dbuser="nextcloud",
mail_domain="nextcloud@example.com",
......
......@@ -63,7 +63,6 @@ part-list =
# database information
db-name = lamp
db-user = lamp
db-password = insecure
#----------------
#-- Instance-level buildout profiles.
......@@ -114,7 +113,6 @@ context =
key custom_application_template custom-application-deployment:path
key db_name custom-application-deployment:db-name
key db_user custom-application-deployment:db-user
key db_password custom-application-deployment:db-password
key lamp_apache_httpd template-apache-httpd:target
[instance-apache-php]
......
......@@ -14,15 +14,15 @@
# not need these here).
[lamp-instance]
filename = instance.cfg.in
md5sum = 603d03f43ea04e95237c80d3b9e72ba7
md5sum = 7854dd0edd48f2d91c16412c4a875ca4
[instance-apache-php]
filename = instance-apache-php.cfg.in
md5sum = 8506f245087dfdc02561e8739a567bd6
md5sum = 9ab14922535d4d85e0db8602c47a707d
[instance-lamp]
filename = instance-lamp.cfg.jinja2.in
md5sum = 3ff36cb2d10f53f932ba9ee99b5fe9e1
md5sum = 347ddf1516bf2ddb5f6fb23539382847
[template-apache.conf]
filename = apache.conf.in
......
......@@ -22,6 +22,14 @@ develop-eggs-directory = {{ develop_eggs_directory }}
offline = true
#----------------
#--
#-- Monitor password aggregation.
[monitor-instance-parameter]
password = {{ slapparameter_dict['monitor-passwd'] }}
#----------------
#--
#-- Creation of all needed directories.
......
......@@ -2,7 +2,6 @@
{% set part_list = [] -%}
{% set ipv6 = (ipv6 | list)[0] -%}
{% set monitor_base_url_dict = {} -%}
{% set mariadb_dict = {} -%}
[directory]
recipe = slapos.cookbook:mkdirectory
......@@ -28,6 +27,7 @@ sla-computer_guid = {{ dumps(slapparameter_dict.get('apache-computer-guid', ''))
config-{{ key }} = {{ dumps(value) }}
{% endif -%}
{% endfor -%}
config-monitor-passwd = ${monitor-instance-parameter:password}
config-database-list = ${request-mariadb:connection-database-list}
return =
backend-url
......@@ -37,24 +37,20 @@ return =
{% do publish_dict.__setitem__('backend-url', '${request-apache:connection-backend-url}') -%}
{% do monitor_base_url_dict.__setitem__('apache', '${request-apache:connection-monitor-base-url}') -%}
{% do mariadb_dict.__setitem__('database-list', [{'name': db_name, 'user': db_user, 'password': db_password }]) -%}
{% do mariadb_dict.__setitem__('test-database-amount', 0) -%}
{% do mariadb_dict.__setitem__('tcpv4-port', 2099) -%}
{% do mariadb_dict.__setitem__('max-slowqueries-threshold', 1000) -%}
{% do mariadb_dict.__setitem__('slowest-query-threshold', '') -%}
{% do mariadb_dict.__setitem__('computer-memory-percent-threshold', 80) -%}
{% do mariadb_dict.__setitem__('monitor-passwd', '${monitor-htpasswd:passwd}') -%}
{% do mariadb_dict.__setitem__('name', 'Mariadb') -%}
{% do mariadb_dict.__setitem__('innodb-file-per-table', slapparameter_dict.get('innodb-file-per-table', 1)) -%}
[request-mariadb]
<= request-common
software-type = mariadb
name = Mariadb
sla-computer_guid = {{ dumps(slapparameter_dict.get('mariadb-computer-guid', '')) }}
{% for key, value in mariadb_dict.items() -%}
config-{{ key }} = {{ dumps(value) }}
{% endfor -%}
config-database-list = {{ dumps([{'name': db_name, 'user': db_user, 'password': db_password }]) }}
config-test-database-amount = {{ dumps(0) }}
config-tcpv4-port = {{ dumps(2099) }}
config-max-slowqueries-threshold = {{ dumps(1000) }}
config-slowest-query-threshold =
config-computer-memory-percent-threshold = {{ dumps(80) }}
config-monitor-passwd = ${monitor-instance-parameter:password}
config-name = ${:name}
config-innodb-file-per-table = {{ dumps(slapparameter_dict.get('innodb-file-per-table', 1)) }}
return =
database-list
monitor-base-url
......
......@@ -40,8 +40,11 @@ context =
${:extra-context}
[dynamic-template-lamp-parameters]
[mariadb-password]
recipe = slapos.cookbook:generate.password
[dynamic-template-lamp-parameters]
[dynamic-template-lamp]
<= jinja2-template-base
......@@ -51,7 +54,7 @@ extra-context =
section parameter_dict dynamic-template-lamp-parameters
raw db_name {{ db_name }}
raw db_user {{ db_user }}
raw db_password {{ db_password }}
key db_password mariadb-password:passwd
[dynamic-template-apache-php-parameters]
{% if application_archive_root %}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment