Skip to content

Commit f94a3a5

Browse files
committed
return error when long-form sa name is used
Returns an error when the long-form name of a ServiceAccount is used with the --serviceaccount (-z) flag in `oc policy ...' commands.
1 parent e92d5c5 commit f94a3a5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pkg/oc/admin/policy/modify_roles.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"io"
7+
"strings"
78

89
"github.com/spf13/cobra"
910

@@ -320,6 +321,13 @@ func (o *RoleModificationOptions) CompleteUserWithSA(f *clientcmd.Factory, cmd *
320321
return errors.New("you must specify at least one user or service account")
321322
}
322323

324+
// return an error if a fully-qualified service-account name is used
325+
for _, sa := range saNames {
326+
if strings.HasPrefix(sa, "system:serviceaccount") {
327+
return errors.New("--serviceaccount (-z) should only be used with short-form serviceaccount names (e.g. \"default\")")
328+
}
329+
}
330+
323331
authorizationClient, err := f.OpenshiftInternalAuthorizationClient()
324332
if err != nil {
325333
return err

0 commit comments

Comments
 (0)