2018-03-20 14:54:24 +00:00
|
|
|
/*
|
2019-04-03 08:46:15 +00:00
|
|
|
Copyright 2018 The Ceph-CSI Authors.
|
2018-03-20 14:54:24 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2019-04-22 21:35:39 +00:00
|
|
|
package util
|
2018-03-20 14:54:24 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2019-02-13 12:57:16 +00:00
|
|
|
var cephConfig = []byte(`[global]
|
2018-03-20 14:54:24 +00:00
|
|
|
auth_cluster_required = cephx
|
|
|
|
auth_service_required = cephx
|
|
|
|
auth_client_required = cephx
|
2019-02-13 12:57:16 +00:00
|
|
|
`)
|
2018-03-20 14:54:24 +00:00
|
|
|
|
|
|
|
const (
|
2019-02-14 10:48:52 +00:00
|
|
|
cephConfigRoot = "/etc/ceph"
|
2021-07-08 14:59:34 +00:00
|
|
|
// CephConfigPath ceph configuration file.
|
2019-04-22 21:35:39 +00:00
|
|
|
CephConfigPath = "/etc/ceph/ceph.conf"
|
2019-07-23 04:36:58 +00:00
|
|
|
|
|
|
|
keyRing = "/etc/ceph/keyring"
|
2018-03-20 14:54:24 +00:00
|
|
|
)
|
|
|
|
|
2019-02-13 12:57:16 +00:00
|
|
|
func createCephConfigRoot() error {
|
2021-07-13 12:21:05 +00:00
|
|
|
return os.MkdirAll(cephConfigRoot, 0o755) // #nosec
|
2019-02-13 12:57:16 +00:00
|
|
|
}
|
|
|
|
|
2019-04-22 21:35:39 +00:00
|
|
|
// WriteCephConfig writes out a basic ceph.conf file, making it easy to use
|
2020-07-19 12:21:03 +00:00
|
|
|
// ceph related CLIs.
|
2019-04-22 21:35:39 +00:00
|
|
|
func WriteCephConfig() error {
|
2021-09-01 12:15:33 +00:00
|
|
|
var err error
|
|
|
|
if err = createCephConfigRoot(); err != nil {
|
2019-02-13 12:57:16 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-09-01 12:15:33 +00:00
|
|
|
// create config file if it does not exist to support backward compatibility
|
|
|
|
if _, err = os.Stat(CephConfigPath); os.IsNotExist(err) {
|
2022-01-21 09:28:27 +00:00
|
|
|
err = os.WriteFile(CephConfigPath, cephConfig, 0o600)
|
2021-09-01 12:15:33 +00:00
|
|
|
}
|
|
|
|
|
2019-07-23 04:36:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return createKeyRingFile()
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
if any ceph commands fails it will log below error message
|
|
|
|
|
|
|
|
7f39ff02a700 -1 auth: unable to find a keyring on
|
|
|
|
/etc/ceph/ceph.client.admin.keyring,/etc/ceph/ceph.keyring,/etc/ceph/keyring,
|
|
|
|
/etc/ceph/keyring.bin,: (2) No such file or directory
|
|
|
|
*/
|
2020-07-19 12:21:03 +00:00
|
|
|
// createKeyRingFile creates the keyring files to fix above error message logging.
|
2019-07-23 04:36:58 +00:00
|
|
|
func createKeyRingFile() error {
|
2021-09-01 12:15:33 +00:00
|
|
|
var err error
|
|
|
|
// create keyring file if it does not exist to support backward compatibility
|
|
|
|
if _, err = os.Stat(keyRing); os.IsNotExist(err) {
|
|
|
|
_, err = os.Create(keyRing)
|
|
|
|
}
|
2021-07-22 05:45:17 +00:00
|
|
|
|
2019-07-23 04:36:58 +00:00
|
|
|
return err
|
2018-03-20 14:54:24 +00:00
|
|
|
}
|