Skip to content

Commit 3769b43

Browse files
authored
fix(ske): prevent usage of UUID for dns extension (#1025)
Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>
1 parent 55a9a43 commit 3769b43

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

stackit/internal/services/ske/cluster/resource.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
serviceenablementUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/serviceenablement/utils"
1313
skeUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/ske/utils"
1414

15+
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
1516
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
1617
"github.com/hashicorp/terraform-plugin-framework/attr"
1718
"github.com/hashicorp/terraform-plugin-framework/diag"
@@ -660,6 +661,9 @@ func (r *clusterResource) Schema(_ context.Context, _ resource.SchemaRequest, re
660661
PlanModifiers: []planmodifier.List{
661662
listplanmodifier.UseStateForUnknown(),
662663
},
664+
Validators: []validator.List{
665+
listvalidator.ValueStringsAre(validate.NoUUID()),
666+
},
663667
},
664668
},
665669
},

stackit/internal/validate/validate.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,23 @@ func UUID() *Validator {
6767
}
6868
}
6969

70+
func NoUUID() *Validator {
71+
description := "value must not be an UUID"
72+
73+
return &Validator{
74+
description: description,
75+
validate: func(_ context.Context, req validator.StringRequest, resp *validator.StringResponse) {
76+
if _, err := uuid.Parse(req.ConfigValue.ValueString()); err == nil {
77+
resp.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic(
78+
req.Path,
79+
description,
80+
req.ConfigValue.ValueString(),
81+
))
82+
}
83+
},
84+
}
85+
}
86+
7087
// IP returns a validator that checks, if the given string is a valid IP address.
7188
// The allowZeroAddress parameter defines, if 0.0.0.0, resp. [::] should be considered valid.
7289
func IP(allowZeroAddress bool) *Validator {

stackit/internal/validate/validate_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,50 @@ func TestUUID(t *testing.T) {
5555
}
5656
}
5757

58+
func TestNoUUID(t *testing.T) {
59+
tests := []struct {
60+
description string
61+
input string
62+
isValid bool
63+
}{
64+
{
65+
"UUID",
66+
"cae27bba-c43d-498a-861e-d11d241c4ff8",
67+
false,
68+
},
69+
{
70+
"no UUID",
71+
"a-b-c-d",
72+
true,
73+
},
74+
{
75+
"Empty",
76+
"",
77+
true,
78+
},
79+
{
80+
"domain name",
81+
"www.test.de",
82+
true,
83+
},
84+
}
85+
for _, tt := range tests {
86+
t.Run(tt.description, func(t *testing.T) {
87+
r := validator.StringResponse{}
88+
NoUUID().ValidateString(context.Background(), validator.StringRequest{
89+
ConfigValue: types.StringValue(tt.input),
90+
}, &r)
91+
92+
if !tt.isValid && !r.Diagnostics.HasError() {
93+
t.Fatalf("Should have failed")
94+
}
95+
if tt.isValid && r.Diagnostics.HasError() {
96+
t.Fatalf("Should not have failed: %v", r.Diagnostics.Errors())
97+
}
98+
})
99+
}
100+
}
101+
58102
func TestIP(t *testing.T) {
59103
tests := []struct {
60104
description string

0 commit comments

Comments
 (0)