Skip to content

Commit 8115614

Browse files
committed
Check pull access when tagging imagestreams
1 parent 829ea8c commit 8115614

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

pkg/image/registry/imagestream/strategy.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"k8s.io/kubernetes/pkg/labels"
1414
"k8s.io/kubernetes/pkg/registry/generic"
1515
"k8s.io/kubernetes/pkg/runtime"
16-
"k8s.io/kubernetes/pkg/util/sets"
1716
"k8s.io/kubernetes/pkg/util/validation/field"
1817

1918
authorizationapi "github.com/openshift/origin/pkg/authorization/api"
@@ -433,19 +432,18 @@ func (v *TagVerifier) Verify(old, stream *api.ImageStream, user user.Info) field
433432
continue
434433
}
435434

436-
subjectAccessReview := authorizationapi.SubjectAccessReview{
435+
// Make sure this user can pull the specified image before allowing them to tag it into another imagestream
436+
subjectAccessReview := authorizationapi.AddUserToSAR(user, &authorizationapi.SubjectAccessReview{
437437
Action: authorizationapi.Action{
438438
Verb: "get",
439439
Group: api.GroupName,
440-
Resource: "imagestreams",
440+
Resource: "imagestreams/layers",
441441
ResourceName: streamName,
442442
},
443-
User: user.GetName(),
444-
Groups: sets.NewString(user.GetGroups()...),
445-
}
443+
})
446444
ctx := kapi.WithNamespace(kapi.NewContext(), tagRef.From.Namespace)
447445
glog.V(4).Infof("Performing SubjectAccessReview for user=%s, groups=%v to %s/%s", user.GetName(), user.GetGroups(), tagRef.From.Namespace, streamName)
448-
resp, err := v.subjectAccessReviewClient.CreateSubjectAccessReview(ctx, &subjectAccessReview)
446+
resp, err := v.subjectAccessReviewClient.CreateSubjectAccessReview(ctx, subjectAccessReview)
449447
if err != nil || resp == nil || (resp != nil && !resp.Allowed) {
450448
errors = append(errors, field.Forbidden(fromPath, fmt.Sprintf("%s/%s", tagRef.From.Namespace, streamName)))
451449
continue

pkg/image/registry/imagestream/strategy_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ func (u *fakeUser) GetGroups() []string {
4343
}
4444

4545
func (u *fakeUser) GetExtra() map[string][]string {
46-
return map[string][]string{}
46+
return map[string][]string{
47+
authorizationapi.ScopesKey: {"a", "b"},
48+
}
4749
}
4850

4951
type fakeDefaultRegistry struct {
@@ -311,11 +313,12 @@ func TestTagVerifier(t *testing.T) {
311313
expectedSar := &authorizationapi.SubjectAccessReview{
312314
Action: authorizationapi.Action{
313315
Verb: "get",
314-
Resource: "imagestreams",
316+
Resource: "imagestreams/layers",
315317
ResourceName: "otherstream",
316318
},
317319
User: "user",
318320
Groups: sets.NewString("group1"),
321+
Scopes: []string{"a", "b"},
319322
}
320323
if e, a := expectedSar, sar.request; !reflect.DeepEqual(e, a) {
321324
t.Errorf("%s: unexpected SAR request: %s", name, diff.ObjectDiff(e, a))

0 commit comments

Comments
 (0)