Skip to content

Commit

Permalink
sanitize namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
fcomte committed Dec 18, 2024
1 parent a95b1f1 commit 19dfb15
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ public HelmInstaller installChart(
}
command.append(chart + " ");
command.append("-n ");
if (namespace.length() > 63 || !rfc1123Pattern.matcher(namespace).matches()) {
throw new IllegalArgumentException(
"Invalid namespace "
+ namespace
+ ". Must be 63 or fewer characters and be a valid RFC 1123 string.");
}
safeConcat(command, namespace);
if (StringUtils.isNotBlank(version)) {
if (!semverPattern.matcher(version).matches()) {
Expand Down Expand Up @@ -211,6 +217,12 @@ public int uninstaller(HelmConfiguration configuration, String name, String name
+ name
+ ". Must be 53 or fewer characters and be a valid RFC 1123 string.");
}
if (namespace.length() > 63 || !rfc1123Pattern.matcher(namespace).matches()) {
throw new IllegalArgumentException(
"Invalid namespace "
+ namespace
+ ". Must be 63 or fewer characters and be a valid RFC 1123 string.");
}
StringBuilder command = new StringBuilder("helm uninstall ");
safeConcat(command, name);
command.append(" -n ");
Expand All @@ -221,6 +233,12 @@ public int uninstaller(HelmConfiguration configuration, String name, String name
public HelmLs[] listChartInstall(HelmConfiguration configuration, String namespace)
throws InvalidExitValueException, IOException, InterruptedException, TimeoutException {
StringBuilder command = new StringBuilder("helm ls -a");
if (namespace.length() > 63 || !rfc1123Pattern.matcher(namespace).matches()) {
throw new IllegalArgumentException(
"Invalid namespace "
+ namespace
+ ". Must be 63 or fewer characters and be a valid RFC 1123 string.");
}
if (namespace != null) {
command.append(" -n ");
safeConcat(command, namespace);
Expand Down Expand Up @@ -253,6 +271,12 @@ public HelmReleaseInfo getAll(HelmConfiguration configuration, String id, String
+ id
+ ". Must be 53 or fewer characters and be a valid RFC 1123 string.");
}
if (namespace.length() > 63 || !rfc1123Pattern.matcher(namespace).matches()) {
throw new IllegalArgumentException(
"Invalid namespace "
+ namespace
+ ". Must be 63 or fewer characters and be a valid RFC 1123 string.");
}
safeConcat(command, id);
command.append(" --namespace ");
safeConcat(command, namespace);
Expand All @@ -278,6 +302,12 @@ private String getReleaseInfo(
+ id
+ ". Must be 53 or fewer characters and be a valid RFC 1123 string.");
}
if (namespace.length() > 63 || !rfc1123Pattern.matcher(namespace).matches()) {
throw new IllegalArgumentException(
"Invalid namespace "
+ namespace
+ ". Must be 63 or fewer characters and be a valid RFC 1123 string.");
}
StringBuilder command = new StringBuilder("helm get " + infoType + " ");
try {
safeConcat(command, id);
Expand Down Expand Up @@ -324,6 +354,12 @@ public HelmLs getAppById(HelmConfiguration configuration, String appId, String n
+ appId
+ ". Must be 53 or fewer characters and be a valid RFC 1123 string.");
}
if (namespace.length() > 63 || !rfc1123Pattern.matcher(namespace).matches()) {
throw new IllegalArgumentException(
"Invalid namespace "
+ namespace
+ ". Must be 63 or fewer characters and be a valid RFC 1123 string.");
}
StringBuilder command = new StringBuilder("helm list --filter ");
safeConcat(command, appId);
command.append(" -n ");
Expand Down

0 comments on commit 19dfb15

Please sign in to comment.