Skip to content

Commit

Permalink
satellites: add TLS handshake daemon for DRBD
Browse files Browse the repository at this point in the history
Adds a new switch .spec.internalTLS.tlsHandshakeDaemon on the
LinstorSatelliteConfiguration. If enabled, it configures
another sidecar on the Satellite that runs "tlshd" with the
same key material as the LINSTOR Satellite.

With this enabled, users can set "DrbdOptions/Net/tls: yes" on
their storage class to enable TLS encryption for DRBD connections.

Signed-off-by: Moritz Wanzenböck <[email protected]>
  • Loading branch information
WanzenBug committed Oct 30, 2023
1 parent 0b7273a commit d818594
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add a new option `.spec.internalTLS.tlsHandshakeDaemon` to enable deployment of `tlshd` alongside the LINSTOR
Satellite.

### Changed

- Fixed service resources relying on default protocol version.
Expand Down
2 changes: 1 addition & 1 deletion api/v1/linstorsatellite_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type LinstorSatelliteSpec struct {
// +kubebuilder:validation:Optional
// + Without "nullable" the k8s API does not accept patches with 'internalTLS: {}', which seems to be a bug.
// +nullable
InternalTLS *TLSConfig `json:"internalTLS,omitempty"`
InternalTLS *TLSConfigWithHandshakeDaemon `json:"internalTLS,omitempty"`
}

// LinstorSatelliteStatus defines the observed state of LinstorSatellite
Expand Down
2 changes: 1 addition & 1 deletion api/v1/linstorsatelliteconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type LinstorSatelliteConfigurationSpec struct {
// +kubebuilder:validation:Optional
// + See LinstorSatelliteSpec.InternalTLS for why nullable is needed.
// +nullable
InternalTLS *TLSConfig `json:"internalTLS,omitempty"`
InternalTLS *TLSConfigWithHandshakeDaemon `json:"internalTLS,omitempty"`
}

// LinstorSatelliteConfigurationStatus defines the observed state of LinstorSatelliteConfiguration
Expand Down
11 changes: 11 additions & 0 deletions api/v1/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,14 @@ type TLSConfig struct {
//+kubebuilder:validation:Optional
CertManager *cmmetav1.ObjectReference `json:"certManager,omitempty"`
}

type TLSConfigWithHandshakeDaemon struct {
TLSConfig `json:",inline"`

// TLSHandshakeDaemon enables tlshd for establishing TLS session for use by DRBD.
//
// If enables, adds a new sidecar to the LINSTOR Satellite that runs the tlshd handshake daemon.
// The daemon uses the tls certificate and key to establish secure connections on behalf of DRBD.
//+kubebuilder:validation:Optional
TLSHandshakeDaemon bool `json:"tlsHandshakeDaemon,omitempty"`
}
20 changes: 18 additions & 2 deletions api/v1/zz_generated.deepcopy.go

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

3 changes: 3 additions & 0 deletions charts/piraeus/templates/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ data:
drbd-shutdown-guard:
tag: v1.0.0
image: drbd-shutdown-guard
ktls-utils:
tag: v0.10
image: ktls-utils
drbd-module-loader:
tag: v9.2.5
# The special "match" attribute is used to select an image based on the node's reported OS.
Expand Down
14 changes: 14 additions & 0 deletions charts/piraeus/templates/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,13 @@ spec:
description: SecretName references a secret holding the TLS key
and certificates.
type: string
tlsHandshakeDaemon:
description: "TLSHandshakeDaemon enables tlshd for establishing
TLS session for use by DRBD. \n If enables, adds a new sidecar
to the LINSTOR Satellite that runs the tlshd handshake daemon.
The daemon uses the tls certificate and key to establish secure
connections on behalf of DRBD."
type: boolean
type: object
nodeSelector:
additionalProperties:
Expand Down Expand Up @@ -909,6 +916,13 @@ spec:
description: SecretName references a secret holding the TLS key
and certificates.
type: string
tlsHandshakeDaemon:
description: "TLSHandshakeDaemon enables tlshd for establishing
TLS session for use by DRBD. \n If enables, adds a new sidecar
to the LINSTOR Satellite that runs the tlshd handshake daemon.
The daemon uses the tls certificate and key to establish secure
connections on behalf of DRBD."
type: boolean
type: object
patches:
description: "Patches is a list of kustomize patches to apply. \n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ spec:
description: SecretName references a secret holding the TLS key
and certificates.
type: string
tlsHandshakeDaemon:
description: "TLSHandshakeDaemon enables tlshd for establishing
TLS session for use by DRBD. \n If enables, adds a new sidecar
to the LINSTOR Satellite that runs the tlshd handshake daemon.
The daemon uses the tls certificate and key to establish secure
connections on behalf of DRBD."
type: boolean
type: object
nodeSelector:
additionalProperties:
Expand Down
7 changes: 7 additions & 0 deletions config/crd/bases/piraeus.io_linstorsatellites.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ spec:
description: SecretName references a secret holding the TLS key
and certificates.
type: string
tlsHandshakeDaemon:
description: "TLSHandshakeDaemon enables tlshd for establishing
TLS session for use by DRBD. \n If enables, adds a new sidecar
to the LINSTOR Satellite that runs the tlshd handshake daemon.
The daemon uses the tls certificate and key to establish secure
connections on behalf of DRBD."
type: boolean
type: object
patches:
description: "Patches is a list of kustomize patches to apply. \n
Expand Down
3 changes: 3 additions & 0 deletions config/manager/0_piraeus_datastore_images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ components:
drbd-shutdown-guard:
tag: v1.0.0
image: drbd-shutdown-guard
ktls-utils:
tag: v0.10
image: ktls-utils
drbd-module-loader:
tag: v9.2.5
# The special "match" attribute is used to select an image based on the node's reported OS.
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/linstorcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var _ = Describe("LinstorCluster controller", func() {
Patches: []piraeusiov1.Patch{
{Target: &piraeusiov1.Selector{Kind: "ServiceAccount"}, Patch: "sa-patch1"},
},
InternalTLS: &piraeusiov1.TLSConfig{},
InternalTLS: &piraeusiov1.TLSConfigWithHandshakeDaemon{},
},
})
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -175,7 +175,7 @@ var _ = Describe("LinstorCluster controller", func() {
{Name: "pool1", LvmPool: &piraeusiov1.LinstorStoragePoolLvm{}},
{Name: "pool2", LvmThinPool: &piraeusiov1.LinstorStoragePoolLvmThin{VolumeGroup: "vg1", ThinPool: "thin1"}, Source: &piraeusiov1.LinstorStoragePoolSource{HostDevices: []string{"/dev/vdb"}}},
},
InternalTLS: &piraeusiov1.TLSConfig{},
InternalTLS: &piraeusiov1.TLSConfigWithHandshakeDaemon{},
}

specZoneB := &piraeusiov1.LinstorSatelliteSpec{
Expand All @@ -191,7 +191,7 @@ var _ = Describe("LinstorCluster controller", func() {
{Name: "pool1", LvmPool: &piraeusiov1.LinstorStoragePoolLvm{}},
{Name: "pool2", LvmThinPool: &piraeusiov1.LinstorStoragePoolLvmThin{}},
},
InternalTLS: &piraeusiov1.TLSConfig{},
InternalTLS: &piraeusiov1.TLSConfigWithHandshakeDaemon{},
}

Expect(&satNode1A.Spec).To(Equal(specZoneA))
Expand Down
9 changes: 9 additions & 0 deletions internal/controller/linstorsatellite_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,15 @@ func (r *LinstorSatelliteReconciler) kustomizeNodeResources(ctx context.Context,

patches = append(patches, p...)
}

if lsatellite.Spec.InternalTLS.TLSHandshakeDaemon {
p, err := SatelliteLinstorHandshakeDaemonPatch()
if err != nil {
return nil, err
}

patches = append(patches, p...)
}
}

var bindMountPaths []string
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/linstorsatellite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ var _ = Describe("LinstorSatelliteReconciler", func() {
TypeMeta: TypeMeta,
ObjectMeta: metav1.ObjectMeta{Name: ExampleNodeName},
Spec: piraeusiov1.LinstorSatelliteSpec{
InternalTLS: &piraeusiov1.TLSConfig{},
InternalTLS: &piraeusiov1.TLSConfigWithHandshakeDaemon{},
},
}, client.Apply, client.FieldOwner("test"))
Expect(err).NotTo(HaveOccurred())
Expand Down
8 changes: 8 additions & 0 deletions internal/controller/patches.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ func SatelliteLinstorInternalTLSCertManagerPatch(secretName string, issuer *cmme
)
}

func SatelliteLinstorHandshakeDaemonPatch() ([]kusttypes.Patch, error) {
return render(
satellite.Resources,
"patches/tlshd.yaml",
nil,
)
}

func SatelliteCommonNodePatch(nodeName string) ([]kusttypes.Patch, error) {
return render(
satellite.Resources,
Expand Down
6 changes: 6 additions & 0 deletions internal/controller/patches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ func TestPatches(t *testing.T) {
return controller.SatelliteLinstorInternalTLSPatch("secret")
},
},
{
name: "SatelliteLinstorHandshakeDaemonPatch",
call: func() ([]kusttypes.Patch, error) {
return controller.SatelliteLinstorHandshakeDaemonPatch()
},
},
{
name: "SatelliteCommonNodePatch",
call: func() ([]kusttypes.Patch, error) {
Expand Down
12 changes: 6 additions & 6 deletions pkg/merge/linstorsatelliteconfiguration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ var (
{Name: "prop1", Value: "config1"},
{Name: "prop2", Value: "config1"},
},
InternalTLS: &piraeusv1.TLSConfig{
InternalTLS: &piraeusv1.TLSConfigWithHandshakeDaemon{TLSConfig: piraeusv1.TLSConfig{
SecretName: "config1",
},
}},
},
}
Config2 = piraeusv1.LinstorSatelliteConfiguration{
Expand Down Expand Up @@ -66,9 +66,9 @@ var (
{Name: "prop2", Value: "config3"},
{Name: "prop3", Value: "config3"},
},
InternalTLS: &piraeusv1.TLSConfig{
InternalTLS: &piraeusv1.TLSConfigWithHandshakeDaemon{TLSConfig: piraeusv1.TLSConfig{
SecretName: "config3",
},
}},
},
}
)
Expand Down Expand Up @@ -118,9 +118,9 @@ func TestMergeSatelliteConfigurations(t *testing.T) {
{Name: "prop2", Value: "config3"},
{Name: "prop3", Value: "config3"},
},
InternalTLS: &piraeusv1.TLSConfig{
InternalTLS: &piraeusv1.TLSConfigWithHandshakeDaemon{TLSConfig: piraeusv1.TLSConfig{
SecretName: "config3",
},
}},
},
},
},
Expand Down
26 changes: 26 additions & 0 deletions pkg/resources/satellite/patches/tlshd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- target:
version: v1
kind: Pod
name: satellite
patch: |
apiVersion: v1
kind: Pod
metadata:
name: satellite
spec:
containers:
- name: ktls-utils
image: ktls-utils
securityContext:
capabilities:
add:
- NET_ADMIN
drop:
- ALL
privileged: true
readOnlyRootFilesystem: true
volumeMounts:
- name: internal-tls
mountPath: /etc/tlshd.d
readOnly: true

0 comments on commit d818594

Please sign in to comment.