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 faker for the pass through api to enable regular user testing #806

Conversation

lucferbux
Copy link
Contributor

@lucferbux lucferbux commented Nov 24, 2022

Closes: #949

Description

This PR adds support for impersonating pass-through API calls with a regular user token.
The main goal here is just to avoid disabling backend functionality in development which needs special admin roles (admin settings, regular jupyter notebooks, dsg project creation...) but enabling pass-through requests with a regular user token.

How Has This Been Tested?

To enable this:

  1. Get a regular user Openshift username and password
  2. Add the DEV_IMPERSONATE_USER and DEV_IMPERSONATE_PASSWORD variables to your env variables file with the regular user's username and password as the values.
  3. Click on your username name in the upper right corner of the dashboard
  4. Select Start impersonate
  5. This way you can replicate some bugs like this:

Screenshot 2022-11-24 at 14 05 39

Merge criteria:

  • The commits are squashed in a cohesive manner and have meaningful messages.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

Copy link
Member

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

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

Neat idea. We should probably log a dev ticket, low priority, to handle thinking on how to make the dev experience better all together. Might be able to avoid granting stupid permissions to do this.

This may also just come for free when we kill the old backend.

backend/src/utils/directCallUtils.ts Outdated Show resolved Hide resolved
backend/src/utils/constants.ts Outdated Show resolved Hide resolved
backend/src/utils/directCallUtils.ts Outdated Show resolved Hide resolved
docs/SDK.md Outdated Show resolved Hide resolved
backend/src/utils/directCallUtils.ts Show resolved Hide resolved
@lucferbux
Copy link
Contributor Author

Neat idea. We should probably log a dev ticket, low priority, to handle thinking on how to make the dev experience better all together. Might be able to avoid granting stupid permissions to do this.

This may also just come for free when we kill the old backend.

@andrewballantyne Yes for sure, I'm creating a new ticket for this, thanks for the feedback (resolved in my branch since I was working offline this evening).

@andrewballantyne
Copy link
Member

Thinking more on this situation -- I wonder if we could set something up that would allow us to start the server with a cluster-admin (aka mimic a service account starting it on cluster) and then somehow making another more basic user to be the one logged in. The one in the top right, the one making all the "oauth" (not really because it does not exist locally) calls, etc, etc

@lucferbux
Copy link
Contributor Author

lucferbux commented Dec 15, 2022

Thinking more on this situation -- I wonder if we could set something up that would allow us to start the server with a cluster-admin (aka mimic a service account starting it on cluster) and then somehow making another more basic user to be the one logged in. The one in the top right, the one making all the "oauth" (not really because it does not exist locally) calls, etc, etc

Yeah, I've been thinking about this too, I think it can be done. There are three main points right now:

  • Pass through API faker: I think that this PR covers most of it.
  • Mimic local permissions to the same as the Dashboard Serviceaccount: This will be very helpful to catch all the permission errors we have with permissions in local development.
  • Fake user for backend: I think this is suuuuper easy to implement, I can have that in this PR if you want @andrewballantyne or maybe in a follow up PR. [EDIT] I've added support for this scenario, you can check this now

@lucferbux
Copy link
Contributor Author

To sum up, with this PR we are now having:

  • Faker for pass-through API k8s calls
  • Faker for backend API calls

It would be really nice to support this in the future:

  • Ability to mimic dashboard serviceaccount permissions for the backend

What do you think, @andrewballantyne ?

@DaoDaoNoCode
Copy link
Member

Can you rebase this PR? So I don't need to run npm install every time when I switch to this branch to test.

Copy link
Member

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

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

Still testing the functionality -- few code review comments.

backend/src/routes/api/status/statusUtils.ts Outdated Show resolved Hide resolved
backend/src/devFlags.ts Outdated Show resolved Hide resolved
backend/src/utils/directCallUtils.ts Outdated Show resolved Hide resolved
backend/src/utils/constants.ts Outdated Show resolved Hide resolved
docs/SDK.md Outdated Show resolved Hide resolved
backend/src/routes/api/status/statusUtils.ts Outdated Show resolved Hide resolved
@DaoDaoNoCode
Copy link
Member

This PR currently covers most of the situations which directly make API calls to k8s resources. However, it could have some problems when making API calls to the external routes (like prometheus), the Impersonate-User field doesn't work, it will still use the bearer token of the login user.

@lucferbux
Copy link
Contributor Author

/assign @andrewballantyne

Copy link
Member

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

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

I think we need to do one more iteration to get this into merging state.

Only downfall I see that is not addressed in my comments is when I change the server code, it does not update my client back to a state of understanding that the impersonation was lost. This is probably fine -- we don't do a lot of server dev, and we have #964 coming.

backend/src/routes/api/dev-impersonate/index.ts Outdated Show resolved Hide resolved
backend/src/utils/directCallUtils.ts Outdated Show resolved Hide resolved
@lucferbux
Copy link
Contributor Author

@andrewballantyne I resolved your comments since @DaoDaoNoCode update the PR, but I just want to add that we still fall short in one scenario, but I think is no longer relevant.

We still use the primary logged user as the rbac for the backend calls, so we still don't have a 1:1 relation to the dashboard's serviceaccount. This is still an issue if we are developing any backend feature (it might work in local as we have cluster admin but then it won't work deployed because the dashboard role doesn't have those permissions).

It's similar to the prometheus workaround, something that we can easily test now as we can deploy images built by that PR. One easy workaround would be create a user that mimics the same permissions as the dashboard serviceaccount, but I would do it outside this PR in addition of the script that Andrew has for creating users in clusters.

@openshift-ci openshift-ci bot added the lgtm label Mar 1, 2023
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 1, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andrewballantyne

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

@openshift-ci openshift-ci bot added the approved label Mar 1, 2023
@openshift-merge-robot openshift-merge-robot merged commit 74188de into opendatahub-io:main Mar 1, 2023
jenny-s51 added a commit to jenny-s51/odh-dashboard that referenced this pull request Mar 6, 2023
more workbenches a11y updates

fix dsp modal

fix more select issues

prettier

Add faker for the pass through api to enable regular user testing (opendatahub-io#806)

* Add faker for the pass through api to enable regular user testing

* Add faker for backend openshift user

* add impersonate function for developers

* address comments and modify the doc

* Update to get the access token by making API call

* update doc

* add error message

* Fix lint issues

* address comments

---------

Co-authored-by: Juntao Wang <juntwang@redhat.com>

Storybook test integration (opendatahub-io#974)

* added storybook boilerplate

added a mock and decorator

added tests

fixed deps for storybook

linter

old tests dont work on jest 28, reverting

linter error fix

fix build errors

fixed deps

* trimmed mocks

fixed tests

* fix webpack changes

* added a11y test to test-runner

fix a11y errors in settings (opendatahub-io#979)

varname

rename bodyText to ariaLabel

add aria label to select

add aria-label to Select

fix a11y violation in cluster storage modal and list view
jenny-s51 added a commit to jenny-s51/odh-dashboard that referenced this pull request Mar 6, 2023
more workbenches a11y updates

fix dsp modal

fix more select issues

prettier

Add faker for the pass through api to enable regular user testing (opendatahub-io#806)

* Add faker for the pass through api to enable regular user testing

* Add faker for backend openshift user

* add impersonate function for developers

* address comments and modify the doc

* Update to get the access token by making API call

* update doc

* add error message

* Fix lint issues

* address comments

---------

Co-authored-by: Juntao Wang <juntwang@redhat.com>

Storybook test integration (opendatahub-io#974)

* added storybook boilerplate

added a mock and decorator

added tests

fixed deps for storybook

linter

old tests dont work on jest 28, reverting

linter error fix

fix build errors

fixed deps

* trimmed mocks

fixed tests

* fix webpack changes

* added a11y test to test-runner

fix a11y errors in settings (opendatahub-io#979)

varname

rename bodyText to ariaLabel

add aria label to select

add aria-label to Select

fix a11y violation in cluster storage modal and list view
jenny-s51 added a commit to jenny-s51/odh-dashboard that referenced this pull request Mar 6, 2023
more workbenches a11y updates

fix dsp modal

fix more select issues

prettier

Add faker for the pass through api to enable regular user testing (opendatahub-io#806)

* Add faker for the pass through api to enable regular user testing

* Add faker for backend openshift user

* add impersonate function for developers

* address comments and modify the doc

* Update to get the access token by making API call

* update doc

* add error message

* Fix lint issues

* address comments

---------

Co-authored-by: Juntao Wang <juntwang@redhat.com>

Storybook test integration (opendatahub-io#974)

* added storybook boilerplate

added a mock and decorator

added tests

fixed deps for storybook

linter

old tests dont work on jest 28, reverting

linter error fix

fix build errors

fixed deps

* trimmed mocks

fixed tests

* fix webpack changes

* added a11y test to test-runner

fix a11y errors in settings (opendatahub-io#979)

varname

rename bodyText to ariaLabel

add aria label to select

add aria-label to Select

fix a11y violation in cluster storage modal and list view
jenny-s51 added a commit to jenny-s51/odh-dashboard that referenced this pull request Mar 7, 2023
more workbenches a11y updates

fix dsp modal

fix more select issues

prettier

Add faker for the pass through api to enable regular user testing (opendatahub-io#806)

* Add faker for the pass through api to enable regular user testing

* Add faker for backend openshift user

* add impersonate function for developers

* address comments and modify the doc

* Update to get the access token by making API call

* update doc

* add error message

* Fix lint issues

* address comments

---------

Co-authored-by: Juntao Wang <juntwang@redhat.com>

Storybook test integration (opendatahub-io#974)

* added storybook boilerplate

added a mock and decorator

added tests

fixed deps for storybook

linter

old tests dont work on jest 28, reverting

linter error fix

fix build errors

fixed deps

* trimmed mocks

fixed tests

* fix webpack changes

* added a11y test to test-runner

fix a11y errors in settings (opendatahub-io#979)

varname

rename bodyText to ariaLabel

add aria label to select

add aria-label to Select

fix a11y violation in cluster storage modal and list view
jenny-s51 added a commit to jenny-s51/odh-dashboard that referenced this pull request Mar 8, 2023
more workbenches a11y updates

fix dsp modal

fix more select issues

prettier

remove unused import

revert id update

fix project modal

wip Workbenches, need image

more workbenches a11y updates

fix dsp modal

fix more select issues

prettier

Add faker for the pass through api to enable regular user testing (opendatahub-io#806)

* Add faker for the pass through api to enable regular user testing

* Add faker for backend openshift user

* add impersonate function for developers

* address comments and modify the doc

* Update to get the access token by making API call

* update doc

* add error message

* Fix lint issues

* address comments

---------

Co-authored-by: Juntao Wang <juntwang@redhat.com>

Storybook test integration (opendatahub-io#974)

* added storybook boilerplate

added a mock and decorator

added tests

fixed deps for storybook

linter

old tests dont work on jest 28, reverting

linter error fix

fix build errors

fixed deps

* trimmed mocks

fixed tests

* fix webpack changes

* added a11y test to test-runner

fix a11y errors in settings (opendatahub-io#979)

varname

rename bodyText to ariaLabel

add aria label to select

add aria-label to Select

fix a11y violation in cluster storage modal and list view

package-lock.json

package-lock.json

update DetailsSection.tsx

remove aria-labelledby

Table PR suggestion from Gage

lint and revert Stack removal
jenny-s51 added a commit to jenny-s51/odh-dashboard that referenced this pull request Mar 9, 2023
more workbenches a11y updates

fix dsp modal

fix more select issues

prettier

remove unused import

revert id update

fix project modal

revert stack

wip Workbenches, need image

more workbenches a11y updates

fix dsp modal

fix more select issues

prettier

Add faker for the pass through api to enable regular user testing (opendatahub-io#806)

* Add faker for the pass through api to enable regular user testing

* Add faker for backend openshift user

* add impersonate function for developers

* address comments and modify the doc

* Update to get the access token by making API call

* update doc

* add error message

* Fix lint issues

* address comments

---------

Co-authored-by: Juntao Wang <juntwang@redhat.com>

Storybook test integration (opendatahub-io#974)

* added storybook boilerplate

added a mock and decorator

added tests

fixed deps for storybook

linter

old tests dont work on jest 28, reverting

linter error fix

fix build errors

fixed deps

* trimmed mocks

fixed tests

* fix webpack changes

* added a11y test to test-runner

fix a11y errors in settings (opendatahub-io#979)

varname

rename bodyText to ariaLabel

add aria label to select

add aria-label to Select

fix a11y violation in cluster storage modal and list view

package-lock.json

package-lock.json

fix a11y in data connections and models/model servers

update DetailsSection to match changes on other branch

update Table file

fix pagination axe error

PR feedback from Andrew

change aria label text on password input
bartoszmajsak pushed a commit to maistra/odh-dashboard that referenced this pull request Mar 30, 2023
…endatahub-io#806)

* Add faker for the pass through api to enable regular user testing

* Add faker for backend openshift user

* add impersonate function for developers

* address comments and modify the doc

* Update to get the access token by making API call

* update doc

* add error message

* Fix lint issues

* address comments

---------

Co-authored-by: Juntao Wang <juntwang@redhat.com>
strangiato pushed a commit to strangiato/odh-dashboard that referenced this pull request Oct 18, 2023
…endatahub-io#806)

* Add faker for the pass through api to enable regular user testing

* Add faker for backend openshift user

* add impersonate function for developers

* address comments and modify the doc

* Update to get the access token by making API call

* update doc

* add error message

* Fix lint issues

* address comments

---------

Co-authored-by: Juntao Wang <juntwang@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Dev]: We have issues testing permissions locally
4 participants