Commit Graph
50 Commits
Author SHA1 Message Date
Travis Nielsen 55c3e4d249 Merge pull request #15997 from subhamkrai/fix-code-syntax
osd: code cleanup in getSecret method
2025-06-17 07:39:31 -06:00
subhamkrai 0123ab0ab3 osd: code cleanup in getSecret method
This change refactors the getSecret method somewhat toward cleaner code.
The only additional change in behavior is the introduction of a switch instead
of multiple if's and error treatment of the case of an empty secret.

Signed-off-by: subhamkrai <srai@redhat.com>
2025-06-17 17:16:48 +05:30
Blaine Gardner 029c345372 Merge pull request #15813 from BlaineEXE/auth-rotate
object: automate RGW cephx key rotation
2025-06-10 12:51:50 -06:00
Blaine Gardner 5f50e85a25 object: implement cephx key rotation for rgw keys
This is the first implementation of CephX key rotation in Rook.
Adds key rotation API from design PR 15915.

Also add helper methods for rotating keys, determining when keys
need to be rotated, and for generating CephX key statuses. These will be
reusable for other Rook reconciles beyond object/RGW.

Signed-off-by: Blaine Gardner <blaine.gardner@ibm.com>
2025-06-10 09:06:58 -06:00
Carlos Barria 030ada45b0 core: fix golangci-lint check QF1003 QF1002
Refactored multiple conditional if-else blocks into switch statements to improve readability and maintainability. Also removed outdated staticcheck rule comments (QF1002, QF1003) from .golangci.yaml.

Signed-off-by: Carlos Barria <cbarria@yahoo.com>
2025-05-27 13:49:49 -04:00
Joshua Hoblitt b721c30dd1 core: fix golangci-lint warn caused by comment in nolint directive
Resolves this warning:

    WARN [runner/nolint_filter] Found unknown linters in //nolint directives: just configuration keys., value not credential

Signed-off-by: Joshua Hoblitt <josh@hoblitt.com>
2025-03-27 09:43:16 -07:00
Joshua Hoblitt 3cb343f62a core: run gofumpt on all files
Signed-off-by: Joshua Hoblitt <josh@hoblitt.com>
2025-03-26 10:41:48 -07:00
df511fb58f ci: update golangci-lint to the latest version (v1.62)
The ci was using a pretty old version og golangci-lint.
This updates to the latest version.

Additionally, it  silences some
gosec integer conversion overflow false positves
and fixes some real errors of this category
 and string format errors found by golangci-lint, while at it.

Co-authored-by: Blaine Gardner <b.blaine.gardner@gmail.com>
Co-authored-by: Travis Nielsen <tnielsen@redhat.com>
Signed-off-by: Michael Adam <obnox@samba.org>
2024-12-14 14:47:30 +01:00
Praveen M d8c0242c29 security: key rotation support for vault kms
Signed-off-by: Praveen M <m.praveen@ibm.com>
2024-10-23 11:43:49 +05:30
clonefetch 29ff8d9823 core: fix function names in comment
Signed-off-by: clonefetch <c0217@outlook.com>
2024-04-16 00:54:42 +08:00
sp98 4efe3982b0 core: azure kms support
Add support for store OSD encryption Keys in Azure KMS

Signed-off-by: sp98 <sapillai@redhat.com>
2024-03-15 11:23:25 +05:30
travisn a74a945202 core: remove vault server module dependencies
The vault server dependencies were pulling a lot of indirect modules
that are not necessary for Rook. The modules were only used
for testing. The vault github explicitly indicates that:

"Some other projects have made a practice of doing so in order to
take advantage of testing tooling that was developed for testing Vault itself.
This is not, and has never been, a supported way to use the Vault project."

When attempting to update to vault v1.13.3, we are hitting
such an unsupported configuration with go modules
that are impossible to satisfy. By removing the tests
that were using the vault server project, we can remove
this large set of dependencies, enable updating to v1.13.3,
and also reduce the modules pulled in by vault.

Signed-off-by: travisn <tnielsen@redhat.com>
2023-07-05 11:33:03 -06:00
travisn c4ec275946 build: update to latest go modules as much as possible
The go modules are updated to the latest client-go, vault,
and other modules. There does not appear to be a combination
of modules that will allow us to use vault v1.13.3, so we
stick with v1.13.2.

Signed-off-by: travisn <tnielsen@redhat.com>
2023-06-23 07:44:17 -06:00
parth-gr 8e317ee074 ci: update golangci-lint version as it fails for some k8s version in 1.10
Closes: https://github.com/rook/rook/issues/11896

Signed-off-by: parth-gr <paarora@redhat.com>
2023-03-16 20:59:22 +05:30
Rakshith R b41fdfbb62 osd: add support for updating secret for default KMS
This commit adds support for updating secret for default KMS.
This is required for encryption key rotation.

Signed-off-by: Rakshith R <rar@redhat.com>
2023-03-08 12:07:26 +05:30
parth-gr a84daf9bf0 core: change io/ioutil package to use io and os package
few functions got change as they were deprecated
for ex: ioutil.Readfile change to os.Readfile
ioutil.TempFile change to os.CreateTemp
And fixed golang-ci-lint-issues

Signed-off-by: parth-gr <paarora@redhat.com>
2023-02-17 20:38:29 +05:30
Rakshith R 9d0d93472f osd: use 256 as cryptographicLength for keys using kmip kms
This commit changes cryptographic length for keys created
for kmip kms to 256 from 128, since it is more secure.

Signed-off-by: Rakshith R <rar@redhat.com>
2022-09-29 11:25:31 +05:30
Rakshith R f21c12234d osd: add kmip encryption support
The cluster-wide encryption feature now
supports KMIP (Key Management Interoperability Protocol)
kms.
KMIP is an extensible communication protocol that defines
message formats for the manipulation of cryptographic keys
on a key management server.

For more information, refer:
https://en.wikipedia.org/wiki/Key_Management_Interoperability_Protocol

Signed-off-by: Rakshith R <rar@redhat.com>
2022-09-09 11:39:33 +05:30
Jiffin Tony Thottan 5c8ca01bd0 object: adding support for sse s3 for RGW
The RGW support server side encryption with help of s3 protocol, till
now the `sse:kms` was support in which keys will be provided by the user
and but it will be saved in external management service like vault. Now
the support for `sse:s3` is added so the entire encryption key
management is performed by RGW itsels.

Signed-off-by: Jiffin Tony Thottan <thottanjiffin@gmail.com>
2022-07-28 11:50:48 +05:30
Eng Zer Jun 8a25b1d903 test: use T.Setenv to set env vars in tests
This commit replaces `os.Setenv` with `t.Setenv` in tests. The
environment variable is automatically restored to its original value
when the test and all its subtests complete.

Reference: https://pkg.go.dev/testing#T.Setenv
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-07-15 23:07:19 +08:00
Sébastien Han 219e017564 osd: do not hide the error
Return the error instead of hiding it, err could be non-nil for a lot of
reasons, eg: a canceled context or a non-existing object.

Signed-off-by: Sébastien Han <seb@redhat.com>
2022-06-03 11:00:10 +02:00
Sébastien Han 6bc7827150 osd: only set kek to env var on encryption scenario
There is a corner case where an env variable populated with the prepare
job could influence and trigger some encryption code. We have an env
variable to discover whether the prepare job will encrypt a drive or not
so let's use that instead of running code as a noop and sometimes
trigger a corner case. In this scenario, the prepare job had an "IBM_"
env variable present in the OS image (IBM OS) so the setKEKinEnv()
  function would get called for no reason.

Signed-off-by: Sébastien Han <seb@redhat.com>
2022-04-11 16:54:18 +02:00
subhamkrai 24802c559e core: fix golangci linter
fix golangci linter

Signed-off-by: subhamkrai <srai@redhat.com>
2022-04-04 20:59:31 +05:30
Divyansh Kamboj 9008409f87 core: add context parameter to functions
This commit adds context parameter to various functions, and remove the
usage of context.TODO.

Closes: https://github.com/rook/rook/issues/8701
Signed-off-by: Divyansh Kamboj <dkamboj@redhat.com>
2022-03-22 08:19:07 +05:30
Sébastien Han 74081d90d3 osd: clarify vault auth error message
When kube authentication is used, let's clarify the error message and
hopefully lead to a better understanding on where to look for.
It could be misleading to print "token auth" when using kube auth,
although internally a token is used (the JWT from the Service
Account).

Signed-off-by: Sébastien Han <seb@redhat.com>
2022-03-10 14:10:19 +01:00
Sébastien Han 23832c8cc7 osd: add namespace in vault client
If the KMS connection details for Vault have a VAULT_NAMESPACE we must
use it when building the vault client to auto-detect the KV internal
version.

Signed-off-by: Sébastien Han <seb@redhat.com>
2022-02-10 12:13:41 +01:00
Sébastien Han 7cc6e23a0b osd: rename a few configuration flags
For better consistency with IBM_KP_SERVICE_API_KEY and use
"ibmkeyprotect" as a provider name for more clarity.

Signed-off-by: Sébastien Han <seb@redhat.com>
2022-01-20 16:01:26 +01:00
Sébastien Han a7acf490b6 osd: add ibm key protect kms
The cluster-wide encryption feature now has a new supported key
management system: IBM Key protect. More information about the backend
can be found in Rook documentation under the

Today's implementation stores OSD encryption keys has "Standard" keys.

Signed-off-by: Sébastien Han <seb@redhat.com>
2022-01-13 16:02:10 +01:00
Jiffin Tony Thottan aba50d3ca9 object: add support in RGW to communicate vault with TLS
From ceph v16.2.6 onwards the vault TLS suppport in RGW was added,
include similar changes for RGW.

Signed-off-by: Jiffin Tony Thottan <thottanjiffin@gmail.com>
2021-11-17 10:19:28 +05:30
Sébastien Han d06a6f93a5 core: run operator with rook user
The rook operator as well as the toolbox pod run with the "rook" user
with UID 2016. The UID was chosen based on the year of the initial
commit in the rook/rook repository.
No more root user running.

Closes: https://github.com/rook/rook/issues/8734
Signed-off-by: Sébastien Han <seb@redhat.com>
2021-11-05 17:22:04 +01:00
Sébastien Han 16729e0e38 osd: use multiple service account for vault role
We can pass bound_service_account_names with a comma separated list of
service accounts. Let's do this instead of remapping new values.
Earlier, we thought a single service account could be added per Vault
role and we were using other variables like
`VAULT_AUTH_KUBERNETES_ROOK_OPERATOR_ROLE` that we were remapping to
`VAULT_AUTH_KUBERNETES_ROLE` internal for the API calls to Vault.

Signed-off-by: Sébastien Han <seb@redhat.com>
2021-11-04 15:15:46 +01:00
Sébastien Han 18a4047679 osd: add support for k8s with vault kms
Rook cluster-wide encryption can now use the native Kubernetes
authentication to interact with vault KMS instead of using the token
method.

Signed-off-by: Sébastien Han <seb@redhat.com>
2021-10-21 13:59:28 +02:00
Sébastien Han 4017f94464 osd: use rook binary to fetch key encryption key
When deploying a cluster-wde encrypted cluster we now use the rook
binary to execute some code to fetch the key encryption key.

Using cURL all the time to fetch the key has its limitations. The
incoming integration with Kubernetes Authentication through service
accounts is leading the usage of cURL to its end.
The logic is really complex and prone to errors. Re-implementing the
Go logic into Bash is not a viable option.

Also, using the lib in a binary allows us to keep a consistent behavior
throughout the life cycle of our code.

Signed-off-by: Sébastien Han <seb@redhat.com>
2021-10-19 17:29:25 +02:00
Sébastien Han 61afadd97e ceph: fix kms auto-detection when full TLS
When TLS is used and includes a caert, client key/cert, we need to copy
the content of the secret to a file in the operator's container
filesystem so that we can build the TLS config and thus the HTTP Client,
which reads those files.
Also, removing the files after each API call so they don't persist on
the filesystem forever.

Signed-off-by: Sébastien Han <seb@redhat.com>
2021-10-13 18:12:58 +02:00
Sébastien Han 2e73baf4f5 ceph: do not fail on keys deletion
Prior, we were returning a nil map and thus the assignment for forced
deletion was not working since we were trying to assign on a nil map.

Signed-off-by: Sébastien Han <seb@redhat.com>
2021-09-29 15:59:18 +02:00
Sébastien Han b89730d895 ceph: refactor operator initialization sequence
This commit is a large refactor on how the operator starts, stops and
how it starts various sub-components such as the ceph-csi driver. It
also refines the way we cancel orchestrations. We don't use breakpoints
anymore but send our self a SIGUP to reload our controller runtime
manager.
The reload will happen under different circonstances like:

* a new adminission controller secret is created/deleted/changed
* a CephCluster CR is edited

As mentioned earlier, the csi driver now has its own controller, just
like flex. It reacts to change in the operator config map for particular
ROOK_CSI_ fields.

A second new controller for the operator's general config has been
created, it manages:

* the logging level
* the ceph CLI command timeout
* the discovery daemon

The operator reacts much more rapidly to cancellation events by stopping
the manager's context and reloading it.

Signed-off-by: Sébastien Han <seb@redhat.com>
2021-09-17 16:57:12 +02:00
Sébastien Han d675969567 ceph: fix vault kv secret engine auto-detection
Passing struct by value essentially gives you a copy, so when modified
within a function, the scope is then reduced to that function. Using
pointers solves that you mutate the struct as many times as you want from
anywhere.
As a result, the auto-detection of the Vault KV backend was not working
correctly.
Also, added a ton of unit tests for Vault.

Signed-off-by: Sébastien Han <seb@redhat.com>
2021-08-31 15:29:04 +02:00
Sébastien Han 99e00dea1e ceph: auto detect vault k/v version
Rook will now auto detect the kv version of the vault server. This
allows users not having to pass the VAULT_BACKEND configuration in the
CephCluster CR.

Signed-off-by: Sébastien Han <seb@redhat.com>
2021-07-29 10:16:31 +02:00
Sébastien Han 7e0b58cc27 ceph: destroy all vault keys on kv version 2
By default, keys stored in Vault KV Secret Engine are versioned and keys
are soft-deleted, see Vault documentation:

When deleting data the standard vault kv delete command will perform a soft
delete.
It will mark the version as deleted and populate a deletion_time timestamp.
Soft deletes do not remove the underlying version data from storage,
which allows the version to be undeleted.
The vault kv undelete command handles undeleting versions. A version's
data is permanently deleted only when the key has more versions than are
allowed by the max-versions setting, or when using vault kv destroy.
When the destroy command is used the underlying version data will be
removed and the key metadata will be marked as destroyed.
If a version is cleaned up by going over max-versions the version
metadata will also be removed from the key.

Signed-off-by: Sébastien Han <seb@redhat.com>
2021-07-09 11:03:17 +02:00
Sébastien Han 26c0f8bcc1 ceph: only pass vault volume projection is necessary
We don't need to pass the Volume with projection for TLS when TLS is not enabled
Somehow when this happens and we try to update a deployment spec it fails with:

```
 ValidationError(Pod.spec.volumes[7].projected): missing required field "sources"
```

Signed-off-by: Sébastien Han <seb@redhat.com>
2021-05-31 16:33:40 +02:00
Jiffin Tony Thottan 8e5c6c126c ceph: modify ValidateConnectionDetails() in kms
The ValidateConnectionDetails() contains `clusterSpec` assuming `SecuritySpec` only
part to `cephCluster` CRD. But we may need to validate same for `SecuritySpec` in
`cephObjectStore` CRD. Hence modifying the signature of the api.

Signed-off-by: Jiffin Tony Thottan <thottanjiffin@gmail.com>
2021-04-28 13:03:16 +05:30
Sébastien Han 29c55575b7 ceph: avoid restarting all encrypted osd on cluster growth
When the cluster is growing, the operator always processes all OSDs and
re-generate their Deployment spec. The generated environment variables
for encryption are coming from a map, which by design is unordered. So
once generated the deployment will see their spec change since the
environment variable position will change.

See from the following diff:

```
        env:							        env:
        - name: KMS_SERVICE_NAME			      <
          value: vault					      <
        - name: VAULT_NAMESPACE				      <
          value: ocsns					      <
        - name: VAULT_TLS_SERVER_NAME			      <
        - name: VAULT_BACKEND_PATH			      <
          value: n_ocs					      <
        - name: VAULT_ADDR					        - name: VAULT_ADDR
          value: https://vault.qe.rh-ocs.com:8200		          value: https://vault.qe.rh-ocs.com:8200
							      >	        - name: VAULT_BACKEND_PATH
							      >	          value: n_ocs
							      >	        - name: VAULT_TLS_SERVER_NAME
        - name: KMS_PROVIDER					        - name: KMS_PROVIDER
          value: vault						          value: vault
							      >	        - name: KMS_SERVICE_NAME
							      >	          value: vault
							      >	        - name: VAULT_NAMESPACE
							      >	          value: ocsns
        - name: VAULT_TOKEN					        - name: VAULT_TOKEN
          valueFrom:						          valueFrom:
            secretKeyRef:					            secretKeyRef:
              key: token					              key: token
              name: ocs-kms-token				              name: ocs-kms-token
```

Signed-off-by: Sébastien Han <seb@redhat.com>
2021-03-26 16:16:13 +01:00
Sébastien Han dd275a2906 ceph: set default vault backend path when not specified
If the path was not specified, the OSD init container would crash loop,
failing to reach the vault path.

Signed-off-by: Sébastien Han <seb@redhat.com>
2021-03-22 16:56:41 +01:00
Satoru Takeuchi 26c8fd9bd1 ceph: improve owner reference management
It's better to validate ownerReferences when setting them. In addition, we should use
controllerrutil.Set{Controller,Owner}Reference, that have such validation, as possible.

Signed-off-by: Satoru Takeuchi <satoru.takeuchi@gmail.com>
2021-03-16 10:29:33 +00:00
Sébastien Han e4c3a4cef7 ceph: revert kms VAULT_KV_VERS to VAULT_BACKEND
The vault env variable VAULT_BACKEND is read by the secret library so we
must not change it. This is reverting
ee6a03dfb8 with a few extra fixes for the
rgw code.

Signed-off-by: Sébastien Han <seb@redhat.com>
2021-03-02 10:08:39 +01:00
Sébastien Han 9a604640ac ceph: do not override existing keys
If the cluster was expanded we would iterate over the entire list of
OSDs again, create a new key and override in Vault... The Secret store
is not impacted since we have a handler for "already exist".

Signed-off-by: Sébastien Han <seb@redhat.com>
2021-02-16 19:20:20 +01:00
Jiffin Tony Thottan da61c9a83e ceph: vault kms configuration for ceph object store
The first patch to configure vault for ceph object store. If the `security.kms` configured in
`clusterSpec` CRD, RGW will be configured with vault kms settings to handle SSE request from s3 clients.

Signed-off-by: Jiffin Tony Thottan <thottanjiffin@gmail.com>
2021-01-22 10:44:03 +05:30
Arun Kumar Mohan 65d16bfc94 ceph: manual changes needed for kubernetes api updates
Fetched latest lib-bucket-provisioner changes as well.

Signed-off-by: Arun Kumar Mohan <amohan@redhat.com>
2020-11-18 21:14:01 +05:30
Sébastien Han b7e0e206d3 ceph: rework unit test
Golang maps order is not always guaranteed to be identical, which makes
the table driven test to fail. Because of the nature of the maps, it is
hard to predict the exact position of an element in the map. This
makes the table driven test flappy.
Reworked the unit test using a contains statement which achieves the
same validation.

Closes: https://github.com/rook/rook/issues/6522
Signed-off-by: Sébastien Han <seb@redhat.com>
2020-11-02 12:14:09 +01:00
Sébastien Han ea1d71cbfb ceph: add vault kms support for osd encryption
When the Ceph cluster runs on PVC and the OSDs are encrypted we can
store LUKS's Key Encryption Key inside a Key Management System. Today,
Rook only supports HashiCorp Vault: https://www.vaultproject.io/

The CephCluster has now a new "security" field which will plug onto the
KMS. Here is an example:

security:
  kms:
    tokenSecretName: <name of the secret containing a Vault token, used
    to authenticate>
    connectionDetails: < a map of strings containing connection
    information>

Refer to the ceph-cluster-crd documentation to lear more.

Closes: https://github.com/rook/rook/issues/6105
Signed-off-by: Sébastien Han <seb@redhat.com>
2020-10-30 16:16:33 +01:00