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

Issue 280: Read InfluxDB credentials from a secret #563

Merged
merged 6 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions deploy/crds/pravega.pravega.io_pravegaclusters_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,10 @@ spec:
repository:
type: string
type: object
influxDBSecret:
description: Name of Secret containing Password based Authentication
Parameters like username, password
type: string
longtermStorage:
description: LongTermStorage is the configuration of Pravega's
tier 2 storage. If no configuration is provided, it will assume
Expand Down
1 change: 1 addition & 0 deletions doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ This document explains how to configure Pravega
* [Configuring Service and Sts Names](service-sts-name-configuration.md)
* [Enable AuthHandlers](auth-handlers.md)
* [Init Containers Usage](init-containers.md)
* [Enable InfluxDB Authentication](influxdb-auth.md)
24 changes: 24 additions & 0 deletions doc/influxdb-auth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Enable InfluxDB Authentication

Operator supports passing influxdb credentials as secret. It is the recommended approach rather than passing username/password as part of Pravega options.

Steps to configure influxdb authentication are as follows:

1. Create a secret for basic authentication. Below is the sample yaml file

```
apiVersion: v1
kind: Secret
metadata:
name: secret-basic-auth
type: kubernetes.io/basic-auth
stringData:
username: admin
password: t0p-Secret
```
2. Modify the Pravega manifest to include the secret name for influxdb

```
influxDBSecret: "secret-basic-auth"
```
3. Once Pravega is deployed, secret will be mounted in `/etc/influxdb-secret-volume` for controller and segment store pods.
3 changes: 3 additions & 0 deletions pkg/apis/pravega/v1beta1/pravega.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ type PravegaSpec struct {

// Details of authplugin to be copied into pravega controller
AuthImplementations *AuthImplementationSpec `json:"authImplementations,omitempty"`

// Name of Secret containing Password based Authentication Parameters like username, password
Copy link
Contributor

Choose a reason for hiding this comment

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

description should specify that this secret is specific to the influxdb credentials

InfluxDBSecret string `json:"influxDBSecret,omitempty"`
}

func (s *PravegaSpec) withDefaults() (changed bool) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/pravega/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ const (
ssAuthVolumeName = "ss-auth-secret"
controllerAuthMountDir = "/etc/controller-auth-volume"
ssAuthMountDir = "/etc/ss-auth-volume"
influxDBSecretVolumeName = "influxdb-secret"
influxDBSecretMountDir = "/etc/influxdb-secret-volume"
)
15 changes: 15 additions & 0 deletions pkg/controller/pravega/pravega_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ func makeControllerPodSpec(p *api.PravegaCluster) *corev1.PodSpec {
configureControllerTLSSecrets(podSpec, p)
configureAuthSecrets(podSpec, p)
configureControllerAuthSecrets(podSpec, p)
configureControllerInfluxDBSecrets(podSpec, p)
return podSpec
}

Expand All @@ -276,6 +277,20 @@ func configureControllerAuthSecrets(podSpec *corev1.PodSpec, p *api.PravegaClust
}
}

func configureControllerInfluxDBSecrets(podSpec *corev1.PodSpec, p *api.PravegaCluster) {
if p.Spec.Pravega.InfluxDBSecret != "" {
addSecretVolumeWithMount(podSpec, p, influxDBSecretVolumeName, p.Spec.Pravega.InfluxDBSecret,
Copy link
Contributor

Choose a reason for hiding this comment

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

could we consider accepting the mount path as a property from the user instead of hardcoding its value in a constant?

influxDBSecretVolumeName, influxDBSecretMountDir)

podSpec.Containers[0].Env = []corev1.EnvVar{
{
Name: "INFLUX_DB_SECRET_MOUNT_PATH",
Value: influxDBSecretMountDir,
},
}
}
}

func addSecretVolumeWithMount(podSpec *corev1.PodSpec, p *api.PravegaCluster,
volumeName string, secretName string,
mountName string, mountDir string) {
Expand Down
6 changes: 6 additions & 0 deletions pkg/controller/pravega/pravega_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ var _ = Describe("Controller", func() {
ControllerPodAnnotations: annotationsMap,
SegmentStoreServiceAnnotations: annotationsMap,
SegmentStorePodLabels: annotationsMap,
InfluxDBSecret: "influxdb-secret",
Image: &v1beta1.ImageSpec{
Repository: "bar/pravega",
},
Expand Down Expand Up @@ -181,6 +182,11 @@ var _ = Describe("Controller", func() {

})

It("should have VolumeMounts created for influxdb secret", func() {
deploy := pravega.MakeControllerPodTemplate(p)
mounthostpath := deploy.Spec.Containers[0].VolumeMounts[9].MountPath
Ω(mounthostpath).Should(Equal("/etc/influxdb-secret-volume"))
})
It("should create the service", func() {
svc := pravega.MakeControllerService(p)
Ω(svc.Spec.Type).To(Equal(corev1.ServiceTypeClusterIP))
Expand Down
27 changes: 27 additions & 0 deletions pkg/controller/pravega/pravega_segmentstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func MakeSegmentStorePodTemplate(p *api.PravegaCluster) corev1.PodTemplateSpec {
func makeSegmentstorePodSpec(p *api.PravegaCluster) corev1.PodSpec {
configMapName := strings.TrimSpace(p.Spec.Pravega.SegmentStoreEnvVars)
secret := p.Spec.Pravega.SegmentStoreSecret

environment := []corev1.EnvFromSource{
{
ConfigMapRef: &corev1.ConfigMapEnvSource{
Expand Down Expand Up @@ -263,6 +264,8 @@ func makeSegmentstorePodSpec(p *api.PravegaCluster) corev1.PodSpec {

configureSegmentstoreAuthSecret(&podSpec, p)

configureInfluxDBSecret(&podSpec, p)

return podSpec
}

Expand Down Expand Up @@ -471,6 +474,30 @@ func configureCaBundleSecret(podSpec *corev1.PodSpec, p *api.PravegaCluster) {
}
}

func configureInfluxDBSecret(podSpec *corev1.PodSpec, p *api.PravegaCluster) {
if p.Spec.Pravega.InfluxDBSecret != "" {
vol := corev1.Volume{
Name: influxDBSecretVolumeName,
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: p.Spec.Pravega.InfluxDBSecret,
},
},
}
podSpec.Volumes = append(podSpec.Volumes, vol)

podSpec.Containers[0].VolumeMounts = append(podSpec.Containers[0].VolumeMounts, corev1.VolumeMount{
Name: influxDBSecretVolumeName,
MountPath: influxDBSecretMountDir,
})

podSpec.Containers[0].Env = append(podSpec.Containers[0].Env, corev1.EnvVar{
Name: "INFLUX_DB_SECRET_MOUNT_PATH",
Value: influxDBSecretMountDir,
})
}
}

func MakeSegmentStoreHeadlessService(p *api.PravegaCluster) *corev1.Service {
serviceport, _ := strconv.Atoi(p.Spec.Pravega.Options["pravegaservice.service.listener.port"])
return &corev1.Service{
Expand Down
19 changes: 15 additions & 4 deletions pkg/controller/pravega/pravega_segmentstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ var _ = Describe("PravegaSegmentstore", func() {
SegmentStorePodLabels: annotationsMap,
SegmentStorePodAnnotations: annotationsMap,
SegmentStoreEnvVars: "SEG_CONFIG_MAP",
InfluxDBSecret: "influxdb-secret",
SegmentStoreSecret: &v1beta1.SegmentStoreSecret{
Secret: "seg-secret",
MountPath: "",
Expand Down Expand Up @@ -120,8 +121,9 @@ var _ = Describe("PravegaSegmentstore", func() {
},
},
Authentication: &v1beta1.AuthenticationParameters{
Enabled: true,
PasswordAuthSecret: "authentication-secret",
Enabled: true,
PasswordAuthSecret: "authentication-secret",
SegmentStoreTokenSecret: "segment-store-secret",
},
}
p.WithDefaults()
Expand Down Expand Up @@ -187,6 +189,8 @@ var _ = Describe("PravegaSegmentstore", func() {
Ω(mounthostpath3).Should(Equal("/opt/pravega/logs"))
mounthostpath4 := sts.Spec.Template.Spec.Containers[0].VolumeMounts[4].MountPath
Ω(mounthostpath4).Should(Equal("/opt/pravega/conf/logback.xml"))
mounthostpath5 := sts.Spec.Template.Spec.Containers[0].VolumeMounts[9].MountPath
Ω(mounthostpath5).Should(Equal("/etc/influxdb-secret-volume"))
Ω(err).Should(BeNil())
})

Expand Down Expand Up @@ -315,11 +319,14 @@ var _ = Describe("PravegaSegmentstore", func() {
Ω(strings.Contains(javaOpts, "-Dpravegaservice.service.listener.port=443")).Should(BeTrue())
Ω(err).Should(BeNil())
})

It("should create a stateful set with filesystem as longtermstorage", func() {
sts := pravega.MakeSegmentStoreStatefulSet(p)
mounthostpath0 := sts.Spec.Template.Spec.Containers[0].VolumeMounts[4].MountPath
Ω(mounthostpath0).Should(Equal("/mnt/tier2"))
})
It("should set external access service type to LoadBalancer", func() {
Ω(p.Spec.ExternalAccess.Type).Should(Equal(corev1.ServiceTypeClusterIP))
})

})
})

Expand Down Expand Up @@ -362,6 +369,10 @@ var _ = Describe("PravegaSegmentstore", func() {
SegmentStoreServiceAnnotations: annotationsMap,
SegmentStorePodLabels: annotationsMap,
SegmentStoreExternalServiceType: corev1.ServiceTypeLoadBalancer,
SegmentStoreSecret: &v1beta1.SegmentStoreSecret{
Secret: "seg-secret",
MountPath: "/tmp/mount",
},
Image: &v1beta1.ImageSpec{
Repository: "bar/pravega",
},
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/resources/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2188,6 +2188,10 @@ spec:
repository:
type: string
type: object
influxDBSecret:
description: Name of Secret containing Password based Authentication
Parameters like username, password
type: string
longtermStorage:
description: LongTermStorage is the configuration of Pravega's
tier 2 storage. If no configuration is provided, it will assume
Expand Down