-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
// 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', |
There was a problem hiding this comment.
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:
can: 'space/content/serve', | |
can: [serve.can], |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ Excellent
There was a problem hiding this 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!
`Buffer` is not available in the worker
* operations related to serving content owned by the Space, including actually | ||
* serving it and recording egress charges. | ||
*/ | ||
export const star = capability({ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh, excellent, thanks!
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
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:
https://bafybeib7l5an3dsnr65gvei4n3x64ihlqkhg4iytcrlyxkbse6m5e6zufm.ipfs.w3s.link
.http://localhost:8787/ipfs/bafybeib7l5an3dsnr65gvei4n3x64ihlqkhg4iytcrlyxkbse6m5e6zufm
w3
CLI.node scripts/delegate-serve.js <space-did> | pbcopy
to copy abase64url
delegation string.node scripts/delegate-serve.js <space-did> <token> | pbcopy
to require a token.?stub_space=<space-did>&stub_delegation=<delegation>
to the URL.authToken=<token>
if a token was required.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 andbase64url
ed. May be given multiple times to add multiple delegations. Every call todelegationsStore.find()
will find all given delegations.Remaining