Skip to content

Commit 476ed69

Browse files
committed
fix: fix docker label matching logic
1 parent b3dca04 commit 476ed69

5 files changed

Lines changed: 23 additions & 16 deletions

File tree

internal/auth/auth.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func (auth *Auth) RecordLoginAttempt(identifier string, success bool) {
234234
}
235235

236236
func (auth *Auth) EmailWhitelisted(email string) bool {
237-
return utils.CheckFilter(auth.Config.OauthWhitelist, email, true)
237+
return utils.CheckFilter(auth.Config.OauthWhitelist, email)
238238
}
239239

240240
func (auth *Auth) CreateSessionCookie(c *gin.Context, data *types.SessionCookie) error {
@@ -368,13 +368,13 @@ func (auth *Auth) ResourceAllowed(c *gin.Context, context types.UserContext, lab
368368
// Check if oauth is allowed
369369
if context.OAuth {
370370
log.Debug().Msg("Checking OAuth whitelist")
371-
return utils.CheckFilter(labels.OAuth.Whitelist, context.Email, true)
371+
return utils.CheckFilter(labels.OAuth.Whitelist, context.Email)
372372
}
373373

374374
// Check users
375375
log.Debug().Msg("Checking users")
376376

377-
return utils.CheckFilter(labels.Users, context.Username, true)
377+
return utils.CheckFilter(labels.Users, context.Username)
378378
}
379379

380380
func (auth *Auth) OAuthGroup(c *gin.Context, context types.UserContext, labels types.Labels) bool {
@@ -394,7 +394,7 @@ func (auth *Auth) OAuthGroup(c *gin.Context, context types.UserContext, labels t
394394

395395
// For every group check if it is in the required groups
396396
for _, group := range oauthGroups {
397-
if utils.CheckFilter(labels.OAuth.Groups, group, true) {
397+
if utils.CheckFilter(labels.OAuth.Groups, group) {
398398
log.Debug().Str("group", group).Msg("Group is in required groups")
399399
return true
400400
}

internal/docker/docker.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (docker *Docker) DockerConnected() bool {
6969
return err == nil
7070
}
7171

72-
func (docker *Docker) GetLabels(id string, domain string) (types.Labels, error) {
72+
func (docker *Docker) GetLabels(app string, domain string) (types.Labels, error) {
7373
// Check if we have access to the Docker API
7474
isConnected := docker.DockerConnected()
7575

@@ -112,9 +112,16 @@ func (docker *Docker) GetLabels(id string, domain string) (types.Labels, error)
112112
continue
113113
}
114114

115-
// Check if the labels match the id or the domain
116-
if strings.TrimPrefix(inspect.Name, "/") == id || utils.CheckFilter(labels.Domain, domain, false) { // Disable regex for now
117-
log.Debug().Str("id", inspect.ID).Msg("Found matching container")
115+
// Check if the container matches the ID or domain
116+
for _, lDomain := range labels.Domain {
117+
if lDomain == domain {
118+
log.Debug().Str("id", inspect.ID).Msg("Found matching container by domain")
119+
return labels, nil
120+
}
121+
}
122+
123+
if strings.TrimPrefix(inspect.Name, "/") == app {
124+
log.Debug().Str("id", inspect.ID).Msg("Found matching container by name")
118125
return labels, nil
119126
}
120127
}

internal/types/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ type Labels struct {
129129
Users string
130130
Allowed string
131131
Headers []string
132-
Domain string
132+
Domain []string
133133
Basic BasicLabels
134134
OAuth OAuthLabels
135135
IP IPLabels

internal/utils/utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,14 @@ func ParseSecretFile(contents string) string {
293293
}
294294

295295
// Check if a string matches a regex or if it is included in a comma separated list
296-
func CheckFilter(filter string, str string, regex bool) bool {
296+
func CheckFilter(filter string, str string) bool {
297297
// Check if the filter is empty
298298
if len(strings.TrimSpace(filter)) == 0 {
299299
return true
300300
}
301301

302302
// Check if the filter is a regex
303-
if strings.HasPrefix(filter, "/") && strings.HasSuffix(filter, "/") && regex {
303+
if strings.HasPrefix(filter, "/") && strings.HasSuffix(filter, "/") {
304304
// Create regex
305305
re, err := regexp.Compile(filter[1 : len(filter)-1])
306306

internal/utils/utils_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ func TestCheckFilter(t *testing.T) {
387387
expected := true
388388

389389
// Test the check filter function
390-
result := utils.CheckFilter(filter, str, false)
390+
result := utils.CheckFilter(filter, str)
391391

392392
// Check if the result is equal to the expected
393393
if result != expected {
@@ -402,7 +402,7 @@ func TestCheckFilter(t *testing.T) {
402402
expected = true
403403

404404
// Test the check filter function
405-
result = utils.CheckFilter(filter, str, true)
405+
result = utils.CheckFilter(filter, str)
406406

407407
// Check if the result is equal to the expected
408408
if result != expected {
@@ -417,7 +417,7 @@ func TestCheckFilter(t *testing.T) {
417417
expected = true
418418

419419
// Test the check filter function
420-
result = utils.CheckFilter(filter, str, false)
420+
result = utils.CheckFilter(filter, str)
421421

422422
// Check if the result is equal to the expected
423423
if result != expected {
@@ -432,7 +432,7 @@ func TestCheckFilter(t *testing.T) {
432432
expected = false
433433

434434
// Test the check filter function
435-
result = utils.CheckFilter(filter, str, true)
435+
result = utils.CheckFilter(filter, str)
436436

437437
// Check if the result is equal to the expected
438438
if result != expected {
@@ -447,7 +447,7 @@ func TestCheckFilter(t *testing.T) {
447447
expected = false
448448

449449
// Test the check filter function
450-
result = utils.CheckFilter(filter, str, false)
450+
result = utils.CheckFilter(filter, str)
451451

452452
// Check if the result is equal to the expected
453453
if result != expected {

0 commit comments

Comments
 (0)