Skip to content

Commit

Permalink
Merge pull request #1476 from mlavacca/invalid-tls-config
Browse files Browse the repository at this point in the history
conformance: all cases for which a TLS secret can be invalid are tested
  • Loading branch information
k8s-ci-robot committed Nov 4, 2022
2 parents deda2d9 + fa67946 commit 2f7ab68
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 77 deletions.
81 changes: 81 additions & 0 deletions conformance/tests/gateway-invalid-tls-certificateref.go
@@ -0,0 +1,81 @@
/*
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, GatewayInvalidTLSConfiguration)
}

var GatewayInvalidTLSConfiguration = suite.ConformanceTest{
ShortName: "GatewayInvalidTLSConfiguration",
Description: "A Gateway should fail to become ready if the Gateway has an invalid TLS configuration",
Manifests: []string{"tests/gateway-invalid-tls-certificateref.yaml"},
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
listeners := []v1beta1.ListenerStatus{{
Name: v1beta1.SectionName("https"),
SupportedKinds: []v1beta1.RouteGroupKind{{
Group: (*v1beta1.Group)(&v1beta1.GroupVersion.Group),
Kind: v1beta1.Kind("HTTPRoute"),
}},
Conditions: []metav1.Condition{{
Type: string(v1beta1.ListenerConditionResolvedRefs),
Status: metav1.ConditionFalse,
Reason: string(v1beta1.ListenerReasonInvalidCertificateRef),
}},
}}

testCases := []struct {
name string
gatewayNamespacedName types.NamespacedName
}{
{
name: "Nonexistent secret referenced as CertificateRef in a Gateway listener",
gatewayNamespacedName: types.NamespacedName{Name: "gateway-certificate-nonexistent-secret", Namespace: "gateway-conformance-infra"},
},
{
name: "Unsupported group resource referenced as CertificateRef in a Gateway listener",
gatewayNamespacedName: types.NamespacedName{Name: "gateway-certificate-unsupported-group", Namespace: "gateway-conformance-infra"},
},
{
name: "Unsupported kind resource referenced as CertificateRef in a Gateway listener",
gatewayNamespacedName: types.NamespacedName{Name: "gateway-certificate-unsupported-kind", Namespace: "gateway-conformance-infra"},
},
{
name: "Malformed secret referenced as CertificateRef in a Gateway listener",
gatewayNamespacedName: types.NamespacedName{Name: "gateway-certificate-malformed-secret", Namespace: "gateway-conformance-infra"},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
kubernetes.GatewayStatusMustHaveListeners(t, s.Client, s.TimeoutConfig, tc.gatewayNamespacedName, listeners)
})
}
},
}
91 changes: 91 additions & 0 deletions conformance/tests/gateway-invalid-tls-certificateref.yaml
@@ -0,0 +1,91 @@
apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
name: gateway-certificate-nonexistent-secret
namespace: gateway-conformance-infra
spec:
gatewayClassName: "{GATEWAY_CLASS_NAME}"
listeners:
- name: https
port: 443
protocol: HTTPS
allowedRoutes:
namespaces:
from: All
tls:
certificateRefs:
- group: ""
kind: Secret
name: nonexistent-certificate
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
name: gateway-certificate-unsupported-group
namespace: gateway-conformance-infra
spec:
gatewayClassName: "{GATEWAY_CLASS_NAME}"
listeners:
- name: https
port: 443
protocol: HTTPS
allowedRoutes:
namespaces:
from: All
tls:
certificateRefs:
- group: wrong.group.company.io
kind: Secret
name: tls-validity-checks-certificate
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
name: gateway-certificate-unsupported-kind
namespace: gateway-conformance-infra
spec:
gatewayClassName: "{GATEWAY_CLASS_NAME}"
listeners:
- name: https
port: 443
protocol: HTTPS
allowedRoutes:
namespaces:
from: All
tls:
certificateRefs:
- group: ""
kind: WrongKind
name: tls-validity-checks-certificate
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
name: gateway-certificate-malformed-secret
namespace: gateway-conformance-infra
spec:
gatewayClassName: "{GATEWAY_CLASS_NAME}"
listeners:
- name: https
port: 443
protocol: HTTPS
allowedRoutes:
namespaces:
from: All
tls:
certificateRefs:
- group: ""
kind: Secret
name: malformed-certificate
---
apiVersion: v1
kind: Secret
metadata:
name: malformed-certificate
namespace: gateway-conformance-infra
data:
# this certificate is invalid because contains an invalid pem (base64 of "Hello world"),
# and the certificate and the key are identical
tls.crt: SGVsbG8gd29ybGQK
tls.key: SGVsbG8gd29ybGQK
type: kubernetes.io/tls
58 changes: 0 additions & 58 deletions conformance/tests/gateway-secret-missing-referenced-secret.go

This file was deleted.

19 changes: 0 additions & 19 deletions conformance/tests/gateway-secret-missing-referenced-secret.yaml

This file was deleted.

2 changes: 2 additions & 0 deletions conformance/utils/suite/suite.go
Expand Up @@ -139,6 +139,8 @@ func (suite *ConformanceTestSuite) Setup(t *testing.T) {
t.Logf("Test Setup: Applying programmatic resources")
secret := kubernetes.MustCreateSelfSignedCertSecret(t, "gateway-conformance-web-backend", "certificate", []string{"*"})
suite.Applier.MustApplyObjectsWithCleanup(t, suite.Client, suite.TimeoutConfig, []client.Object{secret}, suite.Cleanup)
secret = kubernetes.MustCreateSelfSignedCertSecret(t, "gateway-conformance-infra", "tls-validity-checks-certificate", []string{"*"})
suite.Applier.MustApplyObjectsWithCleanup(t, suite.Client, suite.TimeoutConfig, []client.Object{secret}, suite.Cleanup)

t.Logf("Test Setup: Ensuring Gateways and Pods from base manifests are ready")
namespaces := []string{
Expand Down

0 comments on commit 2f7ab68

Please sign in to comment.