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

Identity provider login from mediator CLI #1014

Merged
merged 1 commit into from
Sep 29, 2023

Conversation

eleftherias
Copy link
Contributor

@eleftherias eleftherias commented Sep 25, 2023

Relates to #691.

To try out this PR:

  • Regenerate protobuf stubs make gen
  • Regenerate queries make sqlc
  • Drop existing database and re-run migration make migrateup
  • Start Keycloak (make sure post 8081 is free on your machine) docker-compose up -d keycloak
  • Rebuild make build
  • Add new configuration parameters under identity to your config.yaml (see updates to config/config.yaml.example)
  • Log in with the usual command, minus the username and password ./bin/medic auth login. The superadmin credentials are the same.

Things that you can try:

  • Log in with the same superadmin credentials
  • Superadmin is forced to change their password
  • Additional users can create an account and log in, but they are not authorized to perform any actions yet

To add Social login:

  • For GitHub, create an OAuth2 application here. The callback URL should be http://localhost:8081/realms/stacklok/broker/github/endpoint
  • Open the file identity/import/stacklok-realm-with-user-and-client.json
  • Replace ”identityProviders" : [ ], with the following, using your generated client ID and client secret:
”identityProviders" : [
  {
  "alias" : "github",
  "internalId" : "afb4fd44-b6d7-4cff-a4ff-12735ca09b02",
  "providerId" : "github",
  "enabled" : true,
  "updateProfileFirstLoginMode" : "on",
  "trustEmail" : false,
  "storeToken" : false,
  "addReadTokenRoleOnCreate" : false,
  "authenticateByDefault" : false,
  "linkOnly" : false,
  "firstBrokerLoginFlowAlias" : "first broker login",
  "config" : {
    "clientSecret" : "the-client-secret-you-generated",
    "clientId" : "the-client-id-you-generated"
  }
 }
],

To add Google login, the steps are the same, but with a different provider ID. Feel free to reach out if you want to experiment with Google login and want help.

Alternatively, you can add social login via the Keycloak admin console, but note that this configuration will disappear if you restart Keycloak.

Things for a different PR:

  • Clean up readme and getting started documentation
  • Use refresh token to fetch new access token when needed (currently expires after 5 minutes and log in is required again)
  • Add configurable database connection for user storage
  • Logout
  • Branding and styling on account page
  • Account deletion
  • Forgot password flow
  • Creating organization, group and role for any new users

cmd/server/app/serve.go Outdated Show resolved Hide resolved
Copy link
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

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

Awesome work!

I started to read the PR and left several comments but I haven't really even read the whole PR yet..

docker-compose.yaml Outdated Show resolved Hide resolved
cmd/cli/app/auth/auth_login.go Outdated Show resolved Hide resolved
cmd/cli/app/auth/auth_login.go Outdated Show resolved Hide resolved
cmd/cli/app/auth/auth_login.go Outdated Show resolved Hide resolved
}

// we can create the default user
user, err := qtx.CreateUser(ctx, db.CreateUserParams{
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you have any thoughts on the org admin users going forward, e.g. did you plan on using roles instead of the org admin users?

Copy link
Contributor

Choose a reason for hiding this comment

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

using roles assigned to projects/orgs would be ideal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking when a user logs in for the first time a new org, group and role would be created, making the user an admin of their own org. The same as what we used to do for self-enrolled users.

Copy link
Contributor

Choose a reason for hiding this comment

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

@eleftherias let's go for that, it goes in accordance to our plans for the initial SaaS

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to do this in a separate PR. For now, all users get added to organization 1.

Copy link
Contributor

@JAORMX JAORMX left a comment

Choose a reason for hiding this comment

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

Good progress! Left some comments.

database/migrations/000001_init.up.sql Show resolved Hide resolved
cmd/cli/app/auth/auth_login.go Show resolved Hide resolved
cmd/cli/app/user/user_update.go Outdated Show resolved Hide resolved
internal/config/identity.go Show resolved Hide resolved
internal/auth/jwtauth.go Outdated Show resolved Hide resolved
cmd/server/app/serve.go Outdated Show resolved Hide resolved
}

// we can create the default user
user, err := qtx.CreateUser(ctx, db.CreateUserParams{
Copy link
Contributor

Choose a reason for hiding this comment

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

using roles assigned to projects/orgs would be ideal.

@eleftherias eleftherias force-pushed the social-login branch 5 times, most recently from 43927a4 to a11c4ff Compare September 28, 2023 11:51
@eleftherias eleftherias changed the title WIP: social logins and identity provider Identity provider login from mediator CLI Sep 28, 2023
@eleftherias eleftherias marked this pull request as ready for review September 28, 2023 12:57
JAORMX
JAORMX previously approved these changes Sep 28, 2023
Copy link
Contributor

@JAORMX JAORMX left a comment

Choose a reason for hiding this comment

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

I really dig that this also replaces a bunch of the tech debt we had in JWT validation.

I tried this out locally. Had a small hickup when logging in with a GitHub user the first time, but it worked on the second attempt.

There are some next steps to do:

  • Generate Keycloak config programmatically
  • Allow for a non-git tracked config that folks could overwrite
  • roles for users that come from an idp

But this really moves us forward! great work!

Copy link
Contributor

@lukehinds lukehinds left a comment

Choose a reason for hiding this comment

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

nit: will need a docs update (can be follow up PR, as long as it gets done at some point) https://mediator-docs.stacklok.dev/run-the-login_medic

cmd/cli/app/auth/auth_login.go Show resolved Hide resolved
cmd/cli/app/auth/auth_login.go Outdated Show resolved Hide resolved
Copy link
Contributor

@lukehinds lukehinds left a comment

Choose a reason for hiding this comment

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

lgtm

@eleftherias eleftherias merged commit 38091a0 into mindersec:main Sep 29, 2023
13 checks passed
@eleftherias eleftherias deleted the social-login branch September 29, 2023 07:18
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.

5 participants