Skip to content

Commit 61f07f5

Browse files
committed
feat: add permission validation for RS
1 parent fc30a69 commit 61f07f5

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

model/category/category.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ func (c Category) IsFromES() bool {
158158
c == Misc
159159
}
160160

161+
// IsFromRS checks whether the category is of the reactivesearch category.
162+
func (c Category) IsFromRS() bool {
163+
return c == ReactiveSearch
164+
}
165+
161166
// HasACL checks whether the given acl is a value in the category categories.
162167
func (c Category) HasACL(a acl.ACL) bool {
163168
return acl.Contains(c.ACLs(), a)

plugins/auth/middleware.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,14 @@ func (a *Auth) basicAuth(h http.HandlerFunc) http.HandlerFunc {
166166
util.WriteBackError(w, "invalid password", http.StatusUnauthorized)
167167
return
168168
}
169+
170+
log.Println("THIS IS THE THING HERE", *reqCategory, *reqCategory == category.ReactiveSearch, reqUser.HasCategory(category.ReactiveSearch))
169171
if reqCategory.IsFromES() {
170-
authenticated = *reqUser.IsAdmin
171-
} else {
172172
authenticated = true
173+
} else if *reqCategory == category.ReactiveSearch && reqUser.HasCategory(category.ReactiveSearch) {
174+
authenticated = true
175+
} else {
176+
errorMsg = "credential is only allowed to access elasticsearch"
173177
}
174178

175179
if !authenticated {
@@ -195,8 +199,11 @@ func (a *Auth) basicAuth(h http.HandlerFunc) http.HandlerFunc {
195199
return
196200
}
197201

202+
log.Println("THIS IS THE THING HERE", *reqCategory, *reqCategory == category.ReactiveSearch, reqPermission.HasCategory(category.ReactiveSearch))
198203
if reqCategory.IsFromES() {
199204
authenticated = true
205+
} else if *reqCategory == category.ReactiveSearch && reqPermission.HasCategory(category.ReactiveSearch) {
206+
authenticated = true
200207
} else {
201208
errorMsg = "credential is only allowed to access elasticsearch"
202209
}

0 commit comments

Comments
 (0)