Add possibility to manage file permissions of config files

Fixes-bug: PROD-36558
Change-Id: Ie65b7749b0cbeb1df660192f7f82822eb1014ff1
diff --git a/README.rst b/README.rst
index 4bae229..e9d4666 100644
--- a/README.rst
+++ b/README.rst
@@ -300,6 +300,38 @@
           # Add key without value to remove line from policy.json
           get_quotas:
 
+
+Change files/directories permissions for designate service:
+=======================================
+In order to change file permissions the following should be set:
+
+'files' - block to set permissions for files.
+- full path to file
+- user ( default value is 'root' ) this parameter is optional.
+- group ( default value is 'designate' ) this parameter is optional
+- mode ( default value is '0640' ) this parameter is optional
+
+'directories' - block to set permissions for directories.
+- full path to directory
+- user ( default value is 'root' ) this parameter is optional
+- group ( default value is 'designate' ) this parameter is optional
+- mode ( default value is '0750' ) this parameter is optional
+
+.. code-block:: yaml
+
+    designate:
+      files:
+        /etc/designate/designate.conf:
+          user: 'root'
+          group: 'designate'
+          mode: '0750'
+      directories:
+        /etc/designate:
+          user: 'root'
+          group: 'designate'
+          mode: '0750'
+
+
 Upgrades
 ========
 
diff --git a/designate/file_permissions.sls b/designate/file_permissions.sls
new file mode 100644
index 0000000..cfeb902
--- /dev/null
+++ b/designate/file_permissions.sls
@@ -0,0 +1,22 @@
+{% if pillar.designate.files is defined %}
+{%- for file_full_path, file_mode in pillar.designate.files.iteritems() %}
+{{ file_full_path }}_permissions:
+  file.managed:
+    - name: {{ file_full_path }}
+    - mode: {{ file_mode.get('mode', '0640') }}
+    - user: {{ file_mode.get('user', 'root') }}
+    - group: {{ file_mode.get('group', 'designate') }}
+    - replace: false
+{%- endfor %}
+{% endif %}
+
+{% if pillar.designate.directories is defined %}
+{%- for directory_path, directory_mode in pillar.designate.directories.iteritems() %}
+{{ directory_path }}_permissions:
+  file.directory:
+    - name: {{ directory_path }}
+    - mode: {{ directory_mode.get('mode', '0750') }}
+    - user: {{ directory_mode.get('user', 'root') }}
+    - group: {{ directory_mode.get('group', 'designate') }}
+{%- endfor %}
+{% endif %}
diff --git a/designate/init.sls b/designate/init.sls
index 2d64202..b24a8cc 100644
--- a/designate/init.sls
+++ b/designate/init.sls
@@ -15,4 +15,5 @@
 {%- if pillar.designate.agent is defined %}
 - designate.agent
 {%- endif %}
+- designate.file_permissions
 {%- endif %}
diff --git a/metadata/service/file_permissions.yml b/metadata/service/file_permissions.yml
new file mode 100644
index 0000000..7cc7375
--- /dev/null
+++ b/metadata/service/file_permissions.yml
@@ -0,0 +1,5 @@
+parameters:
+  designate:
+    directories:
+      /etc/designate:
+        mode: '0750'
\ No newline at end of file
diff --git a/metadata/service/server/cluster.yml b/metadata/service/server/cluster.yml
index 72a6ed9..9bf6fe7 100644
--- a/metadata/service/server/cluster.yml
+++ b/metadata/service/server/cluster.yml
@@ -2,6 +2,7 @@
 - designate
 classes:
 - service.designate.support
+- service.designate.file_permissions
 parameters:
   _param:
     openstack_log_appender: false
diff --git a/metadata/service/server/single.yml b/metadata/service/server/single.yml
index ace7f3b..5ff54ce 100644
--- a/metadata/service/server/single.yml
+++ b/metadata/service/server/single.yml
@@ -2,6 +2,7 @@
 - designate
 classes:
 - service.designate.support
+- service.designate.file_permissions
 parameters:
   _param:
     openstack_log_appender: false