@@ -214,14 +214,37 @@ func (s routeStrategy) validateHostUpdate(ctx apirequest.Context, route, older *
214
214
if hostChanged {
215
215
return kvalidation .ValidateImmutableField (route .Spec .Host , older .Spec .Host , field .NewPath ("spec" , "host" ))
216
216
}
217
- if route .Spec .TLS == nil || older .Spec .TLS == nil {
218
- return kvalidation .ValidateImmutableField (route .Spec .TLS , older .Spec .TLS , field .NewPath ("spec" , "tls" ))
217
+
218
+ // if tls is being updated without host being updated, we check if 'create' permission exists on custom-host subresource
219
+ res , err := s .sarClient .Create (
220
+ authorizationutil .AddUserToSAR (
221
+ user ,
222
+ & authorizationapi.SubjectAccessReview {
223
+ Spec : authorizationapi.SubjectAccessReviewSpec {
224
+ ResourceAttributes : & authorizationapi.ResourceAttributes {
225
+ Namespace : apirequest .NamespaceValue (ctx ),
226
+ Verb : "create" ,
227
+ Group : routeapi .GroupName ,
228
+ Resource : "routes" ,
229
+ Subresource : "custom-host" ,
230
+ },
231
+ },
232
+ },
233
+ ),
234
+ )
235
+ if err != nil {
236
+ return field.ErrorList {field .InternalError (field .NewPath ("spec" , "host" ), err )}
237
+ }
238
+ if ! res .Status .Allowed {
239
+ if route .Spec .TLS == nil || older .Spec .TLS == nil {
240
+ return kvalidation .ValidateImmutableField (route .Spec .TLS , older .Spec .TLS , field .NewPath ("spec" , "tls" ))
241
+ }
242
+ errs := kvalidation .ValidateImmutableField (route .Spec .TLS .CACertificate , older .Spec .TLS .CACertificate , field .NewPath ("spec" , "tls" , "caCertificate" ))
243
+ errs = append (errs , kvalidation .ValidateImmutableField (route .Spec .TLS .Certificate , older .Spec .TLS .Certificate , field .NewPath ("spec" , "tls" , "certificate" ))... )
244
+ errs = append (errs , kvalidation .ValidateImmutableField (route .Spec .TLS .DestinationCACertificate , older .Spec .TLS .DestinationCACertificate , field .NewPath ("spec" , "tls" , "destinationCACertificate" ))... )
245
+ errs = append (errs , kvalidation .ValidateImmutableField (route .Spec .TLS .Key , older .Spec .TLS .Key , field .NewPath ("spec" , "tls" , "key" ))... )
246
+ return errs
219
247
}
220
- errs := kvalidation .ValidateImmutableField (route .Spec .TLS .CACertificate , older .Spec .TLS .CACertificate , field .NewPath ("spec" , "tls" , "caCertificate" ))
221
- errs = append (errs , kvalidation .ValidateImmutableField (route .Spec .TLS .Certificate , older .Spec .TLS .Certificate , field .NewPath ("spec" , "tls" , "certificate" ))... )
222
- errs = append (errs , kvalidation .ValidateImmutableField (route .Spec .TLS .DestinationCACertificate , older .Spec .TLS .DestinationCACertificate , field .NewPath ("spec" , "tls" , "destinationCACertificate" ))... )
223
- errs = append (errs , kvalidation .ValidateImmutableField (route .Spec .TLS .Key , older .Spec .TLS .Key , field .NewPath ("spec" , "tls" , "key" ))... )
224
- return errs
225
248
}
226
249
return nil
227
250
}
0 commit comments