Files
my-rook-config/pkg/operator/ceph/object/config.go
T

144 lines
4.3 KiB
Go
Raw Normal View History

2019-02-14 09:16:21 -07:00
/*
Copyright 2019 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package object
import (
"fmt"
"path"
"strconv"
2019-06-13 13:00:22 +02:00
"strings"
2019-02-14 09:16:21 -07:00
cephconfig "github.com/rook/rook/pkg/operator/ceph/config"
"github.com/rook/rook/pkg/operator/ceph/config/keyring"
2019-06-07 23:06:31 +02:00
cephver "github.com/rook/rook/pkg/operator/ceph/version"
2019-02-14 09:16:21 -07:00
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
keyringTemplate = `
2019-06-13 13:00:22 +02:00
[%s]
2019-02-14 09:16:21 -07:00
key = %s
caps mon = "allow rw"
caps osd = "allow rwx"
`
certVolumeName = "rook-ceph-rgw-cert"
certDir = "/etc/ceph/private"
certKeyName = "cert"
certFilename = "rgw-cert.pem"
)
2019-06-07 23:06:31 +02:00
var (
rgwFrontendName = "civetweb"
)
func rgwFrontend(v cephver.CephVersion) string {
if v.IsAtLeastNautilus() {
rgwFrontendName = "beast"
}
return rgwFrontendName
}
2019-07-08 15:48:45 +02:00
func (c *clusterConfig) portString(v cephver.CephVersion) string {
2019-02-14 09:16:21 -07:00
var portString string
2019-07-08 15:48:45 +02:00
2019-02-14 09:16:21 -07:00
port := c.store.Spec.Gateway.Port
if port != 0 {
2019-07-08 15:48:45 +02:00
portString = fmt.Sprintf("port=%s", strconv.Itoa(int(port)))
2019-02-14 09:16:21 -07:00
}
if c.store.Spec.Gateway.SecurePort != 0 && c.store.Spec.Gateway.SSLCertificateRef != "" {
certPath := path.Join(certDir, certFilename)
2019-07-08 15:48:45 +02:00
// This is the beast backend
// Config is: http://docs.ceph.com/docs/master/radosgw/frontends/#id3
if v.IsAtLeastNautilus() {
if port != 0 {
portString = fmt.Sprintf("%s ssl_port=%d ssl_certificate=%s",
portString, c.store.Spec.Gateway.SecurePort, certPath)
} else {
portString = fmt.Sprintf("ssl_port=%d ssl_certificate=%s",
c.store.Spec.Gateway.SecurePort, certPath)
}
} else {
// This is civetweb config
// Config is http://docs.ceph.com/docs/master/radosgw/frontends/#id5
var separator string
if port != 0 {
separator = "+"
} else {
// This means there is only one port and it's a secured one
portString = "port="
}
// with ssl enabled, the port number must end with the letter s.
// e.g., "443s ssl_certificate=/etc/ceph/private/keyandcert.pem"
portString = fmt.Sprintf("%s%s%ds ssl_certificate=%s",
portString, separator, c.store.Spec.Gateway.SecurePort, certPath)
}
2019-02-14 09:16:21 -07:00
}
return portString
}
2019-06-13 13:00:22 +02:00
func generateCephXUser(name string) string {
user := strings.TrimPrefix(name, AppName)
return "client" + strings.Replace(user, "-", ".", -1)
}
func (c *clusterConfig) generateKeyring(rgwConfig *rgwConfig) (string, error) {
user := generateCephXUser(rgwConfig.ResourceName)
2019-02-14 09:16:21 -07:00
/* TODO: this says `osd allow rwx` while template says `osd allow *`; which is correct? */
access := []string{"osd", "allow rwx", "mon", "allow rw"}
s := keyring.GetSecretStore(c.context, c.store.Namespace, &c.ownerRef)
2019-02-14 09:16:21 -07:00
2019-06-13 13:00:22 +02:00
key, err := s.GenerateKey(user, access)
2019-02-14 09:16:21 -07:00
if err != nil {
return "", err
2019-02-14 09:16:21 -07:00
}
2019-06-13 13:00:22 +02:00
keyring := fmt.Sprintf(keyringTemplate, user, key)
return keyring, s.CreateOrUpdate(rgwConfig.ResourceName, keyring)
}
func (c *clusterConfig) associateKeyring(existingKeyring string, ownerRef *metav1.OwnerReference) error {
resourceName := ownerRef.Name
s := keyring.GetSecretStore(c.context, c.store.Namespace, ownerRef)
return s.CreateOrUpdate(resourceName, existingKeyring)
2019-02-14 09:16:21 -07:00
}
2019-11-15 21:56:25 +01:00
func (c *clusterConfig) setDefaultFlagsMonConfigStore(rgwName string) error {
monStore := cephconfig.GetMonStore(c.context, c.store.Namespace)
who := generateCephXUser(rgwName)
configOptions := make(map[string]string)
configOptions["rgw_log_nonexistent_bucket"] = "true"
configOptions["rgw_log_object_name_utc"] = "true"
configOptions["rgw_enable_usage_log"] = "true"
configOptions["rgw_frontends"] = fmt.Sprintf("%s %s", rgwFrontend(c.clusterInfo.CephVersion), c.portString(c.clusterInfo.CephVersion))
configOptions["rgw_zone"] = c.store.Name
configOptions["rgw_zonegroup"] = c.store.Name
for flag, val := range configOptions {
err := monStore.Set(who, flag, val)
if err != nil {
return fmt.Errorf("failed to set %q to %q on %q. %+v", flag, val, who, err)
}
}
return nil
}