-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support RBAC bypass by group for OKD resources with requester annotation #413
Merged
Merged
Changes from 16 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
203db98
ci: release staging version on every push to this branch
royhadad 5c5422e
test: changing CoreV1 to Discovery
royhadad d4fb1a0
add kubectl to image, run raw kubectl get command
royhadad 43ae95c
fix permissions to include the api group
royhadad abff6c1
filter response
royhadad d0c0e6d
fix build
royhadad 2ff81bc
fix build
royhadad a34d914
create openshift client
royhadad d854f32
Merge branch 'main' of github.com:datreeio/admission-webhook-datree i…
royhadad 96c1ed4
feat: finish up openshiftClient
royhadad ef13f93
fix build
royhadad d95e092
first draft
royhadad 3d1a51c
cleanup
royhadad c8979fb
go mod tidy
royhadad 8069566
cleanup
royhadad aa328a8
fix: only overide if succussfull
royhadad 3bb7a00
fix one lint failure
royhadad 0b2b4e3
revert this later
royhadad 02c9097
add logs
royhadad c34b574
refactor & test: extract openshift service and client, test the service
royhadad 61393c6
make the client private, only the service is public
royhadad 098ffcc
cleanup
royhadad 324cc7c
handle errors
royhadad fbb251b
cleanup
royhadad 9c6ae8e
remove deployment on every push to the dev branch
royhadad 8600534
add okd installation command to makefile
royhadad f6b961e
makefile
royhadad 2a64ffb
makefile
royhadad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,4 +89,4 @@ spec: | |
else | ||
echo "Error: Failed to send cluster uninstallation request"; \ | ||
fi | ||
{{- end }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package openshiftClient | ||
|
||
import ( | ||
"context" | ||
userClientV1 "github.com/openshift/client-go/user/clientset/versioned/typed/user/v1" | ||
"github.com/patrickmn/go-cache" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/rest" | ||
"time" | ||
) | ||
|
||
type OpenshiftClient struct { | ||
userClientV1 userClientV1.UserV1Interface | ||
cache *cache.Cache | ||
} | ||
|
||
func NewOpenshiftClient() (*OpenshiftClient, error) { | ||
config, err := rest.InClusterConfig() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
userClientV1Instance, err := userClientV1.NewForConfig(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &OpenshiftClient{ | ||
userClientV1: userClientV1Instance, | ||
cache: cache.New(1*time.Minute, 10*time.Minute), | ||
}, nil | ||
} | ||
|
||
type GroupsByUsers = map[string][]string | ||
|
||
const groupsByUsersCacheKey = "groupsByUsers" | ||
|
||
func (oc *OpenshiftClient) getGroupsByUsers() (GroupsByUsers, error) { | ||
// try to get from cache | ||
valueFromCache, found := oc.cache.Get(groupsByUsersCacheKey) | ||
if found { | ||
return valueFromCache.(GroupsByUsers), nil | ||
} | ||
|
||
// get from API | ||
groups, err := oc.userClientV1.Groups().List(context.TODO(), metav1.ListOptions{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// convert from array of groups to map of users to groups | ||
groupsByUsers := make(GroupsByUsers) | ||
for _, group := range groups.Items { | ||
for _, user := range group.Users { | ||
groupsByUsers[user] = append(groupsByUsers[user], group.Name) | ||
} | ||
} | ||
|
||
// set to cache | ||
oc.cache.Set(groupsByUsersCacheKey, groupsByUsers, 1*time.Minute) | ||
return groupsByUsers, nil | ||
} | ||
func (oc *OpenshiftClient) GetGroupsUserBelongsTo(username string) ([]string, error) { | ||
groupsByUsers, err := oc.getGroupsByUsers() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
groups, found := groupsByUsers[username] | ||
if !found { | ||
return []string{}, nil | ||
} | ||
return groups, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO handle this error somehow