Skip to content

Commit 2a29944

Browse files
authored
feat: Enable impersonation to be configurable through the app config (#82)
* made impersonation configurable through appconfig * remove previous made CORS implementation
1 parent 3aa7ac0 commit 2a29944

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

gateway/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ type Config struct {
1515
LocalDevelopment bool `envconfig:"default=false,optional"`
1616
HandlerCfg HandlerConfig
1717
UserNameClaim string `envconfig:"default=email,optional"`
18+
19+
ShouldImpersonate bool `envconfig:"default=true,optional"`
1820
}
1921

2022
type HandlerConfig struct {

gateway/manager/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func NewManager(log *logger.Logger, cfg *rest.Config, appCfg appConfig.Config) (
6565
cfg.Host = fmt.Sprintf("%s://%s", u.Scheme, u.Host)
6666

6767
cfg.Wrap(func(rt http.RoundTripper) http.RoundTripper {
68-
return NewRoundTripper(log, rt, appCfg.UserNameClaim)
68+
return NewRoundTripper(log, rt, appCfg.UserNameClaim, appCfg.ShouldImpersonate)
6969
})
7070

7171
runtimeClient, err := kcp.NewClusterAwareClientWithWatch(cfg, client.Options{})

gateway/manager/roundtripper.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ import (
1111
type TokenKey struct{}
1212

1313
type roundTripper struct {
14-
userClaim string
15-
log *logger.Logger
16-
base http.RoundTripper // TODO change to awareBaseHttp
14+
userClaim string
15+
log *logger.Logger
16+
base http.RoundTripper // TODO change to awareBaseHttp
17+
impersonate bool
1718
}
1819

19-
func NewRoundTripper(log *logger.Logger, base http.RoundTripper, userNameClaim string) http.RoundTripper {
20+
func NewRoundTripper(log *logger.Logger, base http.RoundTripper, userNameClaim string, impersonate bool) http.RoundTripper {
2021
return &roundTripper{
21-
log: log,
22-
base: base,
23-
userClaim: userNameClaim,
22+
log: log,
23+
base: base,
24+
userClaim: userNameClaim,
25+
impersonate: impersonate,
2426
}
2527
}
2628

@@ -31,6 +33,12 @@ func (rt *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
3133
return rt.base.RoundTrip(req)
3234
}
3335

36+
if !rt.impersonate {
37+
req.Header.Del("Authorization")
38+
t := transport.NewBearerAuthRoundTripper(token, rt.base)
39+
return t.RoundTrip(req)
40+
}
41+
3442
claims := jwt.MapClaims{}
3543
_, _, err := jwt.NewParser().ParseUnverified(token, claims)
3644
if err != nil {

0 commit comments

Comments
 (0)