Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate namespace prefix before tainting route entries #21470

Merged
merged 6 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/24170.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
core: Fixed an instance where incorrect route entries would get tainted. We now pre-calculate namespace specific paths to avoid this.
```
8 changes: 8 additions & 0 deletions vault/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,14 @@ func (c *Core) setupCredentials(ctx context.Context) error {
// Calculate any namespace prefixes here, because when Taint() is called, there won't be
// a namespace to pull from the context. This is similar to what we do above in c.router.Mount().
path = entry.Namespace().Path + path
if entry.Path != path {
VioletHynes marked this conversation as resolved.
Show resolved Hide resolved
nsfc, err := namespace.FromContext(ctx)
if err != nil {
c.logger.Error("error when trying to get the namespace from the context", "error", err)
} else {
c.logger.Debug("tainting a mount but path and namespaced path disagree", "entry_path", entry.Path, "entry_namespace_path", entry.Namespace().Path, "namespace_from_context", nsfc)
}
}
c.router.Taint(ctx, path)
}

Expand Down
13 changes: 12 additions & 1 deletion vault/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,18 @@ func (c *Core) setupMounts(ctx context.Context) error {

// Ensure the path is tainted if set in the mount table
if entry.Tainted {
c.router.Taint(ctx, entry.Path)
// Calculate any namespace prefixes here, because when Taint() is called, there won't be
// a namespace to pull from the context. This is similar to what we do above in c.router.Mount().
path := entry.Namespace().Path + entry.Path
if entry.Path != path {
nsfc, err := namespace.FromContext(ctx)
if err != nil {
c.logger.Error("error when trying to get the namespace from the context", "error", err)
} else {
c.logger.Debug("tainting a mount but path and namespaced path disagree", "entry_path", entry.Path, "entry_namespace_path", entry.Namespace().Path, "namespace_from_context", nsfc)
VioletHynes marked this conversation as resolved.
Show resolved Hide resolved
}
}
c.router.Taint(ctx, path)
}

// Ensure the cache is populated, don't need the result
Expand Down