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

oc login: Show tokenURL message if only IDP is basic and user has not provided username #553

Merged
merged 1 commit into from Oct 14, 2020

Conversation

sallyom
Copy link
Contributor

@sallyom sallyom commented Sep 3, 2020

  • If a user provides oc login -u anything, try for basic auth prompt.
  • If only password IDP available, and no username was provided, show the tokenURL message instead of basic auth prompt.

@sallyom
Copy link
Contributor Author

sallyom commented Sep 3, 2020

/assign @soltysh
/cc @stlaz

this is a guess as to what should happen

@soltysh
Copy link
Member

soltysh commented Sep 3, 2020

I don't think this is a good approach, b/c you're basically forcing username to be passed to pick basic auth. I was rather imagining that when you get information from the server about supported auth methods, and if only basic you'd go with that always. But when more than basic is present always prefer the other one. @stlaz might help you with that and I think that's what @smarterclayton had in mind

@soltysh
Copy link
Member

soltysh commented Sep 3, 2020

@sallyom
Copy link
Contributor Author

sallyom commented Sep 3, 2020

The actual response you're faking here is coming from oauth-server, from here: https://github.com/openshift/oauth-server/blob/dcbeb48c9cedcf0827629556f1e6cdb8538d4ebe/pkg/authenticator/challenger/placeholderchallenger/placeholder_challenger.go#L2

I saw that, ok - i'll rework this.

@sallyom sallyom changed the title oc login: Only offer basic auth if/when a user provides -u|--username, otherwise provide the token request URL message. oc login: Show tokenURL if only IDP is bootstrap IDP and user has not provided "kubeadm" as user Sep 4, 2020
@sallyom sallyom changed the title oc login: Show tokenURL if only IDP is bootstrap IDP and user has not provided "kubeadm" as user oc login: Show tokenURL if only IDP is bootstrap and user has not provided "kubeadm" as user Sep 4, 2020
@sallyom sallyom changed the title oc login: Show tokenURL if only IDP is bootstrap and user has not provided "kubeadm" as user WIP: oc login: Show tokenURL if only IDP is bootstrap and user has not provided "kubeadm" as user Sep 5, 2020
@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 5, 2020
@sallyom sallyom changed the title WIP: oc login: Show tokenURL if only IDP is bootstrap and user has not provided "kubeadm" as user oc login: Show tokenURL if only IDP is bootstrap and user has not provided "kubeadm" as user Sep 8, 2020
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 8, 2020
@sallyom
Copy link
Contributor Author

sallyom commented Sep 8, 2020

I don't think this is a good approach, b/c you're basically forcing username to be passed to pick basic auth. I was rather imagining that when you get information from the server about supported auth methods, and if only basic you'd go with that always. But when more than basic is present always prefer the other one. @stlaz might help you with that and I think that's what @smarterclayton had in mind

I've reworked this:
Change in openshift/oauth-server to mark the bootstrap basic auth with realm "bootstrap" (as @stlaz and I discussed via slack). Here in oc if bootstrap basic challenge and no other password IDP & no username passed, then show the tokenURL.

@sallyom
Copy link
Contributor Author

sallyom commented Sep 8, 2020

/test e2e-cmd

Copy link
Member

@stlaz stlaz left a comment

Choose a reason for hiding this comment

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

you're also going to have to improve

func basicRealm(headers http.Header) (bool, string) {

so that it prefers non-kubeadmin realms

pkg/helpers/tokencmd/request_token.go Outdated Show resolved Hide resolved
@sallyom
Copy link
Contributor Author

sallyom commented Sep 10, 2020

@stlaz pt-another-l, thanks

Copy link
Member

@stlaz stlaz left a comment

Choose a reason for hiding this comment

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

is there any specific code that will handle the warning received from the oauth-server? I couldn't find where the message about the token URL is actually printed in the case of the placeholderchallenger on the oauth-server side

pkg/helpers/tokencmd/request_token.go Outdated Show resolved Hide resolved
pkg/helpers/tokencmd/request_token.go Outdated Show resolved Hide resolved
pkg/helpers/tokencmd/basicauth.go Outdated Show resolved Hide resolved
pkg/helpers/tokencmd/basicauth.go Outdated Show resolved Hide resolved
pkg/helpers/tokencmd/basicauth.go Outdated Show resolved Hide resolved
pkg/helpers/tokencmd/basicauth.go Outdated Show resolved Hide resolved
pkg/helpers/tokencmd/basicauth.go Outdated Show resolved Hide resolved
pkg/helpers/tokencmd/basicauth.go Outdated Show resolved Hide resolved
pkg/helpers/tokencmd/request_token.go Outdated Show resolved Hide resolved
pkg/helpers/tokencmd/request_token.go Outdated Show resolved Hide resolved
pkg/helpers/tokencmd/basicauth.go Outdated Show resolved Hide resolved
@sallyom sallyom force-pushed the login-token-url branch 3 times, most recently from a6f2422 to 0fe41a9 Compare September 15, 2020 03:03
@sallyom
Copy link
Contributor Author

sallyom commented Sep 15, 2020

@stlaz, updated this PR, I fixed all the issues and added unit tests. I have a question about the basic no realm see above. thanks again for your review.

@sallyom
Copy link
Contributor Author

sallyom commented Oct 8, 2020

@stlaz ptal at the unit test changes, head is spinning w/ those, thank you : )

Comment on lines 28 to 31
if _, ok := err.(*basicNoUsername); ok {
return true
}
return false
Copy link
Member

Choose a reason for hiding this comment

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

_, ok := err.(*basicNoUsername)
return ok

or export the error an inline it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, exported/inline, thanks!

pkg/helpers/tokencmd/basicauth.go Outdated Show resolved Hide resolved
pkg/helpers/tokencmd/basicauth.go Outdated Show resolved Hide resolved
pkg/helpers/tokencmd/basicauth_test.go Outdated Show resolved Hide resolved
Copy link
Member

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

/approve
there are some nits from Standa left, so I'm leaving him final tag

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 9, 2020
Copy link
Member

@stlaz stlaz left a comment

Choose a reason for hiding this comment

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

Needs further improvements and refactoring due to the changes of basic challenge handler.

The test case changes seem wrong -> you can add more but keep the behavior of the old tests. Unless I missed anything, the old tests weren't prompting for password only so just do that instead of turning them into negative tests.

pkg/helpers/tokencmd/basicauth.go Outdated Show resolved Hide resolved
pkg/helpers/tokencmd/request_token_test.go Show resolved Hide resolved
pkg/helpers/tokencmd/request_token_test.go Outdated Show resolved Hide resolved
pkg/helpers/tokencmd/request_token_test.go Outdated Show resolved Hide resolved
pkg/helpers/tokencmd/request_token_test.go Outdated Show resolved Hide resolved
pkg/helpers/tokencmd/request_token_test.go Outdated Show resolved Hide resolved
@stlaz
Copy link
Member

stlaz commented Oct 9, 2020

/hold
to prevent random lgtms :)

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 9, 2020
@sallyom sallyom force-pushed the login-token-url branch 5 times, most recently from 709a09a to 97e9b30 Compare October 12, 2020 16:37
@@ -98,34 +98,6 @@ Password: `,
},
},

"interactive challenge": {
Copy link
Member

Choose a reason for hiding this comment

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

@sallyom can this be changed to half-interactive when you pass username it should still ask you for a password, or we have one covering that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this can be omitted, as the one above covers that, it's "interactive challenge with default user"

Copy link
Member

Choose a reason for hiding this comment

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

👍

@sallyom
Copy link
Contributor Author

sallyom commented Oct 12, 2020

@stlaz I've updated all test cases, i think you can remove the hold now, and thanks

Copy link
Member

@stlaz stlaz left a comment

Choose a reason for hiding this comment

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

nits only \o/

The PR looks good to me now

pkg/cli/login/login.go Outdated Show resolved Hide resolved
@@ -14,6 +14,16 @@ import (
"github.com/openshift/oc/pkg/helpers/term"
)

type BasicNoUsername struct{}
Copy link
Member

Choose a reason for hiding this comment

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

godoc please :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added!

Copy link
Member

@stlaz stlaz Oct 14, 2020

Choose a reason for hiding this comment

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

// BasicAuthNoUsernameError is an error that means that basic authentication challenge handling was attempted but the required username was not provided from the command line options
  • rename to BasicAuthNoUsernameError

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated, much better, thanks

@stlaz
Copy link
Member

stlaz commented Oct 13, 2020

/hold cancel

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 13, 2020
Copy link
Member

@stlaz stlaz left a comment

Choose a reason for hiding this comment

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

last nits, I promise

@@ -14,6 +14,16 @@ import (
"github.com/openshift/oc/pkg/helpers/term"
)

type BasicNoUsername struct{}
Copy link
Member

@stlaz stlaz Oct 14, 2020

Choose a reason for hiding this comment

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

// BasicAuthNoUsernameError is an error that means that basic authentication challenge handling was attempted but the required username was not provided from the command line options
  • rename to BasicAuthNoUsernameError

}

// BasicNoUsernameError returns an error for a basic challenge without a username
func BasicNoUsernameError() error {
Copy link
Member

Choose a reason for hiding this comment

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

NewBasicAuthNoUsernameError()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, much better, updated : )

Also, in request_token.go, updated BasicNoUsernameMessage to BasicAuthNoUsernameMessage

@stlaz
Copy link
Member

stlaz commented Oct 14, 2020

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 14, 2020
@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sallyom, soltysh, stlaz

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants