Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0f27da0

Browse files
authored
feat: extend request logs with auth & DB info and log long lived connections early (#17422)
1 parent7c4c504 commit0f27da0

File tree

19 files changed

+714
-94
lines changed

19 files changed

+714
-94
lines changed

‎Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,8 @@ GEN_FILES := \
563563
site/e2e/provisionerGenerated.ts\
564564
examples/examples.gen.json\
565565
$(TAILNETTEST_MOCKS)\
566-
coderd/database/pubsub/psmock/psmock.go
567-
566+
coderd/database/pubsub/psmock/psmock.go\
567+
coderd/httpmw/loggermw/loggermock/loggermock.go
568568

569569
# all gen targets should be added here and to gen/mark-fresh
570570
gen: gen/db$(GEN_FILES)
@@ -598,6 +598,7 @@ gen/mark-fresh:
598598
examples/examples.gen.json\
599599
$(TAILNETTEST_MOCKS)\
600600
coderd/database/pubsub/psmock/psmock.go\
601+
coderd/httpmw/loggermw/loggermock/loggermock.go\
601602
"
602603

603604
for file in $$files; do
@@ -629,6 +630,9 @@ coderd/database/dbmock/dbmock.go: coderd/database/db.go coderd/database/querier.
629630
coderd/database/pubsub/psmock/psmock.go: coderd/database/pubsub/pubsub.go
630631
go generate ./coderd/database/pubsub/psmock
631632

633+
coderd/httpmw/loggermw/loggermock/loggermock.go: coderd/httpmw/loggermw/logger.go
634+
go generate ./coderd/httpmw/loggermw/loggermock/
635+
632636
$(TAILNETTEST_MOCKS): tailnet/coordinator.go tailnet/service.go
633637
go generate ./tailnet/tailnettest/
634638

‎coderd/coderd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import (
6363
"github.com/coder/coder/v2/coderd/healthcheck/derphealth"
6464
"github.com/coder/coder/v2/coderd/httpapi"
6565
"github.com/coder/coder/v2/coderd/httpmw"
66+
"github.com/coder/coder/v2/coderd/httpmw/loggermw"
6667
"github.com/coder/coder/v2/coderd/metricscache"
6768
"github.com/coder/coder/v2/coderd/notifications"
6869
"github.com/coder/coder/v2/coderd/portsharing"
@@ -787,7 +788,7 @@ func New(options *Options) *API {
787788
tracing.Middleware(api.TracerProvider),
788789
httpmw.AttachRequestID,
789790
httpmw.ExtractRealIP(api.RealIPConfig),
790-
httpmw.Logger(api.Logger),
791+
loggermw.Logger(api.Logger),
791792
rolestore.CustomRoleMW,
792793
prometheusMW,
793794
// Build-Version is helpful for debugging.

‎coderd/database/dbauthz/dbauthz.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/coder/coder/v2/coderd/database"
2525
"github.com/coder/coder/v2/coderd/database/dbtime"
2626
"github.com/coder/coder/v2/coderd/httpapi/httpapiconstraints"
27+
"github.com/coder/coder/v2/coderd/httpmw/loggermw"
2728
"github.com/coder/coder/v2/coderd/rbac"
2829
"github.com/coder/coder/v2/coderd/util/slice"
2930
"github.com/coder/coder/v2/provisionersdk"
@@ -162,6 +163,7 @@ func ActorFromContext(ctx context.Context) (rbac.Subject, bool) {
162163

163164
var (
164165
subjectProvisionerd= rbac.Subject{
166+
Type:rbac.SubjectTypeProvisionerd,
165167
FriendlyName:"Provisioner Daemon",
166168
ID:uuid.Nil.String(),
167169
Roles:rbac.Roles([]rbac.Role{
@@ -193,6 +195,7 @@ var (
193195
}.WithCachedASTValue()
194196

195197
subjectAutostart= rbac.Subject{
198+
Type:rbac.SubjectTypeAutostart,
196199
FriendlyName:"Autostart",
197200
ID:uuid.Nil.String(),
198201
Roles:rbac.Roles([]rbac.Role{
@@ -216,6 +219,7 @@ var (
216219

217220
// See unhanger package.
218221
subjectHangDetector= rbac.Subject{
222+
Type:rbac.SubjectTypeHangDetector,
219223
FriendlyName:"Hang Detector",
220224
ID:uuid.Nil.String(),
221225
Roles:rbac.Roles([]rbac.Role{
@@ -236,6 +240,7 @@ var (
236240

237241
// See cryptokeys package.
238242
subjectCryptoKeyRotator= rbac.Subject{
243+
Type:rbac.SubjectTypeCryptoKeyRotator,
239244
FriendlyName:"Crypto Key Rotator",
240245
ID:uuid.Nil.String(),
241246
Roles:rbac.Roles([]rbac.Role{
@@ -254,6 +259,7 @@ var (
254259

255260
// See cryptokeys package.
256261
subjectCryptoKeyReader= rbac.Subject{
262+
Type:rbac.SubjectTypeCryptoKeyReader,
257263
FriendlyName:"Crypto Key Reader",
258264
ID:uuid.Nil.String(),
259265
Roles:rbac.Roles([]rbac.Role{
@@ -271,6 +277,7 @@ var (
271277
}.WithCachedASTValue()
272278

273279
subjectNotifier= rbac.Subject{
280+
Type:rbac.SubjectTypeNotifier,
274281
FriendlyName:"Notifier",
275282
ID:uuid.Nil.String(),
276283
Roles:rbac.Roles([]rbac.Role{
@@ -288,6 +295,7 @@ var (
288295
}.WithCachedASTValue()
289296

290297
subjectSystemRestricted= rbac.Subject{
298+
Type:rbac.SubjectTypeSystemRestricted,
291299
FriendlyName:"System",
292300
ID:uuid.Nil.String(),
293301
Roles:rbac.Roles([]rbac.Role{
@@ -323,6 +331,7 @@ var (
323331
}.WithCachedASTValue()
324332

325333
subjectSystemReadProvisionerDaemons= rbac.Subject{
334+
Type:rbac.SubjectTypeSystemReadProvisionerDaemons,
326335
FriendlyName:"Provisioner Daemons Reader",
327336
ID:uuid.Nil.String(),
328337
Roles:rbac.Roles([]rbac.Role{
@@ -343,47 +352,47 @@ var (
343352
// AsProvisionerd returns a context with an actor that has permissions required
344353
// for provisionerd to function.
345354
funcAsProvisionerd(ctx context.Context) context.Context {
346-
returncontext.WithValue(ctx,authContextKey{},subjectProvisionerd)
355+
returnAs(ctx,subjectProvisionerd)
347356
}
348357

349358
// AsAutostart returns a context with an actor that has permissions required
350359
// for autostart to function.
351360
funcAsAutostart(ctx context.Context) context.Context {
352-
returncontext.WithValue(ctx,authContextKey{},subjectAutostart)
361+
returnAs(ctx,subjectAutostart)
353362
}
354363

355364
// AsHangDetector returns a context with an actor that has permissions required
356365
// for unhanger.Detector to function.
357366
funcAsHangDetector(ctx context.Context) context.Context {
358-
returncontext.WithValue(ctx,authContextKey{},subjectHangDetector)
367+
returnAs(ctx,subjectHangDetector)
359368
}
360369

361370
// AsKeyRotator returns a context with an actor that has permissions required for rotating crypto keys.
362371
funcAsKeyRotator(ctx context.Context) context.Context {
363-
returncontext.WithValue(ctx,authContextKey{},subjectCryptoKeyRotator)
372+
returnAs(ctx,subjectCryptoKeyRotator)
364373
}
365374

366375
// AsKeyReader returns a context with an actor that has permissions required for reading crypto keys.
367376
funcAsKeyReader(ctx context.Context) context.Context {
368-
returncontext.WithValue(ctx,authContextKey{},subjectCryptoKeyReader)
377+
returnAs(ctx,subjectCryptoKeyReader)
369378
}
370379

371380
// AsNotifier returns a context with an actor that has permissions required for
372381
// creating/reading/updating/deleting notifications.
373382
funcAsNotifier(ctx context.Context) context.Context {
374-
returncontext.WithValue(ctx,authContextKey{},subjectNotifier)
383+
returnAs(ctx,subjectNotifier)
375384
}
376385

377386
// AsSystemRestricted returns a context with an actor that has permissions
378387
// required for various system operations (login, logout, metrics cache).
379388
funcAsSystemRestricted(ctx context.Context) context.Context {
380-
returncontext.WithValue(ctx,authContextKey{},subjectSystemRestricted)
389+
returnAs(ctx,subjectSystemRestricted)
381390
}
382391

383392
// AsSystemReadProvisionerDaemons returns a context with an actor that has permissions
384393
// to read provisioner daemons.
385394
funcAsSystemReadProvisionerDaemons(ctx context.Context) context.Context {
386-
returncontext.WithValue(ctx,authContextKey{},subjectSystemReadProvisionerDaemons)
395+
returnAs(ctx,subjectSystemReadProvisionerDaemons)
387396
}
388397

389398
varAsRemoveActor= rbac.Subject{
@@ -401,6 +410,9 @@ func As(ctx context.Context, actor rbac.Subject) context.Context {
401410
// should be removed from the context.
402411
returncontext.WithValue(ctx,authContextKey{},nil)
403412
}
413+
ifrlogger:=loggermw.RequestLoggerFromContext(ctx);rlogger!=nil {
414+
rlogger.WithAuthContext(actor)
415+
}
404416
returncontext.WithValue(ctx,authContextKey{},actor)
405417
}
406418

‎coderd/database/queries.sql.go

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/users.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,10 @@ WHERE
244244
-- This function returns roles for authorization purposes. Implied member roles
245245
-- are included.
246246
SELECT
247-
-- usernameis returned just to help for logging purposes
247+
-- usernameand email are returned just to help for logging purposes
248248
-- status is used to enforce 'suspended' users, as all roles are ignored
249249
--when suspended.
250-
id, username, status,
250+
id, username, status, email,
251251
-- All user roles, including their org roles.
252252
array_cat(
253253
-- All users are members

‎coderd/httpmw/apikey.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,9 @@ func UserRBACSubject(ctx context.Context, db database.Store, userID uuid.UUID, s
465465
}
466466

467467
actor:= rbac.Subject{
468+
Type:rbac.SubjectTypeUser,
468469
FriendlyName:roles.Username,
470+
Email:roles.Email,
469471
ID:userID.String(),
470472
Roles:rbacRoles,
471473
Groups:roles.Groups,

‎coderd/httpmw/logger.go

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp