Skip to content

Commit be1d1c1

Browse files
authored
security/advancedtls: FileWatcher CRL provider initialization enhancement (#6760)
* Add initial scan as a part of FWCP creation * Add comment about default value for RefreshDuration * Promote Close() to the interface level * Revert "Promote Close() to the interface level" This reverts commit 465ebac.
1 parent 482de22 commit be1d1c1

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

security/advancedtls/crl_provider.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (p *StaticCRLProvider) CRL(cert *x509.Certificate) (*CRL, error) {
9191
// FileWatcherCRLProvider.
9292
type FileWatcherOptions struct {
9393
CRLDirectory string // Path of the directory containing CRL files
94-
RefreshDuration time.Duration // Time interval between CRLDirectory scans, can't be smaller than 1 minute
94+
RefreshDuration time.Duration // Time interval (default value is 1 hour) between CRLDirectory scans, can't be smaller than 1 minute
9595
CRLReloadingFailedCallback func(err error) // Custom callback executed when a CRL file can’t be processed
9696
}
9797

@@ -109,8 +109,9 @@ type FileWatcherCRLProvider struct {
109109

110110
// NewFileWatcherCRLProvider returns a new instance of the
111111
// FileWatcherCRLProvider. It uses FileWatcherOptions to validate and apply
112-
// configuration required for creating a new instance. Users should call Close
113-
// to stop the background refresh of CRLDirectory.
112+
// configuration required for creating a new instance. The initial scan of
113+
// CRLDirectory is performed inside this function. Users should call Close to
114+
// stop the background refresh of CRLDirectory.
114115
func NewFileWatcherCRLProvider(o FileWatcherOptions) (*FileWatcherCRLProvider, error) {
115116
if err := o.validate(); err != nil {
116117
return nil, err
@@ -121,6 +122,7 @@ func NewFileWatcherCRLProvider(o FileWatcherOptions) (*FileWatcherCRLProvider, e
121122
stop: make(chan struct{}),
122123
done: make(chan struct{}),
123124
}
125+
provider.scanCRLDirectory()
124126
go provider.run()
125127
return provider, nil
126128
}
@@ -149,7 +151,6 @@ func (p *FileWatcherCRLProvider) run() {
149151
defer close(p.done)
150152
ticker := time.NewTicker(p.opts.RefreshDuration)
151153
defer ticker.Stop()
152-
p.scanCRLDirectory()
153154

154155
for {
155156
select {

security/advancedtls/crl_provider_test.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func (s) TestStaticCRLProvider(t *testing.T) {
4545
rawCRLs = append(rawCRLs, rawCRL)
4646
}
4747
p := NewStaticCRLProvider(rawCRLs)
48+
4849
// Each test data entry contains a description of a certificate chain,
4950
// certificate chain itself, and if CRL is not expected to be found.
5051
tests := []struct {
@@ -154,10 +155,6 @@ func (s) TestFileWatcherCRLProvider(t *testing.T) {
154155
t.Fatal("Unexpected error while creating FileWatcherCRLProvider:", err)
155156
}
156157

157-
// We need to make sure that initial CRLDirectory scan is completed before
158-
// querying the internal map.
159-
p.Close()
160-
161158
// Each test data entry contains a description of a certificate chain,
162159
// certificate chain itself, and if CRL is not expected to be found.
163160
tests := []struct {
@@ -197,6 +194,7 @@ func (s) TestFileWatcherCRLProvider(t *testing.T) {
197194
}
198195
})
199196
}
197+
p.Close()
200198
if diff := cmp.Diff(len(nonCRLFilesSet), nonCRLFilesUnderCRLDirectory); diff != "" {
201199
t.Errorf("Unexpected number Number of callback executions\ndiff (-got +want):\n%s", diff)
202200
}

0 commit comments

Comments
 (0)