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

Token signing key is now randomly generated on demand if not already present #135

Merged
merged 2 commits into from
Apr 13, 2017

Conversation

dseevr
Copy link
Contributor

@dseevr dseevr commented Apr 12, 2017

Additionally, ensure that the PRNG has been seeded

Signed-off-by: Bill Robinson [email protected]

@dseevr dseevr requested a review from yuva29 April 12, 2017 19:31
auth/token.go Outdated
TokenSigningKey = "ccn$!~56"
// this is the datastore key, not the actual bytes used for signing.
// since changes are not handled by an abstraction layer, construct the path manually
tokenSigningKey = types.AuthProxyDir + "/token_signing_key"
Copy link
Contributor

Choose a reason for hiding this comment

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

This the place we maintain all the datastore paths https://github.com/contiv/auth_proxy/blob/master/db/constants.go. And, we use GetPath to get the absolute datastore path like here https://github.com/contiv/auth_proxy/blob/master/db/local.go#L61

I recommend to follow the same style.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

auth/token.go Outdated

var tokenCharacters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")

func generateTokenSigningKey() string {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think of following approach 3 which seems to be fast http://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-golang

And, this func can be named generateRandString. Yay??

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 don't think there's any value in extracting this into a reusable function right now. The valid characters are also specific to the token signing key.

This function is being called extremely infrequently. The cumulative CPU time of everyone who will ever have this code execute on their systems would never add up to the time it would take to replace it with an optimized version. The third option there also doesn't have the same probability for all characters to be chosen.

auth/token.go Outdated
defer signingKeyMutex.Unlock()

// check for an existing existing key
existingKey, err := stateDrv.Read(tokenSigningKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel this is more clear this way

 switch(err) {
 case err == auth_errors.ErrKeyNotFound:
 case err == auth_errors.ErrKeyExists:
 default:
  return "", err
 
 }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

common/crypto.go Outdated
@@ -24,6 +27,10 @@ const (
cost = 13
)

func init() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This package was calling crypto-related stuff without a guaranteed-to-be-seeded PRNG

@dseevr
Copy link
Contributor Author

dseevr commented Apr 12, 2017

PTAL again

@yuva29
Copy link
Contributor

yuva29 commented Apr 12, 2017

Please add test so we can be sure that this works fine.

@dseevr dseevr force-pushed the signing_key branch 4 times, most recently from e397c6b to ee836c6 Compare April 13, 2017 17:15
Copy link
Contributor

@yuva29 yuva29 left a comment

Choose a reason for hiding this comment

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

LGTM expect that one comment.


// make sure the old token does not work
resp, _ = proxyGet(c, firstToken, endpoint)
c.Assert(resp.StatusCode, Equals, 400)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please check the body to be Bad Token

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, but this didn't get collapsed because I didn't edit this line

…present

Additionally, ensure that the PRNG has been seeded

Signed-off-by: Bill Robinson <[email protected]>
…han calling `make` from test code

Test code runs as root in the docker containers and this results in a root-owned "local_certs" directory

Signed-off-by: Bill Robinson <[email protected]>
@dseevr dseevr merged commit 53c548a into contiv:master Apr 13, 2017
@dseevr dseevr deleted the signing_key branch April 13, 2017 22:13
dseevr pushed a commit to dseevr-dev/auth_proxy that referenced this pull request Dec 21, 2017
* sidebarmenu active menu items highlighted.

* sidebarmenu item being highlighted

* Updated code comments
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.

2 participants