mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
SA: Fix name validation so we can prevent creating service account with protected prefix (#94762)
Fix name validation so we can prevent creating service account with protected prefix
This commit is contained in:
parent
bfbbdf5efb
commit
7fba9ba522
@ -183,5 +183,5 @@ func (s *ServiceAccountsProxy) SearchOrgServiceAccounts(ctx context.Context, que
|
||||
}
|
||||
|
||||
func isNameValid(name string) bool {
|
||||
return !strings.HasPrefix(name, serviceaccounts.ExtSvcPrefix)
|
||||
return !strings.HasPrefix(name, strings.TrimSuffix(serviceaccounts.ExtSvcPrefix, "-"))
|
||||
}
|
||||
|
@ -43,12 +43,19 @@ func TestProvideServiceAccount_crudServiceAccount(t *testing.T) {
|
||||
expectedError: nil,
|
||||
},
|
||||
{
|
||||
description: "should not allow to create a service account with extsvc prefix",
|
||||
description: "should not allow to create a service account with extsvc- prefix",
|
||||
form: sa.CreateServiceAccountForm{
|
||||
Name: "extsvc-my-service-account",
|
||||
},
|
||||
expectedError: extsvcaccounts.ErrInvalidName,
|
||||
},
|
||||
{
|
||||
description: "should not allow to create a service account with extsvc prefix",
|
||||
form: sa.CreateServiceAccountForm{
|
||||
Name: "extsvc my-service-account",
|
||||
},
|
||||
expectedError: extsvcaccounts.ErrInvalidName,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
Loading…
Reference in New Issue
Block a user