-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
dba2de5
Change storage of entries from colons to hyphens and add a
jefferai c269fe1
Tests for cert and crl util
calvn 4bf51ca
Fix crl_util test
calvn ced4c88
Add remaining tests
calvn a5ddaab
Rename tests, use HandleRequest() for existing paths
calvn 7fdf4ac
Verify update operation was performed on revokeCert
calvn 38a01b8
Refactor cert_util_test
calvn 74965a8
Add test for ca and crl case
calvn 8c03765
Use variables for string replacements on cert_util
calvn 96bcd50
Include and use normalizeSerial func
calvn 29e5ce6
Minor readability enhancements for migration path from old to new
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package pki | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"strings" | ||
|
||
"github.com/hashicorp/vault/logical" | ||
) | ||
|
||
func TestPki_FetchCertBySerial(t *testing.T) { | ||
storage := &logical.InmemStorage{} | ||
|
||
cases := map[string]struct { | ||
Req *logical.Request | ||
Prefix string | ||
Serial string | ||
}{ | ||
"valid cert": { | ||
&logical.Request{ | ||
Storage: storage, | ||
}, | ||
"certs/", | ||
"00:00:00:00:00:00:00:00", | ||
}, | ||
"revoked cert": { | ||
&logical.Request{ | ||
Storage: storage, | ||
}, | ||
"revoked/", | ||
"11:11:11:11:11:11:11:11", | ||
}, | ||
} | ||
|
||
// Test for colon-based paths in storage | ||
for name, tc := range cases { | ||
storageKey := fmt.Sprintf("%s%s", tc.Prefix, tc.Serial) | ||
err := storage.Put(&logical.StorageEntry{ | ||
Key: storageKey, | ||
Value: []byte("some data"), | ||
}) | ||
if err != nil { | ||
t.Fatalf("error writing to storage on %s colon-based storage path: %s", name, err) | ||
} | ||
|
||
certEntry, err := fetchCertBySerial(tc.Req, tc.Prefix, tc.Serial) | ||
if err != nil { | ||
t.Fatalf("error on %s for colon-based storage path: %s", name, err) | ||
} | ||
|
||
// Check for non-nil on valid/revoked certs | ||
if certEntry == nil { | ||
t.Fatalf("nil on %s for colon-based storage path", name) | ||
} | ||
|
||
// Ensure that cert serials are converted/updated after fetch | ||
expectedKey := tc.Prefix + normalizeSerial(tc.Serial) | ||
se, err := storage.Get(expectedKey) | ||
if err != nil { | ||
t.Fatalf("error on %s for colon-based storage path:%s", name, err) | ||
} | ||
if strings.Compare(expectedKey, se.Key) != 0 { | ||
t.Fatalf("expected: %s, got: %s", expectedKey, certEntry.Key) | ||
} | ||
} | ||
|
||
// Reset storage | ||
storage = &logical.InmemStorage{} | ||
|
||
// Test for hyphen-base paths in storage | ||
for name, tc := range cases { | ||
storageKey := tc.Prefix + normalizeSerial(tc.Serial) | ||
err := storage.Put(&logical.StorageEntry{ | ||
Key: storageKey, | ||
Value: []byte("some data"), | ||
}) | ||
if err != nil { | ||
t.Fatalf("error writing to storage on %s hyphen-based storage path: %s", name, err) | ||
} | ||
|
||
certEntry, err := fetchCertBySerial(tc.Req, tc.Prefix, tc.Serial) | ||
if err != nil || certEntry == nil { | ||
t.Fatalf("error on %s for hyphen-based storage path: err: %v, entry: %v", name, err, certEntry) | ||
} | ||
} | ||
|
||
noConvCases := map[string]struct { | ||
Req *logical.Request | ||
Prefix string | ||
Serial string | ||
}{ | ||
"ca": { | ||
&logical.Request{ | ||
Storage: storage, | ||
}, | ||
"", | ||
"ca", | ||
}, | ||
"crl": { | ||
&logical.Request{ | ||
Storage: storage, | ||
}, | ||
"", | ||
"crl", | ||
}, | ||
} | ||
|
||
// Test for ca and crl case | ||
for name, tc := range noConvCases { | ||
err := storage.Put(&logical.StorageEntry{ | ||
Key: tc.Serial, | ||
Value: []byte("some data"), | ||
}) | ||
if err != nil { | ||
t.Fatalf("error writing to storage on %s: %s", name, err) | ||
} | ||
|
||
certEntry, err := fetchCertBySerial(tc.Req, tc.Prefix, tc.Serial) | ||
if err != nil || certEntry == nil { | ||
t.Fatalf("error on %s: err: %v, entry: %v", name, err, certEntry) | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package pki | ||
|
||
import "strings" | ||
|
||
func normalizeSerial(serial string) string { | ||
return strings.Replace(strings.ToLower(serial), ":", "-", -1) | ||
} |
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, missed that.