Skip to content

Commit 7943a5b

Browse files
authored
fix PG coordinator context and RBAC subject (coder#8223)
Signed-off-by: Spike Curtis <spike@coder.com>
1 parent 5d26637 commit 7943a5b

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

enterprise/coderd/coderd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ func (api *API) updateEntitlements(ctx context.Context) error {
417417
if enabled {
418418
var haCoordinator agpltailnet.Coordinator
419419
if api.AGPL.Experiments.Enabled(codersdk.ExperimentTailnetPGCoordinator) {
420-
haCoordinator, err = tailnet.NewPGCoord(ctx, api.Logger, api.Pubsub, api.Database)
420+
haCoordinator, err = tailnet.NewPGCoord(api.ctx, api.Logger, api.Pubsub, api.Database)
421421
} else {
422422
haCoordinator, err = tailnet.NewCoordinator(api.Logger, api.Pubsub)
423423
}

enterprise/tailnet/pgcoord.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import (
1818
"cdr.dev/slog"
1919

2020
"github.com/coder/coder/coderd/database"
21+
"github.com/coder/coder/coderd/database/dbauthz"
2122
"github.com/coder/coder/coderd/database/pubsub"
23+
"github.com/coder/coder/coderd/rbac"
2224
agpl "github.com/coder/coder/tailnet"
2325
)
2426

@@ -82,7 +84,21 @@ type pgCoord struct {
8284
// NewPGCoord creates a high-availability coordinator that stores state in the PostgreSQL database and
8385
// receives notifications of updates via the pubsub.
8486
func NewPGCoord(ctx context.Context, logger slog.Logger, ps pubsub.Pubsub, store database.Store) (agpl.Coordinator, error) {
85-
ctx, cancel := context.WithCancel(ctx)
87+
ctx, cancel := context.WithCancel(dbauthz.As(ctx, rbac.Subject{
88+
ID: uuid.Nil.String(),
89+
Roles: rbac.Roles([]rbac.Role{
90+
{
91+
Name: "tailnetcoordinator",
92+
DisplayName: "Tailnet Coordinator",
93+
Site: rbac.Permissions(map[string][]rbac.Action{
94+
rbac.ResourceTailnetCoordinator.Type: {rbac.WildcardSymbol},
95+
}),
96+
Org: map[string][]rbac.Permission{},
97+
User: []rbac.Permission{},
98+
},
99+
}),
100+
Scope: rbac.ScopeAll,
101+
}.WithCachedASTValue()))
86102
id := uuid.New()
87103
logger = logger.Named("pgcoord").With(slog.F("coordinator_id", id))
88104
bCh := make(chan binding)
@@ -103,6 +119,7 @@ func NewPGCoord(ctx context.Context, logger slog.Logger, ps pubsub.Pubsub, store
103119
querier: newQuerier(ctx, logger, ps, store, id, cCh, numQuerierWorkers, fHB),
104120
closed: make(chan struct{}),
105121
}
122+
logger.Info(ctx, "starting coordinator")
106123
return c, nil
107124
}
108125

@@ -171,6 +188,7 @@ func (c *pgCoord) ServeAgent(conn net.Conn, id uuid.UUID, name string) error {
171188
}
172189

173190
func (c *pgCoord) Close() error {
191+
c.logger.Info(c.ctx, "closing coordinator")
174192
c.cancel()
175193
c.closeOnce.Do(func() { close(c.closed) })
176194
return nil

0 commit comments

Comments
 (0)