Skip to content
This repository was archived by the owner on May 24, 2023. It is now read-only.

Commit c08c4a3

Browse files
committed
Update secret type of default secret to TLS
1 parent 5724b37 commit c08c4a3

File tree

5 files changed

+58
-13
lines changed

5 files changed

+58
-13
lines changed

deploy/crds/k8s.nginx.org_nginxingresscontrollers_crd.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ spec:
5353
type: object
5454
defaultSecret:
5555
description: The TLS Secret for TLS termination of the default server.
56-
The format is namespace/name. If not specified, the operator will
57-
generate and deploy a TLS Secret with a self-signed certificate and
58-
key.
56+
The format is namespace/name. The secret must be of the type kubernetes.io/tls.
57+
If not specified, the operator will generate and deploy a TLS Secret
58+
with a self-signed certificate and key.
5959
type: string
6060
enableCRDs:
6161
description: Enables the use of NGINX Ingress Resource Definitions (VirtualServer
@@ -235,11 +235,11 @@ spec:
235235
wildcardTLS:
236236
description: A Secret with a TLS certificate and key for TLS termination
237237
of every Ingress host for which TLS termination is enabled but the
238-
Secret is not specified. If the argument is not set, for such Ingress
239-
hosts NGINX will break any attempt to establish a TLS connection.
240-
If the argument is set, but the Ingress controller is not able to
241-
fetch the Secret from Kubernetes API, the Ingress Controller will
242-
fail to start. Format is namespace/name.
238+
Secret is not specified. The secret must be of the type kubernetes.io/tls.
239+
If the argument is not set, for such Ingress hosts NGINX will break
240+
any attempt to establish a TLS connection. If the argument is set,
241+
but the Ingress controller is not able to fetch the Secret from Kubernetes
242+
API, the Ingress Controller will fail to start. Format is namespace/name.
243243
type: string
244244
required:
245245
- enableCRDs

docs/nginx-ingress-controller.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ spec:
8080
| `nginxPlus` | `boolean` | Deploys the Ingress Controller for NGINX Plus. The default is `false` meaning the Ingress Controller will be deployed for NGINX OSS. | No |
8181
| `image` | [image](#nginxingresscontrollerimage) | The image of the Ingress Controller. | Yes |
8282
| `replicas` | `int` | The number of replicas of the Ingress Controller pod. The default is 1. Only applies if the `type` is set to deployment. | No |
83-
| `defaultSecret` | `string` | The TLS Secret for TLS termination of the default server. The format is namespace/name. If not specified, the operator will generate and deploy a TLS Secret with a self-signed certificate and key. | No |
83+
| `defaultSecret` | `string` | The TLS Secret for TLS termination of the default server. The format is namespace/name. The secret must be of the type kubernetes.io/tls. If not specified, the operator will generate and deploy a TLS Secret with a self-signed certificate and key. | No |
8484
| `serviceType` | `string` | The type of the Service for the Ingress Controller. Valid Service types are `NodePort` or `LoadBalancer`. | Yes |
8585
| `enableCRDs` | `boolean` | Enables the use of NGINX Ingress Resource Definitions (VirtualServer and VirtualServerRoute). | No |
8686
| `enableSnippets` | `boolean` | Enable custom NGINX configuration snippets in VirtualServer and VirtualServerRoute resources. Requires enableCRDs set to true. | No |
@@ -93,7 +93,7 @@ spec:
9393
| `nginxStatus` | [nginxStatus](#nginxingresscontrollernginxstatus) | Configures NGINX stub_status, or the NGINX Plus API. | No |
9494
| `reportIngressStatus` | [reportIngressStatus](#nginxingresscontrollerreportingressstatus) | Update the address field in the status of Ingresses resources. | No |
9595
| `enableLeaderElection` | `boolean` | Enables Leader election to avoid multiple replicas of the controller reporting the status of Ingress resources – only one replica will report status. | No |
96-
| `wildcardTLS` | `string` | A Secret with a TLS certificate and key for TLS termination of every Ingress host for which TLS termination is enabled but the Secret is not specified. If the argument is not set, for such Ingress hosts NGINX will break any attempt to establish a TLS connection. If the argument is set, but the Ingress controller is not able to fetch the Secret from Kubernetes API, the Ingress Controller will fail to start. Format is `namespace/name`. | No |
96+
| `wildcardTLS` | `string` | A Secret with a TLS certificate and key for TLS termination of every Ingress host for which TLS termination is enabled but the Secret is not specified. The secret must be of the type kubernetes.io/tls. If the argument is not set, for such Ingress hosts NGINX will break any attempt to establish a TLS connection. If the argument is set, but the Ingress controller is not able to fetch the Secret from Kubernetes API, the Ingress Controller will fail to start. Format is `namespace/name`. | No |
9797
| `prometheus` | [prometheus](#nginxingresscontrollerprometheus) | Configures NGINX or NGINX Plus metrics in the Prometheus format. | No |
9898
| `configMapData` | `map[string]string` | Initial values of the Ingress Controller ConfigMap. Check the [ConfigMap docs](https://docs.nginx.com/nginx-ingress-controller/configuration/global-configuration/configmap-resource/) for more information about possible values. | No |
9999
| `globalConfiguration` | `string` | The GlobalConfiguration resource for global configuration of the Ingress Controller. Format is namespace/name. Requires enableCRDs set to true. | No |

pkg/apis/k8s/v1alpha1/nginxingresscontroller_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type NginxIngressControllerSpec struct {
2323
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
2424
Replicas *int32 `json:"replicas"`
2525
// The TLS Secret for TLS termination of the default server. The format is namespace/name.
26+
// The secret must be of the type kubernetes.io/tls.
2627
// If not specified, the operator will generate and deploy a TLS Secret with a self-signed certificate and key.
2728
// +kubebuilder:validation:Optional
2829
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
@@ -87,6 +88,7 @@ type NginxIngressControllerSpec struct {
8788
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true
8889
EnableLeaderElection bool `json:"enableLeaderElection"`
8990
// A Secret with a TLS certificate and key for TLS termination of every Ingress host for which TLS termination is enabled but the Secret is not specified.
91+
// The secret must be of the type kubernetes.io/tls.
9092
// If the argument is not set, for such Ingress hosts NGINX will break any attempt to establish a TLS connection.
9193
// If the argument is set, but the Ingress controller is not able to fetch the Secret from Kubernetes API, the Ingress Controller will fail to start.
9294
// Format is namespace/name.

pkg/controller/nginxingresscontroller/secret.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ func defaultSecretForNginxIngressController(instance *k8sv1alpha1.NginxIngressCo
3030
Namespace: instance.Namespace,
3131
},
3232
Data: map[string][]byte{
33-
"tls.crt": crt,
34-
"tls.key": key,
33+
corev1.TLSCertKey: crt,
34+
corev1.TLSPrivateKeyKey: key,
3535
},
36-
Type: "Opaque",
36+
Type: corev1.SecretTypeTLS,
3737
}
3838

3939
return secret, nil
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package nginxingresscontroller
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
7+
k8sv1alpha1 "github.com/nginxinc/nginx-ingress-operator/pkg/apis/k8s/v1alpha1"
8+
corev1 "k8s.io/api/core/v1"
9+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
)
11+
12+
func TestDefaultSecretForNginxIngressController(t *testing.T) {
13+
instance := &k8sv1alpha1.NginxIngressController{
14+
ObjectMeta: metav1.ObjectMeta{
15+
Name: "my-nginx-ingress-controller",
16+
Namespace: "my-nginx-ingress-controller-ns",
17+
},
18+
}
19+
20+
expectedObjectMeta := &metav1.ObjectMeta{
21+
Name: "my-nginx-ingress-controller",
22+
Namespace: "my-nginx-ingress-controller-ns",
23+
}
24+
expectedType := corev1.SecretTypeTLS
25+
26+
secret, err := defaultSecretForNginxIngressController(instance)
27+
if err != nil {
28+
t.Fatalf("defaultSecretForNginxIngressController() returned unexpected error %v", err)
29+
}
30+
31+
if reflect.DeepEqual(expectedObjectMeta, secret.ObjectMeta) {
32+
t.Errorf("defaultSecretForNginxIngressController() returned %v but expected %v", secret.ObjectMeta, expectedObjectMeta)
33+
}
34+
if expectedType != secret.Type {
35+
t.Errorf("defaultSecretForNginxIngressController() returned %s but expected %s", secret.Type, expectedType)
36+
}
37+
if len(secret.Data[corev1.TLSCertKey]) == 0 {
38+
t.Errorf("defaultSecretForNginxIngressController() returned empty data key %s", corev1.TLSCertKey)
39+
}
40+
if len(secret.Data[corev1.TLSPrivateKeyKey]) == 0 {
41+
t.Errorf("defaultSecretForNginxIngressController() returned empty data key %s", corev1.TLSPrivateKeyKey)
42+
}
43+
}

0 commit comments

Comments
 (0)