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

Commit68e6b44

Browse files
authored
Merge branch 'main' into jaaydenh/fix-workspace-permissions
2 parentsf8104b0 +42e5d71 commit68e6b44

File tree

4 files changed

+153
-359
lines changed

4 files changed

+153
-359
lines changed

‎agent/agent.go

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,9 +1186,9 @@ func (a *agent) createOrUpdateNetwork(manifestOK, networkOK *checkpoint) func(co
11861186
network:=a.network
11871187
a.closeMutex.Unlock()
11881188
ifnetwork==nil {
1189-
keySeed,err:=WorkspaceKeySeed(manifest.WorkspaceID,manifest.AgentName)
1189+
keySeed,err:=SSHKeySeed(manifest.OwnerName,manifest.WorkspaceName,manifest.AgentName)
11901190
iferr!=nil {
1191-
returnxerrors.Errorf("generateseed from workspace id: %w",err)
1191+
returnxerrors.Errorf("generateSSH key seed: %w",err)
11921192
}
11931193
// use the graceful context here, because creating the tailnet is not itself tied to the
11941194
// agent API.
@@ -1518,14 +1518,11 @@ func (a *agent) runCoordinator(ctx context.Context, tClient tailnetproto.DRPCTai
15181518
a.logger.Info(ctx,"connected to coordination RPC")
15191519

15201520
// This allows the Close() routine to wait for the coordinator to gracefully disconnect.
1521-
a.closeMutex.Lock()
1522-
ifa.isClosed() {
1523-
returnnil
1521+
disconnected:=a.setCoordDisconnected()
1522+
ifdisconnected==nil {
1523+
returnnil// already closed by something else
15241524
}
1525-
disconnected:=make(chanstruct{})
1526-
a.coordDisconnected=disconnected
15271525
deferclose(disconnected)
1528-
a.closeMutex.Unlock()
15291526

15301527
ctrl:=tailnet.NewAgentCoordinationController(a.logger,network)
15311528
coordination:=ctrl.New(coordinate)
@@ -1547,6 +1544,17 @@ func (a *agent) runCoordinator(ctx context.Context, tClient tailnetproto.DRPCTai
15471544
return<-errCh
15481545
}
15491546

1547+
func (a*agent)setCoordDisconnected()chanstruct{} {
1548+
a.closeMutex.Lock()
1549+
defera.closeMutex.Unlock()
1550+
ifa.isClosed() {
1551+
returnnil
1552+
}
1553+
disconnected:=make(chanstruct{})
1554+
a.coordDisconnected=disconnected
1555+
returndisconnected
1556+
}
1557+
15501558
// runDERPMapSubscriber runs a coordinator and returns if a reconnect should occur.
15511559
func (a*agent)runDERPMapSubscriber(ctx context.Context,tClient tailnetproto.DRPCTailnetClient24,network*tailnet.Conn)error {
15521560
defera.logger.Debug(ctx,"disconnected from derp map RPC")
@@ -2068,12 +2076,31 @@ func PrometheusMetricsHandler(prometheusRegistry *prometheus.Registry, logger sl
20682076
})
20692077
}
20702078

2071-
//WorkspaceKeySeed convertsa WorkspaceID UUIDandagent name to an int64 hash.
2079+
//SSHKeySeed convertsan owner userName, workspaceNameandagentName to an int64 hash.
20722080
// This uses the FNV-1a hash algorithm which provides decent distribution and collision
20732081
// resistance for string inputs.
2074-
funcWorkspaceKeySeed(workspaceID uuid.UUID,agentNamestring) (int64,error) {
2082+
//
2083+
// Why owner username, workspace name, and agent name? These are the components that are used in hostnames for the
2084+
// workspace over SSH, and so we want the workspace to have a stable key with respect to these. We don't use the
2085+
// respective UUIDs. The workspace UUID would be different if you delete and recreate a workspace with the same name.
2086+
// The agent UUID is regenerated on each build. Since Coder's Tailnet networking is handling the authentication, we
2087+
// should not be showing users warnings about host SSH keys.
2088+
funcSSHKeySeed(userName,workspaceName,agentNamestring) (int64,error) {
20752089
h:=fnv.New64a()
2076-
_,err:=h.Write(workspaceID[:])
2090+
_,err:=h.Write([]byte(userName))
2091+
iferr!=nil {
2092+
return42,err
2093+
}
2094+
// null separators between strings so that (dog, foodstuff) is distinct from (dogfood, stuff)
2095+
_,err=h.Write([]byte{0})
2096+
iferr!=nil {
2097+
return42,err
2098+
}
2099+
_,err=h.Write([]byte(workspaceName))
2100+
iferr!=nil {
2101+
return42,err
2102+
}
2103+
_,err=h.Write([]byte{0})
20772104
iferr!=nil {
20782105
return42,err
20792106
}

‎cli/ssh_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@ func TestSSH(t *testing.T) {
479479
ctx,cancel:=context.WithTimeout(context.Background(),testutil.WaitLong)
480480
defercancel()
481481

482+
user,err:=client.User(ctx,codersdk.Me)
483+
require.NoError(t,err)
484+
482485
inv,root:=clitest.New(t,"ssh","--stdio",workspace.Name)
483486
clitest.SetupConfig(t,client,root)
484487
inv.Stdin=clientOutput
@@ -490,7 +493,7 @@ func TestSSH(t *testing.T) {
490493
assert.NoError(t,err)
491494
})
492495

493-
keySeed,err:=agent.WorkspaceKeySeed(workspace.ID,"dev")
496+
keySeed,err:=agent.SSHKeySeed(user.Username,workspace.Name,"dev")
494497
assert.NoError(t,err)
495498

496499
signer,err:=agentssh.CoderSigner(keySeed)

‎site/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204
"overrides": {
205205
"@babel/runtime":"7.26.10",
206206
"@babel/helpers":"7.26.10",
207+
"esbuild":"^0.25.0",
207208
"prismjs":"1.30.0"
208209
}
209210
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp