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

add localhost:9000 as a redirect URL #10895

Conversation

juanvallejo
Copy link
Contributor

@juanvallejo juanvallejo commented Sep 13, 2016

Depends on: #10819
Fixes: #10885

This patch adds https://localhost:9000 as a default redirect URI to
the webconsole oauthclient. This is done as a new oc cluster up
startup task.

$ oc cluster up

...
-- Finding server IP ...
   Using <IP> as the server IP
-- Starting OpenShift container ...
   Creating initial OpenShift configuration
   Starting OpenShift using container 'origin'
   Waiting for API server to start listening
   OpenShift server started
-- Adding default OAuthClient redirect URIs ... OK
-- Installing registry ... OK
-- Installing router ... OK
-- Importing image streams ... OK
-- Importing templates ... OK
-- Login to server ... OK
-- Creating initial project "myproject" ... OK
...
$ oc login -u system:admin
$ oc get oauthclients

NAME                              WWW-CHALLENGE   REDIRECT URIS
openshift-web-console             FALSE           https://localhost:9000

cc @fabianofranz @jwforres @csrwng

@@ -45,6 +46,9 @@ const (
initialProjectDisplay = "My Project"
initialProjectDesc = "Initial developer project"

defaultRedirectClient = "oauthclient/openshift-web-console"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fabianofranz
Although I could use the const OpenShiftWebConsoleClientID defined in pkg/cmd/server/origin/auth.go, I did not want to import server packages, but WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

Hrm, yeah, that could result in bringing to oc packages that don't belong here (master.go for example imports a lot of server-side stuff).

@jwforres
Copy link
Member

cc @liggitt

@csrwng
Copy link
Contributor

csrwng commented Sep 13, 2016

@juanvallejo we currently update the config here:
https://github.com/openshift/origin/blob/master/pkg/bootstrap/docker/openshift/helper.go#L446

My preference would be to change it there rather than executing a separate patch command.

@liggitt
Copy link
Contributor

liggitt commented Sep 13, 2016

It's not a server config update, it's an update of the API object

@csrwng
Copy link
Contributor

csrwng commented Sep 13, 2016

ahh got it, thx @liggitt. @juanvallejo please ignore me and carry on :)

@juanvallejo
Copy link
Contributor Author

:) Thanks for the feedback!

@juanvallejo juanvallejo force-pushed the jvallejo_add-localhost-9000-as-default-redirect-oc-cluster branch from d5e389c to 5a80c23 Compare September 13, 2016 21:58
@juanvallejo
Copy link
Contributor Author

[test]

return err
}

patch := fmt.Sprintf("{%q:[%q]}", "redirectURIs", defaultRedirectURI)
Copy link
Contributor

Choose a reason for hiding this comment

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

raises eyebrow... this should really be built by json-serializing a struct

Copy link
Contributor

Choose a reason for hiding this comment

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

actually, why not use the go client to make the call?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@csrwng

actually, why not use the go client to make the call?

Hm, I am not sure what you mean. I thought NewCmdPatch was already using the client to make the remote call?

Copy link
Contributor

Choose a reason for hiding this comment

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

@juanvallejo i mean not invoking the command, simply doing a client get and then an update call with your change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@csrwng Okay, updated to not using NewCmdPatch, PTAL

@juanvallejo juanvallejo force-pushed the jvallejo_add-localhost-9000-as-default-redirect-oc-cluster branch 2 times, most recently from 5e787cd to 4b07d66 Compare September 14, 2016 19:43
@juanvallejo juanvallejo changed the title add localhost:9000 as a default redirect URL DEPENDS ON #10819: add localhost:9000 as a default redirect URL Sep 15, 2016
@csrwng
Copy link
Contributor

csrwng commented Sep 15, 2016

@juanvallejo actually that's not what I had in mind :)
I was thinking of something like:

client, _, err := c.Clients()
webConsoleOAuth, err := client.OAuthClients().Get("openshift-web-console")
// not shown here... check first and don't add it if it's already there
webConsoleOAuth.RedirectURIs = append(webConsoleOAuth.RedirectURIs, "http://localhost:9000")  
err = client.OAuthClients().Update(webConsoleOAuth)

However, I realized that there's no Update method on the client for OAuthClients (you could add one of course)... @liggitt was that left out on purpose?

@liggitt
Copy link
Contributor

liggitt commented Sep 15, 2016

@liggitt was that left out on purpose?

nope

@juanvallejo
Copy link
Contributor Author

@csrwng Thanks for the feedback!

However, I realized that there's no Update method on the client for OAuthClients (you could add one of course)

I have gone ahead and added an Update method to the OAuthClientInterface that receives an *oauthapi.OAuthClient and then makes a Patch request to the server, however the body of the request must contain the patch data ({"redirectURIs": ["https://localhost:9000"]}) as a json object. I was wondering if there is a way to obtain this from the OAuthClient that is passed, or would I just have to Marshal a json struct like I was doing before, and pass that as []bytes to the new Update method? Thanks!

@liggitt
Copy link
Contributor

liggitt commented Sep 15, 2016

I have gone ahead and added an Update method to the OAuthClientInterface that receives an *oauthapi.OAuthClient and then makes a Patch request to the server

no, make Update do an update. look at the other Update client methods and model after that.

just Get, add the redirectURI, and Update

@csrwng
Copy link
Contributor

csrwng commented Sep 15, 2016

@juanvallejo All you need to do for the update implementation is to do a put. For examples, you can see how other object updates are implemented:
https://github.com/openshift/origin/blob/master/pkg/client/oauthclientauthorization.go#L41
https://github.com/openshift/origin/blob/master/pkg/client/clusteresourcequota.go#L56

@@ -17,6 +17,7 @@ type OAuthClientInterface interface {
Get(name string) (*oauthapi.OAuthClient, error)
Delete(name string) error
Watch(opts kapi.ListOptions) (watch.Interface, error)
Update(client *oauthapi.OAuthClient) (*oauthapi.OAuthClient, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

need to update fake_oauthclient.go to implement this as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do, thanks!

@juanvallejo juanvallejo force-pushed the jvallejo_add-localhost-9000-as-default-redirect-oc-cluster branch 4 times, most recently from d99ce99 to dec1b11 Compare September 16, 2016 13:49
@csrwng
Copy link
Contributor

csrwng commented Sep 21, 2016

LGTM after a squash

@juanvallejo juanvallejo force-pushed the jvallejo_add-localhost-9000-as-default-redirect-oc-cluster branch from dec1b11 to 0bed3c0 Compare September 21, 2016 18:53
@juanvallejo
Copy link
Contributor Author

re[test]

@juanvallejo
Copy link
Contributor Author

conformance test flaked on #9548 re[test]

Copy link
Contributor

@liggitt liggitt left a comment

Choose a reason for hiding this comment

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

a couple nits on names and messages. once updated, this can go ahead and merge... it doesn't need to wait for #10819

@@ -45,6 +46,9 @@ const (
initialProjectDisplay = "My Project"
initialProjectDesc = "Initial developer project"

defaultRedirectClient = "openshift-web-console"
defaultRedirectURI = "https://localhost:9000"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this isn't the default redirect URI, it's an additional allowed one... more a "developmentRedirectURI"

return nil
}

webConsoleOAuth, err := oc.OAuthClients().Get(defaultRedirectClient)
Copy link
Contributor

Choose a reason for hiding this comment

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

if the web console OAuth client doesn't exist, I would exit early, rather than error

Copy link
Contributor

Choose a reason for hiding this comment

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

if NotFound, return nil, otherwise, return err

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@liggitt Thanks for clarifying! Updated to check if err is kerrors.IsNotFound

if err != nil {
// announce error without interrupting remaining tasks
suggestedCmd := fmt.Sprintf("oc patch %s -p '{%q:[%q]}'", "oauthclient/openshift-web-console", "redirectURIs", defaultRedirectURI)
errMsg := fmt.Sprintf("Unable to set %q as a default redirect URL for the web console.\nTo manually add it, run %q\n", defaultRedirectURI, suggestedCmd)
Copy link
Contributor

Choose a reason for hiding this comment

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

"unable to add development redirect URI to the openshift-web-console OAuthClient..."

@juanvallejo juanvallejo force-pushed the jvallejo_add-localhost-9000-as-default-redirect-oc-cluster branch from 0bed3c0 to 2367bcb Compare September 26, 2016 20:27
@juanvallejo
Copy link
Contributor Author

@liggitt Addressed review comments, PTAL

@juanvallejo juanvallejo force-pushed the jvallejo_add-localhost-9000-as-default-redirect-oc-cluster branch 2 times, most recently from f89f0ca to 596047f Compare September 26, 2016 20:45
@liggitt liggitt changed the title DEPENDS ON #10819: add localhost:9000 as a default redirect URL add localhost:9000 as a default redirect URL Sep 26, 2016
@liggitt liggitt changed the title add localhost:9000 as a default redirect URL add localhost:9000 as a redirect URL Sep 26, 2016
fmt.Fprintf(out, "Unable to find OAuthClient %q\n", defaultRedirectClient)
return nil
}
return err
Copy link
Contributor

@liggitt liggitt Sep 26, 2016

Choose a reason for hiding this comment

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

if we tolerate an update failure (below), we should probably tolerate a fetch failure as well (not return the error), and print out the same suggestion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@liggitt Sounds good, it no longer returns the err but rather prints a slightly updated suggestion and returns nil

@juanvallejo juanvallejo force-pushed the jvallejo_add-localhost-9000-as-default-redirect-oc-cluster branch from 596047f to 056b1ce Compare September 26, 2016 21:03
@liggitt
Copy link
Contributor

liggitt commented Sep 26, 2016

LGTM

Fixes: openshift#10885

This patch adds `https://localhost:9000` as a default redirect URI to
the webconsole oauthclient. This is done as a new `oc cluster up`
startup task.

```
$ oc cluster up

...
-- Finding server IP ...
   Using <IP> as the server IP
-- Starting OpenShift container ...
   Creating initial OpenShift configuration
   Starting OpenShift using container 'origin'
   Waiting for API server to start listening
   OpenShift server started
-- Adding default oAuthClient redirect URIs ...
   "openshift-web-console" patched
-- Installing registry ... OK
-- Installing router ... OK
-- Importing image streams ... OK
-- Importing templates ... OK
-- Login to server ... OK
-- Creating initial project "myproject" ... OK
...
```

```
$ oc login -u system:admin
$ oc get oauthclients

NAME                              WWW-CHALLENGE   REDIRECT URIS
openshift-web-console             FALSE           https://localhost:9000
```
@juanvallejo juanvallejo force-pushed the jvallejo_add-localhost-9000-as-default-redirect-oc-cluster branch from 056b1ce to b183604 Compare September 26, 2016 21:33
@juanvallejo
Copy link
Contributor Author

[test]

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to b183604

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/9324/)

@liggitt
Copy link
Contributor

liggitt commented Sep 27, 2016

[merge]

@openshift-bot
Copy link
Contributor

openshift-bot commented Sep 27, 2016

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/9324/) (Image: devenv-rhel7_5084)

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to b183604

@openshift-bot openshift-bot merged commit 53d71cb into openshift:master Sep 27, 2016
@smarterclayton
Copy link
Contributor

Maybe I missed this - why is "localhost" the correct value?

@smarterclayton
Copy link
Contributor

Won't localhost be wrong if my docker daemon isn't running on my system?

@liggitt
Copy link
Contributor

liggitt commented Sep 27, 2016

this is enabling web console development (cd $webconsole && grunt serve) out of the box against a cluster up server

@juanvallejo juanvallejo deleted the jvallejo_add-localhost-9000-as-default-redirect-oc-cluster branch September 27, 2016 18:35
@smarterclayton
Copy link
Contributor

Can you add some Godoc to this, because nothing in here makes it obvious why it's localhost:9000, and so it's really for a very specific audience, so that usually requires some justification in the code so other people don't remove it.

juanvallejo added a commit to juanvallejo/origin that referenced this pull request Sep 27, 2016
Spawned from:
openshift#10895 (comment)

This patch adds a brief explanation for the use of "localhost:9000" as a
default develppment redirect URI in the `oc cluster up` setup.
@juanvallejo
Copy link
Contributor Author

@smarterclayton I was not sure if making a new pull request was the way I should do this, but please take a look: #11123

juanvallejo added a commit to juanvallejo/origin that referenced this pull request Sep 28, 2016
Spawned from:
openshift#10895 (comment)

This patch adds a brief explanation for the use of "localhost:9000" as a
default develppment redirect URI in the `oc cluster up` setup.
juanvallejo added a commit to juanvallejo/origin that referenced this pull request Oct 27, 2016
Spawned from:
openshift#10895 (comment)

This patch adds a brief explanation for the use of "localhost:9000" as a
default develppment redirect URI in the `oc cluster up` setup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants