Skip to content

Commit

Permalink
render kube config using the authenticated user.
Browse files Browse the repository at this point in the history
instead of a hardcoded value, the configuration file uses the user
information from the authentication context for the user and context
settings.

closes #45
  • Loading branch information
UiP9AV6Y committed Jan 26, 2022
1 parent 75b0795 commit 6dda52b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
5 changes: 2 additions & 3 deletions handlers/kubecfg/kubecfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
)

const (
templateUser = "kubehook"
queryParamLifetime = "lifetime"
)

Expand Down Expand Up @@ -67,7 +66,7 @@ func Handler(g auth.Generator, template *api.Config, h handlers.AuthHeaders) htt
return
}

y, err := clientcmd.Write(populateUser(template, templateUser, t))
y, err := clientcmd.Write(populateUser(template, u, t))
if err != nil {
http.Error(w, errors.Wrap(err, "cannot marshal template to YAML").Error(), http.StatusInternalServerError)
return
Expand All @@ -89,7 +88,7 @@ func populateUser(cfg *api.Config, username, token string) api.Config {
}
for name, cluster := range cfg.Clusters {
c.Clusters[name] = cluster
c.Contexts[name] = &api.Context{Cluster: name, AuthInfo: templateUser}
c.Contexts[name] = &api.Context{Cluster: name, AuthInfo: username}
}
c.CurrentContext = cfg.CurrentContext
return c
Expand Down
12 changes: 6 additions & 6 deletions handlers/kubecfg/kubecfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ func TestHandler(t *testing.T) {
"b": &api.Cluster{Server: "https://example.net", CertificateAuthorityData: []byte("PAM")},
},
Contexts: map[string]*api.Context{
"a": &api.Context{AuthInfo: templateUser, Cluster: "a"},
"b": &api.Context{AuthInfo: templateUser, Cluster: "b"},
"a": &api.Context{AuthInfo: user, Cluster: "a"},
"b": &api.Context{AuthInfo: user, Cluster: "b"},
},
AuthInfos: map[string]*api.AuthInfo{templateUser: &api.AuthInfo{Token: user}},
AuthInfos: map[string]*api.AuthInfo{user: &api.AuthInfo{Token: user}},
},
},
{
Expand All @@ -83,10 +83,10 @@ func TestHandler(t *testing.T) {
"b": &api.Cluster{Server: "https://example.net", CertificateAuthorityData: []byte("PAM")},
},
Contexts: map[string]*api.Context{
"a": &api.Context{AuthInfo: templateUser, Cluster: "a"},
"b": &api.Context{AuthInfo: templateUser, Cluster: "b"},
"a": &api.Context{AuthInfo: user, Cluster: "a"},
"b": &api.Context{AuthInfo: user, Cluster: "b"},
},
AuthInfos: map[string]*api.AuthInfo{templateUser: &api.AuthInfo{Token: user}},
AuthInfos: map[string]*api.AuthInfo{user: &api.AuthInfo{Token: user}},
},
},
{
Expand Down

0 comments on commit 6dda52b

Please sign in to comment.