Skip to content

Commit 48054af

Browse files
committed
Relax external signer path validation to allow relative paths
1 parent 3a8af5a commit 48054af

File tree

2 files changed

+10
-32
lines changed

2 files changed

+10
-32
lines changed

pkg/controlplane/apiserver/options/validation.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func validateUnknownVersionInteroperabilityProxyFlags(options *Options) []error
9494
return err
9595
}
9696

97-
var pathOrSocket = regexp.MustCompile(`(^(/[^/ ]*)+/?$)|(^@([a-zA-Z0-9_-]+\.)*[a-zA-Z0-9_-]+$)`)
97+
var abstractSocketRegex = regexp.MustCompile(`^@([a-zA-Z0-9_-]+\.)*[a-zA-Z0-9_-]+$`)
9898

9999
func validateServiceAccountTokenSigningConfig(options *Options) []error {
100100
if len(options.ServiceAccountSigningEndpoint) == 0 {
@@ -109,9 +109,9 @@ func validateServiceAccountTokenSigningConfig(options *Options) []error {
109109
if !utilfeature.DefaultFeatureGate.Enabled(features.ExternalServiceAccountTokenSigner) {
110110
errors = append(errors, fmt.Errorf("setting `--service-account-signing-endpoint` requires enabling ExternalServiceAccountTokenSigner feature gate"))
111111
}
112-
// Check if ServiceAccountSigningEndpoint is a linux file path or an abstract socket name.
113-
if !pathOrSocket.MatchString(options.ServiceAccountSigningEndpoint) {
114-
errors = append(errors, fmt.Errorf("invalid value %q passed for `--service-account-signing-endpoint`, should be a valid location on the filesystem or must be prefixed with @ to name UDS in abstract namespace", options.ServiceAccountSigningEndpoint))
112+
// Ensure ServiceAccountSigningEndpoint is a valid abstract socket name if prefixed with '@'.
113+
if strings.HasPrefix(options.ServiceAccountSigningEndpoint, "@") && !abstractSocketRegex.MatchString(options.ServiceAccountSigningEndpoint) {
114+
errors = append(errors, fmt.Errorf("invalid value %q passed for `--service-account-signing-endpoint`, when prefixed with @ must be a valid abstract socket name", options.ServiceAccountSigningEndpoint))
115115
}
116116

117117
return errors

pkg/controlplane/apiserver/options/validation_test.go

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,9 @@ func TestValidateServcieAccountTokenSigningConfig(t *testing.T) {
303303
},
304304
},
305305
{
306-
name: "invalid external signer endpoint provided - 1",
306+
name: "relative external signer endpoint provided",
307307
featureEnabled: true,
308-
expectedErrors: []error{
309-
fmt.Errorf("invalid value \"abc\" passed for `--service-account-signing-endpoint`, should be a valid location on the filesystem or must be prefixed with @ to name UDS in abstract namespace"),
310-
},
308+
expectedErrors: []error{},
311309
options: &Options{
312310
ServiceAccountSigningEndpoint: "abc",
313311
},
@@ -316,7 +314,7 @@ func TestValidateServcieAccountTokenSigningConfig(t *testing.T) {
316314
name: "invalid external signer endpoint provided - 2",
317315
featureEnabled: true,
318316
expectedErrors: []error{
319-
fmt.Errorf("invalid value \"@abc@\" passed for `--service-account-signing-endpoint`, should be a valid location on the filesystem or must be prefixed with @ to name UDS in abstract namespace"),
317+
fmt.Errorf("invalid value \"@abc@\" passed for `--service-account-signing-endpoint`, when prefixed with @ must be a valid abstract socket name"),
320318
},
321319
options: &Options{
322320
ServiceAccountSigningEndpoint: "@abc@",
@@ -326,32 +324,12 @@ func TestValidateServcieAccountTokenSigningConfig(t *testing.T) {
326324
name: "invalid external signer endpoint provided - 3",
327325
featureEnabled: true,
328326
expectedErrors: []error{
329-
fmt.Errorf("invalid value \"@abc.abc .ae\" passed for `--service-account-signing-endpoint`, should be a valid location on the filesystem or must be prefixed with @ to name UDS in abstract namespace"),
327+
fmt.Errorf("invalid value \"@abc.abc .ae\" passed for `--service-account-signing-endpoint`, when prefixed with @ must be a valid abstract socket name"),
330328
},
331329
options: &Options{
332330
ServiceAccountSigningEndpoint: "@abc.abc .ae",
333331
},
334332
},
335-
{
336-
name: "invalid external signer endpoint provided - 4",
337-
featureEnabled: true,
338-
expectedErrors: []error{
339-
fmt.Errorf("invalid value \"/@e_adnb/xyz /efg\" passed for `--service-account-signing-endpoint`, should be a valid location on the filesystem or must be prefixed with @ to name UDS in abstract namespace"),
340-
},
341-
options: &Options{
342-
ServiceAccountSigningEndpoint: "/@e_adnb/xyz /efg",
343-
},
344-
},
345-
{
346-
name: "invalid external signer endpoint provided - 5",
347-
featureEnabled: true,
348-
expectedErrors: []error{
349-
fmt.Errorf("invalid value \"/e /xyz /efg\" passed for `--service-account-signing-endpoint`, should be a valid location on the filesystem or must be prefixed with @ to name UDS in abstract namespace"),
350-
},
351-
options: &Options{
352-
ServiceAccountSigningEndpoint: "/e /xyz /efg",
353-
},
354-
},
355333
{
356334
name: "valid external signer endpoint provided - 1",
357335
featureEnabled: true,
@@ -382,10 +360,10 @@ func TestValidateServcieAccountTokenSigningConfig(t *testing.T) {
382360
expectedErrors: []error{
383361
fmt.Errorf("can't set `--service-account-signing-key-file` and/or `--service-account-key-file` with `--service-account-signing-endpoint` (They are mutually exclusive)"),
384362
fmt.Errorf("setting `--service-account-signing-endpoint` requires enabling ExternalServiceAccountTokenSigner feature gate"),
385-
fmt.Errorf("invalid value \"/e /xyz /efg\" passed for `--service-account-signing-endpoint`, should be a valid location on the filesystem or must be prefixed with @ to name UDS in abstract namespace"),
363+
fmt.Errorf("invalid value \"@a@\" passed for `--service-account-signing-endpoint`, when prefixed with @ must be a valid abstract socket name"),
386364
},
387365
options: &Options{
388-
ServiceAccountSigningEndpoint: "/e /xyz /efg",
366+
ServiceAccountSigningEndpoint: "@a@",
389367
ServiceAccountSigningKeyFile: "/abc/efg",
390368
Authentication: &kubeoptions.BuiltInAuthenticationOptions{
391369
ServiceAccounts: &kubeoptions.ServiceAccountAuthenticationOptions{

0 commit comments

Comments
 (0)