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

Add option to fetch server secret from file #1199

Merged
merged 1 commit into from
Oct 16, 2023
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
20 changes: 20 additions & 0 deletions internal/config/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@

package config

import (
"fmt"
"os"
"path/filepath"
)

// IdentityConfig is the configuration for the identity provider
type IdentityConfig struct {
Cli CliIdentityConfig `mapstructure:"cli"`
Expand All @@ -41,4 +47,18 @@ type ServerIdentityConfig struct {
ClientId string `mapstructure:"client_id" default:"mediator-server"`
// ClientSecret is the client secret for the mediator server
ClientSecret string `mapstructure:"client_secret" default:"secret"`
// ClientSecretFile is the location of a file containing the client secret for the mediator server (optional)
ClientSecretFile string `mapstructure:"client_secret_file"`
}
eleftherias marked this conversation as resolved.
Show resolved Hide resolved

// GetClientSecret returns the mediator-server client secret
func (sic *ServerIdentityConfig) GetClientSecret() (string, error) {
if sic.ClientSecretFile != "" {
data, err := os.ReadFile(filepath.Clean(sic.ClientSecretFile))
if err != nil {
return "", fmt.Errorf("failed to read mediator secret from file: %w", err)
}
return string(data), nil
}
return sic.ClientSecret, nil
}
7 changes: 6 additions & 1 deletion internal/controlplane/handlers_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,14 @@ func (s *Server) DeleteUser(ctx context.Context,

tokenUrl := parsedURL.JoinPath("realms", s.cfg.Identity.Server.Realm, "protocol/openid-connect/token")

clientSecret, err := s.cfg.Identity.Server.GetClientSecret()
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get client secret: %v", err)
}

clientCredentials := clientcredentials.Config{
ClientID: s.cfg.Identity.Server.ClientId,
ClientSecret: s.cfg.Identity.Server.ClientSecret,
ClientSecret: clientSecret,
TokenURL: tokenUrl.String(),
}

Expand Down
8 changes: 7 additions & 1 deletion internal/controlplane/identity_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,15 @@ func HandleEvents(ctx context.Context, store db.Store, cfg *config.Config) {

tokenUrl := parsedURL.JoinPath("realms", cfg.Identity.Server.Realm, "protocol/openid-connect/token")

clientSecret, err := cfg.Identity.Server.GetClientSecret()
if err != nil {
zerolog.Ctx(ctx).Error().Msgf("failed to get client secret: %v", err)
eleftherias marked this conversation as resolved.
Show resolved Hide resolved
return
}

clientCredentials := clientcredentials.Config{
ClientID: cfg.Identity.Server.ClientId,
ClientSecret: cfg.Identity.Server.ClientSecret,
ClientSecret: clientSecret,
TokenURL: tokenUrl.String(),
}

Expand Down