Skip to content

Commit

Permalink
Merge pull request #25 from cleardataeng/feature/vertex-ai-notebook-s…
Browse files Browse the repository at this point in the history
…upport

Add support for Vertex AI notebooks to rpe lib.
  • Loading branch information
jjohndrow authored Dec 2, 2024
2 parents 313e88b + 5516330 commit 6f625ad
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 0 deletions.
14 changes: 14 additions & 0 deletions rpe/extractors/gcp_auditlogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,18 @@ def add_resource():
resource_data["repository"] = name_bits[5]
add_resource()

# Vertex AI Notebook
elif (
res_type == "audited_resource"
and prop("resource.labels.service") == "notebooks.googleapis.com"
):
name_bits = prop("protoPayload.resourceName").split("/")
resource_data = {
"name": name_bits[5],
"project_id": name_bits[1],
"location": name_bits[3],
"resource_type": "notebooks.googleapis.com/Instance",
}
add_resource()

return resources
27 changes: 27 additions & 0 deletions rpe/resources/gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,3 +1146,30 @@ def _get_request_args(self):

def _get_iam_request_args(self):
return {"resource": self._get_resource_string()}


class GcpNotebookInstance(GoogleAPIResource):
"""
Vertex AI Workbench Instance.
"""

service_name = "notebooks"
resource_path = "projects.locations.instances"
version = "v2"

required_resource_data = ["name", "location", "project_id"]

resource_type = "notebooks.googleapis.com/Instance"

inferred_data_map = {
"uniquifier": "id",
}

def _get_request_args(self):
return {
"name": "projects/{}/locations/{}/instances/{}".format(
self._resource_data["project_id"],
self._resource_data["location"],
self._resource_data["name"],
),
}
66 changes: 66 additions & 0 deletions tests/data/notebook_instance_create_01.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"protoPayload": {
"@type": "type.googleapis.com/google.cloud.audit.AuditLog",
"status": {},
"authenticationInfo": {
"principalEmail": "[email protected]",
"principalSubject": "user:[email protected]"
},
"requestMetadata": {
"callerIp": "70.113.39.123",
"callerSuppliedUserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36,gzip(gfe),gzip(gfe)",
"requestAttributes": {
"time": "2024-11-22T19:39:10.510275284Z",
"auth": {}
},
"destinationAttributes": {}
},
"serviceName": "notebooks.googleapis.com",
"methodName": "google.cloud.notebooks.v2.NotebookService.CreateInstance",
"authorizationInfo": [
{
"resource": "projects/test-vertex-ai-project/locations/us-central1-a/instances/test-create-event",
"permission": "notebooks.instances.create",
"granted": true,
"resourceAttributes": {
"service": "notebooks.googleapis.com",
"name": "projects/test-vertex-ai-project/locations/us-central1-a/instances/test-create-event"
},
"permissionType": "ADMIN_WRITE"
}
],
"resourceName": "projects/test-vertex-ai-project/locations/us-central1-a/instances/test-create-event",
"request": {
"instance": {},
"parent": "projects/test-vertex-ai-project/locations/us-central1-a",
"@type": "type.googleapis.com/google.cloud.notebooks.v2.CreateInstanceRequest",
"instance_id": "test-create-event"
},
"response": {
"@type": "type.googleapis.com/google.longrunning.Operation"
},
"resourceLocation": {
"currentLocations": [
"us-central1-a"
]
}
},
"insertId": "dlmvxecay0",
"resource": {
"type": "audited_resource",
"labels": {
"method": "google.cloud.notebooks.v2.NotebookService.CreateInstance",
"project_id": "test-vertex-ai-project",
"service": "notebooks.googleapis.com"
}
},
"timestamp": "2024-11-22T19:39:11.999291772Z",
"severity": "NOTICE",
"logName": "projects/test-vertex-ai-project/logs/cloudaudit.googleapis.com%2Factivity",
"operation": {
"id": "projects/test-vertex-ai-project/locations/us-central1-a/operations/operation-1732304350517-6278589749919-3cddbad0-d4e5f89e",
"producer": "notebooks.googleapis.com",
"first": true
},
"receiveTimestamp": "2024-11-22T19:39:12.712491438Z"
}
62 changes: 62 additions & 0 deletions tests/data/notebook_instance_update_01.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"protoPayload": {
"@type": "type.googleapis.com/google.cloud.audit.AuditLog",
"status": {
"code": 9,
"message": "instance in state \"ACTIVE\" must be stopped before updating one of the following: [accelerator_configs machine_type shielded_instance_config reservation_affinity], failed precondition"
},
"authenticationInfo": {
"principalEmail": "[email protected]",
"principalSubject": "user:[email protected]"
},
"requestMetadata": {
"callerIp": "70.113.39.123",
"callerSuppliedUserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36,gzip(gfe),gzip(gfe)",
"requestAttributes": {
"time": "2024-11-22T21:34:16.882098660Z",
"auth": {}
},
"destinationAttributes": {}
},
"serviceName": "notebooks.googleapis.com",
"methodName": "google.cloud.notebooks.v2.NotebookService.UpdateInstance",
"authorizationInfo": [
{
"resource": "projects/test-gcp-vertex-ai-project/locations/us-central1-a/instances/test-notebook",
"permission": "notebooks.instances.update",
"granted": true,
"resourceAttributes": {
"service": "notebooks.googleapis.com",
"name": "projects/test-gcp-vertex-ai-project/locations/us-central1-a/instances/test-notebook"
},
"permissionType": "ADMIN_WRITE"
}
],
"resourceName": "projects/test-gcp-vertex-ai-project/locations/us-central1-a/instances/test-notebook",
"request": {
"@type": "type.googleapis.com/google.cloud.notebooks.v2.UpdateInstanceRequest",
"instance": {}
},
"response": {
"@type": "type.googleapis.com/google.longrunning.Operation"
},
"resourceLocation": {
"currentLocations": [
"us-central1-a"
]
}
},
"insertId": "dlmvxeceen",
"resource": {
"type": "audited_resource",
"labels": {
"service": "notebooks.googleapis.com",
"project_id": "test-gcp-vertex-ai-project",
"method": "google.cloud.notebooks.v2.NotebookService.UpdateInstance"
}
},
"timestamp": "2024-11-22T21:34:16.891531432Z",
"severity": "ERROR",
"logName": "projects/test-gcp-vertex-ai-project/logs/cloudaudit.googleapis.com%2Factivity",
"receiveTimestamp": "2024-11-22T21:34:17.868613326Z"
}
12 changes: 12 additions & 0 deletions tests/test_extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,18 @@ def get_test_data(filename):
"update",
"test-repository",
),
(
"notebook_instance_create_01.json",
"notebooks.googleapis.com/Instance",
"create",
"test-create-event",
),
(
"notebook_instance_update_01.json",
"notebooks.googleapis.com/Instance",
"update",
"test-notebook",
),
]

test_micromanager_log = [
Expand Down
8 changes: 8 additions & 0 deletions tests/test_resources_cai.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
GcpIamServiceAccount,
GcpIamServiceAccountKey,
GcpMemcacheInstance,
GcpNotebookInstance,
GcpOrganization,
GcpProject,
GcpProjectService,
Expand Down Expand Up @@ -244,6 +245,13 @@
},
resource_cls=GcpDataformWorkspace,
),
CaiTestCase(
data={
"name": "//notebooks.googleapis.com/projects/test-001/locations/us-central1-a/instances/test-instance-01",
"asset_type": "notebooks.googleapis.com/Instance",
},
resource_cls=GcpNotebookInstance,
),
]


Expand Down

0 comments on commit 6f625ad

Please sign in to comment.