-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
ca: properly handle the case where the secondary initializes after the primary #11514
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,19 +16,23 @@ func (s *Server) getCARoots(ws memdb.WatchSet, state *state.Store) (*structs.Ind | |
if err != nil { | ||
return nil, err | ||
} | ||
if config == nil { | ||
return nil, fmt.Errorf("CA has not finished initializing") | ||
} | ||
|
||
indexedRoots := &structs.IndexedCARoots{} | ||
|
||
if config != nil { | ||
// Build TrustDomain based on the ClusterID stored. | ||
signingID := connect.SpiffeIDSigningForCluster(config) | ||
if signingID == nil { | ||
// If CA is bootstrapped at all then this should never happen but be | ||
// defensive. | ||
return nil, fmt.Errorf("no cluster trust domain setup") | ||
} | ||
// Build TrustDomain based on the ClusterID stored. | ||
signingID := connect.SpiffeIDSigningForCluster(config) | ||
if signingID == nil { | ||
// If CA is bootstrapped at all then this should never happen but be | ||
// defensive. | ||
return nil, fmt.Errorf("no cluster trust domain setup") | ||
} | ||
|
||
indexedRoots.TrustDomain = signingID.Host() | ||
indexedRoots.TrustDomain = signingID.Host() | ||
if indexedRoots.TrustDomain == "" { | ||
Comment on lines
+33
to
+34
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.
cc @freddygv |
||
return nil, fmt.Errorf("CA has not finished initializing") | ||
} | ||
|
||
indexedRoots.Index, indexedRoots.Roots = index, roots | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,8 +180,6 @@ func (s *Store) caSetConfigTxn(idx uint64, tx WriteTxn, config *structs.CAConfig | |
if prev != nil { | ||
existing := prev.(*structs.CAConfiguration) | ||
config.CreateIndex = existing.CreateIndex | ||
// Allow the ClusterID to change if it's provided by an internal operation, such | ||
// as a primary datacenter being switched to secondary mode. | ||
Comment on lines
-183
to
-184
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. I deleted this comment since I came across it while tracing this code and it is misleading. We always allow changing the ClusterID. All these next lines do is default it when the new config has it unset. |
||
if config.ClusterID == "" { | ||
config.ClusterID = existing.ClusterID | ||
} | ||
|
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.
This had to move into the retry loop, otherwise it was pointing at the old not initialized provider that existed before the secondary could be initialized.