@@ -18,7 +18,9 @@ import (
18
18
"cdr.dev/slog"
19
19
20
20
"github.com/coder/coder/coderd/database"
21
+ "github.com/coder/coder/coderd/database/dbauthz"
21
22
"github.com/coder/coder/coderd/database/pubsub"
23
+ "github.com/coder/coder/coderd/rbac"
22
24
agpl "github.com/coder/coder/tailnet"
23
25
)
24
26
@@ -82,7 +84,21 @@ type pgCoord struct {
82
84
// NewPGCoord creates a high-availability coordinator that stores state in the PostgreSQL database and
83
85
// receives notifications of updates via the pubsub.
84
86
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 ()))
86
102
id := uuid .New ()
87
103
logger = logger .Named ("pgcoord" ).With (slog .F ("coordinator_id" , id ))
88
104
bCh := make (chan binding )
@@ -103,6 +119,7 @@ func NewPGCoord(ctx context.Context, logger slog.Logger, ps pubsub.Pubsub, store
103
119
querier : newQuerier (ctx , logger , ps , store , id , cCh , numQuerierWorkers , fHB ),
104
120
closed : make (chan struct {}),
105
121
}
122
+ logger .Info (ctx , "starting coordinator" )
106
123
return c , nil
107
124
}
108
125
@@ -171,6 +188,7 @@ func (c *pgCoord) ServeAgent(conn net.Conn, id uuid.UUID, name string) error {
171
188
}
172
189
173
190
func (c * pgCoord ) Close () error {
191
+ c .logger .Info (c .ctx , "closing coordinator" )
174
192
c .cancel ()
175
193
c .closeOnce .Do (func () { close (c .closed ) })
176
194
return nil
0 commit comments