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

Creating providers with config #3334

Merged
merged 8 commits into from
Jun 4, 2024
Merged

Conversation

jhrozek
Copy link
Contributor

@jhrozek jhrozek commented May 15, 2024

Summary

This would create a provider with custom configuration.

The OAuth code is generic and can be used by any provider. The GH App config code is very GH App specific, but that whole flow is unlikely to be reusable, so I think that's fine.

With github you can enroll either with oauth:

minder provider enroll -c github -n my-little-oauth-github -o jakubtestorg --config /tmp/github-config.json --yes

or:

minder provider enroll -c github -n my-little-github -o jakubtestorg -t ghp_token --config /tmp/github-config.json --yes

Change Type

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

Testing

see above

Review Checklist:

  • [not at all] Reviewed my own code for quality and clarity.
  • [nope] Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • [lol no] Included tests that validate the fix or feature.
  • Checked that related changes are merged.

Copy link
Contributor

@stacklokbot stacklokbot left a comment

Choose a reason for hiding this comment

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

✅ No Invisible Unicode Characters Detected.

proto/minder/v1/minder.proto Outdated Show resolved Hide resolved
internal/providers/store.go Outdated Show resolved Hide resolved
@jhrozek jhrozek force-pushed the prov_cfg_create branch from 743b58a to 71b9120 Compare May 15, 2024 21:30
Copy link
Contributor

@stacklokbot stacklokbot left a comment

Choose a reason for hiding this comment

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

✅ No Invisible Unicode Characters Detected.

Copy link
Contributor

@stacklokbot stacklokbot left a comment

Choose a reason for hiding this comment

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

✅ No Mixed Scripts Detected.

internal/controlplane/handlers_oauth.go Outdated Show resolved Hide resolved
internal/providers/github/manager/manager.go Outdated Show resolved Hide resolved
return nil, fmt.Errorf("error getting provider config: %w", err)
}

// This method feels like it should be part of the class manager?
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it probably should :) ... but I would not block on it.

internal/providers/manager/manager.go Outdated Show resolved Hide resolved
internal/providers/manager/manager.go Outdated Show resolved Hide resolved
cmd/cli/app/provider/provider_enroll.go Outdated Show resolved Hide resolved
cmd/cli/app/provider/provider_enroll.go Outdated Show resolved Hide resolved
internal/controlplane/handlers_providers.go Outdated Show resolved Hide resolved
@jhrozek jhrozek force-pushed the prov_cfg_create branch from 71b9120 to d7a8a13 Compare May 17, 2024 14:51
Copy link
Contributor

@stacklokbot stacklokbot left a comment

Choose a reason for hiding this comment

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

✅ No Invisible Unicode Characters Detected.

Copy link
Contributor

@stacklokbot stacklokbot left a comment

Choose a reason for hiding this comment

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

✅ No Mixed Scripts Detected.

@jhrozek jhrozek force-pushed the prov_cfg_create branch from d7a8a13 to 55cae72 Compare May 24, 2024 11:35
@jhrozek jhrozek marked this pull request as ready for review May 24, 2024 11:37
@jhrozek jhrozek requested a review from a team as a code owner May 24, 2024 11:37
@jhrozek
Copy link
Contributor Author

jhrozek commented May 24, 2024

No longer a draft. Even after splitting some patches out, this is still a relatively large PR. I would welcome ideas on how to split it.

@jhrozek jhrozek changed the title WIP: Creating providers with config Creating providers with config May 24, 2024
@jhrozek jhrozek linked an issue May 24, 2024 that may be closed by this pull request
@jhrozek jhrozek force-pushed the prov_cfg_create branch from 55cae72 to 5071c5a Compare May 24, 2024 11:59
@coveralls
Copy link

coveralls commented May 24, 2024

Coverage Status

coverage: 52.699% (+0.2%) from 52.48%
when pulling 377d3a3 on jhrozek:prov_cfg_create
into a896873 on stacklok:main.

@jhrozek jhrozek force-pushed the prov_cfg_create branch from 908ef20 to fd31211 Compare May 27, 2024 09:16
// See the License for the specific language governing permissions and
// limitations under the License.

// Package session contains the business logic for creating providers from session state.
Copy link
Contributor

@dmjb dmjb May 30, 2024

Choose a reason for hiding this comment

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

Thought: I wonder if we should move other session state logic in here in future. (not a blocker for this PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍🏻

return g.ghService.GetConfig(ctx, class, userConfig)
}

func fallbackOAuthClientConfigValues(provider string, cfg *server.OAuthClientConfig) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we do this config-reading logic once at application startup?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@jhrozek jhrozek force-pushed the prov_cfg_create branch from fd31211 to 29c2b04 Compare May 31, 2024 08:54
@jhrozek
Copy link
Contributor Author

jhrozek commented May 31, 2024

@dmjb ready for another review

jhrozek added 8 commits June 4, 2024 11:49
…iderTracker

In order to be able to add the providerAuthManager in the next step and
avoid code duplication, let's make the providerClassManager a little
more reusable by extracting the code that tracks registered classes.
Adds the providerAuthManager interface that exposes per-provider OAuth
settings. This allows the provider creation in an OAuth callback to let
the provider specific code sit in the provider codebase and let the
creation be provider agnostic.

ALso creates a sessionService that currently allows to create a provider
from a session record that is created before the OAuth conversation.

Fixes: mindersec#3263
Adds the CLI support for creating an OAuth provider with a config.
Allows to pass provider configuration when creating a GH app. This will
be useful for creating providers with repository auto-enrollment.

Fixes: mindersec#3263

Unlike the OAuth flow which is reusable for any provider, the GH App
flow is quite GH-app specific and thus uses the original GH app handler.
We added a ProviderConfig-based structure but then in a subsequent patch
we overwrite its values unconditionally. Let's only overwrite them when
set.
Based on review feedback, to isolate the fallback code.
@jhrozek jhrozek force-pushed the prov_cfg_create branch from 29c2b04 to 377d3a3 Compare June 4, 2024 12:31
@jhrozek jhrozek merged commit e578bf8 into mindersec:main Jun 4, 2024
20 checks passed
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.

Add a mechanism to add provider configuration on enrollment
5 participants