generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This checks ReferenceGrant rules for TLSRoute against accepting an invalid ReferenceGrant for the backend service. Signed-off-by: Maartje Eyskens <maartje.eyskens@isovalent.com>
- Loading branch information
Showing
3 changed files
with
235 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package tests | ||
|
||
import ( | ||
"testing" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
|
||
"sigs.k8s.io/gateway-api/apis/v1beta1" | ||
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes" | ||
"sigs.k8s.io/gateway-api/conformance/utils/suite" | ||
) | ||
|
||
func init() { | ||
ConformanceTests = append(ConformanceTests, TLSRouteInvalidReferenceGrant) | ||
} | ||
|
||
var TLSRouteInvalidReferenceGrant = suite.ConformanceTest{ | ||
ShortName: "TLSRouteInvalidReferenceGrant", | ||
Description: "A single TLSRoute in the gateway-conformance-infra namespace, with a backendRef in another namespace without valid ReferenceGrant, should not attach to Gateway in the gateway-conformance-infra namespace", | ||
Features: []suite.SupportedFeature{ | ||
suite.SupportGateway, | ||
suite.SupportTLSRoute, | ||
suite.SupportReferenceGrant, | ||
}, | ||
Manifests: []string{"tests/tlsroute-invalid-reference-grant.yaml"}, | ||
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { | ||
routeNN := types.NamespacedName{Name: "gateway-conformance-infra-test", Namespace: "gateway-conformance-infra"} | ||
gwNN := types.NamespacedName{Name: "gateway-tlsroute", Namespace: "gateway-conformance-infra"} | ||
|
||
kubernetes.GatewayAndTLSRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN) | ||
|
||
t.Run("TLSRoute with BackendRef in another namespace and no ReferenceGrant covering the Service has a ResolvedRefs Condition with status False and Reason RefNotPermitted", func(t *testing.T) { | ||
|
||
resolvedRefsCond := metav1.Condition{ | ||
Type: string(v1beta1.RouteConditionResolvedRefs), | ||
Status: metav1.ConditionFalse, | ||
Reason: string(v1beta1.RouteReasonRefNotPermitted), | ||
} | ||
|
||
kubernetes.TLSRouteMustHaveCondition(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN, resolvedRefsCond) | ||
}) | ||
}, | ||
} |
141 changes: 141 additions & 0 deletions
141
conformance/tests/tlsroute-invalid-reference-grant.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
--- | ||
apiVersion: gateway.networking.k8s.io/v1beta1 | ||
kind: ReferenceGrant | ||
metadata: | ||
name: reference-grant-wrong-namespace | ||
namespace: gateway-conformance-infra | ||
spec: | ||
from: | ||
- group: gateway.networking.k8s.io | ||
kind: TLSRoute | ||
namespace: gateway-conformance-infra | ||
to: | ||
- group: "" | ||
kind: Service | ||
name: tls-backend | ||
--- | ||
apiVersion: gateway.networking.k8s.io/v1beta1 | ||
kind: ReferenceGrant | ||
metadata: | ||
name: reference-grant-wrong-from-group | ||
namespace: gateway-conformance-tls-backend | ||
spec: | ||
from: | ||
- group: not-the-group-youre-looking-for | ||
kind: TLSRoute | ||
namespace: gateway-conformance-infra | ||
to: | ||
- group: "" | ||
kind: Service | ||
name: tls-backend | ||
--- | ||
apiVersion: gateway.networking.k8s.io/v1beta1 | ||
kind: ReferenceGrant | ||
metadata: | ||
name: reference-grant-wrong-from-kind | ||
namespace: gateway-conformance-tls-backend | ||
spec: | ||
from: | ||
- group: gateway.networking.k8s.io | ||
kind: Gateway | ||
namespace: gateway-conformance-infra | ||
to: | ||
- group: "" | ||
kind: Service | ||
name: tls-backend | ||
--- | ||
apiVersion: gateway.networking.k8s.io/v1beta1 | ||
kind: ReferenceGrant | ||
metadata: | ||
name: reference-grant-wrong-from-namespace | ||
namespace: gateway-conformance-tls-backend | ||
spec: | ||
from: | ||
- group: gateway.networking.k8s.io | ||
kind: TLSRoute | ||
namespace: not-the-namespace-youre-looking-for | ||
to: | ||
- group: "" | ||
kind: Service | ||
name: tls-backend | ||
--- | ||
apiVersion: gateway.networking.k8s.io/v1beta1 | ||
kind: ReferenceGrant | ||
metadata: | ||
name: reference-grant-wrong-to-group | ||
namespace: gateway-conformance-tls-backend | ||
spec: | ||
from: | ||
- group: gateway.networking.k8s.io | ||
kind: TLSRoute | ||
namespace: gateway-conformance-infra | ||
to: | ||
- group: not-the-group-youre-looking-for | ||
kind: Service | ||
name: not-the-backend-youre-looking-for | ||
--- | ||
apiVersion: gateway.networking.k8s.io/v1beta1 | ||
kind: ReferenceGrant | ||
metadata: | ||
name: reference-grant-wrong-to-kind | ||
namespace: gateway-conformance-tls-backend | ||
spec: | ||
from: | ||
- group: gateway.networking.k8s.io | ||
kind: TLSRoute | ||
namespace: gateway-conformance-infra | ||
to: | ||
- group: "" | ||
kind: Secret | ||
name: tls-backend | ||
--- | ||
apiVersion: gateway.networking.k8s.io/v1beta1 | ||
kind: ReferenceGrant | ||
metadata: | ||
name: reference-grant-wrong-to-name | ||
namespace: gateway-conformance-tls-backend | ||
spec: | ||
from: | ||
- group: gateway.networking.k8s.io | ||
kind: TLSRoute | ||
namespace: gateway-conformance-infra | ||
to: | ||
- group: "" | ||
kind: Service | ||
name: not-the-service-youre-looking-for | ||
--- | ||
apiVersion: gateway.networking.k8s.io/v1alpha2 | ||
kind: TLSRoute | ||
metadata: | ||
name: gateway-conformance-infra-test | ||
namespace: gateway-conformance-infra | ||
spec: | ||
parentRefs: | ||
- name: gateway-tlsroute | ||
hostnames: | ||
- abc.example.com | ||
rules: | ||
- backendRefs: | ||
- name: tls-backend | ||
namespace: gateway-conformance-tls-backend | ||
port: 443 | ||
--- | ||
apiVersion: gateway.networking.k8s.io/v1beta1 | ||
kind: Gateway | ||
metadata: | ||
name: gateway-tlsroute | ||
namespace: gateway-conformance-infra | ||
spec: | ||
gatewayClassName: "{GATEWAY_CLASS_NAME}" | ||
listeners: | ||
- name: https | ||
port: 443 | ||
protocol: TLS | ||
hostname: "*.example.com" | ||
allowedRoutes: | ||
namespaces: | ||
from: Same | ||
kinds: | ||
- kind: TLSRoute | ||
tls: | ||
mode: Passthrough |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters