Skip to content

Commit f1f928c

Browse files
committed
Authenticate : Say it's ok if we're authenticate as admin
Looking at the user/password provided, first see if it corresponds to the admin ones. If this is the case, accept getting the store without any further test.
1 parent 3a9de08 commit f1f928c

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

meta_store.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,12 @@ func (s *MetaStore) authenticate(authorization string) bool {
243243
}
244244
user, password := cs[:i], cs[i+1:]
245245

246+
// check Basic Authentication (admin)
247+
ok := checkBasicAuth(user, password, true)
248+
if ok {
249+
return true
250+
}
251+
246252
value := ""
247253

248254
s.db.View(func(tx *bolt.Tx) error {

mgmt.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ func cssHandler(w http.ResponseWriter, r *http.Request) {
5151
f.Close()
5252
}
5353

54+
func checkBasicAuth(user string , pass string, ok bool) (bool) {
55+
if !ok {
56+
return false
57+
}
58+
59+
if user != Config.AdminUser || pass != Config.AdminPass {
60+
return false
61+
}
62+
return true
63+
}
64+
5465
func basicAuth(h http.HandlerFunc) http.HandlerFunc {
5566
return func(w http.ResponseWriter, r *http.Request) {
5667
if Config.AdminUser == "" || Config.AdminPass == "" {
@@ -59,13 +70,9 @@ func basicAuth(h http.HandlerFunc) http.HandlerFunc {
5970
}
6071

6172
user, pass, ok := r.BasicAuth()
62-
if !ok {
63-
w.Header().Set("WWW-Authenticate", "Basic realm=mgmt")
64-
writeStatus(w, r, 401)
65-
return
66-
}
6773

68-
if user != Config.AdminUser || pass != Config.AdminPass {
74+
ret := checkBasicAuth(user, pass, ok);
75+
if !ret {
6976
w.Header().Set("WWW-Authenticate", "Basic realm=mgmt")
7077
writeStatus(w, r, 401)
7178
return

0 commit comments

Comments
 (0)