[POLICY] Remove hardcoded credentials from policy-apex-pdp

This patch remove hardcoded healthcheck credentials and trustStorePassword
from policy-apex-pdp.

Issue-ID: OOM-2342
Signed-off-by: Dominik Mizyn <d.mizyn@samsung.com>
Change-Id: Ie8800830919479b87d7a71dfafe934bb95839ede
diff --git a/kubernetes/policy/charts/policy-apex-pdp/resources/config/OnapPfConfig.json b/kubernetes/policy/charts/policy-apex-pdp/resources/config/OnapPfConfig.json
index 3b6813d..767d145 100644
--- a/kubernetes/policy/charts/policy-apex-pdp/resources/config/OnapPfConfig.json
+++ b/kubernetes/policy/charts/policy-apex-pdp/resources/config/OnapPfConfig.json
@@ -3,8 +3,8 @@
     "restServerParameters": {
       "host": "0.0.0.0",
       "port": 6969,
-      "userName": "healthcheck",
-      "password": "zb!XztG34",
+      "userName": "${RESTSERVER_USER}",
+      "password": "${RESTSERVER_PASSWORD}",
       "https": true
     },
     "pdpStatusParameters":{
diff --git a/kubernetes/policy/charts/policy-apex-pdp/resources/config/config.json b/kubernetes/policy/charts/policy-apex-pdp/resources/config/config.json
index 57542c3..5df0a26 100644
--- a/kubernetes/policy/charts/policy-apex-pdp/resources/config/config.json
+++ b/kubernetes/policy/charts/policy-apex-pdp/resources/config/config.json
@@ -18,7 +18,7 @@
 {
   "javaProperties" : [
     ["javax.net.ssl.trustStore", "/opt/app/policy/apex-pdp/etc/ssl/policy-truststore"],
-    ["javax.net.ssl.trustStorePassword", "UG9sMWN5XzBuYXA="]
+    ["javax.net.ssl.trustStorePassword", "${TRUSTSTORE_PASSWORD_BASE64}"]
   ],
   "engineServiceParameters": {
     "name": "MyApexEngine",
diff --git a/kubernetes/policy/charts/policy-apex-pdp/templates/secrets.yaml b/kubernetes/policy/charts/policy-apex-pdp/templates/secrets.yaml
new file mode 100644
index 0000000..bd7eb8e
--- /dev/null
+++ b/kubernetes/policy/charts/policy-apex-pdp/templates/secrets.yaml
@@ -0,0 +1,15 @@
+# Copyright © 2020 Samsung Electronics
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+{{ include "common.secretFast" . }}
diff --git a/kubernetes/policy/charts/policy-apex-pdp/templates/statefulset.yaml b/kubernetes/policy/charts/policy-apex-pdp/templates/statefulset.yaml
index 4d35509..35f8aac 100644
--- a/kubernetes/policy/charts/policy-apex-pdp/templates/statefulset.yaml
+++ b/kubernetes/policy/charts/policy-apex-pdp/templates/statefulset.yaml
@@ -38,6 +38,27 @@
         app: {{ include "common.name" . }}
         release: {{ include "common.release" . }}
     spec:
+      initContainers:
+      - command:
+        - sh
+        args:
+        - -c
+        - "export TRUSTSTORE_PASSWORD_BASE64=`echo -n ${TRUSTSTORE_PASSWORD} | base64`; cd /config-input && for PFILE in `ls -1`; do envsubst <${PFILE} >/config/${PFILE}; done"
+        env:
+        - name: TRUSTSTORE_PASSWORD
+          {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "truststore-pass" "key" "password") | indent 10 }}
+        - name: RESTSERVER_USER
+          {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "restserver-creds" "key" "login") | indent 10 }}
+        - name: RESTSERVER_PASSWORD
+          {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "restserver-creds" "key" "password") | indent 10 }}
+        volumeMounts:
+        - mountPath: /config-input
+          name: apexconfig-input
+        - mountPath: /config
+          name: apexconfig
+        image: "{{ .Values.global.envsubstImage }}"
+        imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
+        name: {{ include "common.name" . }}-update-config
       containers:
         - name: {{ include "common.name" . }}
           image: "{{ include "common.repository" . }}/{{ .Values.image }}"
@@ -87,9 +108,12 @@
             path: /etc/localtime
         - name: policy-logs
           emptyDir: {}
-        - name: apexconfig
+        - name: apexconfig-input
           configMap:
             name: {{ include "common.fullname" . }}-configmap
             defaultMode: 0755
+        - name: apexconfig
+          emptyDir:
+            medium: Memory
       imagePullSecrets:
       - name: "{{ include "common.namespace" . }}-docker-registry-key"
diff --git a/kubernetes/policy/charts/policy-apex-pdp/values.yaml b/kubernetes/policy/charts/policy-apex-pdp/values.yaml
index 1fdc215..8730c9e 100644
--- a/kubernetes/policy/charts/policy-apex-pdp/values.yaml
+++ b/kubernetes/policy/charts/policy-apex-pdp/values.yaml
@@ -25,6 +25,21 @@
   persistence: {}
 
 #################################################################
+# Secrets metaconfig
+#################################################################
+secrets:
+  - uid: restserver-creds
+    type: basicAuth
+    externalSecret: '{{ tpl (default "" .Values.restServer.credsExternalSecret) . }}'
+    login: '{{ .Values.restServer.user }}'
+    password: '{{ .Values.restServer.password }}'
+  - uid: truststore-pass
+    type: password
+    externalSecret: '{{ tpl (default "" .Values.truststore.passwordExternalSecret) . }}'
+    password: '{{ .Values.truststore.password }}'
+    policy: required
+
+#################################################################
 # Application configuration defaults.
 #################################################################
 # application image
@@ -37,6 +52,12 @@
 
 # application configuration
 
+restServer:
+  user: healthcheck
+  password: zb!XztG34
+truststore:
+  password: Pol1cy_0nap
+
 # default number of instances
 replicaCount: 1