Skip to content

Commit 0fb0b0d

Browse files
Scope agent database access to a thread or a database (#936)
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 4e0e7c6 commit 0fb0b0d

12 files changed

Lines changed: 261 additions & 159 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"livekit-api": patch
3+
"livekit-protocol": patch
4+
---
5+
6+
Scope agent database access to a thread or a database: `AgentThreadGrants` gains `sql`, the new `agentDatabase` claim (`AgentDatabaseGrants`, `with_agent_database_grants`) grants `read`, `write` and `delete` on listed databases plus project-wide `create` and `list`, and `AgentGrants.database_admin` is removed.

‎livekit-api/livekit/api/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
AgentGrants,
5151
AgentEndpointGrants,
5252
AgentThreadGrants,
53+
AgentDatabaseGrants,
5354
VideoGrants,
5455
SIPGrants,
5556
AccessToken,
@@ -71,6 +72,7 @@
7172
"AgentGrants",
7273
"AgentEndpointGrants",
7374
"AgentThreadGrants",
75+
"AgentDatabaseGrants",
7476
"VideoGrants",
7577
"SIPGrants",
7678
"AccessToken",

‎livekit-api/livekit/api/access_token.py‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ class AgentGrants:
101101
admin: bool = False
102102
# manage simulations and scenarios for evaluating agents
103103
simulation_admin: bool = False
104-
# access the project's agent databases
105-
database_admin: bool = False
106104
# manage the project's agent dispatch queue
107105
dispatch_admin: bool = False
108106

@@ -130,6 +128,21 @@ class AgentThreadGrants:
130128
write: bool = False
131129
read: bool = False
132130
delete: bool = False
131+
# open a covered thread's database, whose id is the thread's
132+
sql: bool = False
133+
134+
135+
@dataclass
136+
class AgentDatabaseGrants:
137+
# databases that may be read, written and deleted
138+
database_ids: Optional[List[str]] = None
139+
read: bool = False
140+
write: bool = False
141+
delete: bool = False
142+
# create databases in the project
143+
create: bool = False
144+
# list the project's databases
145+
list: bool = False
133146

134147

135148
@dataclass
@@ -145,6 +158,7 @@ class Claims:
145158
agent: Optional[AgentGrants] = None
146159
agent_endpoint: Optional[AgentEndpointGrants] = None
147160
agent_thread: Optional[AgentThreadGrants] = None
161+
agent_database: Optional[AgentDatabaseGrants] = None
148162
attributes: Optional[dict[str, str]] = None
149163
sha256: Optional[str] = None
150164
room_preset: Optional[str] = None
@@ -217,6 +231,10 @@ def with_agent_thread_grants(self, grants: AgentThreadGrants) -> "AccessToken":
217231
self.claims.agent_thread = grants
218232
return self
219233

234+
def with_agent_database_grants(self, grants: AgentDatabaseGrants) -> "AccessToken":
235+
self.claims.agent_database = grants
236+
return self
237+
220238
def with_identity(self, identity: str) -> "AccessToken":
221239
self.identity = identity
222240
return self
@@ -322,6 +340,7 @@ def verify(self, token: str, *, verify_signature: bool = True) -> Claims:
322340
agent=_parse_grants(claims, "agent", AgentGrants),
323341
agent_endpoint=_parse_grants(claims, "agentEndpoint", AgentEndpointGrants),
324342
agent_thread=_parse_grants(claims, "agentThread", AgentThreadGrants),
343+
agent_database=_parse_grants(claims, "agentDatabase", AgentDatabaseGrants),
325344
)
326345

327346
if claims.get("roomPreset"):

‎livekit-protocol/livekit/protocol/agent.py‎

Lines changed: 72 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎livekit-protocol/livekit/protocol/agent.pyi‎

Lines changed: 44 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)