Skip to content

feat: add support for CSI volumes encryption and extraParams. #100

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

Merged
merged 6 commits into from
Jul 23, 2025

Conversation

mlinares1998
Copy link
Contributor

@mlinares1998 mlinares1998 commented Apr 23, 2025

Hi! 👋

I'm currently using the module to evaluate a potential production cluster, and it's been working fantastically so far!
Great job to everyone involved!

Given the module’s emphasis on encryption by default, I believe it's important to also support encryption at the storage level for block volumes.

This PR introduces support for enabling CSI volume encryption during cluster provisioning, using either a randomly generated or a fixed LUKS2 passphrase.

Additionally, it introduces the ability to define extra parameters in the default StorageClass, in line with the Hetzner CSI driver documentation.

Example kubernetes.tf snippet:

# Enable the HCloud CSI driver
hcloud_csi_enabled = true

# Enable volume encryption; a 32-byte random passphrase is generated by default
hcloud_csi_storage_class_encryption_enabled = true

# Optionally, specify your own encryption key
hcloud_csi_storage_class_encryption_key = "passphrase"

# Define additional StorageClass parameters
hcloud_csi_storage_class_extra_parameters = {
  "csi.storage.k8s.io/fstype" = "xfs"
  "fsFormatOption"            = "-i nrext64=1"
}

This is my first contribution to the module, i hope it aligns with the project's standards.
Looking forward to your feedback!

Best regards,

Reference:
https://github.com/hetznercloud/csi-driver/tree/main/docs/kubernetes#volumes-encrypted-with-luks https://github.com/hetznercloud/csi-driver/tree/main/docs/kubernetes#formatting-options

@mlinares1998 mlinares1998 force-pushed the feature/csi-configuration branch from c192052 to 9d6c1e9 Compare April 23, 2025 01:34
@M4t7e
Copy link
Contributor

M4t7e commented May 5, 2025

Many thanks @mlinares1998! That looks great! 🙂

Do you think it could be extended to support multiple storage classes?

@mlinares1998
Copy link
Contributor Author

Many thanks @mlinares1998! That looks great! 🙂

Do you think it could be extended to support multiple storage classes?

Hi!! @M4t7e Thanks for your review!
What do you mean exactly?
Allowing to define multiple storage classes within the module along the default one?

@M4t7e
Copy link
Contributor

M4t7e commented May 5, 2025

Allowing to define multiple storage classes within the module along the default one?

Exactly, that’s what I meant. I can imagine users wanting different storage classes for various use cases.

@mlinares1998
Copy link
Contributor Author

@M4t7e
I've added in 13f0102 support for defining additional StorageClasses alongside the default one.
Additionally, it's now possible to configure the reclaimPolicy for the default StorageClass as well 😄

@mlinares1998
Copy link
Contributor Author

Hi! @M4t7e any updates on this?
Regards! 😄

- Add new variable hcloud_csi_volume_extra_labels to configure default labels for all newly created volumes
- Add example configuration showing how to use volume extra labels

This feature is available in Hcloud CSI chart version 2.14+ and allows users to automatically apply custom labels to all volumes created by the CSI driver, useful for environment tagging, team assignment, and backup policies.
@mlinares1998
Copy link
Contributor Author

Hi @M4t7e!
I have updated the PR with the changes from another branch.
It adds support for the extra volume labels from HCloud CSI 2.14+ to add default labels to all the PVs.
It's really useful in accounts with multiple clusters.

Regards!

@M4t7e
Copy link
Contributor

M4t7e commented Jul 20, 2025

I’d like to merge it soon. I’ve been thinking about this issue and plan to make some adjustments to how storage classes are configured after this is merged. Could you please resolve the conflicts?

@mlinares1998
Copy link
Contributor Author

Hi! @M4t7e
I have fixed the conflicts.
Tell me if you need other changes!
Regards! 😄

@M4t7e M4t7e merged commit 8ea0a55 into hcloud-k8s:main Jul 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants