-
Notifications
You must be signed in to change notification settings - Fork 273
NO-JIRA: KMS Rotation End2End #2452
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
Open
tjungblu
wants to merge
1
commit into
openshift:master
Choose a base branch
from
tjungblu:keyrotkms222
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -216,26 +216,49 @@ func (c *migrationController) migrateKeysIfNeededAndRevisionStable(ctx context.C | |
| // using a write key that another API server has not observed | ||
| // this could lead to etcd storing data that not all API servers can decrypt | ||
| var errs []error | ||
| var writeKeyState state.KeyState | ||
| var writeKeySecretName string | ||
| var migrationWriteKey string | ||
| var hadRemoteKeyMigration bool | ||
| var writeKeyGRs []schema.GroupResource | ||
| var remoteKeyMigratedGRs []schema.GroupResource | ||
| for _, gr := range grs { | ||
| grActualKeys := currentState[gr] | ||
| if !grActualKeys.HasWriteKey() { | ||
| continue // no write key to migrate to | ||
| } | ||
|
|
||
| if alreadyMigrated, _, _ := state.MigratedFor([]schema.GroupResource{gr}, grActualKeys.WriteKey); alreadyMigrated { | ||
| writeKeyState = grActualKeys.WriteKey | ||
| writeKeySecret, err := secrets.FromKeyState(c.instanceName, grActualKeys.WriteKey) | ||
| if err != nil { | ||
| errs = append(errs, err) | ||
| continue | ||
| } | ||
| writeKeySecretName = writeKeySecret.Name | ||
| remoteKeyAnnotations := grActualKeys.WriteKey.RemoteKey() | ||
| migrationWriteKey = secrets.MigrationWriteKeyName(grActualKeys.WriteKey.Key.Name, remoteKeyAnnotations) | ||
| remoteKeyMigration := secrets.NeedsRemoteKeyMigration(remoteKeyAnnotations) | ||
| if remoteKeyMigration { | ||
| hadRemoteKeyMigration = true | ||
| writeKeyGRs = append(writeKeyGRs, gr) | ||
| } | ||
|
|
||
| if !remoteKeyMigration { | ||
| if alreadyMigrated, _, _ := state.MigratedFor([]schema.GroupResource{gr}, grActualKeys.WriteKey); alreadyMigrated { | ||
| continue | ||
| } | ||
| } | ||
|
|
||
| // idem-potent migration start | ||
| finished, result, when, err := c.migrator.EnsureMigration(gr, grActualKeys.WriteKey.Key.Name) | ||
| finished, result, when, err := c.migrator.EnsureMigration(gr, migrationWriteKey) | ||
| if err == nil && finished && result != nil && time.Since(when) > migrationRetryDuration { | ||
| // last migration error is far enough ago. Prune and retry. | ||
| if err := c.migrator.PruneMigration(gr); err != nil { | ||
| errs = append(errs, err) | ||
| continue | ||
| } | ||
| finished, result, when, err = c.migrator.EnsureMigration(gr, grActualKeys.WriteKey.Key.Name) | ||
|
|
||
| // when is not used anymore below | ||
| finished, result, _, err = c.migrator.EnsureMigration(gr, migrationWriteKey) | ||
| } | ||
| if err != nil { | ||
| errs = append(errs, err) | ||
|
|
@@ -251,6 +274,13 @@ func (c *migrationController) migrateKeysIfNeededAndRevisionStable(ctx context.C | |
| continue | ||
| } | ||
|
|
||
| if remoteKeyMigration { | ||
| if result == nil { | ||
| remoteKeyMigratedGRs = append(remoteKeyMigratedGRs, gr) | ||
| } | ||
| continue | ||
| } | ||
|
|
||
| // update secret annotations | ||
| oldWriteKey, err := secrets.FromKeyState(c.instanceName, grActualKeys.WriteKey) | ||
| if err != nil { | ||
|
|
@@ -283,6 +313,23 @@ func (c *migrationController) migrateKeysIfNeededAndRevisionStable(ctx context.C | |
| } | ||
| } | ||
|
|
||
| if hadRemoteKeyMigration && len(writeKeySecretName) > 0 && len(remoteKeyMigratedGRs) == len(writeKeyGRs) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| if remoteKeyID, ok := secrets.RemoteKeyIDFromMigrationWriteKey(writeKeyState.Key.Name, migrationWriteKey); ok { | ||
| if err := secrets.PatchRemoteKeyAnnotations(ctx, c.secretClient.Secrets("openshift-config-managed"), writeKeySecretName, func(rk *secrets.RemoteKeyAnnotations) (bool, error) { | ||
| if !secrets.NeedsRemoteKeyMigration(*rk) { | ||
| return false, nil | ||
| } | ||
| if rk.MigratedRemoteKeyID == remoteKeyID { | ||
| return false, nil | ||
| } | ||
| rk.MigratedRemoteKeyID = remoteKeyID | ||
| return true, nil | ||
| }); err != nil { | ||
| errs = append(errs, err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return migratingResources, errors.NewAggregate(errs) | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
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.
I'm open for a more elegant solution here, we need to get the target key that has triggered the migration