Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deploy: verify the deployer SA has perms to update tags #15162

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions test/extended/deployments/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,19 @@ var _ = g.Describe("deploymentconfigs", func() {
})

g.It("should successfully tag the deployed image", func() {
g.By("creating the deployment config fixture")
_, name, err := createFixture(oc, tagImagesFixture)
o.Expect(err).NotTo(o.HaveOccurred())

g.By("verifying the deployment is marked complete")
o.Expect(waitForLatestCondition(oc, name, deploymentRunTimeout, deploymentReachedCompletion)).NotTo(o.HaveOccurred())

g.By("verifying the deployer service account can update imagestreamtags and user can get them")
err = exutil.WaitForUserBeAuthorized(oc, oc.Username(), "get", "imagestreamtags")
o.Expect(err).NotTo(o.HaveOccurred())
err = exutil.WaitForUserBeAuthorized(oc, "system:serviceaccount:"+oc.Namespace()+":deployer", "update", "imagestreamtags")
o.Expect(err).NotTo(o.HaveOccurred())

g.By("verifying the post deployment action happened: tag is set")
var istag *imageapi.ImageStreamTag
pollErr := wait.PollImmediate(100*time.Millisecond, 1*time.Minute, func() (bool, error) {
Expand Down
21 changes: 21 additions & 0 deletions test/extended/util/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"k8s.io/kubernetes/pkg/quota"
"k8s.io/kubernetes/test/e2e/framework"

authapi "github.com/openshift/origin/pkg/authorization/apis/authorization"
buildapi "github.com/openshift/origin/pkg/build/apis/build"
"github.com/openshift/origin/pkg/client"
deployapi "github.com/openshift/origin/pkg/deploy/apis/apps"
Expand Down Expand Up @@ -1298,3 +1299,23 @@ func (r *podExecutor) Exec(script string) (string, error) {
})
return out, waitErr
}

// WaitForUserBeAuthorized waits a minute until the cluster bootstrap roles are available
// and the provided user is authorized to perform the action on the resource.
func WaitForUserBeAuthorized(oc *CLI, user, verb, resource string) error {
sar := authapi.SubjectAccessReview{
User: user,
Action: authapi.Action{
Namespace: oc.Namespace(),
Verb: verb,
Resource: resource,
},
}
return wait.PollImmediate(1*time.Second, 1*time.Minute, func() (bool, error) {
resp, err := oc.AdminClient().SubjectAccessReviews().Create(&sar)
if err == nil && resp != nil && resp.Allowed {
return true, nil
}
return false, err
})
}