Skip to content

Commit

Permalink
go/worker/keymanager: Optimize enclave initialization
Browse files Browse the repository at this point in the history
Enclave initialization was moved into its own goroutine to avoid blocking
the main loop of the key manager worker. Once initialization is completed,
the resulting state of the enclave is compared to the latest key manager
status. If the latter has changed, initialization is performed again.

This will be useful when we deploy master secret rotation since new secrets
may be generated while old secrets are being replicated which can result
in an outdated state once initialization finishes.
  • Loading branch information
peternose committed Mar 14, 2023
1 parent e161565 commit a3909bb
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 95 deletions.
10 changes: 10 additions & 0 deletions .changelog/5218.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
go/worker/keymanager: Optimize enclave initialization

Enclave initialization was moved into its own goroutine to avoid blocking
the main loop of the key manager worker. Once initialization is completed,
the resulting state of the enclave is compared to the latest key manager
status. If the latter has changed, initialization is performed again.

This will be useful when we deploy master secret rotation since new secrets
may be generated while old secrets are being replicated which can result
in an outdated state once initialization finishes.
38 changes: 19 additions & 19 deletions go/worker/keymanager/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,25 @@ func New(
ctx, cancelFn := context.WithCancel(context.Background())

w := &Worker{
logger: logging.GetLogger("worker/keymanager"),
ctx: ctx,
cancelCtx: cancelFn,
stopCh: make(chan struct{}),
quitCh: make(chan struct{}),
initCh: make(chan struct{}),
updateStatusTickerCh: nil,
clientRuntimes: make(map[common.Namespace]*clientRuntimeWatcher),
accessList: make(map[core.PeerID]map[common.Namespace]struct{}),
privatePeers: make(map[core.PeerID]struct{}),
accessListByRuntime: make(map[common.Namespace][]core.PeerID),
commonWorker: commonWorker,
backend: backend,
enabled: enabled,
mayGenerate: config.GlobalConfig.Keymanager.MayGenerate,
loadSecretCh: make(chan struct{}, 1),
genSecretCh: make(chan struct{}, 1),
genSecretDoneCh: make(chan bool, 1),
genSecretHeight: int64(math.MaxInt64),
logger: logging.GetLogger("worker/keymanager"),
ctx: ctx,
cancelCtx: cancelFn,
stopCh: make(chan struct{}),
quitCh: make(chan struct{}),
initCh: make(chan struct{}),
clientRuntimes: make(map[common.Namespace]*clientRuntimeWatcher),
accessList: make(map[core.PeerID]map[common.Namespace]struct{}),
privatePeers: make(map[core.PeerID]struct{}),
accessListByRuntime: make(map[common.Namespace][]core.PeerID),
commonWorker: commonWorker,
backend: backend,
enabled: enabled,
mayGenerate: config.GlobalConfig.Keymanager.MayGenerate,
initEnclaveDoneCh: make(chan *api.SignedInitResponse, 1),
loadSecretCh: make(chan struct{}, 1),
genSecretCh: make(chan struct{}, 1),
genSecretDoneCh: make(chan bool, 1),
genSecretHeight: int64(math.MaxInt64),
}

if !w.enabled {
Expand Down
7 changes: 6 additions & 1 deletion go/worker/keymanager/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func (w *Worker) GetStatus(ctx context.Context) (*api.Status, error) {
al = append(al, ral)
}

var pc []byte
if w.enclaveStatus != nil {
pc = w.enclaveStatus.InitResponse.PolicyChecksum
}

es := api.EphemeralSecretStats{
NumLoaded: w.numLoadedSecrets,
LastLoaded: w.lastLoadedSecret,
Expand All @@ -72,7 +77,7 @@ func (w *Worker) GetStatus(ctx context.Context) (*api.Status, error) {
AccessList: al,
PrivatePeers: ps,
Policy: w.policy,
PolicyChecksum: w.policyChecksum,
PolicyChecksum: pc,
EphemeralSecrets: es,
}

Expand Down
Loading

0 comments on commit a3909bb

Please sign in to comment.