-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8659 from OpenMined/snwagh/attestation-service
Attestation service in Syft
- Loading branch information
Showing
12 changed files
with
240 additions
and
15 deletions.
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
1 change: 1 addition & 0 deletions
1
packages/grid/enclave/attestation/server/attestation_constants.py
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 @@ | ||
NRAS_URL = "https://nras.attestation.nvidia.com/v1/attest/gpu" |
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
Empty file.
5 changes: 5 additions & 0 deletions
5
packages/syft/src/syft/service/attestation/attestation_constants.py
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,5 @@ | ||
ATTESTATION_SERVICE_URL = ( | ||
"http://localhost:4455" # Replace with "http://attestation:4455" | ||
) | ||
ATTEST_CPU_ENDPOINT = "/attest/cpu" | ||
ATTEST_GPU_ENDPOINT = "/attest/gpu" |
66 changes: 66 additions & 0 deletions
66
packages/syft/src/syft/service/attestation/attestation_service.py
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,66 @@ | ||
# stdlib | ||
from collections.abc import Callable | ||
|
||
# third party | ||
import requests | ||
|
||
# relative | ||
from ...serde.serializable import serializable | ||
from ...store.document_store import DocumentStore | ||
from ...util.util import str_to_bool | ||
from ..context import AuthedServiceContext | ||
from ..response import SyftError | ||
from ..response import SyftSuccess | ||
from ..service import AbstractService | ||
from ..service import service_method | ||
from ..user.user_roles import GUEST_ROLE_LEVEL | ||
from .attestation_constants import ATTESTATION_SERVICE_URL | ||
from .attestation_constants import ATTEST_CPU_ENDPOINT | ||
from .attestation_constants import ATTEST_GPU_ENDPOINT | ||
|
||
|
||
@serializable() | ||
class AttestationService(AbstractService): | ||
"""This service is responsible for getting all sorts of attestations for any client.""" | ||
|
||
def __init__(self, store: DocumentStore) -> None: | ||
self.store = store | ||
|
||
def perform_request( | ||
self, method: Callable, endpoint: str, raw: bool = False | ||
) -> SyftSuccess | SyftError | str: | ||
try: | ||
response = method(f"{ATTESTATION_SERVICE_URL}{endpoint}") | ||
response.raise_for_status() | ||
message = response.json().get("result") | ||
raw_token = response.json().get("token") | ||
if raw: | ||
return raw_token | ||
elif str_to_bool(message): | ||
return SyftSuccess(message=message) | ||
else: | ||
return SyftError(message=message) | ||
except requests.HTTPError: | ||
return SyftError(message=f"{response.json()['detail']}") | ||
except requests.RequestException as e: | ||
return SyftError(message=f"Failed to perform request. {e}") | ||
|
||
@service_method( | ||
path="attestation.get_cpu_attestation", | ||
name="get_cpu_attestation", | ||
roles=GUEST_ROLE_LEVEL, | ||
) | ||
def get_cpu_attestation( | ||
self, context: AuthedServiceContext, raw_token: bool = False | ||
) -> str | SyftError | SyftSuccess: | ||
return self.perform_request(requests.get, ATTEST_CPU_ENDPOINT, raw_token) | ||
|
||
@service_method( | ||
path="attestation.get_gpu_attestation", | ||
name="get_gpu_attestation", | ||
roles=GUEST_ROLE_LEVEL, | ||
) | ||
def get_gpu_attestation( | ||
self, context: AuthedServiceContext, raw_token: bool = False | ||
) -> str | SyftError | SyftSuccess: | ||
return self.perform_request(requests.get, ATTEST_GPU_ENDPOINT, raw_token) |