Drop gqlparser v1 dependency
Only use v2 throughout the repository.
Update and simplify build manifest
Alpine 3.14 uses Go 1.16, but go.mod says 1.17. Also, no external
repository should be required for core-go.
webhooks: skip webhooks with expired credentials
The documentation states [1]:
> When the original authentication method becomes invalid (such as the
> expiration of or revocation of an OAuth 2.0 bearer token), the
> webhook is disabled.
However, this is currently not the case. Expired webhooks are indeed
filtered out in virtually all GraphQL queries (by means of core-go's
FilterWebhooks [2]), so users cannot see or delete them. They are _not_
filtered out upon scheduling, however. This commit fixes that.
The symptoms of this are that active webhooks may simply not be run - if
a user has both an expired and a valid, active webhook for some event,
the scheduling will retrieve both, fail on the expired one, and stop
processing, without any feedback to the user who scheduled the hooks.
This is a problem across all services, so core-go seems like the best
place to fix this.
[1]: https://man.sr.ht/graphql.md#webhook-authentication
[2]: https://git.sr.ht/~sircmpwn/core-go/tree/master/item/webhooks/config.go#L74,81
Migrate to chi v5
v1 is not maintained anymore.
database: don't panic on context.DeadlineExceeded
Checking context.Cancelled is not enough, I also see the same issue
with context.DeadlineExceeded:
panic: Transaction error: driver: bad connection
Closure error: context deadline exceeded
goroutine 66664 [running]:
git.sr.ht/~sircmpwn/core-go/database.WithTx({0x5578e1847a58, 0xc0002c44e0}, 0x50?, 0xc000285f38)
e7b8e02696a1">git.sr.ht/~sircmpwn/core-go@v0.0.0-20231129165057-e7b8e02696a1/database/middleware.go:74 +0x2ce
git.sr.ht/~sircmpwn/builds.sr.ht/api/loaders.fetchUsersByID.func1({0xc0002cf190, 0x1, 0x1})
git.sr.ht/~sircmpwn/builds.sr.ht/api/loaders/middleware.go:34 +0x118
git.sr.ht/~sircmpwn/builds.sr.ht/api/loaders.(*usersByIDLoaderBatch).end(...)
git.sr.ht/~sircmpwn/builds.sr.ht/api/loaders/usersbyidloader_gen.go:222
git.sr.ht/~sircmpwn/builds.sr.ht/api/loaders.(*usersByIDLoaderBatch).startTimer(0xc00044a360, 0xc00042d380)
git.sr.ht/~sircmpwn/builds.sr.ht/api/loaders/usersbyidloader_gen.go:218 +0xe7
created by git.sr.ht/~sircmpwn/builds.sr.ht/api/loaders.(*usersByIDLoaderBatch).keyIndex
git.sr.ht/~sircmpwn/builds.sr.ht/api/loaders/usersbyidloader_gen.go:191 +0x119
server/email: use go-message for address parsing
No need to additionally depend on net/mail
database: print both errors in WithTx
Make it easier to debug panics by printing both errors instead of
sending one of them to /dev/null.
database/middleware: fix error value used in panic
We were checking txErr, but panic'ing with err.
Fixes: a06a6247898c ("database: don't panic with ErrBadConn")
database: specify field name for graphql.CollectedField
Newer versions of the graphql package add new fields to this struct.
This results in errors:
database/ql.go:40:4: too few values in struct literal of type graphql.CollectedField
database/ql.go:71:4: too few values in struct literal of type graphql.CollectedField
email: EnqueueStd: set Content-Type with charset=UTF-8 instead of just text/plain
Mails are now
--11d2cbf164a9ae0dfbb310faf818762607dcfd20aa74e07c7be0eec1458d
Mime-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
=D1=82=D1=80=D1=83=D0=BF=D0=B08
--=20
View on the web: http://192.168.1.101:5003/~nab2/trupa/8
--11d2cbf164a9ae0dfbb310faf818762607dcfd20aa74e07c7be0eec1458d
Content-Type: application/pgp-signature
-----BEGIN PGP MESSAGE-----
wnUEARYIACcFAmUavj0JkKdioLsBS5scFiEE+ts/9LaoXcZuSmrHp2KguwFLmxwA
AIm9AP9KB4cZyiby7jiiRMRESDeJXrdb4kNqyA3D3nVOt14bKgD/UiDfUKE1MwiV
pOqj/S0wiJdChKW52zRAkwuQ7PtKkgI=
=AiY9
-----END PGP MESSAGE-----
--11d2cbf164a9ae0dfbb310faf818762607dcfd20aa74e07c7be0eec1458d--
which is correct, and decodes correctly in neomutt.
Fixes: https://lists.sr.ht/~sircmpwn/sr.ht-discuss/%3C4uxbrlspm45s5i4bhhmqgmry374i22oqcxedtowda5zrzd7bpf2%405pyosds5owty%3E
database: don't panic with ErrBadConn
Sometimes we're panic'ing like so:
panic: driver: bad connection
goroutine 9333 [running]:
git.sr.ht/~sircmpwn/core-go/database.WithTx({0x561c2e623478, 0xc0002b6ed0}, 0x50?, 0xc00025ff38)
65b1657b30a1">git.sr.ht/~sircmpwn/core-go@v0.0.0-20230816134313-65b1657b30a1/database/middleware.go:57 +0x1fc
git.sr.ht/~sircmpwn/builds.sr.ht/api/loaders.fetchUsersByID.func1({0xc0002d80f0, 0x1, 0x1})
git.sr.ht/~sircmpwn/builds.sr.ht/api/loaders/middleware.go:34 +0x118
git.sr.ht/~sircmpwn/builds.sr.ht/api/loaders.(*usersByIDLoaderBatch).end(...)
git.sr.ht/~sircmpwn/builds.sr.ht/api/loaders/usersbyidloader_gen.go:222
git.sr.ht/~sircmpwn/builds.sr.ht/api/loaders.(*usersByIDLoaderBatch).startTimer(0xc0004e5380, 0xc0000e5140)
git.sr.ht/~sircmpwn/builds.sr.ht/api/loaders/usersbyidloader_gen.go:218 +0xe7
created by git.sr.ht/~sircmpwn/builds.sr.ht/api/loaders.(*usersByIDLoaderBatch).keyIndex
git.sr.ht/~sircmpwn/builds.sr.ht/api/loaders/usersbyidloader_gen.go:191 +0x119
I believe this is a pq bug, see the linked bug report. Stop
panic'ing in that case.
auth: make DecodeGrants return an error
We'll use this function to validate grants passed in via
builds.sr.ht manifests.
auth: add AuthContext.Access
Same logic as server.Access, but lower-level. Useful to check for
a permission not covered by the GraphQL schema @access directives
(such as builds.sr.ht secrets).
server/email: don't panic in EmailRecover
A panic in here is not great, because this function is supposed to
be the panic handler. Let's just log the error instead.
server/email: log missing mail::error-to, treat empty string as unset
Log a message when mail::error-to is unset, just in case the admin
forgot to set it. Don't try to parse an email address if error-to
is set to the empty string (the default value in the default config
file).
server/email: simplify and cleanup
- Only print the error once
- Remove unnecessary var
- Use debug.Stack instead of hand-rolled logic
- Ignore json.Marshal errors in a simpler way
server: fix error message on missing grant in Access
The error returned when a token is missing a required grant would
be "Access denied for invalid auth method" which is confusing.
Fix this with a more accurate error message.
database/middleware: don't use sql.Conn in WithTx
We can just use sql.DB instead of sql.Conn here. Simplifies the
code and reduces the risk of getting "bad connection" errors.
auth: add /query/external/* to anonymous whitelist