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

feat: Implement login manager and login/logout commands #910

Merged
merged 15 commits into from
Oct 21, 2020
Merged

Conversation

mmorhun
Copy link
Contributor

@mmorhun mmorhun commented Oct 7, 2020

Signed-off-by: Mykola Morhun mmorhun@redhat.com

What does this PR do?

Before this change users had to provide Che server API URL and access token for each run of all commands that require authentication. This is not a user-friendly way to go. In this PR login manager is implemented and new commands introduced:

  • auth:login logins user into a Che server. So, after login user can just run commands without Che API URL and access token parameters.
  • auth:logout logs out user from current Che server
  • auth:get - show current login info
  • auth:list - shows all available logins
  • auth:use - switches between login sessions
  • auth:delete - deletes specified login session or all logins for the given Che server

Also, comfortable interface for using in commands is created.

The implementation supports 3 login methods via:

  • refresh token
  • username and password
  • oc login

Note, login manager does not (and should not) depend on kubectl or oc login information. It might use it, thought, to simplify login process.

Under the hood, login manager saves users refresh tokens. Also it is capable to automatically remove outdated ones.

What issues does this PR fix or reference?

eclipse-che/che#16415

How to test this PR?

At least two running instances of Eclispe Che is needed (s1, s2) with two users (u1(admin user), u2) in each. One instance should have OAuth enabled on Openshift, where the second one should use password login on Kubernetes. For testing purposes I used workspace:list command, so it is helpful when each account has different workspaces (ideally different number of them).
User scenario:

  1. Logout of all oc and kubectl sessions. After each of the steps perform chectl workspace:list and chectl context:list commands
  2. Login into s1u2: chectl auth:login <s1> -t <refresh-token>.
  3. Login into s2u1: chectl auth:login <s2> -u <username> -p <password>
  4. Login into s2u2: chectl auth:login <s2> -u <username> (password should be asked)
  5. Login by oc into s1u1. Run chectl auth:login (if u1 is not admin user, provide <s1> argument)
  6. Switch context to another user. For example: chectl auth:use <s2> -u <u2>
  7. Logout from non current instance by chectl auth:delete <s1> -u <u1>
  8. Logout from current session by chectl auth:logout
  9. Try to login into s3 which is a single user Che installation
  10. Try to run chectl workspace:list --che-api-endpoint <s3> for single user instance.
  11. Another tried use cases are welcomed.

See docs how to get refresh token manually and feel the difference =)

PR Checklist

As the author of this Pull Request I made sure that:

Reviewers

Reviewers, please comment how you tested the PR when approving it.

@openshift-ci-robot
Copy link
Collaborator

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@mmorhun
Copy link
Contributor Author

mmorhun commented Oct 7, 2020

Only workspace:list command is reworked for now. I'll rework the rest if no objections is given to the current way of implementation.
Command line arguments names for server:login and server:logout commands are topic to discuss.
After logout current login context is not automatically set. Should we set another one, if any?
Also yarn.lock is not updated yet to avoid merge conflicts for now.

@tolusha
Copy link
Collaborator

tolusha commented Oct 8, 2020

It is better to split login/logout functionality into the following commands: context:[use/get/list/delete]

src/api/che-api-client.ts Outdated Show resolved Hide resolved
@mmorhun mmorhun force-pushed the che-16415 branch 2 times, most recently from d21dd75 to 4f6ed85 Compare October 12, 2020 11:12
Signed-off-by: Mykola Morhun <mmorhun@redhat.com>
Signed-off-by: Mykola Morhun <mmorhun@redhat.com>
…atly.

Signed-off-by: Mykola Morhun <mmorhun@redhat.com>
@mmorhun
Copy link
Contributor Author

mmorhun commented Oct 21, 2020

Rebased

Signed-off-by: Mykola Morhun <mmorhun@redhat.com>
Copy link
Collaborator

@tolusha tolusha left a comment

Choose a reason for hiding this comment

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

We can merge it and improve later if needed.

Copy link
Contributor

@AndrienkoAleksandr AndrienkoAleksandr left a comment

Choose a reason for hiding this comment

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

@mmorhun Impressive work!

Copy link

@yhontyk yhontyk left a comment

Choose a reason for hiding this comment

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

Some tiny suggestions regarding the messages

[USERNAME_KEY]: username,
interactive: flags.boolean({
char: 'i',
description: 'Select active login session in interactive mode',
Copy link

Choose a reason for hiding this comment

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

Suggested change
description: 'Select active login session in interactive mode',
description: 'Select an active login session in interactive mode',

'chectl auth:use -u another-user-on-this-server',
'\n\n# Switch to the only user on the given cluster:\n' +
'chectl auth:use my.cluster.net',
'\n\n# Select active login session in interactive mode:\n' +
Copy link

Choose a reason for hiding this comment

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

Suggested change
'\n\n# Select active login session in interactive mode:\n' +
'\n\n# Select an active login session in interactive mode:\n' +

if (error && error.response && error.response.data && error.response.data.error_description) {
message = error.response.data.error_description
}
throw new Error(`Failed to get access token from ${keycloakTokenUrl}. Cause: ${message}`)
Copy link

Choose a reason for hiding this comment

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

Suggested change
throw new Error(`Failed to get access token from ${keycloakTokenUrl}. Cause: ${message}`)
throw new Error(`Failed to get the access token from ${keycloakTokenUrl}. Cause: ${message}`)

@@ -44,6 +47,37 @@ describe('Eclipse Che deploy test suite', () => {
})
})

describe('Che server authentication', () => {
it('Should login into Che server with username and password', async () => {
Copy link

Choose a reason for hiding this comment

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

Suggested change
it('Should login into Che server with username and password', async () => {
it('Should log in to Che server with username and password', async () => {

Signed-off-by: Mykola Morhun <mmorhun@redhat.com>
@openshift-ci-robot
Copy link
Collaborator

New changes are detected. LGTM label has been removed.

@mmorhun mmorhun merged commit f448adc into master Oct 21, 2020
@mmorhun mmorhun deleted the che-16415 branch October 21, 2020 15:18
rhopp added a commit to eclipse-che/che that referenced this pull request Oct 22, 2020
This is needed because of che-incubator/chectl#910

Signed-off-by: Radim Hopp <rhopp@redhat.com>
rhopp added a commit to eclipse-che/che that referenced this pull request Oct 22, 2020
This is needed because of che-incubator/chectl#910

Signed-off-by: Radim Hopp <rhopp@redhat.com>
rhopp added a commit to eclipse-che/che that referenced this pull request Oct 22, 2020
This is needed because of che-incubator/chectl#910

Signed-off-by: Radim Hopp <rhopp@redhat.com>
rhopp added a commit to eclipse-che/che that referenced this pull request Oct 22, 2020
This is needed because of che-incubator/chectl#910

Signed-off-by: Radim Hopp <rhopp@redhat.com>
rhopp added a commit to rhopp/che-tests-playground that referenced this pull request Apr 16, 2021
This is needed because of che-incubator/chectl#910

Signed-off-by: Radim Hopp <rhopp@redhat.com>
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.

None yet

6 participants