Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitde14cfa

Browse files
committed
feat: add API key scope for workspace agents to support running without user data access
Change-Id: Ia5a7085afea6ad6ab7fdba2ab738357f4c519966Signed-off-by: Thomas Kosiewski <tk@coder.com>
1 parenteb6412a commitde14cfa

28 files changed

+823
-446
lines changed

‎coderd/coderd.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,11 @@ func New(options *Options) *API {
802802
PostAuthAdditionalHeadersFunc:options.PostAuthAdditionalHeadersFunc,
803803
})
804804

805+
workspaceAgentInfo:=httpmw.ExtractWorkspaceAgentAndLatestBuild(httpmw.ExtractWorkspaceAgentAndLatestBuildConfig{
806+
DB:options.Database,
807+
Optional:false,
808+
})
809+
805810
// API rate limit middleware. The counter is local and not shared between
806811
// replicas or instances of this middleware.
807812
apiRateLimiter:=httpmw.RateLimit(options.APIRateLimit,time.Minute)
@@ -1289,10 +1294,7 @@ func New(options *Options) *API {
12891294
httpmw.RequireAPIKeyOrWorkspaceProxyAuth(),
12901295
).Get("/connection",api.workspaceAgentConnectionGeneric)
12911296
r.Route("/me",func(r chi.Router) {
1292-
r.Use(httpmw.ExtractWorkspaceAgentAndLatestBuild(httpmw.ExtractWorkspaceAgentAndLatestBuildConfig{
1293-
DB:options.Database,
1294-
Optional:false,
1295-
}))
1297+
r.Use(workspaceAgentInfo)
12961298
r.Get("/rpc",api.workspaceAgentRPC)
12971299
r.Patch("/logs",api.patchWorkspaceAgentLogs)
12981300
r.Patch("/app-status",api.patchWorkspaceAgentAppStatus)

‎coderd/database/dbauthz/dbauthz_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4018,8 +4018,9 @@ func (s *MethodTestSuite) TestSystemFunctions() {
40184018
s.Run("InsertWorkspaceAgent",s.Subtest(func(db database.Store,check*expects) {
40194019
dbtestutil.DisableForeignKeysAndTriggers(s.T(),db)
40204020
check.Args(database.InsertWorkspaceAgentParams{
4021-
ID:uuid.New(),
4022-
Name:"dev",
4021+
ID:uuid.New(),
4022+
Name:"dev",
4023+
APIKeyScope:database.AgentKeyScopeEnumAll,
40234024
}).Asserts(rbac.ResourceSystem,policy.ActionCreate)
40244025
}))
40254026
s.Run("InsertWorkspaceApp",s.Subtest(func(db database.Store,check*expects) {

‎coderd/database/dbgen/dbgen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ func WorkspaceAgent(t testing.TB, db database.Store, orig database.WorkspaceAgen
212212
MOTDFile:takeFirst(orig.TroubleshootingURL,""),
213213
DisplayApps:append([]database.DisplayApp{},orig.DisplayApps...),
214214
DisplayOrder:takeFirst(orig.DisplayOrder,1),
215+
APIKeyScope:takeFirst(orig.APIKeyScope,database.AgentKeyScopeEnumAll),
215216
})
216217
require.NoError(t,err,"insert workspace agent")
217218
returnagt

‎coderd/database/dbmem/dbmem.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9620,6 +9620,7 @@ func (q *FakeQuerier) InsertWorkspaceAgent(_ context.Context, arg database.Inser
96209620
LifecycleState:database.WorkspaceAgentLifecycleStateCreated,
96219621
DisplayApps:arg.DisplayApps,
96229622
DisplayOrder:arg.DisplayOrder,
9623+
APIKeyScope:arg.APIKeyScope,
96239624
}
96249625

96259626
q.workspaceAgents=append(q.workspaceAgents,agent)

‎coderd/database/dump.sql

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- Remove the api_key_scope column from the workspace_agents table
2+
ALTERTABLE workspace_agents
3+
DROP COLUMN IF EXISTS api_key_scope;
4+
5+
-- Drop the enum type for API key scope
6+
DROPTYPE IF EXISTS agent_key_scope_enum;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- Create the enum type for API key scope
2+
CREATETYPEagent_key_scope_enumAS ENUM ('all','no_user_data');
3+
4+
-- Add the api_key_scope column to the workspace_agents table
5+
-- It defaults to 'all' to maintain existing behavior for current agents.
6+
ALTERTABLE workspace_agents
7+
ADD COLUMN api_key_scope agent_key_scope_enumNOT NULL DEFAULT'all';
8+
9+
-- Add a comment explaining the purpose of the column
10+
COMMENT ON COLUMN workspace_agents.api_key_scope IS'Defines the scope of the API key associated with the agent.''all'' allows access to everything,''no_user_data'' restricts it to exclude user data.';

‎coderd/database/models.go

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp