You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ambari.apache.org by GitBox <gi...@apache.org> on 2021/01/21 13:13:28 UTC

[GitHub] [ambari] payert opened a new pull request #3279: AMBARI-25547 Update Grafana version to 6.7.4 to avoid CVE-2020-13379

payert opened a new pull request #3279:
URL: https://github.com/apache/ambari/pull/3279


   ## What changes were proposed in this pull request?
   
   Grafana version is bumped up to v6.7.4 to fix security issues.
   
   ## How was this patch tested?
   
   The test was mostly manual by installing and upgrading Ambari from various source versions.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ambari] payert commented on a change in pull request #3279: AMBARI-25547 Update Grafana version to 6.7.4 to avoid CVE-2020-13379

Posted by GitBox <gi...@apache.org>.
payert commented on a change in pull request #3279:
URL: https://github.com/apache/ambari/pull/3279#discussion_r561913816



##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {

Review comment:
       Done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ambari] payert commented on a change in pull request #3279: AMBARI-25547 Update Grafana version to 6.7.4 to avoid CVE-2020-13379

Posted by GitBox <gi...@apache.org>.
payert commented on a change in pull request #3279:
URL: https://github.com/apache/ambari/pull/3279#discussion_r561920338



##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {
+        for (Cluster cluster : clusterMap.values()) {
+          Set<String> installedServices = cluster.getServices().keySet();
+          if (installedServices.contains("AMBARI_METRICS")) {
+            String contentText = cluster.getDesiredConfigByType("ams-grafana-ini").getProperties().get("content");
+            if (contentText != null) {
+              String addAfter;
+              String toInsert;
+              String toFind;
+              String toReplace;
+              StringBuilder content = new StringBuilder(contentText);
+
+              addAfter = "; app_mode = production";
+              toInsert = "\n" +
+                  "\n# instance name, defaults to HOSTNAME environment variable value or hostname if HOSTNAME var is empty" +
+                  "\n; instance_name = ${HOSTNAME}";
+              insertAfterIfNotThere(content, addAfter, toInsert);
+
+              addAfter = "logs = {{ams_grafana_log_dir}}";
+              String pluginsConfLine = "plugins = /var/lib/ambari-metrics-grafana/plugins";

Review comment:
       Right again.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ambari] dvitiiuk commented on a change in pull request #3279: AMBARI-25547 Update Grafana version to 6.7.4 to avoid CVE-2020-13379

Posted by GitBox <gi...@apache.org>.
dvitiiuk commented on a change in pull request #3279:
URL: https://github.com/apache/ambari/pull/3279#discussion_r561884114



##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -17,16 +17,27 @@
  */
 package org.apache.ambari.server.upgrade;
 
+import static org.apache.ambari.server.utils.CustomStringUtils.deleteSubstring;

Review comment:
       Should all these changes be moved to UpgradeCatalog276 instead of this?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ambari] dvitiiuk commented on a change in pull request #3279: AMBARI-25547 Update Grafana version to 6.7.4 to avoid CVE-2020-13379

Posted by GitBox <gi...@apache.org>.
dvitiiuk commented on a change in pull request #3279:
URL: https://github.com/apache/ambari/pull/3279#discussion_r561902376



##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {
+        for (Cluster cluster : clusterMap.values()) {
+          Set<String> installedServices = cluster.getServices().keySet();
+          if (installedServices.contains("AMBARI_METRICS")) {
+            String contentText = cluster.getDesiredConfigByType("ams-grafana-ini").getProperties().get("content");
+            if (contentText != null) {
+              String addAfter;
+              String toInsert;
+              String toFind;
+              String toReplace;
+              StringBuilder content = new StringBuilder(contentText);
+
+              addAfter = "; app_mode = production";
+              toInsert = "\n" +
+                  "\n# instance name, defaults to HOSTNAME environment variable value or hostname if HOSTNAME var is empty" +
+                  "\n; instance_name = ${HOSTNAME}";
+              insertAfterIfNotThere(content, addAfter, toInsert);
+
+              addAfter = "logs = {{ams_grafana_log_dir}}";
+              String pluginsConfLine = "plugins = /var/lib/ambari-metrics-grafana/plugins";
+              toInsert = "\n" +
+                  "\n# Directory where grafana will automatically scan and look for plugins" +
+                  "\n" + pluginsConfLine;
+              insertAfterIfNotThere(content, addAfter, toInsert, pluginsConfLine);
+
+              deleteSubstring(content, ";protocol = http\n");
+              deleteSubstring(content, ";http_port = 3000\n");
+              deleteSubstring(content, ";static_root_path = public\n");
+              deleteSubstring(content, ";cert_file =\n");
+              deleteSubstring(content, ";cert_key =\n");
+
+              addAfter = "cert_key = {{ams_grafana_cert_key}}";
+              toInsert = "\n" +
+                  "\n# Unix socket path" +
+                  "\n;socket =";
+              insertAfterIfNotThere(content, addAfter, toInsert);
+
+              toFind = ";password =";
+              toReplace = "# If the password contains # or ; you have to wrap it with triple quotes. Ex \"\"\"#password;\"\"\"" +
+                  "\n;password =" +
+                  "\n" +
+                  "\n# Use either URL or the previous fields to configure the database" +
+                  "\n# Example: mysql://user:secret@host:port/database" +
+                  "\n;url =";
+              replaceIfNotThere(content, toFind, toReplace);
+
+              addAfter = ";session_life_time = 86400";
+              toInsert = "\n" +

Review comment:
       If a user modified the after line to "session_life_time = ***" then no lines will be added, right?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ambari] payert merged pull request #3279: AMBARI-25547 Update Grafana version to 6.7.4 to avoid CVE-2020-13379

Posted by GitBox <gi...@apache.org>.
payert merged pull request #3279:
URL: https://github.com/apache/ambari/pull/3279


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ambari] dvitiiuk commented on a change in pull request #3279: AMBARI-25547 Update Grafana version to 6.7.4 to avoid CVE-2020-13379

Posted by GitBox <gi...@apache.org>.
dvitiiuk commented on a change in pull request #3279:
URL: https://github.com/apache/ambari/pull/3279#discussion_r561884114



##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -17,16 +17,27 @@
  */
 package org.apache.ambari.server.upgrade;
 
+import static org.apache.ambari.server.utils.CustomStringUtils.deleteSubstring;

Review comment:
       Should it be added to UpgradeCatalog276 instead of this?

##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {

Review comment:
       Can we use MapUtils.isNotEmpty() for this?

##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {
+        for (Cluster cluster : clusterMap.values()) {
+          Set<String> installedServices = cluster.getServices().keySet();
+          if (installedServices.contains("AMBARI_METRICS")) {
+            String contentText = cluster.getDesiredConfigByType("ams-grafana-ini").getProperties().get("content");
+            if (contentText != null) {
+              String addAfter;
+              String toInsert;
+              String toFind;
+              String toReplace;
+              StringBuilder content = new StringBuilder(contentText);
+
+              addAfter = "; app_mode = production";
+              toInsert = "\n" +
+                  "\n# instance name, defaults to HOSTNAME environment variable value or hostname if HOSTNAME var is empty" +
+                  "\n; instance_name = ${HOSTNAME}";
+              insertAfterIfNotThere(content, addAfter, toInsert);
+
+              addAfter = "logs = {{ams_grafana_log_dir}}";
+              String pluginsConfLine = "plugins = /var/lib/ambari-metrics-grafana/plugins";
+              toInsert = "\n" +
+                  "\n# Directory where grafana will automatically scan and look for plugins" +
+                  "\n" + pluginsConfLine;
+              insertAfterIfNotThere(content, addAfter, toInsert, pluginsConfLine);
+
+              deleteSubstring(content, ";protocol = http\n");
+              deleteSubstring(content, ";http_port = 3000\n");
+              deleteSubstring(content, ";static_root_path = public\n");
+              deleteSubstring(content, ";cert_file =\n");
+              deleteSubstring(content, ";cert_key =\n");
+
+              addAfter = "cert_key = {{ams_grafana_cert_key}}";
+              toInsert = "\n" +
+                  "\n# Unix socket path" +
+                  "\n;socket =";
+              insertAfterIfNotThere(content, addAfter, toInsert);
+
+              toFind = ";password =";
+              toReplace = "# If the password contains # or ; you have to wrap it with triple quotes. Ex \"\"\"#password;\"\"\"" +
+                  "\n;password =" +
+                  "\n" +
+                  "\n# Use either URL or the previous fields to configure the database" +
+                  "\n# Example: mysql://user:secret@host:port/database" +
+                  "\n;url =";
+              replaceIfNotThere(content, toFind, toReplace);
+
+              addAfter = ";session_life_time = 86400";
+              toInsert = "\n" +

Review comment:
       The same

##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {
+        for (Cluster cluster : clusterMap.values()) {
+          Set<String> installedServices = cluster.getServices().keySet();
+          if (installedServices.contains("AMBARI_METRICS")) {
+            String contentText = cluster.getDesiredConfigByType("ams-grafana-ini").getProperties().get("content");
+            if (contentText != null) {
+              String addAfter;
+              String toInsert;
+              String toFind;
+              String toReplace;
+              StringBuilder content = new StringBuilder(contentText);
+
+              addAfter = "; app_mode = production";
+              toInsert = "\n" +

Review comment:
       If a user modified the after line to "app_mode = ***" then no lines will be added, right?

##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {
+        for (Cluster cluster : clusterMap.values()) {
+          Set<String> installedServices = cluster.getServices().keySet();
+          if (installedServices.contains("AMBARI_METRICS")) {
+            String contentText = cluster.getDesiredConfigByType("ams-grafana-ini").getProperties().get("content");

Review comment:
       Possible NPE if getDesiredConfigByType returns null.

##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {
+        for (Cluster cluster : clusterMap.values()) {
+          Set<String> installedServices = cluster.getServices().keySet();
+          if (installedServices.contains("AMBARI_METRICS")) {
+            String contentText = cluster.getDesiredConfigByType("ams-grafana-ini").getProperties().get("content");
+            if (contentText != null) {
+              String addAfter;
+              String toInsert;
+              String toFind;
+              String toReplace;
+              StringBuilder content = new StringBuilder(contentText);
+
+              addAfter = "; app_mode = production";
+              toInsert = "\n" +
+                  "\n# instance name, defaults to HOSTNAME environment variable value or hostname if HOSTNAME var is empty" +
+                  "\n; instance_name = ${HOSTNAME}";
+              insertAfterIfNotThere(content, addAfter, toInsert);
+
+              addAfter = "logs = {{ams_grafana_log_dir}}";
+              String pluginsConfLine = "plugins = /var/lib/ambari-metrics-grafana/plugins";

Review comment:
       The same.

##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -17,16 +17,27 @@
  */
 package org.apache.ambari.server.upgrade;
 
+import static org.apache.ambari.server.utils.CustomStringUtils.deleteSubstring;

Review comment:
       Should all these changes be moved to UpgradeCatalog276 instead of this?

##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {
+        for (Cluster cluster : clusterMap.values()) {
+          Set<String> installedServices = cluster.getServices().keySet();
+          if (installedServices.contains("AMBARI_METRICS")) {
+            String contentText = cluster.getDesiredConfigByType("ams-grafana-ini").getProperties().get("content");
+            if (contentText != null) {
+              String addAfter;
+              String toInsert;
+              String toFind;
+              String toReplace;
+              StringBuilder content = new StringBuilder(contentText);
+
+              addAfter = "; app_mode = production";
+              toInsert = "\n" +
+                  "\n# instance name, defaults to HOSTNAME environment variable value or hostname if HOSTNAME var is empty" +
+                  "\n; instance_name = ${HOSTNAME}";
+              insertAfterIfNotThere(content, addAfter, toInsert);
+
+              addAfter = "logs = {{ams_grafana_log_dir}}";
+              String pluginsConfLine = "plugins = /var/lib/ambari-metrics-grafana/plugins";
+              toInsert = "\n" +
+                  "\n# Directory where grafana will automatically scan and look for plugins" +
+                  "\n" + pluginsConfLine;
+              insertAfterIfNotThere(content, addAfter, toInsert, pluginsConfLine);
+
+              deleteSubstring(content, ";protocol = http\n");
+              deleteSubstring(content, ";http_port = 3000\n");
+              deleteSubstring(content, ";static_root_path = public\n");
+              deleteSubstring(content, ";cert_file =\n");
+              deleteSubstring(content, ";cert_key =\n");
+
+              addAfter = "cert_key = {{ams_grafana_cert_key}}";
+              toInsert = "\n" +
+                  "\n# Unix socket path" +
+                  "\n;socket =";
+              insertAfterIfNotThere(content, addAfter, toInsert);
+
+              toFind = ";password =";
+              toReplace = "# If the password contains # or ; you have to wrap it with triple quotes. Ex \"\"\"#password;\"\"\"" +
+                  "\n;password =" +
+                  "\n" +
+                  "\n# Use either URL or the previous fields to configure the database" +
+                  "\n# Example: mysql://user:secret@host:port/database" +
+                  "\n;url =";
+              replaceIfNotThere(content, toFind, toReplace);
+
+              addAfter = ";session_life_time = 86400";
+              toInsert = "\n" +

Review comment:
       If a user modified the after line to "session_life_time = ***" then no lines will be added, right?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ambari] payert commented on a change in pull request #3279: AMBARI-25547 Update Grafana version to 6.7.4 to avoid CVE-2020-13379

Posted by GitBox <gi...@apache.org>.
payert commented on a change in pull request #3279:
URL: https://github.com/apache/ambari/pull/3279#discussion_r561919348



##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {
+        for (Cluster cluster : clusterMap.values()) {
+          Set<String> installedServices = cluster.getServices().keySet();
+          if (installedServices.contains("AMBARI_METRICS")) {
+            String contentText = cluster.getDesiredConfigByType("ams-grafana-ini").getProperties().get("content");

Review comment:
       Very unlikely but still possible. Fixed.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ambari] payert commented on a change in pull request #3279: AMBARI-25547 Update Grafana version to 6.7.4 to avoid CVE-2020-13379

Posted by GitBox <gi...@apache.org>.
payert commented on a change in pull request #3279:
URL: https://github.com/apache/ambari/pull/3279#discussion_r561909402



##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -17,16 +17,27 @@
  */
 package org.apache.ambari.server.upgrade;
 
+import static org.apache.ambari.server.utils.CustomStringUtils.deleteSubstring;

Review comment:
       The same configuration come with the previous Grafana version included 2.7.5, but then - as a bug the config file updating was not done. This caused problem if one upgraded from 2.6.x. Now, that is the reason that code part is placed here, because it should have been added here at the previous Grafana upgrade.

##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {

Review comment:
       Done

##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {
+        for (Cluster cluster : clusterMap.values()) {
+          Set<String> installedServices = cluster.getServices().keySet();
+          if (installedServices.contains("AMBARI_METRICS")) {
+            String contentText = cluster.getDesiredConfigByType("ams-grafana-ini").getProperties().get("content");

Review comment:
       Very unlikely but still possible. Fixed.

##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {
+        for (Cluster cluster : clusterMap.values()) {
+          Set<String> installedServices = cluster.getServices().keySet();
+          if (installedServices.contains("AMBARI_METRICS")) {
+            String contentText = cluster.getDesiredConfigByType("ams-grafana-ini").getProperties().get("content");
+            if (contentText != null) {
+              String addAfter;
+              String toInsert;
+              String toFind;
+              String toReplace;
+              StringBuilder content = new StringBuilder(contentText);
+
+              addAfter = "; app_mode = production";
+              toInsert = "\n" +
+                  "\n# instance name, defaults to HOSTNAME environment variable value or hostname if HOSTNAME var is empty" +
+                  "\n; instance_name = ${HOSTNAME}";
+              insertAfterIfNotThere(content, addAfter, toInsert);
+
+              addAfter = "logs = {{ams_grafana_log_dir}}";
+              String pluginsConfLine = "plugins = /var/lib/ambari-metrics-grafana/plugins";
+              toInsert = "\n" +
+                  "\n# Directory where grafana will automatically scan and look for plugins" +
+                  "\n" + pluginsConfLine;
+              insertAfterIfNotThere(content, addAfter, toInsert, pluginsConfLine);
+
+              deleteSubstring(content, ";protocol = http\n");
+              deleteSubstring(content, ";http_port = 3000\n");
+              deleteSubstring(content, ";static_root_path = public\n");
+              deleteSubstring(content, ";cert_file =\n");
+              deleteSubstring(content, ";cert_key =\n");
+
+              addAfter = "cert_key = {{ams_grafana_cert_key}}";
+              toInsert = "\n" +
+                  "\n# Unix socket path" +
+                  "\n;socket =";
+              insertAfterIfNotThere(content, addAfter, toInsert);
+
+              toFind = ";password =";
+              toReplace = "# If the password contains # or ; you have to wrap it with triple quotes. Ex \"\"\"#password;\"\"\"" +
+                  "\n;password =" +
+                  "\n" +
+                  "\n# Use either URL or the previous fields to configure the database" +
+                  "\n# Example: mysql://user:secret@host:port/database" +
+                  "\n;url =";
+              replaceIfNotThere(content, toFind, toReplace);
+
+              addAfter = ";session_life_time = 86400";
+              toInsert = "\n" +

Review comment:
       Right.

##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {
+        for (Cluster cluster : clusterMap.values()) {
+          Set<String> installedServices = cluster.getServices().keySet();
+          if (installedServices.contains("AMBARI_METRICS")) {
+            String contentText = cluster.getDesiredConfigByType("ams-grafana-ini").getProperties().get("content");
+            if (contentText != null) {
+              String addAfter;
+              String toInsert;
+              String toFind;
+              String toReplace;
+              StringBuilder content = new StringBuilder(contentText);
+
+              addAfter = "; app_mode = production";
+              toInsert = "\n" +

Review comment:
       Right.

##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {
+        for (Cluster cluster : clusterMap.values()) {
+          Set<String> installedServices = cluster.getServices().keySet();
+          if (installedServices.contains("AMBARI_METRICS")) {
+            String contentText = cluster.getDesiredConfigByType("ams-grafana-ini").getProperties().get("content");
+            if (contentText != null) {
+              String addAfter;
+              String toInsert;
+              String toFind;
+              String toReplace;
+              StringBuilder content = new StringBuilder(contentText);
+
+              addAfter = "; app_mode = production";
+              toInsert = "\n" +
+                  "\n# instance name, defaults to HOSTNAME environment variable value or hostname if HOSTNAME var is empty" +
+                  "\n; instance_name = ${HOSTNAME}";
+              insertAfterIfNotThere(content, addAfter, toInsert);
+
+              addAfter = "logs = {{ams_grafana_log_dir}}";
+              String pluginsConfLine = "plugins = /var/lib/ambari-metrics-grafana/plugins";

Review comment:
       Right again.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ambari] dvitiiuk commented on a change in pull request #3279: AMBARI-25547 Update Grafana version to 6.7.4 to avoid CVE-2020-13379

Posted by GitBox <gi...@apache.org>.
dvitiiuk commented on a change in pull request #3279:
URL: https://github.com/apache/ambari/pull/3279#discussion_r561884114



##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -17,16 +17,27 @@
  */
 package org.apache.ambari.server.upgrade;
 
+import static org.apache.ambari.server.utils.CustomStringUtils.deleteSubstring;

Review comment:
       Should it be added to UpgradeCatalog276 instead of this?

##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {

Review comment:
       Can we use MapUtils.isNotEmpty() for this?

##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {
+        for (Cluster cluster : clusterMap.values()) {
+          Set<String> installedServices = cluster.getServices().keySet();
+          if (installedServices.contains("AMBARI_METRICS")) {
+            String contentText = cluster.getDesiredConfigByType("ams-grafana-ini").getProperties().get("content");
+            if (contentText != null) {
+              String addAfter;
+              String toInsert;
+              String toFind;
+              String toReplace;
+              StringBuilder content = new StringBuilder(contentText);
+
+              addAfter = "; app_mode = production";
+              toInsert = "\n" +
+                  "\n# instance name, defaults to HOSTNAME environment variable value or hostname if HOSTNAME var is empty" +
+                  "\n; instance_name = ${HOSTNAME}";
+              insertAfterIfNotThere(content, addAfter, toInsert);
+
+              addAfter = "logs = {{ams_grafana_log_dir}}";
+              String pluginsConfLine = "plugins = /var/lib/ambari-metrics-grafana/plugins";
+              toInsert = "\n" +
+                  "\n# Directory where grafana will automatically scan and look for plugins" +
+                  "\n" + pluginsConfLine;
+              insertAfterIfNotThere(content, addAfter, toInsert, pluginsConfLine);
+
+              deleteSubstring(content, ";protocol = http\n");
+              deleteSubstring(content, ";http_port = 3000\n");
+              deleteSubstring(content, ";static_root_path = public\n");
+              deleteSubstring(content, ";cert_file =\n");
+              deleteSubstring(content, ";cert_key =\n");
+
+              addAfter = "cert_key = {{ams_grafana_cert_key}}";
+              toInsert = "\n" +
+                  "\n# Unix socket path" +
+                  "\n;socket =";
+              insertAfterIfNotThere(content, addAfter, toInsert);
+
+              toFind = ";password =";
+              toReplace = "# If the password contains # or ; you have to wrap it with triple quotes. Ex \"\"\"#password;\"\"\"" +
+                  "\n;password =" +
+                  "\n" +
+                  "\n# Use either URL or the previous fields to configure the database" +
+                  "\n# Example: mysql://user:secret@host:port/database" +
+                  "\n;url =";
+              replaceIfNotThere(content, toFind, toReplace);
+
+              addAfter = ";session_life_time = 86400";
+              toInsert = "\n" +

Review comment:
       The same

##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {
+        for (Cluster cluster : clusterMap.values()) {
+          Set<String> installedServices = cluster.getServices().keySet();
+          if (installedServices.contains("AMBARI_METRICS")) {
+            String contentText = cluster.getDesiredConfigByType("ams-grafana-ini").getProperties().get("content");
+            if (contentText != null) {
+              String addAfter;
+              String toInsert;
+              String toFind;
+              String toReplace;
+              StringBuilder content = new StringBuilder(contentText);
+
+              addAfter = "; app_mode = production";
+              toInsert = "\n" +

Review comment:
       If a user modified the after line to "app_mode = ***" then no lines will be added, right?

##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {
+        for (Cluster cluster : clusterMap.values()) {
+          Set<String> installedServices = cluster.getServices().keySet();
+          if (installedServices.contains("AMBARI_METRICS")) {
+            String contentText = cluster.getDesiredConfigByType("ams-grafana-ini").getProperties().get("content");

Review comment:
       Possible NPE if getDesiredConfigByType returns null.

##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {
+        for (Cluster cluster : clusterMap.values()) {
+          Set<String> installedServices = cluster.getServices().keySet();
+          if (installedServices.contains("AMBARI_METRICS")) {
+            String contentText = cluster.getDesiredConfigByType("ams-grafana-ini").getProperties().get("content");
+            if (contentText != null) {
+              String addAfter;
+              String toInsert;
+              String toFind;
+              String toReplace;
+              StringBuilder content = new StringBuilder(contentText);
+
+              addAfter = "; app_mode = production";
+              toInsert = "\n" +
+                  "\n# instance name, defaults to HOSTNAME environment variable value or hostname if HOSTNAME var is empty" +
+                  "\n; instance_name = ${HOSTNAME}";
+              insertAfterIfNotThere(content, addAfter, toInsert);
+
+              addAfter = "logs = {{ams_grafana_log_dir}}";
+              String pluginsConfLine = "plugins = /var/lib/ambari-metrics-grafana/plugins";

Review comment:
       The same.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ambari] payert commented on a change in pull request #3279: AMBARI-25547 Update Grafana version to 6.7.4 to avoid CVE-2020-13379

Posted by GitBox <gi...@apache.org>.
payert commented on a change in pull request #3279:
URL: https://github.com/apache/ambari/pull/3279#discussion_r561919866



##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {
+        for (Cluster cluster : clusterMap.values()) {
+          Set<String> installedServices = cluster.getServices().keySet();
+          if (installedServices.contains("AMBARI_METRICS")) {
+            String contentText = cluster.getDesiredConfigByType("ams-grafana-ini").getProperties().get("content");
+            if (contentText != null) {
+              String addAfter;
+              String toInsert;
+              String toFind;
+              String toReplace;
+              StringBuilder content = new StringBuilder(contentText);
+
+              addAfter = "; app_mode = production";
+              toInsert = "\n" +
+                  "\n# instance name, defaults to HOSTNAME environment variable value or hostname if HOSTNAME var is empty" +
+                  "\n; instance_name = ${HOSTNAME}";
+              insertAfterIfNotThere(content, addAfter, toInsert);
+
+              addAfter = "logs = {{ams_grafana_log_dir}}";
+              String pluginsConfLine = "plugins = /var/lib/ambari-metrics-grafana/plugins";
+              toInsert = "\n" +
+                  "\n# Directory where grafana will automatically scan and look for plugins" +
+                  "\n" + pluginsConfLine;
+              insertAfterIfNotThere(content, addAfter, toInsert, pluginsConfLine);
+
+              deleteSubstring(content, ";protocol = http\n");
+              deleteSubstring(content, ";http_port = 3000\n");
+              deleteSubstring(content, ";static_root_path = public\n");
+              deleteSubstring(content, ";cert_file =\n");
+              deleteSubstring(content, ";cert_key =\n");
+
+              addAfter = "cert_key = {{ams_grafana_cert_key}}";
+              toInsert = "\n" +
+                  "\n# Unix socket path" +
+                  "\n;socket =";
+              insertAfterIfNotThere(content, addAfter, toInsert);
+
+              toFind = ";password =";
+              toReplace = "# If the password contains # or ; you have to wrap it with triple quotes. Ex \"\"\"#password;\"\"\"" +
+                  "\n;password =" +
+                  "\n" +
+                  "\n# Use either URL or the previous fields to configure the database" +
+                  "\n# Example: mysql://user:secret@host:port/database" +
+                  "\n;url =";
+              replaceIfNotThere(content, toFind, toReplace);
+
+              addAfter = ";session_life_time = 86400";
+              toInsert = "\n" +

Review comment:
       Right.

##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -122,4 +134,169 @@ protected void removeDfsHAInitial() {
       blueprintDAO.merge(blueprintEntity);
     }
   }
+
+  protected void updateAmsGrafanaIniConfig() throws AmbariException {
+    AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class);
+    Clusters clusters = ambariManagementController.getClusters();
+    if (clusters != null) {
+      Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters);
+      if (clusterMap != null && !clusterMap.isEmpty()) {
+        for (Cluster cluster : clusterMap.values()) {
+          Set<String> installedServices = cluster.getServices().keySet();
+          if (installedServices.contains("AMBARI_METRICS")) {
+            String contentText = cluster.getDesiredConfigByType("ams-grafana-ini").getProperties().get("content");
+            if (contentText != null) {
+              String addAfter;
+              String toInsert;
+              String toFind;
+              String toReplace;
+              StringBuilder content = new StringBuilder(contentText);
+
+              addAfter = "; app_mode = production";
+              toInsert = "\n" +

Review comment:
       Right.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ambari] payert merged pull request #3279: AMBARI-25547 Update Grafana version to 6.7.4 to avoid CVE-2020-13379

Posted by GitBox <gi...@apache.org>.
payert merged pull request #3279:
URL: https://github.com/apache/ambari/pull/3279


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ambari] payert commented on a change in pull request #3279: AMBARI-25547 Update Grafana version to 6.7.4 to avoid CVE-2020-13379

Posted by GitBox <gi...@apache.org>.
payert commented on a change in pull request #3279:
URL: https://github.com/apache/ambari/pull/3279#discussion_r561909402



##########
File path: ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog275.java
##########
@@ -17,16 +17,27 @@
  */
 package org.apache.ambari.server.upgrade;
 
+import static org.apache.ambari.server.utils.CustomStringUtils.deleteSubstring;

Review comment:
       The same configuration come with the previous Grafana version included 2.7.5, but then - as a bug the config file updating was not done. This caused problem if one upgraded from 2.6.x. Now, that is the reason that code part is placed here, because it should have been added here at the previous Grafana upgrade.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org