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

IP Restriction at TCP Level. #6679

Closed
rohank2002 opened this issue Dec 22, 2020 · 15 comments · Fixed by #10245
Closed

IP Restriction at TCP Level. #6679

rohank2002 opened this issue Dec 22, 2020 · 15 comments · Fixed by #10245
Labels
task/feature Requests for new features in Kong

Comments

@rohank2002
Copy link

Summary

I am using Kong IP restriction plugin, according to the documentation its only compatible with HTTP and HTTPs, wanted to apply it at TCP level. Is there such a provision in Kong? Or a work around.

@bungle bungle added the task/feature Requests for new features in Kong label Dec 22, 2020
@bungle
Copy link
Member

bungle commented Dec 22, 2020

That should be doable. PR welcome, or I/we (at Kong) can take a look, but cannot promise exactly when.

@scrudge
Copy link
Contributor

scrudge commented Dec 22, 2020

We are willing to submit a PR, if someone can point us in the right direction.

@dndx
Copy link
Member

dndx commented Dec 29, 2020

Hello @scrudge,

If you use the L4 proxy functionalities provided by Kong, It should works at the L3. See: https://docs.konghq.com/2.2.x/proxy/#proxy-tcptls-traffic

The reason why Kong's IP restriction plugin under HTTP mode (and Nginx's own ngx_http_access_module, for that matter) works in L7 mode is because the client may present headers such as X-Forwarded-For which is not available at L3. If we close the connection early, we will have no chance to know if the request contains any of such headers, or if such header should be trusted, etc.

@dndx dndx added the pending author feedback Waiting for the issue author to get back to a maintainer with findings, more details, etc... label Dec 29, 2020
@guanlan guanlan closed this as completed Feb 5, 2021
@Mokto
Copy link

Mokto commented Aug 11, 2022

Sorry for reviving this but has anyone managed to use TCPIngress with ip restriction?

apiVersion: configuration.konghq.com/v1beta1
kind: TCPIngress
metadata:
  name: clickhouse
  annotations:
    kubernetes.io/ingress.class: kong
    konghq.com/plugins: ip-restriction
spec:
  rules:
  - host: XXXX-tcp.domain.io
    port: 9443
    backend:
      serviceName: clickhouse-lb
      servicePort: 9000

The IP restriction works for HTTP but not TCP.

@merusso
Copy link

merusso commented Dec 6, 2022

The plugin currently only works for HTTP, not TCP.

See:

We want for this to work on TCPIngress objects also. It looks like the plugin needs to be reworked to support TCP.

Ideally it would use the configured real_ip_header if available, fallback to proxy_protocol source IP if available, or fallback to TCP source IP as a last resort.

@hbagdi
Copy link
Member

hbagdi commented Dec 20, 2022

Re-opening this since this is a fair ask.
When operating at L4, the TCP byte stream won't be available. The plugin will probably restrict based on peer IP address or the IP obtained via proxy protocol (provided it comes from a trusted_ips).

PRs welcome.

@scrudge
Copy link
Contributor

scrudge commented Dec 21, 2022

We are currently testing these changes. Plan on submitting PR in the near future.

@hbagdi hbagdi reopened this Dec 21, 2022
@stale
Copy link

stale bot commented Jan 5, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 5, 2023
@merusso
Copy link

merusso commented Jan 13, 2023

The change we've made is based on release/2.8.x. Can we submit a PR to merge these changes into a new 2.x release?

@stale stale bot removed the stale label Jan 13, 2023
@stale
Copy link

stale bot commented Feb 4, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@locao
Copy link
Contributor

locao commented Feb 6, 2023

@merusso thank you for your interest in submitting a new feature for Kong!

Kong 2.8 is not under active development now, this means we are only adding fixes to bugs or security vulnerabilities, and a new feature would not see the sunlight. Please, open a PR targeting master and we will review it.

@scrudge
Copy link
Contributor

scrudge commented Feb 6, 2023

@locao We have also included a PR for the master branch as well. We are requesting that both PRs be accepted, as we are currently stuck on 2.8.x because of open issue we have with v3 that prevents us from upgrading. I'll update the Kong support ticket with more info.

@stale stale bot closed this as completed Feb 17, 2023
@merusso
Copy link

merusso commented Feb 18, 2023

Can this issue be reopened? We have open PRs meant to resolve this issue.

@hbagdi
Copy link
Member

hbagdi commented Feb 21, 2023

Reopening to keep tracking this.

@hbagdi hbagdi reopened this Feb 21, 2023
hanshuebner pushed a commit to merusso/kong that referenced this issue Mar 6, 2023
Resolves Kong#6679

This change adds TCP support to the ip-restriction plugin by
implementing the Stream module's preread function.

When a TCP connection is rejected due to IP restriction rules, a JSON
error response is written to the stream and the connection is closed.
@stale stale bot closed this as completed Mar 11, 2023
@locao
Copy link
Contributor

locao commented Mar 14, 2023

We forgot to remove the "pending author feedback" label so it was closed. Reopening.

@locao locao reopened this Mar 14, 2023
@stale stale bot removed the stale label Mar 14, 2023
@locao locao removed the pending author feedback Waiting for the issue author to get back to a maintainer with findings, more details, etc... label Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
task/feature Requests for new features in Kong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants