Skip to content
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

Add client-set proxy headers to PDS #2251

Merged
merged 51 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
6a26396
tidy bsky auth
dholms Feb 29, 2024
125f721
hook up new auth verifier
dholms Feb 29, 2024
36da1d9
update auth throughout ozone
dholms Feb 29, 2024
32b3de8
handle mod signing keys
dholms Feb 29, 2024
b1f07d5
add client proxy heads to pds
dholms Feb 29, 2024
ef236a4
hook up rest of routes
dholms Feb 29, 2024
bfbb586
simplify pipethrough & add some SSRF protection
dholms Feb 29, 2024
92d9268
tests
dholms Feb 29, 2024
199b754
fix bad var
dholms Feb 29, 2024
d1d39ff
merge main
dholms Feb 29, 2024
cb53fdc
fix key parsing in pds
dholms Feb 29, 2024
e3bfb17
fix admin auth test
dholms Mar 1, 2024
a642063
rename test
dholms Mar 1, 2024
88c2412
add pipethrough to write routes
dholms Mar 1, 2024
a30ac47
Merge branch 'ozone-acls-take2' into pds-proxy-headers
dholms Mar 1, 2024
f7ef546
update did doc id values
dholms Mar 4, 2024
dbe9aff
Merge branch 'ozone-acls-take2' into pds-proxy-headers
dholms Mar 4, 2024
0482a92
null creds string -> `none`
dholms Mar 4, 2024
cccade6
Merge branch 'ozone-acls-take2' into pds-proxy-headers
dholms Mar 4, 2024
5df31de
fix fetchLabels auth check
dholms Mar 5, 2024
04dc443
Merge branch 'ozone-acls-take2' into pds-proxy-headers
dholms Mar 5, 2024
dd891d4
:sparkles: Add a couple more proxied requests that we use in ozone ui
foysalit Mar 5, 2024
2ca4fee
Add runit to the services/bsky Dockerfile (#2254)
Jacob2161 Feb 29, 2024
6ba5f6c
Improve tag detection (#2260)
estrattonbailey Mar 1, 2024
9b2500e
Version packages (#2261)
github-actions[bot] Mar 1, 2024
c76fd03
:bug: Increment attempt count after each attempt to push ozone event …
foysalit Mar 4, 2024
87f00f2
Ozone delegates email sending to actor's pds (#2272)
devinivy Mar 5, 2024
ccfc4d9
Merge branch 'ozone-acls-take2' into pds-proxy-headers
dholms Mar 5, 2024
8341c7a
fix auth verifier method
dholms Mar 5, 2024
207e208
Merge branch 'ozone-acls-take2' into pds-proxy-headers
dholms Mar 5, 2024
f936105
build branch
dholms Mar 5, 2024
11b7af2
merge main
dholms Mar 5, 2024
abe4b03
Merge branch 'ozone-acls-take2' into pds-proxy-headers
dholms Mar 5, 2024
5f3c91b
fix url check
dholms Mar 5, 2024
037f163
better error handling for get account infos
dholms Mar 5, 2024
fc1c40d
fix labeler service id
dholms Mar 5, 2024
483b71f
Merge branch 'ozone-acls-take2' into pds-proxy-headers
dholms Mar 5, 2024
5e1c5fd
fix iss on auth headers
dholms Mar 5, 2024
64d99dd
Merge branch 'ozone-acls-take2' into pds-proxy-headers
dholms Mar 5, 2024
82acea2
fix dev-env ozone did
dholms Mar 5, 2024
4c7db5c
fix tests & another jwt issuer
dholms Mar 5, 2024
514b437
Merge branch 'ozone-acls-take2' into pds-proxy-headers
dholms Mar 5, 2024
81f9d69
ozone: fix ip check
devinivy Mar 5, 2024
c74fd23
Merge remote-tracking branch 'origin/ozone-acls-take2' into pds-proxy…
devinivy Mar 5, 2024
7be8445
fix aud check on pds mod service auth
dholms Mar 5, 2024
7a490d2
Merge branch 'ozone-acls-take2' into pds-proxy-headers
dholms Mar 5, 2024
592518c
tidy
dholms Mar 5, 2024
402cc7b
Merge branch 'ozone-acls-take2' into pds-proxy-headers
dholms Mar 5, 2024
5b6b9ee
Merge branch 'main' into pds-proxy-headers
dholms Mar 6, 2024
5aec85f
merge main
dholms Mar 7, 2024
b4211ea
fix pipethrough of headers
dholms Mar 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-and-push-bsky-ghcr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
branches:
- main
- appview-v2
- pds-proxy-headers
env:
REGISTRY: ghcr.io
USERNAME: ${{ github.actor }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-and-push-ozone-aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
branches:
- main
- ozone-cdn-invalidation
- pds-proxy-headers
env:
REGISTRY: ${{ secrets.AWS_ECR_REGISTRY_USEAST2_PACKAGES_REGISTRY }}
USERNAME: ${{ secrets.AWS_ECR_REGISTRY_USEAST2_PACKAGES_USERNAME }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build-and-push-pds-ghcr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- main
- pds-proxy-headers
env:
REGISTRY: ghcr.io
USERNAME: ${{ github.actor }}
Expand Down
4 changes: 2 additions & 2 deletions packages/common-web/src/did-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const getNotifEndpoint = (doc: DidDocument): string | undefined => {

export const getServiceEndpoint = (
doc: DidDocument,
opts: { id: string; type: string },
opts: { id: string; type?: string },
) => {
const did = getDid(doc)
let services = doc.service
Expand All @@ -94,7 +94,7 @@ export const getServiceEndpoint = (
(service) => service.id === opts.id || service.id === `${did}${opts.id}`,
)
if (!found) return undefined
if (found.type !== opts.type) {
if (opts.type && found.type !== opts.type) {
return undefined
}
if (typeof found.serviceEndpoint !== 'string') {
Expand Down
1 change: 1 addition & 0 deletions packages/dev-env/src/pds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class TestPds {
await fs.mkdir(dataDirectory, { recursive: true })

const env: pds.ServerEnvironment = {
devMode: true,
port,
dataDirectory: dataDirectory,
blobstoreDiskLocation: blobstoreLoc,
Expand Down
17 changes: 4 additions & 13 deletions packages/pds/src/api/app/bsky/actor/getProfile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Server } from '../../../../lexicon'
import AppContext from '../../../../context'
import { authPassthru } from '../../../proxy'
import { OutputSchema } from '../../../../lexicon/types/app/bsky/actor/getProfile'
import {
LocalViewer,
Expand All @@ -15,18 +14,10 @@ export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.actor.getProfile({
auth: ctx.authVerifier.accessOrRole,
handler: async ({ req, auth, params }) => {
const requester =
auth.credentials.type === 'access' ? auth.credentials.did : null
const res = await pipethrough(
bskyAppView.url,
METHOD_NSID,
params,
requester
? await ctx.appviewAuthHeaders(requester, req)
: authPassthru(req),
)
auth: ctx.authVerifier.access,
handler: async ({ req, auth }) => {
const requester = auth.credentials.did
const res = await pipethrough(ctx, req, requester)
if (!requester) {
return res
}
Expand Down
9 changes: 2 additions & 7 deletions packages/pds/src/api/app/bsky/actor/getProfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,10 @@ export default function (server: Server, ctx: AppContext) {
if (!bskyAppView) return
server.app.bsky.actor.getProfiles({
auth: ctx.authVerifier.access,
handler: async ({ auth, params, req }) => {
handler: async ({ req, auth }) => {
const requester = auth.credentials.did

const res = await pipethrough(
bskyAppView.url,
METHOD_NSID,
params,
await ctx.appviewAuthHeaders(requester, req),
)
const res = await pipethrough(ctx, req, requester)
return handleReadAfterWrite(
ctx,
METHOD_NSID,
Expand Down
9 changes: 2 additions & 7 deletions packages/pds/src/api/app/bsky/actor/getSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ export default function (server: Server, ctx: AppContext) {
if (!bskyAppView) return
server.app.bsky.actor.getSuggestions({
auth: ctx.authVerifier.access,
handler: async ({ params, auth, req }) => {
handler: async ({ req, auth }) => {
const requester = auth.credentials.did
return pipethrough(
bskyAppView.url,
'app.bsky.actor.getSuggestions',
params,
await ctx.appviewAuthHeaders(requester, req),
)
return pipethrough(ctx, req, requester)
},
})
}
9 changes: 2 additions & 7 deletions packages/pds/src/api/app/bsky/actor/searchActors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ export default function (server: Server, ctx: AppContext) {
if (!bskyAppView) return
server.app.bsky.actor.searchActors({
auth: ctx.authVerifier.access,
handler: async ({ params, auth, req }) => {
handler: async ({ req, auth }) => {
const requester = auth.credentials.did
return pipethrough(
bskyAppView.url,
'app.bsky.actor.searchActors',
params,
await ctx.appviewAuthHeaders(requester, req),
)
return pipethrough(ctx, req, requester)
},
})
}
9 changes: 2 additions & 7 deletions packages/pds/src/api/app/bsky/actor/searchActorsTypeahead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ export default function (server: Server, ctx: AppContext) {
if (!bskyAppView) return
server.app.bsky.actor.searchActorsTypeahead({
auth: ctx.authVerifier.access,
handler: async ({ params, auth, req }) => {
handler: async ({ req, auth }) => {
const requester = auth.credentials.did
return pipethrough(
bskyAppView.url,
'app.bsky.actor.searchActorsTypeahead',
params,
await ctx.appviewAuthHeaders(requester, req),
)
return pipethrough(ctx, req, requester)
},
})
}
9 changes: 2 additions & 7 deletions packages/pds/src/api/app/bsky/feed/getActorFeeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ export default function (server: Server, ctx: AppContext) {
if (!bskyAppView) return
server.app.bsky.feed.getActorFeeds({
auth: ctx.authVerifier.access,
handler: async ({ auth, params, req }) => {
handler: async ({ req, auth }) => {
const requester = auth.credentials.did
return pipethrough(
bskyAppView.url,
'app.bsky.feed.getActorFeeds',
params,
await ctx.appviewAuthHeaders(requester, req),
)
return pipethrough(ctx, req, requester)
},
})
}
17 changes: 4 additions & 13 deletions packages/pds/src/api/app/bsky/feed/getActorLikes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Server } from '../../../../lexicon'
import AppContext from '../../../../context'
import { authPassthru } from '../../../proxy'
import { OutputSchema } from '../../../../lexicon/types/app/bsky/feed/getAuthorFeed'
import {
LocalViewer,
Expand All @@ -15,18 +14,10 @@ export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.feed.getActorLikes({
auth: ctx.authVerifier.accessOrRole,
handler: async ({ req, params, auth }) => {
const requester =
auth.credentials.type === 'access' ? auth.credentials.did : null
const res = await pipethrough(
bskyAppView.url,
METHOD_NSID,
params,
requester
? await ctx.appviewAuthHeaders(requester, req)
: authPassthru(req),
)
auth: ctx.authVerifier.access,
handler: async ({ req, auth }) => {
const requester = auth.credentials.did
const res = await pipethrough(ctx, req, requester)

if (!requester) {
return res
Expand Down
17 changes: 4 additions & 13 deletions packages/pds/src/api/app/bsky/feed/getAuthorFeed.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Server } from '../../../../lexicon'
import AppContext from '../../../../context'
import { authPassthru } from '../../../proxy'
import { OutputSchema } from '../../../../lexicon/types/app/bsky/feed/getAuthorFeed'
import { isReasonRepost } from '../../../../lexicon/types/app/bsky/feed/defs'
import {
Expand All @@ -16,18 +15,10 @@ export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.feed.getAuthorFeed({
auth: ctx.authVerifier.accessOrRole,
handler: async ({ req, params, auth }) => {
const requester =
auth.credentials.type === 'access' ? auth.credentials.did : null
const res = await pipethrough(
bskyAppView.url,
METHOD_NSID,
params,
requester
? await ctx.appviewAuthHeaders(requester, req)
: authPassthru(req),
)
auth: ctx.authVerifier.access,
handler: async ({ req, auth }) => {
const requester = auth.credentials.did
const res = await pipethrough(ctx, req, requester)
if (!requester) {
return res
}
Expand Down
17 changes: 2 additions & 15 deletions packages/pds/src/api/app/bsky/feed/getFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,9 @@ export default function (server: Server, ctx: AppContext) {
const { data: feed } =
await appViewAgent.api.app.bsky.feed.getFeedGenerator(
{ feed: params.feed },
await ctx.appviewAuthHeaders(requester, req),
await ctx.appviewAuthHeaders(requester),
)
const serviceAuthHeaders = await ctx.serviceAuthHeaders(
requester,
feed.view.did,
req,
)
// forward accept-language header to upstream services
serviceAuthHeaders.headers['accept-language'] =
req.headers['accept-language']
return pipethrough(
bskyAppView.url,
'app.bsky.feed.getFeed',
params,
serviceAuthHeaders,
)
return pipethrough(ctx, req, requester, feed.view.did)
},
})
}
9 changes: 2 additions & 7 deletions packages/pds/src/api/app/bsky/feed/getFeedGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ export default function (server: Server, ctx: AppContext) {
if (!bskyAppView) return
server.app.bsky.feed.getFeedGenerator({
auth: ctx.authVerifier.access,
handler: async ({ params, auth, req }) => {
handler: async ({ req, auth }) => {
const requester = auth.credentials.did
return pipethrough(
bskyAppView.url,
'app.bsky.feed.getFeedGenerator',
params,
await ctx.appviewAuthHeaders(requester, req),
)
return pipethrough(ctx, req, requester)
},
})
}
9 changes: 2 additions & 7 deletions packages/pds/src/api/app/bsky/feed/getFeedGenerators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ export default function (server: Server, ctx: AppContext) {
if (!bskyAppView) return
server.app.bsky.feed.getFeedGenerators({
auth: ctx.authVerifier.access,
handler: async ({ params, auth, req }) => {
handler: async ({ req, auth }) => {
const requester = auth.credentials.did
return pipethrough(
bskyAppView.url,
'app.bsky.feed.getFeedGenerators',
params,
await ctx.appviewAuthHeaders(requester, req),
)
return pipethrough(ctx, req, requester)
},
})
}
9 changes: 2 additions & 7 deletions packages/pds/src/api/app/bsky/feed/getLikes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ export default function (server: Server, ctx: AppContext) {
if (!bskyAppView) return
server.app.bsky.feed.getLikes({
auth: ctx.authVerifier.access,
handler: async ({ params, auth, req }) => {
handler: async ({ req, auth }) => {
const requester = auth.credentials.did
return pipethrough(
bskyAppView.url,
'app.bsky.feed.getLikes',
params,
await ctx.appviewAuthHeaders(requester, req),
)
return pipethrough(ctx, req, requester)
},
})
}
9 changes: 2 additions & 7 deletions packages/pds/src/api/app/bsky/feed/getListFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ export default function (server: Server, ctx: AppContext) {
if (!bskyAppView) return
server.app.bsky.feed.getListFeed({
auth: ctx.authVerifier.access,
handler: async ({ auth, params, req }) => {
handler: async ({ req, auth }) => {
const requester = auth.credentials.did
return pipethrough(
bskyAppView.url,
'app.bsky.feed.getListFeed',
params,
await ctx.appviewAuthHeaders(requester, req),
)
return pipethrough(ctx, req, requester)
},
})
}
26 changes: 5 additions & 21 deletions packages/pds/src/api/app/bsky/feed/getPostThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { AtUri } from '@atproto/syntax'
import { Headers, XRPCError } from '@atproto/xrpc'
import { Server } from '../../../../lexicon'
import AppContext from '../../../../context'
import { authPassthru } from '../../../proxy'
import {
ThreadViewPost,
isThreadViewPost,
Expand All @@ -30,27 +29,12 @@ export default function (server: Server, ctx: AppContext) {
const { bskyAppView } = ctx.cfg
if (!bskyAppView) return
server.app.bsky.feed.getPostThread({
auth: ctx.authVerifier.accessOrRole,
handler: async ({ req, params, auth }) => {
const requester =
auth.credentials.type === 'access' ? auth.credentials.did : null

if (!requester) {
return pipethrough(
bskyAppView.url,
METHOD_NSID,
params,
authPassthru(req),
)
}
auth: ctx.authVerifier.access,
handler: async ({ req, auth, params }) => {
const requester = auth.credentials.did

try {
const res = await pipethrough(
bskyAppView.url,
METHOD_NSID,
params,
await ctx.appviewAuthHeaders(requester, req),
)
const res = await pipethrough(ctx, req, requester)

return await handleReadAfterWrite(
ctx,
Expand Down Expand Up @@ -206,7 +190,7 @@ const readAfterWriteNotFound = async (
assert(ctx.appViewAgent)
const parentsRes = await ctx.appViewAgent.api.app.bsky.feed.getPostThread(
{ uri: highestParent, parentHeight: params.parentHeight, depth: 0 },
await ctx.appviewAuthHeaders(requester, null),
await ctx.appviewAuthHeaders(requester),
)
thread.parent = parentsRes.data.thread
} catch (err) {
Expand Down
9 changes: 2 additions & 7 deletions packages/pds/src/api/app/bsky/feed/getPosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ export default function (server: Server, ctx: AppContext) {
if (!bskyAppView) return
server.app.bsky.feed.getPosts({
auth: ctx.authVerifier.access,
handler: async ({ params, auth, req }) => {
handler: async ({ req, auth }) => {
const requester = auth.credentials.did
return pipethrough(
bskyAppView.url,
'app.bsky.feed.getPosts',
params,
await ctx.appviewAuthHeaders(requester, req),
)
return pipethrough(ctx, req, requester)
},
})
}
Loading
Loading