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

feat: support oidc federated authentication #166

Merged
merged 2 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ func (c *Config) NewAuthorizer(ctx context.Context, api environments.Api) (Autho
}
}

if c.EnableClientFederatedAuth {
a, err := NewClientFederatedAuthorizer(ctx, c.Environment, api, c.Version, c.TenantID, c.AuxiliaryTenantIDs, c.ClientID, c.FederatedAssertion)
if err != nil {
return nil, fmt.Errorf("could not configure ClientCertificate Authorizer: %s", err)
}
if a != nil {
return a, nil
}
}

if c.EnableGitHubOIDCAuth {
a, err := NewGitHubOIDCAuthorizer(context.Background(), c.Environment, api, c.TenantID, c.AuxiliaryTenantIDs, c.ClientID, c.IDTokenRequestURL, c.IDTokenRequestToken)
if err != nil {
Expand Down Expand Up @@ -163,6 +173,22 @@ func NewClientSecretAuthorizer(ctx context.Context, environment environments.Env
return conf.TokenSource(ctx, ClientCredentialsSecretType), nil
}

// NewClientSecretAuthorizer returns an authorizer which uses client secret authentication.
func NewClientFederatedAuthorizer(ctx context.Context, environment environments.Environment, api environments.Api, tokenVersion TokenVersion, tenantId string, auxTenantIds []string, clientId, federatedAssertion string) (Authorizer, error) {
conf := ClientCredentialsConfig{
Environment: environment,
TenantID: tenantId,
AuxiliaryTenantIDs: auxTenantIds,
ClientID: clientId,
FederatedAssertion: federatedAssertion,
Resource: api.Resource(),
Scopes: []string{api.DefaultScope()},
TokenVersion: tokenVersion,
}

return conf.TokenSource(ctx, ClientCredentialsAssertionType), nil
}

// NewGitHubOIDCAuthorizer returns an authorizer which acquires a client assertion from a GitHub endpoint, then uses client assertion authentication to obtain an access token.
func NewGitHubOIDCAuthorizer(ctx context.Context, environment environments.Environment, api environments.Api, tenantId string, auxTenantIds []string, clientId, idTokenRequestUrl, idTokenRequestToken string) (Authorizer, error) {
conf := GitHubOIDCConfig{
Expand Down
6 changes: 6 additions & 0 deletions auth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ type Config struct {
// Specifies the password to authenticate with using client secret authentication
ClientSecret string

// Enables OIDC Federated authentication
EnableClientFederatedAuth bool

// Specifies the federated assertion to authenticate using client credentials
FederatedAssertion string

// Enables GitHub OIDC authentication
EnableGitHubOIDCAuth bool

Expand Down