Skip to content
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

security/advancedtls: FileWatcher CRL provider initialization enhancement #6760

Merged
merged 4 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions security/advancedtls/crl_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (p *StaticCRLProvider) CRL(cert *x509.Certificate) (*CRL, error) {
// FileWatcherCRLProvider.
type FileWatcherOptions struct {
CRLDirectory string // Path of the directory containing CRL files
RefreshDuration time.Duration // Time interval between CRLDirectory scans, can't be smaller than 1 minute
RefreshDuration time.Duration // Time interval (default value is 1 hour) between CRLDirectory scans, can't be smaller than 1 minute
CRLReloadingFailedCallback func(err error) // Custom callback executed when a CRL file can’t be processed
}

Expand All @@ -109,8 +109,9 @@ type FileWatcherCRLProvider struct {

// NewFileWatcherCRLProvider returns a new instance of the
// FileWatcherCRLProvider. It uses FileWatcherOptions to validate and apply
// configuration required for creating a new instance. Users should call Close
// to stop the background refresh of CRLDirectory.
// configuration required for creating a new instance. The initial scan of
// CRLDirectory is performed inside this function. Users should call Close to
// stop the background refresh of CRLDirectory.
func NewFileWatcherCRLProvider(o FileWatcherOptions) (*FileWatcherCRLProvider, error) {
if err := o.validate(); err != nil {
return nil, err
Expand All @@ -121,6 +122,7 @@ func NewFileWatcherCRLProvider(o FileWatcherOptions) (*FileWatcherCRLProvider, e
stop: make(chan struct{}),
done: make(chan struct{}),
}
provider.scanCRLDirectory()
go provider.run()
return provider, nil
}
Expand Down Expand Up @@ -149,7 +151,6 @@ func (p *FileWatcherCRLProvider) run() {
defer close(p.done)
ticker := time.NewTicker(p.opts.RefreshDuration)
defer ticker.Stop()
p.scanCRLDirectory()

for {
select {
Expand Down
6 changes: 2 additions & 4 deletions security/advancedtls/crl_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (s) TestStaticCRLProvider(t *testing.T) {
rawCRLs = append(rawCRLs, rawCRL)
}
p := NewStaticCRLProvider(rawCRLs)

// Each test data entry contains a description of a certificate chain,
// certificate chain itself, and if CRL is not expected to be found.
tests := []struct {
Expand Down Expand Up @@ -154,10 +155,6 @@ func (s) TestFileWatcherCRLProvider(t *testing.T) {
t.Fatal("Unexpected error while creating FileWatcherCRLProvider:", err)
}

// We need to make sure that initial CRLDirectory scan is completed before
// querying the internal map.
p.Close()

// Each test data entry contains a description of a certificate chain,
// certificate chain itself, and if CRL is not expected to be found.
tests := []struct {
Expand Down Expand Up @@ -197,6 +194,7 @@ func (s) TestFileWatcherCRLProvider(t *testing.T) {
}
})
}
p.Close()
if diff := cmp.Diff(len(nonCRLFilesSet), nonCRLFilesUnderCRLDirectory); diff != "" {
t.Errorf("Unexpected number Number of callback executions\ndiff (-got +want):\n%s", diff)
}
Expand Down
Loading