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

When tainting a route during setup, pre-calculate the namespace specific path #15067

Merged
merged 9 commits into from Apr 26, 2022

Conversation

raskchanky
Copy link
Contributor

No description provided.

@@ -835,6 +835,9 @@ func (c *Core) setupCredentials(ctx context.Context) error {

// Ensure the path is tainted if set in the mount table
if entry.Tainted {
// 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
c.router.Taint(ctx, path)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this is called as part of postUnseal(), as best as I can tell, we're passing an empty context all the way through these methods, originating here: https://github.com/hashicorp/vault/blob/main/vault/core.go#L1693 That means the namespace specific path that we need to add to the path won't exist in the context, as Taint() expects it to. Instead, we use the namespace specific path from the mount entry.

Copy link
Contributor

@HridoyRoy HridoyRoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm!

@raskchanky raskchanky added this to the 1.10.2 milestone Apr 15, 2022
@raskchanky raskchanky marked this pull request as ready for review April 18, 2022 15:56
@@ -47,6 +47,8 @@ func NewRouter() *Router {
storagePrefix: radix.New(),
mountUUIDCache: radix.New(),
mountAccessorCache: radix.New(),
// this will get replaced in production with a real logger but it's useful to have a default in place for tests
logger: hclog.NewNullLogger(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The router has a logger, but before this PR, it didn't get assigned as part of NewRouter(). That made lots of tests that exercise the router fail with nil pointer exceptions, due to the new logging lines. The actual logger for the router gets assigned here, as part of CreateCore() but it felt like a good idea to have a default assigned to the router from the get-go. Does this seem acceptable as is, or should this default be a more legit logger?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this.

vault/router.go Outdated Show resolved Hide resolved
vault/router.go Outdated Show resolved Hide resolved
vault/router.go Outdated Show resolved Hide resolved
vault/router.go Outdated
}
r.l.RUnlock()
if !ok {
r.logger.Trace("route entry not found", "path", req.Path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also result in a very high log volume. Can you use a metric instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up removing this in favor of augmented error messages. I could add additional metrics as well, but after thinking this over a bit, I wasn't sure what kind of metric to add. Are you thinking of a counter each time this failure happens? Or something else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants