fix(keymanager): parse key files strictly, warn on writable files, and pin the unpinned controls - #477
Merged
Conversation
… directories, and pin the mode, tighten and recovery controls Signed-off-by: Jaro-c <75870284+Jaro-c@users.noreply.github.com>
…e current key's id Signed-off-by: Jaro-c <75870284+Jaro-c@users.noreply.github.com>
…ent first start as it works Signed-off-by: Jaro-c <75870284+Jaro-c@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #476 in three commits, each building and passing on its own.
keymanager
decodePEMBlockis the one parser behind both key files andFromPEM: the input must start with a PEM block, the block must be labelledPRIVATE KEYorPUBLIC KEYas expected, carry no headers, and be the only thing in the input apart from whitespace. The refresh-secret error no longer wraps the hex package's error, which quotes a byte of the file. A key file with text before or after its block, or with headers, is refused at startup now. Files written by authcore, byopenssl genpkey/pkey -pubout, and byauthcore-keygenare unaffected.0o066), so a secret file others can replace is reported, andLoadwarns whenKeysDiris group- or world-writable without the sticky bit (a Kubernetes Secret mount is1777and is not reported).Newstill tightens the directory instead.existsmakes callers "fail closed rather than generating" now say what it feeds.KeyID:
Newrefuses aKeyStorewhoseKeysreport an emptyKeyID, andjwt.Newrefuses aPreviousPublicKeysentry whose id equals the current key's, withErrInvalidConfig, instead of letting it replace the current key in the verification set. TheKeys.KeyIDcontract anddocs/key-management.mdsay so. I did not require a custom store to reproduce the built-in derivation: it is an internal detail, and a store with its own stable ids has worked and keeps working.docs:
docs/faq.mdno longer tells an operator to delete.authcore;docs/containers.mddescribes concurrent first start as measured today rather than as "being reworked".Tests
mode_table_test.go: {New,Load} × {private key, refresh secret} × {0640, 0604, 0602, 0620, 0600, 0400}, exactly one warning naming the file for the four open modes and none otherwise;Loadon a 0777 and 0733 directory warns, on 1777 (sticky), 0700 and 0750 does not, and the mode is left as found.review_round2_internal_test.go:Newon a 0555 directory leaves it at 0500 and 0750 at 0700; recovery with an unrelated staging directory that sorts first still completes from the one whose private key matches; seven non-canonical PEM inputs refused with the reason named and the canonical pair (with surrounding whitespace) accepted; the not-hex error names no byte of the file and a hex file of the same length loads.TestNewWarnsWhenTheParentCannotBeSynced,TestNew_refusesAnEmptyKeyID(with a custom non-empty id accepted),TestNew_refusesAPreviousKeyWithTheCurrentKeyID(with a different key registered).Sabotage, each edit confirmed to change the file:
New/ the private-key warning onLoadChmod(dir, dirMode)instead ofmode&dirMode|| true)KeyID/ a previous key with the current idgofmt,go vet ./...,go test -race -count=1 ./..., gosec and the nine example builds are clean.internal/keymanageris at 90.3%, the root package at 96.2%,auth/jwtat 94.5%. The keymanager figure sits close to the floor because the strict parser and the directory warning add branches; the untested ones are the Windows returns and the non-permission parent-sync failure, which has no fault seam.Signed-off-by: Jaro-c 75870284+Jaro-c@users.noreply.github.com