@@ -123,13 +123,17 @@ func HydrateMemoryFromBackingStore() {
123123 log .Log ().Info (fName , "msg" , "HydrateMemoryFromBackingStore" )
124124
125125 secrets := persist .ReadAllSecrets ()
126- if len (secrets ) == 0 {
127- return
126+ if len (secrets ) > 0 {
127+ state . ImportSecrets ( secrets )
128128 }
129+ log .Log ().Info (fName , "msg" , "HydrateMemoryFromBackingStore: secrets loaded" )
129130
130- state .ImportSecrets (secrets )
131+ policies := persist .ReadAllPolicies ()
132+ if len (policies ) > 0 {
133+ state .ImportPolicies (policies )
134+ }
131135
132- log .Log ().Info (fName , "msg" , "HydrateMemoryFromBackingStore: secrets loaded" )
136+ log .Log ().Info (fName , "msg" , "HydrateMemoryFromBackingStore: policies loaded" )
133137}
134138
135139// RestoreBackingStoreUsingPilotShards restores the backing store using the
@@ -153,13 +157,37 @@ func HydrateMemoryFromBackingStore() {
153157func RestoreBackingStoreUsingPilotShards (shards []ShamirShard ) {
154158 const fName = "RestoreBackingStoreUsingPilotShards"
155159
160+ log .Log ().Info (fName , "msg" , "Restoring backing store using pilot shards" )
161+
162+ // Sanity check:
163+ for shard := range shards {
164+ value := shards [shard ].Value
165+ id := shards [shard ].Id
166+
167+ if mem .Zeroed32 (value ) || id == 0 {
168+ log .Log ().Error (
169+ fName ,
170+ "msg" , "Bad input: ID or Value of a shard is zero. Exiting recovery" ,
171+ )
172+ return
173+ }
174+ }
175+
176+ log .Log ().Info (fName ,
177+ "msg" , "Recovering backing store using pilot shards" ,
178+ "threshold" , env .ShamirThreshold (),
179+ "len" , len (shards ),
180+ )
181+
156182 // Ensure we have at least the threshold number of shards
157183 if len (shards ) < env .ShamirThreshold () {
158184 log .Log ().Error (fName , "msg" , "Insufficient shards for recovery" ,
159185 "provided" , len (shards ), "required" , env .ShamirThreshold ())
160186 return
161187 }
162188
189+ log .Log ().Info (fName , "msg" , "Recovering backing store using pilot shards" )
190+
163191 // Recover the root key using the threshold number of shards
164192 binaryRec := RecoverRootKey (shards )
165193 // Security: Ensure the root key is zeroed out after use.
@@ -202,9 +230,7 @@ func SendShardsPeriodically(source *workloadapi.X509Source) {
202230
203231 log .Log ().Info (fName , "msg" , "Will send shards to keepers" )
204232
205- // TODO: get this from config.
206- //ticker := time.NewTicker(5 * time.Minute)
207- ticker := time .NewTicker (30 * time .Second )
233+ ticker := time .NewTicker (env .RecoveryKeeperUpdateInterval ())
208234 defer ticker .Stop ()
209235
210236 for range ticker .C {
@@ -255,6 +281,7 @@ func NewPilotRecoveryShards() map[int]*[32]byte {
255281 log .Log ().Info (fName , "msg" , "Generating pilot recovery shards" )
256282
257283 if state .RootKeyZero () {
284+ log .Log ().Info (fName , "msg" , "No root key; skipping" )
258285 return nil
259286 }
260287
@@ -271,6 +298,8 @@ func NewPilotRecoveryShards() map[int]*[32]byte {
271298 var result = make (map [int ]* [32 ]byte )
272299
273300 for _ , share := range rootShares {
301+ log .Log ().Info (fName , "msg" , "Generating share" , "share.id" , share .ID )
302+
274303 contribution , err := share .Value .MarshalBinary ()
275304 if err != nil {
276305 log .Log ().Error (fName , "msg" , "Failed to marshal share" )
@@ -282,8 +311,7 @@ func NewPilotRecoveryShards() map[int]*[32]byte {
282311 return nil
283312 }
284313
285- var bb []byte
286- err = share .ID .UnmarshalBinary (bb )
314+ bb , err := share .ID .MarshalBinary ()
287315 if err != nil {
288316 log .Log ().Error (fName , "msg" , "Failed to unmarshal share Id" )
289317 return nil
@@ -300,9 +328,12 @@ func NewPilotRecoveryShards() map[int]*[32]byte {
300328 var rs [32 ]byte
301329 copy (rs [:], contribution )
302330
331+ log .Log ().Info (fName , "msg" , "Generated shares" , "len" , len (rs ))
332+
303333 result [int (ii )] = & rs
304334 }
305335
336+ log .Log ().Info (fName , "msg" , "Successfully generated pilot recovery shards." )
306337 return result
307338}
308339
0 commit comments