Skip to content

Commit 9c90d61

Browse files
myishayYishay Mendelsohn
andauthored
fix: bypass using serviceaccount when openshift requester exists (#424)
* fix: bypass using serviceaccount when openshift requester exists * fix: logic fix for requester bypass --------- Co-authored-by: Yishay Mendelsohn <yishaymendelsohn@Yishays-MacBook-Pro-2.local>
1 parent ff42571 commit 9c90d61

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

pkg/services/validationService.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import (
44
"encoding/json"
55
"errors"
66
"fmt"
7-
"github.com/datreeio/admission-webhook-datree/pkg/openshiftService"
87
"net/http"
98
"os"
109
"regexp"
1110
"strings"
1211
"sync"
1312
"time"
1413

14+
"github.com/datreeio/admission-webhook-datree/pkg/openshiftService"
15+
1516
authenticationv1 "k8s.io/api/authentication/v1"
1617

1718
"github.com/datreeio/admission-webhook-datree/pkg/errorReporter"
@@ -412,9 +413,6 @@ func (vs *ValidationService) shouldBypassByPermissions(userInfo authenticationv1
412413
userName := userInfo.Username
413414
groups := userInfo.Groups
414415
if openShiftRequester != "" {
415-
// override username
416-
userName = openShiftRequester
417-
418416
// override groups
419417
groupsFromOpenshiftService, err := vs.OpenshiftService.GetGroupsUserBelongsTo(openShiftRequester)
420418
if err != nil {
@@ -425,8 +423,16 @@ func (vs *ValidationService) shouldBypassByPermissions(userInfo authenticationv1
425423
}
426424

427425
for _, userAccount := range bypassPermissions.UserAccounts {
428-
if match, _ := regexp.MatchString(userAccount, userName); match {
429-
return true
426+
if openShiftRequester != "" {
427+
matchOpenshiftRequester, _ := regexp.MatchString(userAccount, openShiftRequester)
428+
if matchOpenshiftRequester {
429+
return true
430+
}
431+
} else {
432+
matchUsername, _ := regexp.MatchString(userAccount, userName)
433+
if matchUsername {
434+
return true
435+
}
430436
}
431437
}
432438

0 commit comments

Comments
 (0)