Skip to content

Commit fc942c1

Browse files
committed
[PLAT-16001]: Gflag checks for YSQL major version upgrade.
Summary: hostssl entry clientcert=1 is not supported in PG-15, which if supplied results in tserver crashloop. Hence, added a check in YBA: if the user has set the clientcert=1 as an hostssl entry in YSQL_HBA_CONF_CSV flags, an error will be thrown if a YSQL major upgrade is attempted. Test Plan: Tested manually and UTs Reviewers: sanketh Reviewed By: sanketh Subscribers: yugaware Differential Revision: https://phorge.dev.yugabyte.com/D42264
1 parent 240cfa8 commit fc942c1

File tree

2 files changed

+92
-9
lines changed

2 files changed

+92
-9
lines changed

managed/src/main/java/com/yugabyte/yw/forms/SoftwareUpgradeParams.java

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,30 @@
1010
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
1111
import com.google.common.collect.ImmutableSet;
1212
import com.yugabyte.yw.commissioner.Common.CloudType;
13+
import com.yugabyte.yw.commissioner.tasks.UniverseTaskBase.ServerType;
1314
import com.yugabyte.yw.common.PlatformServiceException;
1415
import com.yugabyte.yw.common.Util;
1516
import com.yugabyte.yw.common.config.GlobalConfKeys;
1617
import com.yugabyte.yw.common.config.RuntimeConfigFactory;
18+
import com.yugabyte.yw.common.gflags.GFlagsUtil;
1719
import com.yugabyte.yw.common.gflags.GFlagsValidation;
1820
import com.yugabyte.yw.common.inject.StaticInjectorHolder;
1921
import com.yugabyte.yw.models.Universe;
2022
import com.yugabyte.yw.models.common.YbaApi;
2123
import com.yugabyte.yw.models.common.YbaApi.YbaApiVisibility;
24+
import com.yugabyte.yw.models.helpers.NodeDetails;
2225
import io.swagger.annotations.ApiModelProperty;
26+
import java.util.Map;
2327
import java.util.Set;
28+
import java.util.regex.Matcher;
29+
import java.util.regex.Pattern;
30+
import lombok.extern.slf4j.Slf4j;
31+
import org.apache.commons.lang3.StringUtils;
2432
import play.mvc.Http.Status;
2533

2634
@JsonIgnoreProperties(ignoreUnknown = true)
2735
@JsonDeserialize(converter = SoftwareUpgradeParams.Converter.class)
36+
@Slf4j
2837
public class SoftwareUpgradeParams extends UpgradeTaskParams {
2938

3039
public String ybSoftwareVersion = null;
@@ -141,15 +150,55 @@ public void verifyParams(Universe universe, boolean isFirstTry) {
141150
boolean isYsqlMajorVersionUpgrade =
142151
gFlagsValidation.ysqlMajorVersionUpgrade(currentVersion, ybSoftwareVersion);
143152

144-
if (isYsqlMajorVersionUpgrade
145-
&& currentIntent.enableYSQL
146-
&& Util.compareYBVersions(
147-
currentVersion, "2024.2.1.0-b1", "2.25.0.0-b1", true /* suppressFormatError */)
148-
< 0) {
149-
throw new PlatformServiceException(
150-
Status.BAD_REQUEST,
151-
"YSQL major version upgrade is only supported from 2024.2.1.0-b1. Please upgrade to a"
152-
+ " version >= 2024.2.1.0-b1 before proceeding with the upgrade.");
153+
if (isYsqlMajorVersionUpgrade && currentIntent.enableYSQL) {
154+
if (Util.compareYBVersions(
155+
currentVersion, "2024.2.1.0-b1", "2.25.0.0-b1", true /* suppressFormatError */)
156+
< 0) {
157+
throw new PlatformServiceException(
158+
Status.BAD_REQUEST,
159+
"YSQL major version upgrade is only supported from 2024.2.1.0-b1. Please upgrade to a"
160+
+ " version >= 2024.2.1.0-b1 before proceeding with the upgrade.");
161+
}
162+
163+
for (Cluster cluster : universe.getUniverseDetails().clusters) {
164+
for (NodeDetails node : universe.getNodesInCluster(cluster.uuid)) {
165+
if (node.isMaster) {
166+
validateYSQLHBAConfEntriesForYSQLMajorUpgrade(
167+
universe, cluster, node, ServerType.MASTER);
168+
}
169+
if (node.isTserver) {
170+
validateYSQLHBAConfEntriesForYSQLMajorUpgrade(
171+
universe, cluster, node, ServerType.TSERVER);
172+
}
173+
}
174+
}
175+
}
176+
}
177+
178+
private void validateYSQLHBAConfEntriesForYSQLMajorUpgrade(
179+
Universe universe, Cluster cluster, NodeDetails node, ServerType serverType) {
180+
Map<String, String> gflag =
181+
GFlagsUtil.getGFlagsForNode(
182+
node, serverType, cluster, universe.getUniverseDetails().clusters);
183+
if (gflag.containsKey(GFlagsUtil.YSQL_HBA_CONF_CSV)) {
184+
String hbaConfValue = gflag.get(GFlagsUtil.YSQL_HBA_CONF_CSV);
185+
if (StringUtils.isEmpty(hbaConfValue)) {
186+
return;
187+
}
188+
String regex = "clientcert\\s*=\\s*(\\d+)";
189+
Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
190+
Matcher matcher = pattern.matcher(hbaConfValue);
191+
if (matcher.find()) {
192+
String value = matcher.group(1);
193+
if (value.equals("1")) {
194+
throw new PlatformServiceException(
195+
Status.BAD_REQUEST,
196+
"YSQL major version upgrade is not supported when clientcert=1 is present in the"
197+
+ " ysql_hba_conf_csv. Please update the clientcert=1 entry with equivalent PG-15"
198+
+ " value with before proceeding with the upgrade. Update the value to"
199+
+ " clientcert=verify-ca or clientcert=verify-full before proceeding.");
200+
}
201+
}
153202
}
154203
}
155204

managed/src/test/java/com/yugabyte/yw/controllers/UpgradeUniverseControllerTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import com.yugabyte.yw.common.config.RuntimeConfGetter;
6262
import com.yugabyte.yw.common.config.RuntimeConfigFactory;
6363
import com.yugabyte.yw.common.gflags.AutoFlagUtil;
64+
import com.yugabyte.yw.common.gflags.GFlagsUtil;
6465
import com.yugabyte.yw.common.gflags.GFlagsValidation;
6566
import com.yugabyte.yw.common.gflags.SpecificGFlags;
6667
import com.yugabyte.yw.forms.CertificateParams;
@@ -735,6 +736,39 @@ public void testSoftwareUpgradeWithState(SoftwareUpgradeState state) {
735736
}
736737
}
737738

739+
@Test
740+
public void testYSQLMajorUpgradeWithInValidClientCert() {
741+
SpecificGFlags gFlags =
742+
SpecificGFlags.construct(
743+
Map.of(GFlagsUtil.YSQL_HBA_CONF_CSV, "hostssl all all all trust clientcert=1"),
744+
Map.of(GFlagsUtil.YSQL_HBA_CONF_CSV, "hostssl all all all trust clientcert=1"));
745+
defaultUniverse =
746+
Universe.saveDetails(
747+
defaultUniverse.getUniverseUUID(),
748+
universe -> {
749+
universe.getUniverseDetails().getPrimaryCluster().userIntent.specificGFlags = gFlags;
750+
universe.getUniverseDetails().getPrimaryCluster().userIntent.ybSoftwareVersion =
751+
"2024.2.2.0-b35";
752+
});
753+
String url =
754+
"/api/customers/"
755+
+ customer.getUuid()
756+
+ "/universes/"
757+
+ defaultUniverse.getUniverseUUID()
758+
+ "/upgrade/db_version";
759+
ObjectNode bodyJson = Json.newObject().put("ybSoftwareVersion", "2025.1.0.0-b1");
760+
when(mockGFlagsValidation.ysqlMajorVersionUpgrade(any(), any())).thenReturn(true);
761+
Result result =
762+
assertPlatformException(
763+
() -> doRequestWithAuthTokenAndBody("POST", url, authToken, bodyJson));
764+
assertBadRequest(
765+
result,
766+
"YSQL major version upgrade is not supported when clientcert=1 is present in the"
767+
+ " ysql_hba_conf_csv. Please update the clientcert=1 entry with equivalent PG-15 value"
768+
+ " with before proceeding with the upgrade. Update the value to clientcert=verify-ca"
769+
+ " or clientcert=verify-full before proceeding.");
770+
}
771+
738772
// RollBack Upgrade
739773

740774
@Test

0 commit comments

Comments
 (0)