Skip to content

Commit

Permalink
fix: bypass using serviceaccount when openshift requester exists (#424)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
myishay and Yishay Mendelsohn authored Jul 19, 2023
1 parent ff42571 commit 9c90d61
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pkg/services/validationService.go
Original file line number Diff line number Diff line change
@@ -4,14 +4,15 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/datreeio/admission-webhook-datree/pkg/openshiftService"
"net/http"
"os"
"regexp"
"strings"
"sync"
"time"

"github.com/datreeio/admission-webhook-datree/pkg/openshiftService"

authenticationv1 "k8s.io/api/authentication/v1"

"github.com/datreeio/admission-webhook-datree/pkg/errorReporter"
@@ -412,9 +413,6 @@ func (vs *ValidationService) shouldBypassByPermissions(userInfo authenticationv1
userName := userInfo.Username
groups := userInfo.Groups
if openShiftRequester != "" {
// override username
userName = openShiftRequester

// override groups
groupsFromOpenshiftService, err := vs.OpenshiftService.GetGroupsUserBelongsTo(openShiftRequester)
if err != nil {
@@ -425,8 +423,16 @@ func (vs *ValidationService) shouldBypassByPermissions(userInfo authenticationv1
}

for _, userAccount := range bypassPermissions.UserAccounts {
if match, _ := regexp.MatchString(userAccount, userName); match {
return true
if openShiftRequester != "" {
matchOpenshiftRequester, _ := regexp.MatchString(userAccount, openShiftRequester)
if matchOpenshiftRequester {
return true
}
} else {
matchUsername, _ := regexp.MatchString(userAccount, userName)
if matchUsername {
return true
}
}
}

0 comments on commit 9c90d61

Please sign in to comment.