Skip to content

Commit

Permalink
[OSD-20024] Allow GetRestConfigAsUser with elevationReason (#294)
Browse files Browse the repository at this point in the history
* Allow GetRestConfigAsUser with elevationReason

* integrate suggestions
  • Loading branch information
Tof1973 committed Dec 18, 2023
1 parent 4fd23c7 commit 47cdaea
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cmd/ocm-backplane/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,20 @@ func GetRestConfig(bp config.BackplaneConfiguration, clusterID string) (*rest.Co

// GetRestConfigAsUser returns a client-go *rest.Config like GetRestConfig, but supports configuring an
// impersonation username. Commonly, this is "backplane-cluster-admin"
func GetRestConfigAsUser(bp config.BackplaneConfiguration, clusterID, username string) (*rest.Config, error) {
// best practice would be to add at least one elevationReason in order to justity the impersonation
func GetRestConfigAsUser(bp config.BackplaneConfiguration, clusterID, username string, elevationReasons ...string) (*rest.Config, error) {
cfg, err := GetRestConfig(bp, clusterID)
if err != nil {
return nil, err
}

cfg.Impersonate = rest.ImpersonationConfig{UserName: username}
cfg.Impersonate = rest.ImpersonationConfig{
UserName: username,
}

if len(elevationReasons) > 0 {
cfg.Impersonate.Extra = map[string][]string{"reason": elevationReasons}
}

return cfg, nil
}
Expand Down

0 comments on commit 47cdaea

Please sign in to comment.