Skip to content

Commit

Permalink
Add GitHub as a Provider (#157)
Browse files Browse the repository at this point in the history
Primarily for a demo, because it looks cool, but also because I'm using
a non-Google/Microsoft account, and as it happens GitHub acts as a great
aggregator of email accounts.
  • Loading branch information
spjmurray authored Jan 23, 2025
1 parent 824b494 commit e897d64
Show file tree
Hide file tree
Showing 7 changed files with 357 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ spec:
OAuth2ProviderSpec defines the required configuration for an oauth2
provider.
properties:
authorizatonURI:
description: AuthorizationURI is used when OIDC (discovery) is not
available.
type: string
clientID:
description: ClientID is the assigned client identifier.
type: string
Expand Down Expand Up @@ -84,6 +88,9 @@ spec:
- value
type: object
type: array
tokenURI:
description: TokenURI is used when OIDC (discovery) is not available.
type: string
type:
description: |-
Type defines the interface to use with the provider, specifically
Expand All @@ -95,6 +102,7 @@ spec:
- custom
- google
- microsoft
- github
type: string
required:
- clientID
Expand Down
5 changes: 1 addition & 4 deletions charts/identity/templates/oauth2provider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,5 @@ metadata:
unikorn-cloud.org/description: {{ $spec.description }}
{{- end }}
spec:
type: {{ $spec.type }}
issuer: {{ $spec.issuer }}
clientID: {{ $spec.clientID }}
clientSecret: {{ $spec.clientSecret }}
{{- toYaml $spec | nindent 2 }}
{{- end }}
9 changes: 7 additions & 2 deletions pkg/apis/unikorn/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import (

// IdentityProviderType defines the type of identity provider, and in turn
// that defines the required configuration and API interfaces.
// +kubebuilder:validation:Enum=custom;google;microsoft
// +kubebuilder:validation:Enum=custom;google;microsoft;github
type IdentityProviderType string

const (
GoogleIdentity IdentityProviderType = "google"
MicrosoftEntra IdentityProviderType = "microsoft"
GitHub IdentityProviderType = "github"
)

// OAuth2ClientList is a typed list of frontend clients.
Expand Down Expand Up @@ -114,7 +115,11 @@ type OAuth2ProviderSpec struct {
// ClientID is the assigned client identifier.
ClientID string `json:"clientID"`
// ClientSecret is created by the IdP for token exchange.
ClientSecret *string `json:"clientSecret,omitempty"`
ClientSecret string `json:"clientSecret,omitempty"`
// AuthorizationURI is used when OIDC (discovery) is not available.
AuthorizationURI *string `json:"authorizatonURI,omitempty"`
// TokenURI is used when OIDC (discovery) is not available.
TokenURI *string `json:"tokenURI,omitempty"`
}

// OAuth2ProviderStatus defines the status of the server.
Expand Down
9 changes: 7 additions & 2 deletions pkg/apis/unikorn/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (h *Handler) GetOauth2V2Jwks(w http.ResponseWriter, r *http.Request) {
}

func (h *Handler) GetOidcCallback(w http.ResponseWriter, r *http.Request) {
h.oauth2.OIDCCallback(w, r)
h.oauth2.Callback(w, r)
}

func (h *Handler) GetApiV1Oauth2providers(w http.ResponseWriter, r *http.Request) {
Expand Down
10 changes: 7 additions & 3 deletions pkg/handler/oauth2providers/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,16 @@ func (c *Client) generate(ctx context.Context, organization *organizations.Meta,
out := &unikornv1.OAuth2Provider{
ObjectMeta: conversion.NewObjectMetadata(&in.Metadata, organization.Namespace, info.Userinfo.Sub).WithOrganization(organization.ID).Get(),
Spec: unikornv1.OAuth2ProviderSpec{
Issuer: in.Spec.Issuer,
ClientID: in.Spec.ClientID,
ClientSecret: in.Spec.ClientSecret,
Issuer: in.Spec.Issuer,
ClientID: in.Spec.ClientID,
},
}

// TODO: always require this to be written.
if in.Spec.ClientSecret != nil {
out.Spec.ClientSecret = *in.Spec.ClientSecret
}

out.Spec.Tags = conversion.GenerateTagList(in.Metadata.Tags)

return out, nil
Expand Down
Loading

0 comments on commit e897d64

Please sign in to comment.