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

dry run rotate [T813] #269

Merged
merged 5 commits into from
Oct 11, 2018
Merged

dry run rotate [T813] #269

merged 5 commits into from
Oct 11, 2018

Conversation

Lagovas
Copy link
Collaborator

@Lagovas Lagovas commented Oct 10, 2018

acra-rotate with flag --dry-run will fetch acrastructs (from files or database), decrypt, rotate in memory keys, encrypt with new public keys and print result json with new public keys without saving rotated keys and acrastructs (to filesystem or database)

@@ -152,43 +79,36 @@ func rotateDb(selectQuery, updateQuery string, db *sql.DB, keystore keystore.Key
return false
}
logger := log.WithFields(log.Fields{"ZoneId": string(acraStructID)})
logger.Infof("Rotate AcraStruct with ZoneId=%s", string(acraStructID))
logger.Infof("Rotate AcraStruct")
Copy link
Collaborator

@vixentael vixentael Oct 10, 2018

Choose a reason for hiding this comment

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

why we don't log zone id anymore?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should log smth like Rotating in dry-run mode if dry-run is true

Copy link
Collaborator Author

@Lagovas Lagovas Oct 11, 2018

Choose a reason for hiding this comment

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

why we don't log zone id anymore?

because row above create logger with zone as field that always will be included in log messages

I think we should log smth like Rotating in dry-run mode if dry-run is true

agree

return output, nil
}

// runFileRotation read map zones to files, re-generate zone key pairs and re-encrypt files
func runFileRotation(fileMapConfigPath string, keystorage keystore.KeyStore) {
func runFileRotation(fileMapConfigPath string, keystorage keystore.KeyStore, dryRun bool) {
fileMap, err := loadFileMap(fileMapConfigPath)
if err != nil {
log.WithError(err).Errorln("Can't load config with map <ZoneId>: <FilePath>")
os.Exit(1)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same, I think we should log "Starting in .. dry-run mode"

}

func (rotator *keyRotator) clearKeys() {
for _, keypair := range rotator.newKeypairs {
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

logger.WithField("acrastruct", hex.EncodeToString(acrastruct)).WithError(err).Errorln("Can't decrypt AcraStruct")
return nil, err
}
utils.FillSlice(0, privateKey.Value)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

}
decrypted, err := base.DecryptAcrastruct(acrastruct, privateKey, zoneID)
if err != nil {
logger.WithField("acrastruct", hex.EncodeToString(acrastruct)).WithError(err).Errorln("Can't decrypt AcraStruct")
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe it worth zero-ing private key in case of error too?

@@ -105,26 +106,27 @@ func testGeneratingDataEncryptionKeys(store *FilesystemKeyStore, t *testing.T) {
}
}

func checkPath(path string, t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@@ -57,12 +57,13 @@ func (rotator *keyRotator) rotateAcrastruct(zoneID, acrastruct []byte) ([]byte,
logger.WithField("acrastruct", hex.EncodeToString(acrastruct)).WithError(err).Errorln("Can't get private key")
return nil, err
}
defer utils.FillSlice(0, privateKey.Value)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@vixentael
Copy link
Collaborator

Looks awesome!

@vixentael vixentael merged commit 5c21bdf into cossacklabs:master Oct 11, 2018
@Lagovas Lagovas deleted the lagovas/T813-dry-run-rotate branch October 25, 2018 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants