-
Notifications
You must be signed in to change notification settings - Fork 4.8k
add kubeadmin login test #21733
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
Merged
openshift-merge-robot
merged 1 commit into
openshift:master
from
sallyom:add-smoke-4-test
Jan 16, 2019
Merged
add kubeadmin login test #21733
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
| 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, | ||
| }, | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
Conformanceok?There was a problem hiding this comment.
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.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oc loginwith kubeadmin.
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.
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
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.