Skip to content

Commit 74019ec

Browse files
committed
to fix bugzilla 1424946
1 parent 69a0cc6 commit 74019ec

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

pkg/cmd/admin/policy/subject_review.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var (
3131
`)
3232
subjectReviewExamples = templates.Examples(`# Check whether user bob can create a pod specified in myresource.yaml
3333
$ %[1]s -u bob -f myresource.yaml
34-
34+
3535
# Check whether user bob who belongs to projectAdmin group can create a pod specified in myresource.yaml
3636
$ %[1]s -u bob -g projectAdmin -f myresource.yaml
3737
@@ -85,12 +85,17 @@ func (o *sccSubjectReviewOptions) Complete(f *clientcmd.Factory, args []string,
8585
if len(o.User) > 0 && len(o.serviceAccount) > 0 {
8686
return fmt.Errorf("--user and --serviceaccount are mutually exclusive")
8787
}
88-
if strings.HasPrefix(o.serviceAccount, serviceaccount.ServiceAccountUsernamePrefix) {
89-
_, user, err := serviceaccount.SplitUsername(o.serviceAccount)
90-
if err != nil {
91-
return err
88+
if len(o.serviceAccount) > 0 { // check whether user supplied a list of SA
89+
if len(strings.Split(o.serviceAccount, ",")) > 1 {
90+
return fmt.Errorf("only one Service Account is supported")
91+
}
92+
if strings.HasPrefix(o.serviceAccount, serviceaccount.ServiceAccountUsernamePrefix) {
93+
_, user, err := serviceaccount.SplitUsername(o.serviceAccount)
94+
if err != nil {
95+
return err
96+
}
97+
o.serviceAccount = user
9298
}
93-
o.serviceAccount = user
9499
}
95100
var err error
96101
o.namespace, o.enforceNamespace, err = f.DefaultNamespace()

test/cmd/policy.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ os::cmd::expect_success_and_text 'oc policy can-i --list --user harold --groups
101101
os::cmd::expect_failure 'oc policy scc-subject-review'
102102
os::cmd::expect_failure 'oc policy scc-review'
103103
os::cmd::expect_failure_and_text 'oc policy scc-subject-review -f ${OS_ROOT}/test/testdata/pspreview_unsupported_statefulset.yaml' 'error: StatefulSet "rd" with spec.volumeClaimTemplates currently not supported.'
104+
os::cmd::expect_failure_and_text 'oc policy scc-subject-review -z foo,bar -f ${OS_ROOT}/test/testdata/job.yaml' 'error: only one Service Account is supported'
105+
os::cmd::expect_failure_and_text 'oc policy scc-subject-review -z system:serviceaccount:test:default,system:serviceaccount:test:builder -f ${OS_ROOT}/test/testdata/job.yaml' 'error: only one Service Account is supported'
104106
os::cmd::expect_failure_and_text 'oc policy scc-review -f ${OS_ROOT}/test/testdata/pspreview_unsupported_statefulset.yaml' 'error: StatefulSet "rd" with spec.volumeClaimTemplates currently not supported.'
105107
os::cmd::expect_success_and_text 'oc policy scc-subject-review -f ${OS_ROOT}/test/testdata/job.yaml -o=jsonpath={.status.AllowedBy.name}' 'anyuid'
106108
os::cmd::expect_success_and_text 'oc policy scc-subject-review -f ${OS_ROOT}/test/testdata/redis-slave.yaml -o=jsonpath={.status.AllowedBy.name}' 'anyuid'

0 commit comments

Comments
 (0)