Open JohnXLivingston opened 2 years ago
Hi, for the Peertube instance of my public company in educational sector, we have to limit the access of some videos to our country (for legal reasons). Those videos could be in various visibility state.
The need : To be able to block some countries from accessing peertube.mydomain.com and also any website where our videos could have been embed, and also every other peertube instance federated (maybe the most difficult part ?). This geoblocking should be possible at the video or channel level (and for other user, maybe for the whole instance but there other solution like reverse proxy could do the job I guess).
Regarding my needs, I've discussed with John the idea of a plugin based on the geoIP database and allowing us to specify some basic rule (for example "block entire world") then some specific rules (eg "allow FR" and "allow UK"). Then, in a new tab of the video edit page, the owner can specify which rule will be applied to his video (for example by checking the box "block entire world" and the box "allow FR").
For this specific use case, John suggest that this functionnality could be implemented in his own georegister plugin, or in a new plugin (maybe cleaner), but that it could be relevant to discuss it here. For example, he's wondering if a "helper" could be more usefull than a hook (or in addition to). I'm not a developper so I let you discuss the Pro and Cons.
Thanks for your thoughs about it.
Thanks @EricGuic for the summary.
Indeed, I think that a helper method, taking res
as parameter, and returning the country code could be really usefull. And if geoip is not enabled on Peertube, just don't provide this helper.
So we could write something like:
const country = peertubeHelpers.getRequestCountry ? peertubeHelpers.getRequestCountry(res) : null
And to respond to my first need, ensure I can get res
in the filter:api.user.signup.allowed.result
filter (see this discussion: some hooks/filters don't get res
as parameter).
Describe the problem to be solved
Some time ago, I created the plugin georegister. With this plugin, you can configure a set of countries allowes to create account, or disallowed to create account. I then use the IP provided to the hook filter:api.user.signup.allowed.result to check the country. I didn't want to download and maintain a geoip list at the time I wrote this plugin. So I use the
whois
command, and check the country in the whois result.Describe the solution you would like
Now that Peertube has an (optional) geoip database (used for viewing stats), it would be nice to provide the IP's country as parameter here:
https://github.com/Chocobozzz/PeerTube/blob/76ab0208dba043d837db835cf5ed390f718fd956/server/lib/server-config-manager.ts#L261-L268
Of course, only if the geoip database is configured. If not, just don't pass any
country
attribute.