Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize helm names and namespace #542

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -205,6 +211,18 @@ public HelmInstaller installChart(

public int uninstaller(HelmConfiguration configuration, String name, String namespace)
throws InvalidExitValueException, IOException, InterruptedException, TimeoutException {
if (name.length() > 53 || !rfc1123Pattern.matcher(name).matches()) {
throw new IllegalArgumentException(
"Invalid release "
+ 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 @@ -215,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 All @@ -241,6 +265,18 @@ public String getNotes(HelmConfiguration configuration, String id, String namesp

public HelmReleaseInfo getAll(HelmConfiguration configuration, String id, String namespace) {
StringBuilder command = new StringBuilder("helm get all ");
if (id.length() > 53 || !rfc1123Pattern.matcher(id).matches()) {
throw new IllegalArgumentException(
"Invalid release "
+ 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 @@ -260,6 +296,18 @@ private String getReleaseInfo(
throw new IllegalArgumentException(
"Invalid info type " + infoType + ", should be manifest, notes or values");
}
if (id.length() > 53 || !rfc1123Pattern.matcher(id).matches()) {
throw new IllegalArgumentException(
"Invalid release "
+ 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 @@ -306,7 +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
Loading