Skip to content
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
89 changes: 89 additions & 0 deletions test/extended/bootstrap_user/bootstrap_user_login.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package bootstrap_user

import (
g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
"github.com/openshift/origin/pkg/oauthserver/server/crypto"

"k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
e2e "k8s.io/kubernetes/test/e2e/framework"

"github.com/openshift/library-go/pkg/operator/events"
"github.com/openshift/library-go/pkg/operator/resource/resourceapply"
exutil "github.com/openshift/origin/test/extended/util"
"golang.org/x/crypto/bcrypt"
)

var _ = g.Describe("The bootstrap user", func() {
defer g.GinkgoRecover()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smarterclayton It's unclear to me what the exact label for this should be. Conformance ok?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on what this is supposed to test. You can't couple an extended test to the installer artifacts (e2e tests have to run against anyone's cluster). Mo owns testing that we can set / update a bootstrap user on a cluster, so at that point you're more about establishing that a newly created cluster has a bootstrap user. However, not all users are going to run extended against a cluster with a bootstrap user, so we'd have to make the test conditional on that behavior.

  • A test that verifies the installer itself creates a bootstrap user would belong to the installer and be in that repo.
  • A test that verifies that a conformant openshift cluster can have a bootstrap user and exercises the secret creation paths and verifies oauth logins work would be here, but would not be part of the conformance suite (this is what I alluded to mo owning)

I think you're trying to build more of the former rather than the latter - since you're trying to verify that the installer correctly sets up the password AND that the password is useful, so this really belongs in the installer test suite.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also want to confirm that what has to happen via authentication/osin/oauthconfig for token-generation is not broken.
We could go back to my original plan of checking that both are kosher in the cluster-launch-installer-* templates, by logging in/switching back to system:admin context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verify that the installer correctly sets up the password AND that the password is useful

  • the installer already 'tests' that the password is created, by spitting it out at the end (and errors if not read, in cmd/openshift-install/create.go).
  • to test that it's useful, have to go through oauthserver. I still don't see how that test belongs in the installer. It requires an unsupportedConfigOverrides oauthConfig section in kubeAPIServerOperatorConfig patched, etc. Only way to test that that completed is to run oc login with kubeadmin
    .

this really belongs in the installer test suite.

AFAIK there isn't an installer test suite atm? There was a smoke tests suite but it's not currently run/they're outdated/tectonic references still. I can look at updating those, but that might take awhile, and the auth team needs assurance now that upcoming changes don't break kube:admin.

A test that verifies that a conformant openshift cluster can have a bootstrap user and exercises the secret creation paths and verifies oauth logins work would be here

Yes, this! So I need to make this extended test conditional on clusters that have the bootstrap kubeadmin password (ie, any cluster created with openshift/installer)? Or, easiest way (for now) is to put this check in the cluster-launch-installer-* CI templates, for all jobs running against a cluster launched w/ openshift/installer like so: openshift/release#2440

Copy link
Contributor Author

@sallyom sallyom Jan 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@enj mentioned I can create or apply new data to the kubeadmin secret in the extended test that conforms to the pw requirements, then check for kubeadmin user login, since every 4.0 cluster has the ability to create kubeadmin user, I'll go with that.

var oc *exutil.CLI
var originalPasswordHash []byte
secretExists := true
recorder := events.NewInMemoryRecorder("")
oc = exutil.NewCLI("bootstrap-login", exutil.KubeConfigPath())
g.It("should successfully login with password decoded from kubeadmin secret", func() {
// We aren't testing that the installer has created this secret here, instead,
// we create it/apply new data/restore it after (if it existed, or delete it if
// it didn't. Here, we are only testing the oauth flow
// of authenticating/creating the special kube:admin user.
// Testing that the installer properly generated the password/secret is the
// responsibility of the installer.
secret, err := oc.AsAdmin().KubeClient().CoreV1().Secrets("kube-system").Get("kubeadmin", metav1.GetOptions{})
if err != nil {
if !kerrors.IsNotFound(err) {
o.Expect(err).NotTo(o.HaveOccurred())
} else {
secretExists = false
}
}
if secretExists {
// not validating secret here, but it should have this if it's there
originalPasswordHash = secret.Data["kubeadmin"]
}
password, passwordHash, err := generatePassword()
o.Expect(err).NotTo(o.HaveOccurred())
kubeadminSecret := generateSecret(passwordHash)
_, _, err = resourceapply.ApplySecret(oc.AsAdmin().KubeClient().CoreV1(), recorder, kubeadminSecret)
o.Expect(err).NotTo(o.HaveOccurred())
e2e.Logf("logging in as kubeadmin user")
out, err := oc.Run("login").Args("-u", "kubeadmin", "-p", password).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("Login successful"))
user, err := oc.Run("whoami").Args().Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(user).To(o.ContainSubstring("kube:admin"))
//Now, restore cluster to original state
if secretExists {
originalKubeadminSecret := generateSecret(originalPasswordHash)
e2e.Logf("restoring original kubeadmin user")
_, _, err = resourceapply.ApplySecret(oc.AsAdmin().KubeClient().CoreV1(), recorder, originalKubeadminSecret)
o.Expect(err).NotTo(o.HaveOccurred())
} else {
err := oc.AsAdmin().KubeClient().CoreV1().Secrets("kube-system").Delete("kubeadmin", &metav1.DeleteOptions{})
o.Expect(err).NotTo(o.HaveOccurred())
}
})
})

func generatePassword() (string, []byte, error) {
password := crypto.Random256BitsString()
bytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
if err != nil {
return "", nil, err
}
return password, bytes, nil
}

func generateSecret(data []byte) *v1.Secret {
return &v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "kubeadmin",
Namespace: "kube-system",
},
Data: map[string][]byte{
"kubeadmin": data,
},
}
}
1 change: 1 addition & 0 deletions test/extended/include.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

// _ "k8s.io/kubernetes/test/e2e/ui"

_ "github.com/openshift/origin/test/extended/bootstrap_user"
_ "github.com/openshift/origin/test/extended/builds"
_ "github.com/openshift/origin/test/extended/cli"
_ "github.com/openshift/origin/test/extended/cluster"
Expand Down