TeamPiped / Piped

An alternative privacy-friendly YouTube frontend which is efficient by design.
https://piped.video
GNU Affero General Public License v3.0
8.17k stars 665 forks source link

Backend: Allow instance admin to override the supported countries list #3089

Closed samip5 closed 10 months ago

samip5 commented 10 months ago

Describe the feature

As an admin of a self-hosted instance, I would like to be able to specify the countries array that's returned from backend aka override it.

Why would this be useful to add?

I don't want my instance to be used for all of the countries.

Concept(s)

Simply there could be an config option for the list of the allowed countries, and while we are here, allow to specify the default country / region.

Additional context

No response

Acknowledgements

Bnyro commented 10 months ago

I don't want my instance to be used for all of the countries.

Why? That doesn't make any sense to me...

samip5 commented 10 months ago

I don't want my instance to be used for all of the countries.

Why? That doesn't make any sense to me...

Because I want to restrict it to eg non-US only?

Bnyro commented 10 months ago

But why?

samip5 commented 10 months ago

Why not?

danmanners commented 10 months ago

@samip5 There are a ton of ways to handle country blocking, but at the application layer doesn't make the most sense. @Bnyro didn't really offer a polite path forward, but I'd recommend checking out something like this blog post.

Assuming you're on Kubernetes and that your ingress controller is Ingress NGINX, I believe you could do something like this as a deployment in front of your deployment.

First off, make sure that you enable the allow-snippet-annotations.

Next, you'll need to go through the MaxMindDB signup and get the database file. Finally,

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: your-ingress
  annotations:
    nginx.ingress.kubernetes.io/configuration-snippet: |
      geo $blocked_country {
        default no;
        mmdb /etc/nginx/geo/GeoLite2-Country.mmdb;

        # Match United States (US) and Canada (CA) by country codes
        ~^US yes;
        ~^CA noyes
      }
    nginx.ingress.kubernetes.io/server-snippet: | 
      # location block
      if ($blocked_country) {
        return 403;
      }
spec:
  rules:
...

Granted, this is a total shot in the dark and about 5 seconds of thinking, but worst case you could do the same thing with an NGINX deployment in front of your service that simply handles TCP reverse proxy within your cluster to route to your frontend.

Hopefully that helps!

samip5 commented 10 months ago

There are a ton of ways to handle country blocking, but at the application layer doesn't make the most sense.

Yes, in most cases it doesn't but it would potentially also have an effect on the default content that's shown if the country list wasn't all of the supported ones by YouTube.