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

Change storage of PKI entries from colons to hyphens #2575

Merged
merged 11 commits into from
May 3, 2017

Conversation

jefferai
Copy link
Member

@jefferai jefferai commented Apr 6, 2017

Also add a lookup/migration path

Fixes #2552

@jefferai jefferai added this to the 0.7.1 milestone Apr 6, 2017
lookup/migration path

Still TODO: tests on migration path

Fixes #2552
@calvn
Copy link
Member

calvn commented Apr 26, 2017

I figured out why it was failing. I was passing in the JSON encoded cert DER, but for valid certs I was still using PEM format. I wonder why I was passing half of the time before though...

Schema: pathSetSignedIntermediate(b).Fields,
}

resp, err := b.pathSetSignedIntermediate(req, fd)
Copy link
Member

Choose a reason for hiding this comment

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

On a second thought, I think I should be using b.HandleRequest(req) here instead, with the appropriate req.Path and req.Data. Is that correct @jefferai?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, that's the best approach usually. Also it takes care of setting the field data for you!

},
}

resp, err := b.pathIssueSignCert(req, fd, role, false, false)
Copy link
Member

Choose a reason for hiding this comment

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

Same here, use b.HandleRequest(req)?

Copy link
Member

Choose a reason for hiding this comment

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

I've changed the other tests to use b.HandleRequest(req) where appropriate, but not sure what to do with this one, since it's not really an exposed path.

Schema: pathGenerateRoot(b).Fields,
}

resp, err := b.pathCAGenerateRoot(req, fd)
Copy link
Member

Choose a reason for hiding this comment

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

Same here, use b.HandleRequest(req)?

Schema: pathSignIntermediate(b).Fields,
}

resp, err := b.pathCASignIntermediate(req, fd)
Copy link
Member

Choose a reason for hiding this comment

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

b.HandleRequest(req)?

@calvn
Copy link
Member

calvn commented Apr 28, 2017

@jefferai I took a look at code around references for Storage.Put, Storage.Get, and fetchCertBySerial on the pki package and didn't find any cases uncovered. I think I heard you mention there were two that you found, so let me know otherwise.

@jefferai jefferai changed the title [WIP] Change storage of entries from colons to hyphens Change storage of entries from colons to hyphens Apr 28, 2017
@jefferai
Copy link
Member Author

I think this LGTM, adding Chris for another look.

@jefferai jefferai changed the title Change storage of entries from colons to hyphens Change storage of PKI entries from colons to hyphens Apr 28, 2017
Copy link
Contributor

@chrishoffman chrishoffman left a comment

Choose a reason for hiding this comment

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

Overall this looks good. Just a few minor revisions requested.

// If we get here we need to check for old-style paths using colons
switch {
case strings.HasPrefix(prefix, "revoked/"):
path = "revoked/" + strings.Replace(strings.ToLower(serial), "-", ":", -1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of flipping the path back and forth, could we store two path variables and use them as we need them? I think this would improve the readability of this code.

"certs/",
"00:00:00:00:00:00:00:00",
},
"revoked cert": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add some cases that do not need the upgrade?

Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/hashicorp/vault/pull/2575/files/74965a87af47099b859552fdf2674038228a2c2e#diff-d9cca2f9a1b12f082084eaa700fff503R72 handles the cases for valid/revoked certs where the underlying path is already hyphenated so that there is no need to update the paths.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, missed that.

@jefferai
Copy link
Member Author

jefferai commented May 2, 2017

I can't approve my own PR. :-/

return nil, nil
}

// Save the desired path
desiredPath := 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 path is no longer needed. You can use hyphenSerial.

Copy link
Member

Choose a reason for hiding this comment

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

Good catch!

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh nevermind. That does not work. That was also one of the reason I wanted to move away from the multiple replacements... Maybe it makes sense to create the legacyPath and path instead of just tracking the serial.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, path in this case includes the prefix, so I think we have to save it as desiredPath instead of simply using hyphenSerial.

@@ -196,7 +197,7 @@ func (b *backend) pathSetSignedIntermediate(
return nil, err
}

entry.Key = "certs/" + cb.SerialNumber
entry.Key = "certs/" + strings.ToLower(strings.Replace(cb.SerialNumber, ":", "-", -1))
Copy link
Member

Choose a reason for hiding this comment

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

Can we have this creation of hyphenSerial in a function and use it in all the places? Seems like we are doing it in a couple of places. Easy to miss out if some if we make changes to this.

Copy link
Member

@vishalnayak vishalnayak left a comment

Choose a reason for hiding this comment

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

LGTM!

@chrishoffman chrishoffman merged commit cf4ef59 into master May 3, 2017
@@ -216,22 +218,12 @@ func fetchCertBySerial(req *logical.Request, prefix, serial string) (*logical.St
}

// No point checking these, no old/new style colons/hyphens
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this comment makes sense any more. We should keep the check with path for clarity, or update the comment to say why return if legacyPath is empty.

@jefferai jefferai deleted the pki-colons-to-hyphens branch May 3, 2017 19:43
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.

4 participants