- Notifications
You must be signed in to change notification settings - Fork906
fix!: use names not IDs for agent SSH key seed#17258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
29 changes: 24 additions & 5 deletionsagent/agent.go
This file contains hidden or 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 |
---|---|---|
@@ -1186,9 +1186,9 @@ func (a *agent) createOrUpdateNetwork(manifestOK, networkOK *checkpoint) func(co | ||
network := a.network | ||
a.closeMutex.Unlock() | ||
if network == nil { | ||
keySeed, err :=SSHKeySeed(manifest.OwnerName, manifest.WorkspaceName, manifest.AgentName) | ||
if err != nil { | ||
return xerrors.Errorf("generateSSH key seed: %w", err) | ||
} | ||
// use the graceful context here, because creating the tailnet is not itself tied to the | ||
// agent API. | ||
@@ -2068,12 +2068,31 @@ func PrometheusMetricsHandler(prometheusRegistry *prometheus.Registry, logger sl | ||
}) | ||
} | ||
//SSHKeySeed convertsan owner userName, workspaceNameandagentName to an int64 hash. | ||
// This uses the FNV-1a hash algorithm which provides decent distribution and collision | ||
// resistance for string inputs. | ||
// | ||
// Why owner username, workspace name, and agent name? These are the components that are used in hostnames for the | ||
// workspace over SSH, and so we want the workspace to have a stable key with respect to these. We don't use the | ||
// respective UUIDs. The workspace UUID would be different if you delete and recreate a workspace with the same name. | ||
// The agent UUID is regenerated on each build. Since Coder's Tailnet networking is handling the authentication, we | ||
// should not be showing users warnings about host SSH keys. | ||
func SSHKeySeed(userName, workspaceName, agentName string) (int64, error) { | ||
h := fnv.New64a() | ||
_, err := h.Write([]byte(userName)) | ||
if err != nil { | ||
return 42, err | ||
} | ||
// null separators between strings so that (dog, foodstuff) is distinct from (dogfood, stuff) | ||
_, err = h.Write([]byte{0}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. 👍🏻 | ||
if err != nil { | ||
return 42, err | ||
} | ||
_, err = h.Write([]byte(workspaceName)) | ||
if err != nil { | ||
return 42, err | ||
} | ||
_, err = h.Write([]byte{0}) | ||
if err != nil { | ||
return 42, err | ||
} | ||
5 changes: 4 additions & 1 deletioncli/ssh_test.go
This file contains hidden or 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
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.