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

SSO: Add GitHub auth configuration page #78933

Merged
merged 54 commits into from
Dec 21, 2023
Merged

SSO: Add GitHub auth configuration page #78933

merged 54 commits into from
Dec 21, 2023

Conversation

Clarity-89
Copy link
Contributor

What is this feature?

Enable configuring SSO for GitHub from the UI.

Which issue(s) does this PR fix?:

Part of https://github.com/grafana/identity-access-team/issues/500.

Special notes for your reviewer:
Screenshot 2023-12-01 at 7 56 26

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

@Clarity-89 Clarity-89 self-assigned this Dec 1, 2023
@grafana-delivery-bot grafana-delivery-bot bot added this to the 10.3.x milestone Dec 1, 2023
@@ -0,0 +1,117 @@
import { css } from '@emotion/css';
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 is a copy of the component from Enterprise. It'd be removed from there and this version should be used instead.

@Clarity-89 Clarity-89 marked this pull request as ready for review December 1, 2023 08:19
@Clarity-89 Clarity-89 requested review from a team as code owners December 1, 2023 08:19
@Clarity-89 Clarity-89 requested review from tskarhed, L-M-K-B and mgyongyosi and removed request for a team, tskarhed and L-M-K-B December 1, 2023 08:19
@Clarity-89
Copy link
Contributor Author

/deploy-to-hg

@ephemeral-instances-bot
Copy link

  • Preparing your instance. A comment containing your instance's url will be added to this PR when the instance is ready.
  • Your instance will be ready in ~10 minutes.
  • Check the GitHub actions tab to follow the workflow progress
  • Slack channel: #proj-ephemeral-hg-instances
  • Building instance with sso/advanced-auth oss branch and main enterprise branch. How to choose a branch

@ephemeral-instances-bot
Copy link

# Conflicts:
#	docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md
Copy link
Contributor

@dmihai dmihai left a comment

Choose a reason for hiding this comment

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

The UI for configuring the SSO settings for providers looks good, I only found a couple of small issues while testing locally:

  • When clicking on a provider from the /admin/authentication page, the UI can load the provider data using the get provider endpoint (for github: /api/v1/sso-settings/github) instead of list all providers endpoint (api/v1/sso-settings)
  • In the provider form page (admin/authentication/advanced/github), if the user clicks on any field without modifying its value then the form becomes "dirty" and clicking on Discard will show the modal with the 2 options: Continue editing and Discard unsaved changes. I think the form should become dirty only after a value has been modified.
  • After saving the changes from a provider config page (admin/authentication/advanced/github) the notification Settings saved appears but then the user cannot directly navigate to a different page because the modal Leave page? Changes that you made may not be saved. with 2 options (leave page, discard changes) appears. This may happen because UI expects PUT api/v1/sso-settings/github to respond with 204 No Content instead of 200 OK (I modified this while testing locally).
  • When the user changes the config for a provider, The UI should send only the fields that the user can change. For example, for github those fields are: clientId, clientSecret, teamIds, allowedOrganizations. Now the UI also sends fields that cannot be modified by the user, for example: tlsClientCa, hostedDomain.

public/app/features/auth-config/fields.ts Outdated Show resolved Hide resolved
public/app/features/auth-config/types.ts Outdated Show resolved Hide resolved
@Clarity-89
Copy link
Contributor Author

  • When the user changes the config for a provider, The UI should send only the fields that the user can change. For example, for github those fields are: clientId, clientSecret, teamIds, allowedOrganizations. Now the UI also sends fields that cannot be modified by the user, for example: tlsClientCa, hostedDomain.

This was specifically requested, so that's why it works the way it is.

@dmihai
Copy link
Contributor

dmihai commented Dec 21, 2023

  • When the user changes the config for a provider, The UI should send only the fields that the user can change. For example, for github those fields are: clientId, clientSecret, teamIds, allowedOrganizations. Now the UI also sends fields that cannot be modified by the user, for example: tlsClientCa, hostedDomain.

This was specifically requested, so that's why it works the way it is.

Okay, lets keep the current behaviour for now and see later if we want to change it.

@Clarity-89
Copy link
Contributor Author

  • After saving the changes from a provider config page (admin/authentication/advanced/github) the notification Settings saved appears but then the user cannot directly navigate to a different page because the modal Leave page? Changes that you made may not be saved. with 2 options (leave page, discard changes) appears. This may happen because UI expects PUT api/v1/sso-settings/github to respond with 204 No Content instead of 200 OK (I modified this while testing locally).

I thought that part was not ready yet? When I try to submit a form for any provider I get Bad request error and see this in the logs:

ERROR[12-21|13:14:39] Failed to parse request body logger=context userId=1 orgId=1 uname=admin error="json: cannot unmarshal string into Go struct field .source of type models.SettingsSource" remote_addr=127.0.0.1 traceID=

@Clarity-89
Copy link
Contributor Author

  • After saving the changes from a provider config page (admin/authentication/advanced/github) the notification Settings saved appears but then the user cannot directly navigate to a different page because the modal Leave page? Changes that you made may not be saved. with 2 options (leave page, discard changes) appears. This may happen because UI expects PUT api/v1/sso-settings/github to respond with 204 No Content instead of 200 OK (I modified this while testing locally).

I thought that part was not ready yet? When I try to submit a form for any provider I get Bad request error and see this in the logs:

ERROR[12-21|13:14:39] Failed to parse request body logger=context userId=1 orgId=1 uname=admin error="json: cannot unmarshal string into Go struct field .source of type models.SettingsSource" remote_addr=127.0.0.1 traceID=

I've figured out how to fix this without a working API.

@Clarity-89 Clarity-89 removed request for grafanabot and a team December 21, 2023 12:06
Copy link
Contributor

@dmihai dmihai left a comment

Choose a reason for hiding this comment

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

Tested and it works/looks great. Great work!

return async (dispatch) => {
if (!config.featureToggles.ssoSettingsApi) {
return [];
}
const result = await getBackendSrv().get('/api/v1/sso-settings');
dispatch(providersLoaded(result));
const result = await getBackendSrv().get(`/api/v1/sso-settings/${provider}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

If provider is empty and we want the list of all providers then the URL should not contain the ending /. So for requesting the list of providers this should be used /api/v1/sso-settings instead of /api/v1/sso-settings/. If we include the / at the end then the backend will interpret it as a single provider request with an empty provider name (and it will return an error).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, I'll fix it.

@Clarity-89 Clarity-89 merged commit fde8a00 into main Dec 21, 2023
18 checks passed
@Clarity-89 Clarity-89 deleted the sso/advanced-auth branch December 21, 2023 13:26
@summerwollin summerwollin modified the milestones: 10.3.x, 10.3.0 Jan 22, 2024
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.

None yet

5 participants