fix(coderd): normalize workspace secret path comparisons (#32868)
## Why `~/.token` and `~//.token` point to the same file, but a workspace build could accept a different secret for each spelling. Replacing a secret on a later build could leave the old value active alongside its replacement. ## How Validation, carry-forward, and delivery now use the same key to compare file paths. The stored paths stay as entered, so existing secrets need no migration. <details> <summary>Decision and regression coverage</summary> Comparison is lexical: `~/../~/x` and `~/x` count as a collision even if they would resolve to different files on the agent. A regression test pins that behavior. The database still indexes the original spelling, so existing aliases can carry forward together until a new secret claims their target. Regression tests check the field-specific validation error and verify that only the replacement survives a later build. Original report: https://github.com/coder/coder/pull/30250#discussion_r4272372439 (RELAY-64). </details> Created by Coder Agents on behalf of @Emyrk.
This commit is contained in:
1 parent
94f40c3a73
commit
b16153960d
4 files changed
+51
-12
No files matched your search
@@ -52,6 +52,16 @@ func (r Resolved) Delivered() bool {
|
||||
return r.DeliveredEnvName != "" || r.DeliveredFilePath != ""
|
||||
}
|
||||
|
||||
// FilePathKey compares secret targets lexically without expanding the agent's
|
||||
// home directory. In particular, "~/../~/x" and "~/x" collide even though the
|
||||
// former can point into a directory literally named "~". An empty path is unset.
|
||||
func FilePathKey(filePath string) string {
|
||||
if filePath == "" {
|
||||
return ""
|
||||
}
|
||||
return path.Clean(filePath)
|
||||
}
|
||||
|
||||
// Resolve returns the delivery outcome of the user secrets and the workspace
|
||||
// build secrets, each in input order.
|
||||
//
|
||||
@@ -71,7 +81,7 @@ func Resolve(user, build []Secret, policy FilePathPolicy) (resolvedUser, resolve
|
||||
if claim(envOwner, s.EnvName, s.ID, &r.EnvReplacedBy) {
|
||||
r.DeliveredEnvName = s.EnvName
|
||||
}
|
||||
if policy == FilePathAllowed && s.FilePath != "" && claim(fileOwner, path.Clean(s.FilePath), s.ID, &r.FileReplacedBy) {
|
||||
if policy == FilePathAllowed && claim(fileOwner, FilePathKey(s.FilePath), s.ID, &r.FileReplacedBy) {
|
||||
r.DeliveredFilePath = s.FilePath
|
||||
}
|
||||
return r
|
||||
|
||||
Reference in new issue
Block a user