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

Remove all IPV6 listeners in ingress resources with -disable-ipv6 command line #3139

1 change: 1 addition & 0 deletions internal/configs/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func generateNginxCfg(ingEx *IngressEx, apResources *AppProtectResources, dosRes
AppProtectEnable: cfgParams.AppProtectEnable,
AppProtectLogEnable: cfgParams.AppProtectLogEnable,
SpiffeCerts: cfgParams.SpiffeServerCerts,
DisableIPV6: staticParams.DisableIPV6,
}

warnings := addSSLConfig(&server, ingEx.Ingress, rule.Host, ingEx.Ingress.Spec.TLS, ingEx.SecretRefs, isWildcardEnabled)
Expand Down
19 changes: 19 additions & 0 deletions internal/configs/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,25 @@ func TestGenerateNginxCfgWithWildcardTLSSecret(t *testing.T) {
}
}

func TestGenerateNginxCfgWithIPV6Disabled(t *testing.T) {
t.Parallel()
cafeIngressEx := createCafeIngressEx()
isPlus := false
configParams := NewDefaultConfigParams(isPlus)

expected := createExpectedConfigForCafeIngressEx(isPlus)
expected.Servers[0].DisableIPV6 = true

result, warnings := generateNginxCfg(&cafeIngressEx, nil, nil, false, configParams, isPlus, false, &StaticConfigParams{DisableIPV6: true}, false)

if !cmp.Equal(expected, result) {
t.Errorf("generateNginxCfg() returned unexpected result (-want +got):\n%s", cmp.Diff(expected, result))
}
if len(warnings) != 0 {
t.Errorf("generateNginxCfg() returned warnings: %v", warnings)
}
}

func TestPathOrDefaultReturnDefault(t *testing.T) {
t.Parallel()
path := ""
Expand Down
1 change: 0 additions & 1 deletion internal/configs/version1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type IngressNginxConfig struct {
Keepalive string
Ingress Ingress
SpiffeClientCerts bool
DisableIPV6 bool
}

// Ingress holds information about an Ingress resource.
Expand Down
8 changes: 8 additions & 0 deletions tests/data/disable-ipv6-ingress/disable-ipv6-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: disable-ipv6-secret
type: kubernetes.io/tls
data:
tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURMakNDQWhZQ0NRREFPRjl0THNhWFdqQU5CZ2txaGtpRzl3MEJBUXNGQURCYU1Rc3dDUVlEVlFRR0V3SlYKVXpFTE1Ba0dBMVVFQ0F3Q1EwRXhJVEFmQmdOVkJBb01HRWx1ZEdWeWJtVjBJRmRwWkdkcGRITWdVSFI1SUV4MApaREViTUJrR0ExVUVBd3dTWTJGbVpTNWxlR0Z0Y0d4bExtTnZiU0FnTUI0WERURTRNRGt4TWpFMk1UVXpOVm9YCkRUSXpNRGt4TVRFMk1UVXpOVm93V0RFTE1Ba0dBMVVFQmhNQ1ZWTXhDekFKQmdOVkJBZ01Ba05CTVNFd0h3WUQKVlFRS0RCaEpiblJsY201bGRDQlhhV1JuYVhSeklGQjBlU0JNZEdReEdUQVhCZ05WQkFNTUVHTmhabVV1WlhoaApiWEJzWlM1amIyMHdnZ0VpTUEwR0NTcUdTSWIzRFFFQkFRVUFBNElCRHdBd2dnRUtBb0lCQVFDcDZLbjdzeTgxCnAwanVKL2N5ayt2Q0FtbHNmanRGTTJtdVpOSzBLdGVjcUcyZmpXUWI1NXhRMVlGQTJYT1N3SEFZdlNkd0kyaloKcnVXOHFYWENMMnJiNENaQ0Z4d3BWRUNyY3hkam0zdGVWaVJYVnNZSW1tSkhQUFN5UWdwaW9iczl4N0RsTGM2SQpCQTBaalVPeWwwUHFHOVNKZXhNVjczV0lJYTVyRFZTRjJyNGtTa2JBajREY2o3TFhlRmxWWEgySTVYd1hDcHRDCm42N0pDZzQyZitrOHdnemNSVnA4WFprWldaVmp3cTlSVUtEWG1GQjJZeU4xWEVXZFowZXdS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RnZGQ3haWWRidUI4NENtWmlodnhicFJBb0dBSWJqcWFNWVBUWXVrbENkYTVTNzkKWVNGSjFKelplMUtqYS8vdER3MXpGY2dWQ0thMzFqQXdjaXowZi9sU1JxM0hTMUdHR21lemhQVlRpcUxmZVpxYwpSMGlLYmhnYk9jVlZrSkozSzB5QXlLd1BUdW14S0haNnpJbVpTMGMwYW0rUlk5WUdxNVQ3WXJ6cHpjZnZwaU9VCmZmZTNSeUZUN2NmQ21mb09oREN0enVrQ2dZQjMwb0xDMVJMRk9ycW40M3ZDUzUxemM1em9ZNDR1QnpzcHd3WU4KVHd2UC9FeFdNZjNWSnJEakJDSCtULzZzeXNlUGJKRUltbHpNK0l3eXRGcEFOZmlJWEV0LzQ4WGY2ME54OGdXTQp1SHl4Wlp4L05LdER3MFY4dlgxUE9ucTJBNWVpS2ErOGpSQVJZS0pMWU5kZkR1d29seHZHNmJaaGtQaS80RXRUCjNZMThzUUtCZ0h0S2JrKzdsTkpWZXN3WEU1Y1VHNkVEVXNEZS8yVWE3ZlhwN0ZjanFCRW9hcDFMU3crNlRYcDAKWmdybUtFOEFSek00NytFSkhVdmlpcS9udXBFMTVnMGtKVzNzeWhwVTl6WkxPN2x0QjBLSWtPOVpSY21Vam84UQpjcExsSE1BcWJMSjhXWUdKQ2toaVd4eWFsNmhZVHlXWTRjVmtDMHh0VGwvaFVFOUllTktvCi0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg==
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: disable-ipv6-ingress-master
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.org/mergeable-ingress-type: "master"
spec:
tls:
- hosts:
- disable-ipv6.example.com
secretName: disable-ipv6-secret
rules:
- host: disable-ipv6.example.com
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: disable-ipv6-ingress-backend1-minion
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.org/mergeable-ingress-type: "minion"
spec:
rules:
- host: disable-ipv6.example.com
http:
paths:
- path: /backend1
pathType: Prefix
backend:
service:
name: backend1-svc
port:
number: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: disable-ipv6-ingress-backend2-minion
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.org/mergeable-ingress-type: "minion"
spec:
rules:
- host: disable-ipv6.example.com
http:
paths:
- path: /backend2
pathType: Prefix
backend:
service:
name: backend2-svc
port:
number: 80
29 changes: 29 additions & 0 deletions tests/data/disable-ipv6-ingress/standard/disable-ipv6-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
name: disable-ipv6-ingress
spec:
ingressClassName: nginx
tls:
- hosts:
- disable-ipv6.example.com
secretName: disable-ipv6-secret
rules:
- host: disable-ipv6.example.com
http:
paths:
- path: /backend2
pathType: Prefix
backend:
service:
name: backend2-svc
port:
number: 80
- path: /backend1
pathType: Prefix
backend:
service:
name: backend1-svc
port:
number: 80
112 changes: 112 additions & 0 deletions tests/suite/test_disable_ipv6_ingress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import pytest
from settings import TEST_DATA
from suite.fixtures import PublicEndpoint
from suite.resources_utils import (
create_example_app,
create_items_from_yaml,
create_secret_from_yaml,
delete_common_app,
delete_items_from_yaml,
delete_secret,
ensure_connection_to_public_endpoint,
get_first_pod_name,
get_ingress_nginx_template_conf,
get_nginx_template_conf,
wait_before_test,
wait_until_all_pods_are_ready,
)
from suite.yaml_utils import get_first_ingress_host_from_yaml, get_name_from_yaml

paths = ["backend1", "backend2"]


class DisableIPV6Setup:
"""
Encapsulate the Disable IPV6 Example details.

Attributes:
public_endpoint (PublicEndpoint):
ingress_name (str):
ingress_host (str):
ingress_pod_name (str):
namespace (str):
"""

def __init__(self, public_endpoint: PublicEndpoint, ingress_name, ingress_host, ingress_pod_name, namespace):
self.public_endpoint = public_endpoint
self.ingress_host = ingress_host
self.ingress_name = ingress_name
self.ingress_pod_name = ingress_pod_name
self.namespace = namespace


@pytest.fixture(scope="class", params=["standard", "mergeable"])
def disable_ipv6_setup(
request,
kube_apis,
ingress_controller_prerequisites,
ingress_controller_endpoint,
ingress_controller,
test_namespace,
) -> DisableIPV6Setup:
print("------------------------- Deploy Disable IPV6 Example -----------------------------------")
secret_name = create_secret_from_yaml(
kube_apis.v1, test_namespace, f"{TEST_DATA}/disable-ipv6-ingress/disable-ipv6-secret.yaml"
)

create_items_from_yaml(
kube_apis, f"{TEST_DATA}/disable-ipv6-ingress/{request.param}/disable-ipv6-ingress.yaml", test_namespace
)
ingress_name = get_name_from_yaml(f"{TEST_DATA}/disable-ipv6-ingress/{request.param}/disable-ipv6-ingress.yaml")
ingress_host = get_first_ingress_host_from_yaml(
f"{TEST_DATA}/disable-ipv6-ingress/{request.param}/disable-ipv6-ingress.yaml"
)
create_example_app(kube_apis, "simple", test_namespace)
wait_until_all_pods_are_ready(kube_apis.v1, test_namespace)

ensure_connection_to_public_endpoint(
ingress_controller_endpoint.public_ip,
ingress_controller_endpoint.port,
ingress_controller_endpoint.port_ssl,
)
ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace)

def fin():
print("Clean up the Disable IPV6 Application:")
delete_common_app(kube_apis, "simple", test_namespace)
delete_items_from_yaml(
kube_apis, f"{TEST_DATA}/disable-ipv6-ingress/{request.param}/disable-ipv6-ingress.yaml", test_namespace
)
delete_secret(kube_apis.v1, secret_name, test_namespace)

request.addfinalizer(fin)

return DisableIPV6Setup(ingress_controller_endpoint, ingress_name, ingress_host, ic_pod_name, test_namespace)


@pytest.mark.ingresses
class TestDisableIPV6:
@pytest.mark.parametrize(
"ingress_controller",
[
pytest.param({"extra_args": ["-disable-ipv6"]}, id="one-additional-cli-args"),
Copy link
Contributor

@shaun-nx shaun-nx Oct 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the id="one-additional-cli-args" option do? I haven't seen that before

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just the test ID of the parametrize values in pytest. Since I only have one set of values, I have removed the id and let pytest generate it.

],
indirect=True,
)
def test_ipv6_listeners_not_in_config(
self,
kube_apis,
disable_ipv6_setup: DisableIPV6Setup,
ingress_controller_prerequisites,
):
wait_before_test()
nginx_config = get_nginx_template_conf(kube_apis.v1, ingress_controller_prerequisites.namespace)
upstream_conf = get_ingress_nginx_template_conf(
kube_apis.v1,
disable_ipv6_setup.namespace,
disable_ipv6_setup.ingress_name,
disable_ipv6_setup.ingress_pod_name,
ingress_controller_prerequisites.namespace,
)
assert "listen [::]:" not in nginx_config
assert "listen [::]:" not in upstream_conf