Skip to content

Commit 5987cd4

Browse files
committed
Enable to switch context on kubeconfig
When user is logged in with kubeconfig, add selections for contexts included in kubeconfig into user menu and enable to switch contexts included in kubeconfig. This commit implements basic functionalities for switching contexts, so to set dashboard-metrics-scraper host for each `cluster`, you need to describe it as `sidecarHost` in `cluster` directive in kubeconfig. Note: To test this with `npm run start*`, enlarge maximum http header size with `export NODE_OPTIONS=--max-http-header-size=102400`.
1 parent a83047e commit 5987cd4

35 files changed

+717
-141
lines changed

aio/develop/run-npm-on-container.sh

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2626
LOCAL_UID=$(id -u)
2727
LOCAL_GID=$(id -g)
2828

29+
# Set max http header size for NodeJS
30+
NODE_OPTIONS=${NODE_OPTIONS:-"--max-http-header-size=102400"}
31+
2932
# K8S_DASHBOARD_NPM_CMD will be passed into container and will be used
3033
# by run-npm-command.sh on container. Then the shell sciprt will run `npm`
3134
# command with K8S_DASHBOAD_NPM_CMD.
@@ -88,6 +91,7 @@ docker run \
8891
-e K8S_DASHBOARD_DEBUG=${K8S_DASHBOARD_DEBUG} \
8992
-e LOCAL_UID="${LOCAL_UID}" \
9093
-e LOCAL_GID="${LOCAL_GID}" \
94+
-e NODE_OPTIONS="${NODE_OPTIONS}" \
9195
-p ${K8S_DASHBOARD_PORT}:${K8S_DASHBOARD_PORT} \
9296
-p ${K8S_DASHBOARD_DEBUG_PORT}:${K8S_DASHBOARD_DEBUG_PORT} \
9397
${DOCKER_RUN_OPTS} \

i18n/de/messages.de.xlf

+2-2
Original file line numberDiff line numberDiff line change
@@ -3020,7 +3020,7 @@
30203020
<target>Anmelden</target>
30213021
<context-group purpose="location">
30223022
<context context-type="sourcefile">../src/app/frontend/chrome/userpanel/template.html</context>
3023-
<context context-type="linenumber">37</context>
3023+
<context context-type="linenumber">43</context>
30243024
</context-group>
30253025
</trans-unit>
30263026
<trans-unit id="6426cc90184df1cdb238f45fce5220df8438ed62" datatype="html">
@@ -3029,7 +3029,7 @@
30293029
<target>Abmelden</target>
30303030
<context-group purpose="location">
30313031
<context context-type="sourcefile">../src/app/frontend/chrome/userpanel/template.html</context>
3032-
<context context-type="linenumber">42</context>
3032+
<context context-type="linenumber">48</context>
30333033
</context-group>
30343034
</trans-unit>
30353035
<trans-unit id="192867803de476e3137425685702cb44b3bb9981" datatype="html">

i18n/fr/messages.fr.xlf

+2-2
Original file line numberDiff line numberDiff line change
@@ -3024,7 +3024,7 @@
30243024
<target>Connexion</target>
30253025
<context-group purpose="location">
30263026
<context context-type="sourcefile">../src/app/frontend/chrome/userpanel/template.html</context>
3027-
<context context-type="linenumber">37</context>
3027+
<context context-type="linenumber">43</context>
30283028
</context-group>
30293029
</trans-unit>
30303030
<trans-unit id="6426cc90184df1cdb238f45fce5220df8438ed62" datatype="html">
@@ -3033,7 +3033,7 @@
30333033
<target>Déconnexion</target>
30343034
<context-group purpose="location">
30353035
<context context-type="sourcefile">../src/app/frontend/chrome/userpanel/template.html</context>
3036-
<context context-type="linenumber">42</context>
3036+
<context context-type="linenumber">48</context>
30373037
</context-group>
30383038
</trans-unit>
30393039
<trans-unit id="192867803de476e3137425685702cb44b3bb9981" datatype="html">

i18n/ja/messages.ja.xlf

+2-2
Original file line numberDiff line numberDiff line change
@@ -2750,7 +2750,7 @@
27502750
<target>サインイン</target>
27512751
<context-group purpose="location">
27522752
<context context-type="sourcefile">../src/app/frontend/chrome/userpanel/template.html</context>
2753-
<context context-type="linenumber">37</context>
2753+
<context context-type="linenumber">43</context>
27542754
</context-group>
27552755
</trans-unit>
27562756
<trans-unit id="6426cc90184df1cdb238f45fce5220df8438ed62" datatype="html">
@@ -2759,7 +2759,7 @@
27592759
<target>サインアウト</target>
27602760
<context-group purpose="location">
27612761
<context context-type="sourcefile">../src/app/frontend/chrome/userpanel/template.html</context>
2762-
<context context-type="linenumber">42</context>
2762+
<context context-type="linenumber">48</context>
27632763
</context-group>
27642764
</trans-unit>
27652765
<trans-unit id="192867803de476e3137425685702cb44b3bb9981" datatype="html">

i18n/ko/messages.ko.xlf

+2-2
Original file line numberDiff line numberDiff line change
@@ -2805,7 +2805,7 @@
28052805
</target>
28062806
<context-group purpose="location">
28072807
<context context-type="sourcefile">../src/app/frontend/chrome/userpanel/template.html</context>
2808-
<context context-type="linenumber">37</context>
2808+
<context context-type="linenumber">43</context>
28092809
</context-group>
28102810
</trans-unit>
28112811
<trans-unit id="6426cc90184df1cdb238f45fce5220df8438ed62" datatype="html">
@@ -2815,7 +2815,7 @@
28152815
</target>
28162816
<context-group purpose="location">
28172817
<context context-type="sourcefile">../src/app/frontend/chrome/userpanel/template.html</context>
2818-
<context context-type="linenumber">42</context>
2818+
<context context-type="linenumber">48</context>
28192819
</context-group>
28202820
</trans-unit>
28212821
<trans-unit id="192867803de476e3137425685702cb44b3bb9981" datatype="html">

i18n/messages.xlf

+2-2
Original file line numberDiff line numberDiff line change
@@ -2597,15 +2597,15 @@
25972597
</source>
25982598
<context-group purpose="location">
25992599
<context context-type="sourcefile">../src/app/frontend/chrome/userpanel/template.html</context>
2600-
<context context-type="linenumber">37</context>
2600+
<context context-type="linenumber">43</context>
26012601
</context-group>
26022602
</trans-unit>
26032603
<trans-unit id="6426cc90184df1cdb238f45fce5220df8438ed62" datatype="html">
26042604
<source>Sign out
26052605
</source>
26062606
<context-group purpose="location">
26072607
<context context-type="sourcefile">../src/app/frontend/chrome/userpanel/template.html</context>
2608-
<context context-type="linenumber">42</context>
2608+
<context context-type="linenumber">48</context>
26092609
</context-group>
26102610
</trans-unit>
26112611
<trans-unit id="192867803de476e3137425685702cb44b3bb9981" datatype="html">

i18n/zh-Hans/messages.zh-Hans.xlf

+2-2
Original file line numberDiff line numberDiff line change
@@ -2805,7 +2805,7 @@
28052805
</target>
28062806
<context-group purpose="location">
28072807
<context context-type="sourcefile">../src/app/frontend/chrome/userpanel/template.html</context>
2808-
<context context-type="linenumber">37</context>
2808+
<context context-type="linenumber">43</context>
28092809
</context-group>
28102810
</trans-unit>
28112811
<trans-unit id="6426cc90184df1cdb238f45fce5220df8438ed62" datatype="html">
@@ -2815,7 +2815,7 @@
28152815
</target>
28162816
<context-group purpose="location">
28172817
<context context-type="sourcefile">../src/app/frontend/chrome/userpanel/template.html</context>
2818-
<context context-type="linenumber">42</context>
2818+
<context context-type="linenumber">48</context>
28192819
</context-group>
28202820
</trans-unit>
28212821
<trans-unit id="192867803de476e3137425685702cb44b3bb9981" datatype="html">

i18n/zh-Hant-HK/messages.zh-Hant-HK.xlf

+2-2
Original file line numberDiff line numberDiff line change
@@ -2809,7 +2809,7 @@
28092809
</target>
28102810
<context-group purpose="location">
28112811
<context context-type="sourcefile">../src/app/frontend/chrome/userpanel/template.html</context>
2812-
<context context-type="linenumber">37</context>
2812+
<context context-type="linenumber">43</context>
28132813
</context-group>
28142814
</trans-unit>
28152815
<trans-unit id="6426cc90184df1cdb238f45fce5220df8438ed62" datatype="html">
@@ -2819,7 +2819,7 @@
28192819
</target>
28202820
<context-group purpose="location">
28212821
<context context-type="sourcefile">../src/app/frontend/chrome/userpanel/template.html</context>
2822-
<context context-type="linenumber">42</context>
2822+
<context context-type="linenumber">48</context>
28232823
</context-group>
28242824
</trans-unit>
28252825
<trans-unit id="192867803de476e3137425685702cb44b3bb9981" datatype="html">

i18n/zh-Hant/messages.zh-Hant.xlf

+2-2
Original file line numberDiff line numberDiff line change
@@ -2809,7 +2809,7 @@
28092809
</target>
28102810
<context-group purpose="location">
28112811
<context context-type="sourcefile">../src/app/frontend/chrome/userpanel/template.html</context>
2812-
<context context-type="linenumber">37</context>
2812+
<context context-type="linenumber">43</context>
28132813
</context-group>
28142814
</trans-unit>
28152815
<trans-unit id="6426cc90184df1cdb238f45fce5220df8438ed62" datatype="html">
@@ -2819,7 +2819,7 @@
28192819
</target>
28202820
<context-group purpose="location">
28212821
<context context-type="sourcefile">../src/app/frontend/chrome/userpanel/template.html</context>
2822-
<context context-type="linenumber">42</context>
2822+
<context context-type="linenumber">48</context>
28232823
</context-group>
28242824
</trans-unit>
28252825
<trans-unit id="192867803de476e3137425685702cb44b3bb9981" datatype="html">

package-lock.json

+11-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
"angular-page-visibility": "9.0.0",
118118
"ansi-to-html": "0.6.14",
119119
"c3": "0.7.18",
120+
"camelcase-keys": "6.2.2",
120121
"core-js": "3.6.5",
121122
"d3": "5.16.0",
122123
"file-saver": "2.0.2",
@@ -126,6 +127,7 @@
126127
"ng-in-viewport": "6.1.1",
127128
"ngx-cookie-service": "3.0.4",
128129
"ngx-filter-pipe": "2.1.2",
130+
"ngx-webstorage": "5.0.0",
129131
"normalize.css": "8.0.1",
130132
"roboto-fontface": "0.10.0",
131133
"rxjs": "6.6.0",

src/app/backend/auth/api/types.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ const (
2929

3030
// Expiration time (in seconds) of tokens generated by dashboard. Default: 15 min.
3131
DefaultTokenTTL = 900
32+
33+
// Default user name for AuthInfo. This should be empty string in order not to match with user specified name.
34+
DefaultUserName = ""
3235
)
3336

3437
// AuthenticationModes represents auth modes supported by dashboard.
@@ -111,8 +114,8 @@ type TokenManager interface {
111114
// - Kubeconfig based - Authenticates user based on kubeconfig file. Only token/basic modes are supported within
112115
// the kubeconfig file.
113116
type Authenticator interface {
114-
// GetAuthInfo returns filled AuthInfo structure that can be used for K8S api client creation.
115-
GetAuthInfo() (api.AuthInfo, error)
117+
// GetAuthInfos returns filled AuthInfo structures that can be used for K8S api client creation.
118+
GetAuthInfos() (map[string]api.AuthInfo, error)
116119
}
117120

118121
// LoginSpec is extracted from request coming from Dashboard frontend during login request. It contains all the
@@ -127,21 +130,25 @@ type LoginSpec struct {
127130
// KubeConfig is the content of users' kubeconfig file. It will be parsed and auth data will be extracted.
128131
// Kubeconfig can not contain any paths. All data has to be provided within the file.
129132
KubeConfig string `json:"kubeconfig,omitempty"`
133+
// Server is API server endpoint
134+
Server string `json:"server,omitempty"`
135+
// CertificateAuthorityData is CA data for API server endpoint
136+
CertificateAuthorityData string `json:"certificateAuthorityData,omitempty"`
130137
}
131138

132139
// AuthResponse is returned from our backend as a response for login/refresh requests. It contains generated JWEToken
133140
// and a list of non-critical errors such as 'Failed authentication'.
134141
type AuthResponse struct {
135-
// JWEToken is a token generated during login request that contains AuthInfo data in the payload.
136-
JWEToken string `json:"jweToken"`
142+
// JWETokens are tokens generated during login request that contains AuthInfo data in the payload.
143+
JWETokens map[string]string `json:"jweTokens"`
137144
// Errors are a list of non-critical errors that happened during login request.
138145
Errors []error `json:"errors"`
139146
}
140147

141148
// TokenRefreshSpec contains token that is required by token refresh operation.
142149
type TokenRefreshSpec struct {
143150
// JWEToken is a token generated during login request that contains AuthInfo data in the payload.
144-
JWEToken string `json:"jweToken"`
151+
JWETokens map[string]string `json:"jweTokens"`
145152
}
146153

147154
// LoginModesResponse contains list of auth modes supported by dashboard.

src/app/backend/auth/basic.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ type basicAuthenticator struct {
2626
}
2727

2828
// GetAuthInfo implements Authenticator interface. See Authenticator for more information.
29-
func (self *basicAuthenticator) GetAuthInfo() (api.AuthInfo, error) {
30-
return api.AuthInfo{
31-
Username: self.username,
32-
Password: self.password,
29+
func (self *basicAuthenticator) GetAuthInfos() (map[string]api.AuthInfo, error) {
30+
return map[string]api.AuthInfo{
31+
authApi.DefaultUserName: {
32+
Username: self.username,
33+
Password: self.password,
34+
},
3335
}, nil
3436
}
3537

src/app/backend/auth/handler.go

+27-7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package auth
1616

1717
import (
1818
"net/http"
19+
"net/url"
1920

2021
"github.com/emicklei/go-restful"
2122

@@ -64,6 +65,21 @@ func (self AuthHandler) handleLogin(request *restful.Request, response *restful.
6465
return
6566
}
6667

68+
cookie, err := request.Request.Cookie("server")
69+
if err == nil && len(cookie.Value) > 0 {
70+
server, err := url.QueryUnescape(cookie.Value)
71+
if err == nil {
72+
loginSpec.Server = server
73+
}
74+
}
75+
cookie, err = request.Request.Cookie("certificateAuthorityData")
76+
if err == nil && len(cookie.Value) > 0 {
77+
ca, err := url.QueryUnescape(cookie.Value)
78+
if err == nil {
79+
loginSpec.CertificateAuthorityData = ca
80+
}
81+
}
82+
6783
loginResponse, err := self.manager.Login(loginSpec)
6884
if err != nil {
6985
response.AddHeader("Content-Type", "text/plain")
@@ -86,16 +102,20 @@ func (self *AuthHandler) handleJWETokenRefresh(request *restful.Request, respons
86102
return
87103
}
88104

89-
refreshedJWEToken, err := self.manager.Refresh(tokenRefreshSpec.JWEToken)
90-
if err != nil {
91-
response.AddHeader("Content-Type", "text/plain")
92-
response.WriteErrorString(errors.HandleHTTPError(err), err.Error()+"\n")
93-
return
105+
refreshedJWETokens := map[string]string{}
106+
for userName, token := range tokenRefreshSpec.JWETokens {
107+
refreshedJWEToken, err := self.manager.Refresh(token)
108+
if err != nil {
109+
response.AddHeader("Content-Type", "text/plain")
110+
response.WriteErrorString(errors.HandleHTTPError(err), err.Error()+"\n")
111+
return
112+
}
113+
refreshedJWETokens[userName] = refreshedJWEToken
94114
}
95115

96116
response.WriteHeaderAndEntity(http.StatusOK, &authApi.AuthResponse{
97-
JWEToken: refreshedJWEToken,
98-
Errors: make([]error, 0),
117+
JWETokens: refreshedJWETokens,
118+
Errors: make([]error, 0),
99119
})
100120
}
101121

0 commit comments

Comments
 (0)