Skip to content

Implement access monitor#53769

Merged
bernardjkim merged 4 commits into
masterfrom
bernard/access-monitor
Apr 15, 2025
Merged

Implement access monitor#53769
bernardjkim merged 4 commits into
masterfrom
bernard/access-monitor

Conversation

@bernardjkim
Copy link
Copy Markdown
Contributor

Supports: #51682
RFD: #51979

This PR implements an access monitor. This monitor watches access_monitoring_rule and access_request events, and then it executes the configured handlers for each event.

This access monitor is a slightly refactored implementation of the integrations/accessrequest.App. I'd like to unify the integrations/accessrequest Apps with this new implementation in future PRs.

These changes are split from a larger PR. To see how it'll be used with the access review handler, see #52988.

@github-actions github-actions Bot requested review from espadolini and rudream April 7, 2025 17:55
@bernardjkim bernardjkim added the no-changelog Indicates that a PR does not require a changelog entry label Apr 7, 2025
Comment thread lib/accessmonitoring/monitor.go
Comment thread lib/accessmonitoring/monitor.go Outdated
@bernardjkim bernardjkim force-pushed the bernard/access-monitor branch from e7365a0 to e2e559a Compare April 14, 2025 16:34
@bernardjkim bernardjkim requested review from marcoandredinis and tigrato and removed request for espadolini and rudream April 14, 2025 17:03
@bernardjkim
Copy link
Copy Markdown
Contributor Author

Hey @tigrato @marcoandredinis, could you also take a look at this PR when you have some time. Thanks!

// of restarting indefinitely. Fail fast mode should only be used within a
// plugin environment. See https://github.com/gravitational/teleport/pull/30039
// for more details.
// TODO(bernardjkim): Investigate if fail fast mode is still required.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this TODO still relevant?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, Hugo raised this concern in #53769 (comment).

The plan is to eventually replace the access request plugin Apps with this AccessMonitor implementation. I'll investigate further at that time if we still need to support a fail fast mode.

Comment thread lib/accessmonitoring/monitor.go Outdated
Comment on lines +141 to +150
s.cfg.Logger.ErrorContext(
ctx,
"Encountered a fatal error, it will restart after backoff.",
"component", componentName,
"error", err,
"restart_after", waitWithJitter,
)
if s.cfg.FailFast {
return trace.Wrap(err)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If FailFast is enabled, it will not restart as the log line says.
Should we swap the log with the if block?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Updated in 4277e42

select {
case initEvent := <-watcher.Events():
if initEvent.Type != types.OpInit {
return trace.BadParameter("watcher yielded %[1]v (%[1]d) as first event, expected Init (this is a bug)", initEvent.Type)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this string valid for string formatting?
It has two placeholders (%[1]v and %[1]d), but only one value (initEvent.Type)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so. The %[1] should resolve to the argument at index 1. Just to double check, this would return something like: watcher yielded Delete (2) as first event, expected Init (this is a bug).

@bernardjkim bernardjkim added this pull request to the merge queue Apr 15, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 15, 2025
@bernardjkim bernardjkim added this pull request to the merge queue Apr 15, 2025
Merged via the queue into master with commit 6f20eee Apr 15, 2025
39 checks passed
@bernardjkim bernardjkim deleted the bernard/access-monitor branch April 15, 2025 23:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automatic-reviews no-changelog Indicates that a PR does not require a changelog entry size/md

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants