Merge "[PORTAL] Non-root user for back-end database"
authorSylvain Desbureaux <sylvain.desbureaux@orange.com>
Fri, 2 Oct 2020 15:48:42 +0000 (15:48 +0000)
committerGerrit Code Review <gerrit@onap.org>
Fri, 2 Oct 2020 15:48:42 +0000 (15:48 +0000)
kubernetes/portal/components/portal-app/resources/config/deliveries/properties/ONAPPORTAL/system.properties
kubernetes/portal/components/portal-app/templates/deployment.yaml
kubernetes/portal/components/portal-app/values.yaml
kubernetes/portal/components/portal-mariadb/resources/config/mariadb/docker-entrypoint.sh
kubernetes/portal/components/portal-mariadb/templates/deployment.yaml
kubernetes/portal/components/portal-mariadb/templates/secrets.yaml
kubernetes/portal/components/portal-mariadb/values.yaml
kubernetes/portal/components/portal-sdk/resources/config/deliveries/properties/ONAPPORTALSDK/system.properties
kubernetes/portal/components/portal-sdk/templates/deployment.yaml
kubernetes/portal/components/portal-sdk/values.yaml
kubernetes/portal/values.yaml

index b5b4e48..c8a292f 100755 (executable)
@@ -16,8 +16,8 @@
 #mysql
 db.driver = org.mariadb.jdbc.Driver
 db.connectionURL = jdbc:mariadb:failover://portal-db:3306/portal
-db.userName =root
-db.password =Aa123456
+db.userName =${PORTAL_DB_USER}
+db.password =${PORTAL_DB_PASSWORD}
 db.hib.dialect = org.hibernate.dialect.MySQLDialect
 db.min_pool_size = 5
 db.max_pool_size = 10
@@ -122,4 +122,4 @@ remote_centralized_system_access = {{.Values.global.aafEnabled}}
 ext_central_access_user_name = aaf_admin@people.osaaf.org
 ext_central_access_password = demo123456!
 ext_central_access_url = {{.Values.aafURL}}
-ext_central_access_user_domain = @people.osaaf.org
\ No newline at end of file
+ext_central_access_user_domain = @people.osaaf.org
index 0be1fdc..d61f876 100644 (file)
@@ -61,6 +61,10 @@ spec:
             {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "portal-cass" "key" "password") | indent 12 }}
           - name: CIPHER_ENC_KEY
             {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "cipher-enc-key" "key" "password") | indent 12 }}
+          - name: PORTAL_DB_USER
+            {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "portal-backend-db" "key" "login") | indent 12 }}
+          - name: PORTAL_DB_PASSWORD
+            {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "portal-backend-db" "key" "password") | indent 12 }}
         volumeMounts:
         - mountPath: /config-input
           name: properties-onapportal-scrubbed
index 55a7ccc..bd1ed58 100644 (file)
@@ -43,6 +43,12 @@ secrets:
     externalSecret: '{{ .Values.config.cipherEncKeyExternalSecret}}'
     password: '{{ .Values.config.cipherEncKey }}'
     passwordPolicy: required
+  - uid: portal-backend-db
+    type: basicAuth
+    externalSecret: '{{ tpl (default "" .Values.mariadb.config.backendDbExternalSecret) . }}'
+    login: '{{ .Values.mariadb.config.backendUserName }}'
+    password: '{{ .Values.mariadb.config.backendPassword }}'
+    passwordPolicy: required
 
 #################################################################
 # Application configuration defaults.
@@ -120,6 +126,10 @@ service:
 mariadb:
   service:
     name: portal-db
+  config:
+    # backendDbExternalSecret: some secret
+    backendUserName: portal
+    backendPassword: portal
 widget:
   service:
     name: portal-widget
index 28fcee1..93d2b67 100644 (file)
@@ -182,6 +182,13 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
                        echo
                done
 
+               file_env 'PORTAL_DB_TABLES'
+               for i in $(echo $PORTAL_DB_TABLES | sed "s/,/ /g")
+                       do
+                           echo "Granting portal user ALL PRIVILEGES for table $i"
+                                       echo "GRANT ALL ON \`$i\`.* TO '$MYSQL_USER'@'%' ;" | "${mysql[@]}"
+                       done
+
                if ! kill -s TERM "$pid" || ! wait "$pid"; then
                        echo >&2 'MySQL init process failed.'
                        exit 1
@@ -193,4 +200,4 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
        fi
 fi
 
-exec "$@"
\ No newline at end of file
+exec "$@"
index ec6cc50..196a2d1 100644 (file)
@@ -69,6 +69,18 @@ spec:
                 secretKeyRef:
                   name: {{ template "common.fullname" . }}
                   key: db-root-password
+            - name: MYSQL_USER
+              valueFrom:
+                secretKeyRef:
+                  name: {{ template "common.fullname" . }}
+                  key: backend-db-user
+            - name: MYSQL_PASSWORD
+              valueFrom:
+                secretKeyRef:
+                  name: {{ template "common.fullname" . }}
+                  key: backend-db-password
+            - name: PORTAL_DB_TABLES
+              value: {{ .Values.config.backend_portal_tables }}
           volumeMounts:
           - mountPath: /var/lib/mysql
             name: mariadb-data
index ad1db77..4415c5e 100644 (file)
@@ -26,3 +26,6 @@ metadata:
 type: Opaque
 data:
   db-root-password: {{ .Values.config.mariadbRootPassword | b64enc | quote }}
+stringData:
+  backend-db-user: {{ .Values.config.backendDbUser }}
+  backend-db-password: {{ .Values.config.backendDbPassword }}
index 3435feb..fc1eca8 100644 (file)
@@ -35,6 +35,11 @@ mariadbInitImage: "oomk8s/mariadb-client-init:3.0.0"
 config:
   mariadbUser: root
   mariadbRootPassword: Aa123456
+  backendDbUser: portal
+  backendDbPassword: portal
+  #backend_portal_tables is a comma delimited string listing back-end tables
+  #that backendDbUser needs access to, such as to portal and ecomp_sdk tables
+  backend_portal_tables: portal,ecomp_sdk
   #The directory where sql files are found in the projects gerrit repo.
   sqlSourceDirectory: portal/deliveries
   # sdc frontend assignment for port 9443
index 2a2ec59..1faed41 100755 (executable)
@@ -40,8 +40,8 @@ decryption_key                                  = AGLDdG4D04BKm2IxIWEr8o==
 
 db.driver = org.mariadb.jdbc.Driver
 db.connectionURL = jdbc:mariadb://portal-db:3306/ecomp_sdk
-db.userName = root
-db.password = Aa123456
+db.userName =${PORTAL_DB_USER}
+db.password =${PORTAL_DB_PASSWORD}
 db.min_pool_size = 5
 db.max_pool_size = 10
 hb.dialect = org.hibernate.dialect.MySQLDialect
@@ -90,4 +90,4 @@ remote_centralized_system_access = {{.Values.global.aafEnabled}}
 ext_central_access_user_name = aaf_admin@people.osaaf.org
 ext_central_access_password = demo123456!
 ext_central_access_url = {{.Values.aafURL}}
-ext_central_access_user_domain = @people.osaaf.org
\ No newline at end of file
+ext_central_access_user_domain = @people.osaaf.org
index f79098f..fabefde 100644 (file)
@@ -61,6 +61,10 @@ spec:
             {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "portal-cass" "key" "password") | indent 12 }}
           - name: CIPHER_ENC_KEY
             {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "cipher-enc-key" "key" "password") | indent 12 }}
+          - name: PORTAL_DB_USER
+            {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "portal-backend-db" "key" "login") | indent 12 }}
+          - name: PORTAL_DB_PASSWORD
+            {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "portal-backend-db" "key" "password") | indent 12 }}
         volumeMounts:
         - mountPath: /config-input
           name: properties-onapportalsdk-scrubbed
index c0f1b58..4056b2a 100644 (file)
@@ -39,6 +39,12 @@ secrets:
     login: '{{ .Values.cassandra.config.cassandraUsername }}'
     password: '{{ .Values.cassandra.config.cassandraPassword }}'
     passwordPolicy: required
+  - uid: portal-backend-db
+    type: basicAuth
+    externalSecret: '{{ tpl (default "" .Values.mariadb.config.backendDbExternalSecret) . }}'
+    login: '{{ .Values.mariadb.config.backendUserName }}'
+    password: '{{ .Values.mariadb.config.backendPassword }}'
+    passwordPolicy: required
   - uid: cipher-enc-key
     type: password
     externalSecret: '{{ .Values.config.cipherEncKeyExternalSecret}}'
@@ -115,6 +121,10 @@ service:
 mariadb:
   service:
     name: portal-db
+  config:
+    # backendDbExternalSecret: some secret
+    backendUserName: portal
+    backendPassword: portal
 widget:
   service:
     name: portal-widget
index 2a760cd..0d4b023 100644 (file)
@@ -32,12 +32,19 @@ secrets:
     externalSecret: '{{ tpl (default "" .Values.config.casandraCredsExternalSecret) . }}'
     login: '{{ .Values.config.cassandraUsername }}'
     password: '{{ .Values.config.cassandraPassword }}'
+  - uid: portal-backend-db
+    name: &backendDbSecretName '{{ include "common.release" . }}-portal-backend-creds'
+    type: basicAuth
+    externalSecret: '{{ tpl (default "" .Values.mariadb.config.backendDbExternalSecret) . }}'
+    login: '{{ .Values.mariadb.config.backendUserName }}'
+    password: '{{ .Values.mariadb.config.backendPassword }}'
+    passwordPolicy: required
 
 config:
   logstashServiceName: log-ls
   logstashPort: 5044
   cassandraUsername: root
-# cassandraPassword: Aa123456
+  cassandraPassword: Aa123456
 # casandraCredsExternalSecret: some secret
 
 portal-mariadb:
@@ -45,6 +52,11 @@ portal-mariadb:
 mariadb:
   service:
     name: portal-db
+  config:
+#   backendDbExternalSecret: some secret
+    backendUserName: portal
+    backendPassword: portal
+
 widget:
   service:
     name: portal-widget
@@ -54,10 +66,16 @@ cassandra:
   config:
     cassandraExternalSecret: *dbSecretName
 portal-app:
+  mariadb:
+    config:
+      backendDbExternalSecret: *backendDbSecretName
   cassandra:
     config:
       cassandraExternalSecret: *dbSecretName
 portal-sdk:
+  mariadb:
+    config:
+      backendDbExternalSecret: *backendDbSecretName
   cassandra:
     config:
       cassandraExternalSecret: *dbSecretName