ceph: add api to fetch cacert for RGW server
Rook operator sends S3 to RGW server for bucket operations performed by healthchecker, bucketprovisioner etc. Add api to fetch cacert if the TLS enabled for RGW. Signed-off-by: Jiffin Tony Thottan <thottanjiffin@gmail.com>
This commit is contained in:
1 parent
b60c495561
commit
7a5928d2c5
2 files changed
+28
-17
No files matched your search
@@ -17,17 +17,13 @@ limitations under the License.
|
||||
package object
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
|
||||
"github.com/rook/rook/pkg/clusterd"
|
||||
"github.com/rook/rook/pkg/operator/k8sutil"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
)
|
||||
@@ -123,11 +119,9 @@ func (c *bucketChecker) checkObjectStoreHealth() error {
|
||||
|
||||
Always keep the bucket and the user for the health check, just do PUT and GET because bucket creation is expensive
|
||||
*/
|
||||
ctx := context.TODO()
|
||||
var s3AccessKey string
|
||||
var s3SecretKey string
|
||||
var tlsCert []byte
|
||||
var tlsSecretCert *v1.Secret
|
||||
s3endpoint := buildDNSEndpoint(BuildDomainName(c.objContext.Name, c.namespacedName.Namespace), c.port, c.objectStoreSpec.IsTLSEnabled())
|
||||
|
||||
// Generate unique user and bucket name
|
||||
@@ -152,17 +146,9 @@ func (c *bucketChecker) checkObjectStoreHealth() error {
|
||||
s3SecretKey = *user.SecretKey
|
||||
|
||||
if c.objectStoreSpec.IsTLSEnabled() {
|
||||
if c.objectStoreSpec.Gateway.SSLCertificateRef != "" {
|
||||
tlsSecretCert, err = c.context.Clientset.CoreV1().Secrets(c.namespacedName.Namespace).Get(ctx, c.objectStoreSpec.Gateway.SSLCertificateRef, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to get %q secret containing TLS certificate", c.objectStoreSpec.Gateway.SSLCertificateRef)
|
||||
}
|
||||
tlsCert = tlsSecretCert.Data[certKeyName]
|
||||
} else if c.objectStoreSpec.GetServiceServingCert() != "" {
|
||||
tlsCert, err = ioutil.ReadFile(ServiceServingCertCAFile)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to fetch TLS certificate from %q", ServiceServingCertCAFile)
|
||||
}
|
||||
tlsCert, err = GetTlsCaCert(c.objContext, c.objectStoreSpec)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to fetch CA cert for the user %q to establish TLS connection with the object store %q", userConfig.UserID, c.namespacedName.Name)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ package object
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"reflect"
|
||||
"syscall"
|
||||
|
||||
@@ -317,3 +318,27 @@ func buildDNSEndpoint(domainName string, port int32, secure bool) string {
|
||||
}
|
||||
return fmt.Sprintf("%s://%s:%d", httpPrefix, domainName, port)
|
||||
}
|
||||
|
||||
// GetTLSCACert fetch cacert for internal RGW requests
|
||||
func GetTlsCaCert(objContext *Context, objectStoreSpec *cephv1.ObjectStoreSpec) ([]byte, error) {
|
||||
ctx := context.TODO()
|
||||
var (
|
||||
tlsCert []byte
|
||||
err error
|
||||
)
|
||||
|
||||
if objectStoreSpec.Gateway.SSLCertificateRef != "" {
|
||||
tlsSecretCert, err := objContext.Context.Clientset.CoreV1().Secrets(objContext.clusterInfo.Namespace).Get(ctx, objectStoreSpec.Gateway.SSLCertificateRef, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get secret %s containing TLS certificate defined in %s", objectStoreSpec.Gateway.SSLCertificateRef, objContext.Name)
|
||||
}
|
||||
tlsCert = tlsSecretCert.Data[certKeyName]
|
||||
} else if objectStoreSpec.GetServiceServingCert() != "" {
|
||||
tlsCert, err = ioutil.ReadFile(ServiceServingCertCAFile)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to fetch TLS certificate from %q", ServiceServingCertCAFile)
|
||||
}
|
||||
}
|
||||
|
||||
return tlsCert, nil
|
||||
}
|
||||
Reference in new issue
Block a user