Skip to content

Commit

Permalink
[v17] Using discovery service poll_interval for access graph sync (#4…
Browse files Browse the repository at this point in the history
…8846)

* Using discovery service poll_interval for access graph sync

* Adding a new poll_interval field to access graph sync config

* Update lib/srv/discovery/access_graph.go

Co-authored-by: Ryan Clark <[email protected]>

* Adding default poll interval

* Make fix-imports

* Updating derived functions for config

* Apply suggestions from code review

Co-authored-by: Tiago Silva <[email protected]>

* Followup from PR comments

* Applying protobuf tags to avoid conversion

* Removing conversion

* Regen grpc from rebase

* Adding warning message and checking for nil config

---------

Co-authored-by: Ryan Clark <[email protected]>
Co-authored-by: Tiago Silva <[email protected]>
  • Loading branch information
3 people committed Nov 12, 2024
1 parent dff5bcb commit 30f967e
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 8 deletions.
6 changes: 6 additions & 0 deletions api/proto/teleport/legacy/types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6966,6 +6966,12 @@ message OktaOptions {
message AccessGraphSync {
// AWS is a configuration for AWS Access Graph service poll service.
repeated AccessGraphAWSSync AWS = 1 [(gogoproto.jsontag) = "aws,omitempty"];
// PollInterval is the frequency at which to poll for AWS resources
google.protobuf.Duration PollInterval = 2 [

Check failure on line 6970 in api/proto/teleport/legacy/types/types.proto

View workflow job for this annotation

GitHub Actions / Lint (Go)

field types.AccessGraphSync.PollInterval: unknown type google.protobuf.Duration
(gogoproto.jsontag) = "poll_interval,omitempty",
(gogoproto.nullable) = false,
(gogoproto.stdduration) = true
];
}

// AccessGraphAWSSync is a configuration for AWS Access Graph service poll service.
Expand Down
3 changes: 2 additions & 1 deletion api/types/discoveryconfig/derived.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 49 additions & 4 deletions api/types/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,9 @@ kubernetes matchers are present`)
AssumeRole: assumeRole,
})
}
if fc.Discovery.AccessGraph.PollInterval > 0 {
tMatcher.PollInterval = fc.Discovery.AccessGraph.PollInterval
}
cfg.Discovery.AccessGraph = &tMatcher
}

Expand Down
2 changes: 2 additions & 0 deletions lib/config/fileconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,8 @@ type GCPMatcher struct {
type AccessGraphSync struct {
// AWS is the AWS configuration for the AccessGraph Sync service.
AWS []AccessGraphAWSSync `yaml:"aws,omitempty"`
// PollInterval is the frequency at which to poll for AWS resources
PollInterval time.Duration `yaml:"poll_interval,omitempty"`
}

// AccessGraphAWSSync represents the configuration for the AWS AccessGraph Sync service.
Expand Down
29 changes: 26 additions & 3 deletions lib/srv/discovery/access_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const (
// batchSize is the maximum number of resources to send in a single
// request to the access graph service.
batchSize = 500
// defaultPollInterval is the default interval between polling for access graph resources
defaultPollInterval = 15 * time.Minute
)

// errNoAccessGraphFetchers is returned when there are no TAG fetchers.
Expand Down Expand Up @@ -354,9 +356,23 @@ func (s *Server) initializeAndWatchAccessGraph(ctx context.Context, reloadCh <-c
}
}()

// Configure the poll interval
tickerInterval := defaultPollInterval
if s.Config.Matchers.AccessGraph != nil {
if s.Config.Matchers.AccessGraph.PollInterval > defaultPollInterval {
tickerInterval = s.Config.Matchers.AccessGraph.PollInterval
} else {
s.Log.WarnContext(ctx,
"Access graph service poll interval cannot be less than the default",
"default_poll_interval",
defaultPollInterval)
}
}
s.Log.InfoContext(ctx, "Access graph service poll interval", "poll_interval", tickerInterval)

currentTAGResources := &aws_sync.Resources{}
ticker := time.NewTicker(15 * time.Minute)
defer ticker.Stop()
timer := time.NewTimer(tickerInterval)
defer timer.Stop()
for {
err := s.reconcileAccessGraph(ctx, currentTAGResources, stream, features)
if errors.Is(err, errNoAccessGraphFetchers) {
Expand All @@ -369,10 +385,17 @@ func (s *Server) initializeAndWatchAccessGraph(ctx context.Context, reloadCh <-c
}
return trace.Wrap(err)
}
if !timer.Stop() {
select {
case <-timer.C: // drain
default:
}
}
timer.Reset(tickerInterval)
select {
case <-ctx.Done():
return trace.Wrap(ctx.Err())
case <-ticker.C:
case <-timer.C:
case <-reloadCh:
}
}
Expand Down

0 comments on commit 30f967e

Please sign in to comment.