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

Egress is authorized with UCAN (stubbed) #126

Merged
merged 12 commits into from
Nov 6, 2024
Merged

Egress is authorized with UCAN (stubbed) #126

merged 12 commits into from
Nov 6, 2024

Conversation

Peeja
Copy link
Member

@Peeja Peeja commented Nov 4, 2024

Implements the UCAN validation for egress, except: can't yet get Spaces from the Indexing Service or get/store delegations, but both are stubbed so we can build from here.

To test/use:

  1. Start with a Freeway URL, like https://bafybeib7l5an3dsnr65gvei4n3x64ihlqkhg4iytcrlyxkbse6m5e6zufm.ipfs.w3s.link.
    • To test on localhost, convert from a subdomain gateway URL to a path gateway URL—eg, http://localhost:8787/ipfs/bafybeib7l5an3dsnr65gvei4n3x64ihlqkhg4iytcrlyxkbse6m5e6zufm
  2. Grab the Space's DID. (This doesn't actually have to be the correct Space, as long as it's consistent, since we're stubbing the Space lookup and the delegation store.)
  3. Make sure you're logged into the w3 CLI.
  4. Run node scripts/delegate-serve.js <space-did> | pbcopy to copy a base64url delegation string.
    • Or, use node scripts/delegate-serve.js <space-did> <token> | pbcopy to require a token.
  5. Add ?stub_space=<space-did>&stub_delegation=<delegation> to the URL.
    • Add authToken=<token> if a token was required.
  6. The content should load!
    • If the token does not match, it shouldn't load.
    • If the Space does not match, it shouldn't load.
    • If the delegation is missing, it shouldn't load.
    • If additional delegations are provided, it should still load.

The Stubs

  • stub_space: The Space DID to "find" the content in. The lookup will really locate the content, but will add the given Space to whatever results it gets back.
  • stub_delegation: A delegation to add to the "delegation store" for the request, .archive()ed to a CAR and base64urled. May be given multiple times to add multiple delegations. Every call to delegationsStore.find() will find all given delegations.

Remaining

  • Update to new ability names and wildcard delegation

// Look up delegations that might authorize us to serve the content.
const relevantDelegationsResult = await ctx.delegationsStorage.find({
audience: ctx.gatewayIdentity.did(),
can: 'space/content/serve',
Copy link
Member

@fforbeck fforbeck Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Importing the definition from the capability directly simplifies future refactoring:

Suggested change
can: 'space/content/serve',
can: [serve.can],

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great call!

expect(error.message).to.equal('Not Found')
})

it('should serve a found CID when stored in multiple Spaces', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ Excellent

Copy link
Member

@fforbeck fforbeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks pretty good to me!

* operations related to serving content owned by the Space, including actually
* serving it and recording egress charges.
*/
export const star = capability({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: I've released the new version of the w3up capabilities package in case you want to use the new space/content/serve/* from that lib.

Copy link
Member Author

@Peeja Peeja Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, excellent, thanks!

@Peeja Peeja merged commit cde2abf into main Nov 6, 2024
1 check passed
@Peeja Peeja deleted the ucan-auth branch November 6, 2024 16:53
fforbeck pushed a commit that referenced this pull request Nov 6, 2024
Implements the UCAN validation for egress, except: can't yet get Spaces
from the Indexing Service or get/store delegations, but both are stubbed
so we can build from here.

1. Start with a Freeway URL, like
`https://bafybeib7l5an3dsnr65gvei4n3x64ihlqkhg4iytcrlyxkbse6m5e6zufm.ipfs.w3s.link`.
* To test on localhost, convert from a subdomain gateway URL to a path
gateway URL—eg,
`http://localhost:8787/ipfs/bafybeib7l5an3dsnr65gvei4n3x64ihlqkhg4iytcrlyxkbse6m5e6zufm`
2. Grab the Space's DID. (This doesn't actually have to be the correct
Space, as long as it's consistent, since we're stubbing the Space lookup
*and* the delegation store.)
3. Make sure you're logged into the `w3` CLI.
4. Run `node scripts/delegate-serve.js <space-did> | pbcopy` to copy a
`base64url` delegation string.
* Or, use `node scripts/delegate-serve.js <space-did> <token> | pbcopy`
to require a token.
5. Add `?stub_space=<space-did>&stub_delegation=<delegation>` to the
URL.
    * Add `authToken=<token>` if a token was required.
6. The content should load!
    * If the token does not match, it shouldn't load.
    * If the Space does not match, it shouldn't load.
    * If the delegation is missing, it shouldn't load.
    * If additional delegations are provided, it should still load.

* **`stub_space`:** The Space DID to "find" the content in. The lookup
will really locate the content, but will add the given Space to whatever
results it gets back.
* **`stub_delegation`:** A delegation to add to the "delegation store"
for the request, `.archive()`ed to a CAR and `base64url`ed. May be given
multiple times to add multiple delegations. Every call to
`delegationsStore.find()` will find all given delegations.

- [x] Update to new ability names and wildcard delegation
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