Skip to content

Commit

Permalink
fix(cacert): Use --tls_ca_cert_file to pass the file (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pothulapati authored Oct 27, 2023
1 parent 1f0bae0 commit 04c3e71
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
5 changes: 2 additions & 3 deletions api/v1alpha1/dragonfly_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,9 @@ type Authentication struct {
PasswordFromSecret *corev1.SecretKeySelector `json:"passwordFromSecret,omitempty"`

// (Optional) If specified, the Dragonfly instance will check if the
// client certificate is signed by one of this CA. Server TLS must be enabled for this.
// Multiple CAs can be specified with various key names.
// client certificate is signed by this CA. Server TLS must be enabled for this.
// +optional
ClientCaCertSecret *corev1.SecretReference `json:"clientCaCertSecret,omitempty"`
ClientCaCertSecret *corev1.SecretKeySelector `json:"clientCaCertSecret,omitempty"`
}

// DragonflyStatus defines the observed state of Dragonfly
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 14 additions & 9 deletions config/crd/bases/dragonflydb.io_dragonflies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -879,18 +879,23 @@ spec:
properties:
clientCaCertSecret:
description: (Optional) If specified, the Dragonfly instance will
check if the client certificate is signed by one of this CA.
Server TLS must be enabled for this. Multiple CAs can be specified
with various key names.
check if the client certificate is signed by this CA. Server
TLS must be enabled for this.
properties:
name:
description: name is unique within a namespace to reference
a secret resource.
key:
description: The key of the secret to select from. Must be
a valid secret key.
type: string
namespace:
description: namespace defines the space within which the
secret name must be unique.
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
optional:
description: Specify whether the Secret or its key must be
defined
type: boolean
required:
- key
type: object
x-kubernetes-map-type: atomic
passwordFromSecret:
Expand Down
13 changes: 9 additions & 4 deletions internal/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (

const (
TlsPath = "/etc/dragonfly-tls"
TLSCACertDirArg = "--tls_ca_cert_dir"
TLSCACertDirArg = "--tls_ca_cert_file"
TLSCACertDir = "/etc/dragonfly/client-ca-cert"
TLSCACertVolumeName = "client-ca-cert"
)
Expand Down Expand Up @@ -251,12 +251,18 @@ func GetDragonflyResources(ctx context.Context, df *resourcesv1.Dragonfly) ([]cl
}

if df.Spec.Authentication.ClientCaCertSecret != nil {
// mount the secret as a volume
// mount the secrets as a volume
statefulset.Spec.Template.Spec.Volumes = append(statefulset.Spec.Template.Spec.Volumes, corev1.Volume{
Name: TLSCACertVolumeName,
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: df.Spec.Authentication.ClientCaCertSecret.Name,
Items: []corev1.KeyToPath{
{
Key: df.Spec.Authentication.ClientCaCertSecret.Key,
Path: "ca.crt",
},
},
},
},
})
Expand All @@ -268,8 +274,7 @@ func GetDragonflyResources(ctx context.Context, df *resourcesv1.Dragonfly) ([]cl
})

// pass it as an arg
statefulset.Spec.Template.Spec.Containers[0].Args = append(statefulset.Spec.Template.Spec.Containers[0].Args, fmt.Sprintf("%s=%s", TLSCACertDirArg, TLSCACertDir))

statefulset.Spec.Template.Spec.Containers[0].Args = append(statefulset.Spec.Template.Spec.Containers[0].Args, fmt.Sprintf("%s=%s/ca.crt", TLSCACertDirArg, TLSCACertDir))
}
}

Expand Down

0 comments on commit 04c3e71

Please sign in to comment.