-
Notifications
You must be signed in to change notification settings - Fork 904
fix: fix PG coordinator context and RBAC subject #8223
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,9 @@ import ( | |
"cdr.dev/slog" | ||
|
||
"github.com/coder/coder/coderd/database" | ||
"github.com/coder/coder/coderd/database/dbauthz" | ||
"github.com/coder/coder/coderd/database/pubsub" | ||
"github.com/coder/coder/coderd/rbac" | ||
agpl "github.com/coder/coder/tailnet" | ||
) | ||
|
||
|
@@ -82,7 +84,21 @@ type pgCoord struct { | |
// NewPGCoord creates a high-availability coordinator that stores state in the PostgreSQL database and | ||
// receives notifications of updates via the pubsub. | ||
func NewPGCoord(ctx context.Context, logger slog.Logger, ps pubsub.Pubsub, store database.Store) (agpl.Coordinator, error) { | ||
ctx, cancel := context.WithCancel(ctx) | ||
ctx, cancel := context.WithCancel(dbauthz.As(ctx, rbac.Subject{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect that you learned about the need for RBAC context the hard way... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I intellectually knew it, in as much as I helped with the design of dbauthz, but then just forgot when the time came. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be safer if we can adopt any additional linter to spot these places. cc @johnstcn There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is more easily caught by an integration test than a linter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. very difficult to spot with a linter, because the subject could be added to the context anywhere along the stack down to the actual DB call. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, the current ruleguard linter we use doesn't have the capacity to do that kind of context analysis I don't think. Testing should pick this stuff up pretty quick since it should always fail if you don't add a subject context. |
||
ID: uuid.Nil.String(), | ||
Roles: rbac.Roles([]rbac.Role{ | ||
{ | ||
Name: "tailnetcoordinator", | ||
DisplayName: "Tailnet Coordinator", | ||
Site: rbac.Permissions(map[string][]rbac.Action{ | ||
rbac.ResourceTailnetCoordinator.Type: {rbac.WildcardSymbol}, | ||
}), | ||
Org: map[string][]rbac.Permission{}, | ||
User: []rbac.Permission{}, | ||
johnstcn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}), | ||
Scope: rbac.ScopeAll, | ||
}.WithCachedASTValue())) | ||
id := uuid.New() | ||
logger = logger.Named("pgcoord").With(slog.F("coordinator_id", id)) | ||
bCh := make(chan binding) | ||
|
@@ -103,6 +119,7 @@ func NewPGCoord(ctx context.Context, logger slog.Logger, ps pubsub.Pubsub, store | |
querier: newQuerier(ctx, logger, ps, store, id, cCh, numQuerierWorkers, fHB), | ||
closed: make(chan struct{}), | ||
} | ||
logger.Info(ctx, "starting coordinator") | ||
return c, nil | ||
} | ||
|
||
|
@@ -171,6 +188,7 @@ func (c *pgCoord) ServeAgent(conn net.Conn, id uuid.UUID, name string) error { | |
} | ||
|
||
func (c *pgCoord) Close() error { | ||
c.logger.Info(c.ctx, "closing coordinator") | ||
c.cancel() | ||
c.closeOnce.Do(func() { close(c.closed) }) | ||
return nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: oh, I thought that this is the same context passed down
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, but this is a much easier way to be sure.