-
Notifications
You must be signed in to change notification settings - Fork 1
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
Triton gpt uids #8
Open
RockfordMankiniUCSD
wants to merge
3
commits into
main
Choose a base branch
from
triton-gpt-uids
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
GPU_LABEL = "nvidia.com/gpu" | ||
GPU_LIMIT_ANNOTATION = 'gpu-limit' | ||
LOW_PRIORITY_CLASS = "low" | ||
LOW_PRIORITY_CLASS = "low" |
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,33 @@ | ||
from dataclasses import dataclass | ||
import json | ||
from typing import List, Optional | ||
|
||
from dataclasses_json import dataclass_json | ||
from dsmlp.plugin.awsed import AwsedClient, UnsuccessfulRequest | ||
from dsmlp.plugin.console import Console | ||
from dsmlp.plugin.course import ConfigProvider | ||
from dsmlp.plugin.kube import KubeClient, NotFound | ||
import jsonify | ||
|
||
from dsmlp.plugin.logger import Logger | ||
from dsmlp.app.types import * | ||
from dsmlp.app.config import * | ||
|
||
# used in order to bypass awsed for tritonGPT while still maintaining UID security. | ||
class TritonGPTValidator(ComponentValidator): | ||
|
||
def __init__(self, kube: KubeClient, logger: Logger) -> None: | ||
self.kube = kube | ||
self.logger = logger | ||
|
||
def validate_pod(self, request: Request): | ||
|
||
namespace = self.kube.get_namespace(request.namespace) | ||
|
||
permitted_uids = self.kube.get_tgpt_uids(namespace) | ||
requested_uid = request.object.spec.securityContext.runAsUser | ||
|
||
# if request.uid is not in kube.get_tgpt_uids | ||
# return validationfailure | ||
if str(requested_uid) not in permitted_uids: | ||
raise ValidationFailure(f"TritonGPT Validator: user with access to UIDs {permitted_uids} attempted to run a pod as {requested_uid}. Pod denied.") |
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,165 @@ | ||
import inspect | ||
from operator import contains | ||
from dsmlp.app.validator import Validator | ||
from dsmlp.plugin.awsed import ListTeamsResponse, TeamJson, UserResponse | ||
from dsmlp.plugin.kube import Namespace | ||
from hamcrest import assert_that, contains_inanyorder, equal_to, has_item | ||
from tests.fakes import FakeAwsedClient, FakeLogger, FakeKubeClient | ||
|
||
|
||
class TestTGPTValidator: | ||
def setup_method(self) -> None: | ||
self.logger = FakeLogger() | ||
self.awsed_client = FakeAwsedClient() | ||
self.kube_client = FakeKubeClient() | ||
|
||
self.awsed_client.add_user( | ||
'user10', UserResponse(uid=30, enrollments=[])) | ||
self.awsed_client.add_teams('user10', ListTeamsResponse( | ||
teams=[TeamJson(gid=1000)] | ||
)) | ||
|
||
self.kube_client.add_namespace('user10', Namespace( | ||
name='user10', labels={'k8s-sync': 'true', 'tgpt-validator': 'enabled', 'permitted-uids': '30,3000'}, gpu_quota=10)) | ||
|
||
self.awsed_client.add_user( | ||
'user100', UserResponse(uid=10, enrollments=[])) | ||
self.awsed_client.add_teams('user10', ListTeamsResponse( | ||
teams=[TeamJson(gid=1000)] | ||
)) | ||
|
||
self.kube_client.add_namespace('user100', Namespace( | ||
name='user100', labels={'k8s-sync': 'true', 'tgpt-validator': 'disabled', 'permitted-uids': '10'}, gpu_quota=10)) | ||
|
||
def test_good_request(self): | ||
self.when_validate( | ||
{ | ||
"request": { | ||
"uid": "705ab4f5-6393-11e8-b7cc-42010a800002", | ||
"namespace": "user10", | ||
"userInfo": { | ||
"username": "system:kube-system" | ||
}, | ||
"object": { | ||
"metadata": { | ||
"labels": {} | ||
}, | ||
"spec": { | ||
"containers": [{}], | ||
"securityContext": {"runAsUser": 30}, | ||
}, | ||
} | ||
} | ||
} | ||
) | ||
|
||
assert_that(self.logger.messages, has_item( | ||
f"INFO Allowed request username=system:kube-system namespace=user10 uid=705ab4f5-6393-11e8-b7cc-42010a800002")) | ||
|
||
def test_good_request_2(self): | ||
self.when_validate( | ||
{ | ||
"request": { | ||
"uid": "705ab4f5-6393-11e8-b7cc-42010a800002", | ||
"namespace": "user10", | ||
"userInfo": { | ||
"username": "system:kube-system" | ||
}, | ||
"object": { | ||
"metadata": { | ||
"labels": {} | ||
}, | ||
"spec": { | ||
"containers": [{}], | ||
"securityContext": {"runAsUser": 3000}, | ||
}, | ||
} | ||
} | ||
} | ||
) | ||
|
||
assert_that(self.logger.messages, has_item( | ||
f"INFO Allowed request username=system:kube-system namespace=user10 uid=705ab4f5-6393-11e8-b7cc-42010a800002")) | ||
|
||
def test_bad_request(self): | ||
self.when_validate( | ||
{ | ||
"request": { | ||
"uid": "705ab4f5-6393-11e8-b7cc-42010a800002", | ||
"namespace": "user10", | ||
"userInfo": { | ||
"username": "system:kube-system" | ||
}, | ||
"object": { | ||
"metadata": { | ||
"labels": {} | ||
}, | ||
"spec": { | ||
"containers": [{}], | ||
"securityContext": {"runAsUser": 300}, | ||
}, | ||
} | ||
} | ||
} | ||
) | ||
|
||
assert_that(self.logger.messages, has_item( | ||
f"INFO Denied request username=system:kube-system namespace=user10 reason=TritonGPT Validator: user with access to UIDs ['30', '3000'] attempted to run a pod as 300. Pod denied. uid=705ab4f5-6393-11e8-b7cc-42010a800002")) | ||
|
||
def test_good_request_not_enabled_permitted_on(self): | ||
self.when_validate( | ||
{ | ||
"request": { | ||
"uid": "705ab4f5-6393-11e8-b7cc-42010a800002", | ||
"namespace": "user100", | ||
"userInfo": { | ||
"username": "system:kube-system" | ||
}, | ||
"object": { | ||
"metadata": { | ||
"labels": {} | ||
}, | ||
"spec": { | ||
"containers": [{}], | ||
"securityContext": {"runAsUser": 10}, | ||
}, | ||
} | ||
} | ||
} | ||
) | ||
|
||
assert_that(self.logger.messages, has_item( | ||
f"INFO Allowed request username=system:kube-system namespace=user100 uid=705ab4f5-6393-11e8-b7cc-42010a800002")) | ||
|
||
#assert_that(self.logger.messages, has_item( | ||
#"INFO Allowed request username=user10 namespace=user10 uid=705ab4f5-6393-11e8-b7cc-42010a800002")) | ||
|
||
# def test_gpu_quota_request(self): | ||
# self.awsed_client.add_user_gpu_quota('user10', 10) | ||
# self.awsed_client.get_user_gpu_quota('user10') | ||
|
||
# response = self.when_validate( | ||
# { | ||
# "request": { | ||
# "uid": "705ab4f5-6393-11e8-b7cc-42010a800002", | ||
# "namespace": "user10", | ||
# "userInfo": { | ||
# "username": "user10" | ||
# }, | ||
# "object": { | ||
# "metadata": { | ||
# "labels": {} | ||
# }, | ||
# "spec": { | ||
# "containers": [{}] | ||
# } | ||
# } | ||
# } | ||
# } | ||
# ) | ||
|
||
def when_validate(self, json): | ||
validator = Validator(self.awsed_client, self.kube_client, self.logger) | ||
response = validator.validate_request(json) | ||
|
||
return response |
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.
to streamline logic - how about something like this?
` #
`