As far as I am aware, best practice for securing IPFS is to use an api gateway or proxy to restrict access to the ipfs api.
ipfs/kubo#1532
Bearer Authentication is common, here are some more details on the practice:
https://swagger.io/docs/specification/authentication/bearer-authentication/
I have tested using Kong to secure IPFS in this way and had success, but I find myself wanting to add a header to every network request made by js-ipfs-api.
We could support adding a header to the config:
const ipfsConfig = {
host: 'localhost',
port: 5001,
protocol: 'https',
headers: {
authorization: 'Bearer ' + ACCESS_TOKEN
}
};
Here where the user agent is added:
https://github.com/ipfs/js-ipfs-api/blob/master/src/utils/send-request.js#L111
We could add the authorization header to every request.
Axios http client supports this:
axios/axios#209
The api gateway (kong/ tyk) would be responsible for validating the jwt token.
I'm happy to submit a PR for this work, but I'm not sure the potential security implications for the rest of the api.
At a minimum it would seem wise to only allow the authorization header (assuming it is formatted correctly).
Interested to hear if this would be useful for others.