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

[bsky did 4] Special-case configured bsky DID and URL #3333

Merged
merged 1 commit into from
Jan 7, 2025

Conversation

rafaelbsky
Copy link
Contributor

@rafaelbsky rafaelbsky commented Jan 6, 2025

Testing:

  1. Checkout this branch.
  2. Let's first remove the special-casing and ensure the PDS is proxying to the service endpoint specified on the DID doc:
    diff --git a/packages/dev-env/src/bsky.ts b/packages/dev-env/src/bsky.ts
    index b20191257..bdf8e94a4 100644
    --- a/packages/dev-env/src/bsky.ts
    +++ b/packages/dev-env/src/bsky.ts
    @@ -34,6 +34,8 @@ export class TestBsky {
           signer: serviceKeypair,
         })
     
    +    console.log('bsky DID:', serverDid)
    +
         const endpoint = `http://localhost:${port}`
     
         await plcClient.updateData(serverDid, serviceKeypair, (x) => {
    @@ -43,7 +45,7 @@ export class TestBsky {
           }
           x.services['bsky_appview'] = {
             type: 'BskyAppView',
    -        endpoint,
    +        endpoint: 'http://localhost',
           }
           return x
         })
    diff --git a/packages/pds/src/pipethrough.ts b/packages/pds/src/pipethrough.ts
    index c54cf81ea..eb6a065e4 100644
    --- a/packages/pds/src/pipethrough.ts
    +++ b/packages/pds/src/pipethrough.ts
    @@ -262,12 +262,12 @@ export const parseProxyHeader = async (
       }
     
       // Special case a configured appview, while still proxying correctly any other appview
    -  if (
    -    ctx.cfg.bskyAppView &&
    -    proxyTo === `${ctx.cfg.bskyAppView.did}#bsky_appview`
    -  ) {
    -    return { did, url: ctx.cfg.bskyAppView.url }
    -  }
    +  // if (
    +  //   ctx.cfg.bskyAppView &&
    +  //   proxyTo === `${ctx.cfg.bskyAppView.did}#bsky_appview`
    +  // ) {
    +  //   return { did, url: ctx.cfg.bskyAppView.url }
    +  // }
     
       return { did, url }
     }
    
  3. On atproto folder, make run build and make run-dev-env.
  4. Copy the bsky DID that was printed in the terminal (added in the patch above).
  5. Create a session:
    curl --location 'http://localhost:2583/xrpc/com.atproto.server.createSession' \
    --header 'Content-Type: application/json' \
    --data '{
        "identifier": "alice.test",
        "password": "hunter2"
    }
    '
  6. Copy the accessJwt, and together with the DID you copied earlier, do (replacing the 2 placeholders):
    curl --location 'http://localhost:2583/xrpc/app.bsky.actor.getProfile?actor=alice.test' \
    --header 'atproto-proxy: <did>#bsky_appview' \
    --header 'Authorization: Bearer <accessJwt>'
  7. This should fail with {"error":"UpstreamFailure","message":"Upstream service unreachable"}. This means it tried to use the endpoint from the DID doc, which as you can see on step 2, was set to http://localhost, which is incorrect (missing the port).
  8. Reset all changes, apply this patch, then build and run again. Copy the new DID printed.
    diff --git a/packages/dev-env/src/bsky.ts b/packages/dev-env/src/bsky.ts
    index b20191257..bdf8e94a4 100644
    --- a/packages/dev-env/src/bsky.ts
    +++ b/packages/dev-env/src/bsky.ts
    @@ -34,6 +34,8 @@ export class TestBsky {
           signer: serviceKeypair,
         })
     
    +    console.log('bsky DID:', serverDid)
    +
         const endpoint = `http://localhost:${port}`
     
         await plcClient.updateData(serverDid, serviceKeypair, (x) => {
    @@ -43,7 +45,7 @@ export class TestBsky {
           }
           x.services['bsky_appview'] = {
             type: 'BskyAppView',
    -        endpoint,
    +        endpoint: 'http://localhost',
           }
           return x
         })
  9. Run (copy the accessJwt from the result):
    curl --location 'http://localhost:2583/xrpc/com.atproto.server.createSession' \
    --header 'Content-Type: application/json' \
    --data '{
        "identifier": "alice.test",
        "password": "hunter2"
    }
    '
  10. Run this (replacing the 2 placeholders with the values copied from the previous 2 steps):
    curl --location 'http://localhost:2583/xrpc/app.bsky.actor.getProfile?actor=alice.test' \
    --header 'atproto-proxy: <did>#bsky_appview' \
    --header 'Authorization: Bearer <accessJwt>'
  11. Note how this succeeds. This means that, even though the DID document states the service endpoint as http://localhost, it is using the configured endpoint of http://localhost:2584. So the special-casing for the configured DID is working (it is using the configured URL).

@rafaelbsky rafaelbsky changed the title [bsky did 4] Special case configured bsky DID and URL [bsky did 4] Special-case configured bsky DID and URL Jan 7, 2025
@rafaelbsky rafaelbsky merged commit 96c4698 into appview-did-0 Jan 7, 2025
10 checks passed
@rafaelbsky rafaelbsky deleted the appview-did-4 branch January 7, 2025 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants