From b57f8c381e0bfb5f08f9c33d13ab103a11bbf74c Mon Sep 17 00:00:00 2001 From: Duologic Date: Tue, 24 Dec 2024 00:11:53 +0100 Subject: [PATCH] fix(grafanaplane): validate Stack slug --- grafanaplane/main.libsonnet | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/grafanaplane/main.libsonnet b/grafanaplane/main.libsonnet index 3d8243c..21d1b62 100644 --- a/grafanaplane/main.libsonnet +++ b/grafanaplane/main.libsonnet @@ -77,9 +77,22 @@ local raw = import './raw.libsonnet'; cloud: { local this = self, + local validStackSlug(slug) = + xtd.ascii.isLower(slug[0]) + && std.all( + std.map( + function(c) + xtd.ascii.isNumber(c) + || xtd.ascii.isLower(c), + std.stringChars(slug) + ) + ), + stack: { new(name, namespace, cloudProviderConfigName, secretName=name + '-providerConfigToken'): { stack: + assert validStackSlug(name) : + 'The slug/name needs to be a valid subdomain. One word. Only lowercase letters and numbers allowed. Must start with a letter. No dots, dashes, underscores, or spaces.'; raw.cloud.v1alpha1.stack.new(name) + raw.cloud.v1alpha1.stack.spec.parameters.providerConfigRef.withName(cloudProviderConfigName) + raw.cloud.v1alpha1.stack.spec.parameters.withExternalName(name)