2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2019-10-23 01:59:13 -04:00
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2021-11-10 13:01:32 -05:00
|
|
|
"context"
|
2019-10-23 01:59:13 -04:00
|
|
|
"encoding/json"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
2019-11-05 09:18:26 -05:00
|
|
|
"strconv"
|
2019-12-04 18:32:37 -05:00
|
|
|
"strings"
|
2019-10-23 01:59:13 -04:00
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
2021-05-06 11:52:02 -04:00
|
|
|
"github.com/minio/madmin-go"
|
2021-06-01 17:59:40 -04:00
|
|
|
"github.com/minio/minio/internal/config"
|
|
|
|
"github.com/minio/minio/internal/config/cache"
|
|
|
|
"github.com/minio/minio/internal/config/etcd"
|
|
|
|
xldap "github.com/minio/minio/internal/config/identity/ldap"
|
|
|
|
"github.com/minio/minio/internal/config/identity/openid"
|
|
|
|
"github.com/minio/minio/internal/config/policy/opa"
|
|
|
|
"github.com/minio/minio/internal/config/storageclass"
|
|
|
|
"github.com/minio/minio/internal/logger"
|
2021-05-30 00:16:42 -04:00
|
|
|
iampolicy "github.com/minio/pkg/iam/policy"
|
2019-10-23 01:59:13 -04:00
|
|
|
)
|
|
|
|
|
2020-04-07 22:30:59 -04:00
|
|
|
// DelConfigKVHandler - DELETE /minio/admin/v3/del-config-kv
|
2019-10-23 01:59:13 -04:00
|
|
|
func (a adminAPIHandlers) DelConfigKVHandler(w http.ResponseWriter, r *http.Request) {
|
2020-05-11 13:34:08 -04:00
|
|
|
ctx := newContext(r, w, "DeleteConfigKV")
|
|
|
|
|
2021-01-26 16:21:51 -05:00
|
|
|
defer logger.AuditLog(ctx, w, r, mustGetClaimsFromToken(r))
|
2019-10-23 01:59:13 -04:00
|
|
|
|
2021-08-09 21:14:38 -04:00
|
|
|
objectAPI, cred := validateAdminReq(ctx, w, r, iampolicy.ConfigUpdateAdminAction)
|
2019-10-23 01:59:13 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if r.ContentLength > maxEConfigJSONSize || r.ContentLength == -1 {
|
|
|
|
// More than maxConfigSize bytes were available
|
|
|
|
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrAdminConfigTooLarge), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-25 01:36:48 -04:00
|
|
|
password := cred.SecretKey
|
2019-10-23 01:59:13 -04:00
|
|
|
kvBytes, err := madmin.DecryptData(password, io.LimitReader(r.Body, r.ContentLength))
|
|
|
|
if err != nil {
|
|
|
|
logger.LogIf(ctx, err, logger.Application)
|
|
|
|
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrAdminConfigBadJSON), r.URL)
|
|
|
|
return
|
|
|
|
}
|
2019-11-27 12:36:08 -05:00
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
cfg, err := readServerConfig(ctx, objectAPI)
|
|
|
|
if err != nil {
|
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-27 12:36:08 -05:00
|
|
|
if err = cfg.DelFrom(bytes.NewReader(kvBytes)); err != nil {
|
2019-10-23 01:59:13 -04:00
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-21 07:24:51 -05:00
|
|
|
if err = saveServerConfig(ctx, objectAPI, cfg); err != nil {
|
2019-10-23 01:59:13 -04:00
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
2021-11-10 13:01:32 -05:00
|
|
|
|
|
|
|
dynamic := config.SubSystemsDynamic.Contains(string(kvBytes))
|
|
|
|
if dynamic {
|
|
|
|
applyDynamic(ctx, objectAPI, cfg, r, w)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func applyDynamic(ctx context.Context, objectAPI ObjectLayer, cfg config.Config, r *http.Request, w http.ResponseWriter) {
|
|
|
|
// Apply dynamic values.
|
|
|
|
if err := applyDynamicConfig(GlobalContext, objectAPI, cfg); err != nil {
|
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
globalNotificationSys.SignalService(serviceReloadDynamic)
|
|
|
|
// Tell the client that dynamic config was applied.
|
|
|
|
w.Header().Set(madmin.ConfigAppliedHeader, madmin.ConfigAppliedTrue)
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:30:59 -04:00
|
|
|
// SetConfigKVHandler - PUT /minio/admin/v3/set-config-kv
|
2019-10-23 01:59:13 -04:00
|
|
|
func (a adminAPIHandlers) SetConfigKVHandler(w http.ResponseWriter, r *http.Request) {
|
2020-05-11 13:34:08 -04:00
|
|
|
ctx := newContext(r, w, "SetConfigKV")
|
|
|
|
|
2021-01-26 16:21:51 -05:00
|
|
|
defer logger.AuditLog(ctx, w, r, mustGetClaimsFromToken(r))
|
2019-10-23 01:59:13 -04:00
|
|
|
|
2021-08-09 21:14:38 -04:00
|
|
|
objectAPI, cred := validateAdminReq(ctx, w, r, iampolicy.ConfigUpdateAdminAction)
|
2019-10-23 01:59:13 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if r.ContentLength > maxEConfigJSONSize || r.ContentLength == -1 {
|
|
|
|
// More than maxConfigSize bytes were available
|
|
|
|
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrAdminConfigTooLarge), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-25 01:36:48 -04:00
|
|
|
password := cred.SecretKey
|
2019-10-23 01:59:13 -04:00
|
|
|
kvBytes, err := madmin.DecryptData(password, io.LimitReader(r.Body, r.ContentLength))
|
|
|
|
if err != nil {
|
|
|
|
logger.LogIf(ctx, err, logger.Application)
|
|
|
|
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrAdminConfigBadJSON), r.URL)
|
|
|
|
return
|
|
|
|
}
|
2019-11-27 12:36:08 -05:00
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
cfg, err := readServerConfig(ctx, objectAPI)
|
|
|
|
if err != nil {
|
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
2021-01-22 15:09:24 -05:00
|
|
|
|
2020-12-04 12:32:35 -05:00
|
|
|
dynamic, err := cfg.ReadConfig(bytes.NewReader(kvBytes))
|
|
|
|
if err != nil {
|
2019-11-27 19:13:07 -05:00
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-09-01 14:34:07 -04:00
|
|
|
if err = validateConfig(cfg); err != nil {
|
2019-10-23 01:59:13 -04:00
|
|
|
writeCustomErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrAdminConfigBadJSON), err.Error(), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the actual server config on disk.
|
2019-11-21 07:24:51 -05:00
|
|
|
if err = saveServerConfig(ctx, objectAPI, cfg); err != nil {
|
2019-10-23 01:59:13 -04:00
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write to the config input KV to history.
|
|
|
|
if err = saveServerConfigHistory(ctx, objectAPI, kvBytes); err != nil {
|
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
2019-11-09 12:27:23 -05:00
|
|
|
|
2020-12-04 12:32:35 -05:00
|
|
|
if dynamic {
|
2021-11-10 13:01:32 -05:00
|
|
|
applyDynamic(ctx, objectAPI, cfg, r, w)
|
2020-12-04 12:32:35 -05:00
|
|
|
}
|
2019-11-26 13:08:25 -05:00
|
|
|
writeSuccessResponseHeadersOnly(w)
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:30:59 -04:00
|
|
|
// GetConfigKVHandler - GET /minio/admin/v3/get-config-kv?key={key}
|
2019-10-23 01:59:13 -04:00
|
|
|
func (a adminAPIHandlers) GetConfigKVHandler(w http.ResponseWriter, r *http.Request) {
|
2020-05-11 13:34:08 -04:00
|
|
|
ctx := newContext(r, w, "GetConfigKV")
|
|
|
|
|
2021-01-26 16:21:51 -05:00
|
|
|
defer logger.AuditLog(ctx, w, r, mustGetClaimsFromToken(r))
|
2019-10-23 01:59:13 -04:00
|
|
|
|
2021-08-09 21:14:38 -04:00
|
|
|
objectAPI, cred := validateAdminReq(ctx, w, r, iampolicy.ConfigUpdateAdminAction)
|
2019-10-23 01:59:13 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-06-24 19:24:12 -04:00
|
|
|
cfg := globalServerConfig.Clone()
|
2019-10-23 01:59:13 -04:00
|
|
|
vars := mux.Vars(r)
|
2019-10-30 03:04:39 -04:00
|
|
|
var buf = &bytes.Buffer{}
|
2019-11-27 12:36:08 -05:00
|
|
|
cw := config.NewConfigWriteTo(cfg, vars["key"])
|
|
|
|
if _, err := cw.WriteTo(buf); err != nil {
|
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
2019-10-30 03:04:39 -04:00
|
|
|
|
2020-04-25 01:36:48 -04:00
|
|
|
password := cred.SecretKey
|
2019-10-30 03:04:39 -04:00
|
|
|
econfigData, err := madmin.EncryptData(password, buf.Bytes())
|
2019-10-23 01:59:13 -04:00
|
|
|
if err != nil {
|
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
writeSuccessResponseJSON(w, econfigData)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a adminAPIHandlers) ClearConfigHistoryKVHandler(w http.ResponseWriter, r *http.Request) {
|
2020-05-11 13:34:08 -04:00
|
|
|
ctx := newContext(r, w, "ClearConfigHistoryKV")
|
|
|
|
|
2021-01-26 16:21:51 -05:00
|
|
|
defer logger.AuditLog(ctx, w, r, mustGetClaimsFromToken(r))
|
2019-10-23 01:59:13 -04:00
|
|
|
|
2021-08-09 21:14:38 -04:00
|
|
|
objectAPI, _ := validateAdminReq(ctx, w, r, iampolicy.ConfigUpdateAdminAction)
|
2019-10-23 01:59:13 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
vars := mux.Vars(r)
|
|
|
|
restoreID := vars["restoreId"]
|
|
|
|
if restoreID == "" {
|
|
|
|
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrInvalidRequest), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if restoreID == "all" {
|
2019-11-05 09:18:26 -05:00
|
|
|
chEntries, err := listServerConfigHistory(ctx, objectAPI, false, -1)
|
2019-10-23 01:59:13 -04:00
|
|
|
if err != nil {
|
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, chEntry := range chEntries {
|
|
|
|
if err = delServerConfigHistory(ctx, objectAPI, chEntry.RestoreID); err != nil {
|
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := delServerConfigHistory(ctx, objectAPI, restoreID); err != nil {
|
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RestoreConfigHistoryKVHandler - restores a config with KV settings for the given KV id.
|
|
|
|
func (a adminAPIHandlers) RestoreConfigHistoryKVHandler(w http.ResponseWriter, r *http.Request) {
|
2020-05-11 13:34:08 -04:00
|
|
|
ctx := newContext(r, w, "RestoreConfigHistoryKV")
|
|
|
|
|
2021-01-26 16:21:51 -05:00
|
|
|
defer logger.AuditLog(ctx, w, r, mustGetClaimsFromToken(r))
|
2019-10-23 01:59:13 -04:00
|
|
|
|
2021-08-09 21:14:38 -04:00
|
|
|
objectAPI, _ := validateAdminReq(ctx, w, r, iampolicy.ConfigUpdateAdminAction)
|
2019-10-23 01:59:13 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
vars := mux.Vars(r)
|
|
|
|
restoreID := vars["restoreId"]
|
|
|
|
if restoreID == "" {
|
|
|
|
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrInvalidRequest), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
kvBytes, err := readServerConfigHistory(ctx, objectAPI, restoreID)
|
|
|
|
if err != nil {
|
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg, err := readServerConfig(ctx, objectAPI)
|
|
|
|
if err != nil {
|
2019-11-27 12:36:08 -05:00
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
|
|
|
|
2020-12-04 12:32:35 -05:00
|
|
|
if _, err = cfg.ReadConfig(bytes.NewReader(kvBytes)); err != nil {
|
2019-10-23 01:59:13 -04:00
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-09-01 14:34:07 -04:00
|
|
|
if err = validateConfig(cfg); err != nil {
|
2019-10-23 01:59:13 -04:00
|
|
|
writeCustomErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrAdminConfigBadJSON), err.Error(), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-21 07:24:51 -05:00
|
|
|
if err = saveServerConfig(ctx, objectAPI, cfg); err != nil {
|
2019-10-23 01:59:13 -04:00
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
delServerConfigHistory(ctx, objectAPI, restoreID)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ListConfigHistoryKVHandler - lists all the KV ids.
|
|
|
|
func (a adminAPIHandlers) ListConfigHistoryKVHandler(w http.ResponseWriter, r *http.Request) {
|
2020-05-11 13:34:08 -04:00
|
|
|
ctx := newContext(r, w, "ListConfigHistoryKV")
|
|
|
|
|
2021-01-26 16:21:51 -05:00
|
|
|
defer logger.AuditLog(ctx, w, r, mustGetClaimsFromToken(r))
|
2019-10-23 01:59:13 -04:00
|
|
|
|
2021-08-09 21:14:38 -04:00
|
|
|
objectAPI, cred := validateAdminReq(ctx, w, r, iampolicy.ConfigUpdateAdminAction)
|
2019-10-23 01:59:13 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-05 09:18:26 -05:00
|
|
|
vars := mux.Vars(r)
|
|
|
|
count, err := strconv.Atoi(vars["count"])
|
|
|
|
if err != nil {
|
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
chEntries, err := listServerConfigHistory(ctx, objectAPI, true, count)
|
2019-10-23 01:59:13 -04:00
|
|
|
if err != nil {
|
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := json.Marshal(chEntries)
|
|
|
|
if err != nil {
|
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-25 01:36:48 -04:00
|
|
|
password := cred.SecretKey
|
2019-11-05 09:18:26 -05:00
|
|
|
econfigData, err := madmin.EncryptData(password, data)
|
|
|
|
if err != nil {
|
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
writeSuccessResponseJSON(w, econfigData)
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:30:59 -04:00
|
|
|
// HelpConfigKVHandler - GET /minio/admin/v3/help-config-kv?subSys={subSys}&key={key}
|
2019-10-23 01:59:13 -04:00
|
|
|
func (a adminAPIHandlers) HelpConfigKVHandler(w http.ResponseWriter, r *http.Request) {
|
2020-05-11 13:34:08 -04:00
|
|
|
ctx := newContext(r, w, "HelpConfigKV")
|
|
|
|
|
2021-01-26 16:21:51 -05:00
|
|
|
defer logger.AuditLog(ctx, w, r, mustGetClaimsFromToken(r))
|
2019-10-23 01:59:13 -04:00
|
|
|
|
2021-08-09 21:14:38 -04:00
|
|
|
objectAPI, _ := validateAdminReq(ctx, w, r, iampolicy.ConfigUpdateAdminAction)
|
2019-10-23 01:59:13 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
vars := mux.Vars(r)
|
2019-10-30 03:04:39 -04:00
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
subSys := vars["subSys"]
|
|
|
|
key := vars["key"]
|
|
|
|
|
2021-08-08 01:43:01 -04:00
|
|
|
_, envOnly := r.Form["env"]
|
2019-10-30 03:04:39 -04:00
|
|
|
|
|
|
|
rd, err := GetHelp(subSys, key, envOnly)
|
2019-10-23 01:59:13 -04:00
|
|
|
if err != nil {
|
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-10-30 03:04:39 -04:00
|
|
|
json.NewEncoder(w).Encode(rd)
|
2019-10-23 01:59:13 -04:00
|
|
|
}
|
|
|
|
|
2020-04-07 22:30:59 -04:00
|
|
|
// SetConfigHandler - PUT /minio/admin/v3/config
|
2019-10-23 01:59:13 -04:00
|
|
|
func (a adminAPIHandlers) SetConfigHandler(w http.ResponseWriter, r *http.Request) {
|
2020-05-11 13:34:08 -04:00
|
|
|
ctx := newContext(r, w, "SetConfig")
|
|
|
|
|
2021-01-26 16:21:51 -05:00
|
|
|
defer logger.AuditLog(ctx, w, r, mustGetClaimsFromToken(r))
|
2019-10-23 01:59:13 -04:00
|
|
|
|
2021-08-09 21:14:38 -04:00
|
|
|
objectAPI, cred := validateAdminReq(ctx, w, r, iampolicy.ConfigUpdateAdminAction)
|
2019-10-23 01:59:13 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if r.ContentLength > maxEConfigJSONSize || r.ContentLength == -1 {
|
|
|
|
// More than maxConfigSize bytes were available
|
|
|
|
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrAdminConfigTooLarge), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-25 01:36:48 -04:00
|
|
|
password := cred.SecretKey
|
2019-11-26 13:08:25 -05:00
|
|
|
kvBytes, err := madmin.DecryptData(password, io.LimitReader(r.Body, r.ContentLength))
|
2019-10-23 01:59:13 -04:00
|
|
|
if err != nil {
|
|
|
|
logger.LogIf(ctx, err, logger.Application)
|
|
|
|
writeErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrAdminConfigBadJSON), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-26 13:08:25 -05:00
|
|
|
cfg := newServerConfig()
|
2020-12-04 12:32:35 -05:00
|
|
|
if _, err = cfg.ReadConfig(bytes.NewReader(kvBytes)); err != nil {
|
2019-11-26 13:08:25 -05:00
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
2019-10-23 01:59:13 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-09-01 14:34:07 -04:00
|
|
|
if err = validateConfig(cfg); err != nil {
|
2019-10-23 01:59:13 -04:00
|
|
|
writeCustomErrorResponseJSON(ctx, w, errorCodes.ToAPIErr(ErrAdminConfigBadJSON), err.Error(), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-26 13:08:25 -05:00
|
|
|
// Update the actual server config on disk.
|
2019-11-21 07:24:51 -05:00
|
|
|
if err = saveServerConfig(ctx, objectAPI, cfg); err != nil {
|
2019-10-23 01:59:13 -04:00
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-26 13:08:25 -05:00
|
|
|
// Write to the config input KV to history.
|
|
|
|
if err = saveServerConfigHistory(ctx, objectAPI, kvBytes); err != nil {
|
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
writeSuccessResponseHeadersOnly(w)
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:30:59 -04:00
|
|
|
// GetConfigHandler - GET /minio/admin/v3/config
|
2019-10-23 01:59:13 -04:00
|
|
|
// Get config.json of this minio setup.
|
|
|
|
func (a adminAPIHandlers) GetConfigHandler(w http.ResponseWriter, r *http.Request) {
|
2020-05-11 13:34:08 -04:00
|
|
|
ctx := newContext(r, w, "GetConfig")
|
|
|
|
|
2021-01-26 16:21:51 -05:00
|
|
|
defer logger.AuditLog(ctx, w, r, mustGetClaimsFromToken(r))
|
2019-10-23 01:59:13 -04:00
|
|
|
|
2021-08-09 21:14:38 -04:00
|
|
|
objectAPI, cred := validateAdminReq(ctx, w, r, iampolicy.ConfigUpdateAdminAction)
|
2019-10-23 01:59:13 -04:00
|
|
|
if objectAPI == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-06-24 19:24:12 -04:00
|
|
|
cfg := globalServerConfig.Clone()
|
2019-10-23 01:59:13 -04:00
|
|
|
|
2019-12-04 18:32:37 -05:00
|
|
|
var s strings.Builder
|
|
|
|
hkvs := config.HelpSubSysMap[""]
|
2019-12-20 17:47:14 -05:00
|
|
|
var count int
|
|
|
|
for _, hkv := range hkvs {
|
|
|
|
count += len(cfg[hkv.Key])
|
|
|
|
}
|
2019-12-04 18:32:37 -05:00
|
|
|
for _, hkv := range hkvs {
|
|
|
|
v := cfg[hkv.Key]
|
|
|
|
for target, kv := range v {
|
|
|
|
off := kv.Get(config.Enable) == config.EnableOff
|
|
|
|
switch hkv.Key {
|
|
|
|
case config.EtcdSubSys:
|
|
|
|
off = !etcd.Enabled(kv)
|
|
|
|
case config.CacheSubSys:
|
|
|
|
off = !cache.Enabled(kv)
|
|
|
|
case config.StorageClassSubSys:
|
|
|
|
off = !storageclass.Enabled(kv)
|
|
|
|
case config.PolicyOPASubSys:
|
|
|
|
off = !opa.Enabled(kv)
|
|
|
|
case config.IdentityOpenIDSubSys:
|
|
|
|
off = !openid.Enabled(kv)
|
|
|
|
case config.IdentityLDAPSubSys:
|
|
|
|
off = !xldap.Enabled(kv)
|
2021-09-07 22:03:48 -04:00
|
|
|
case config.IdentityTLSSubSys:
|
|
|
|
off = !globalSTSTLSConfig.Enabled
|
2019-12-04 18:32:37 -05:00
|
|
|
}
|
|
|
|
if off {
|
|
|
|
s.WriteString(config.KvComment)
|
|
|
|
s.WriteString(config.KvSpaceSeparator)
|
|
|
|
}
|
|
|
|
s.WriteString(hkv.Key)
|
|
|
|
if target != config.Default {
|
|
|
|
s.WriteString(config.SubSystemSeparator)
|
|
|
|
s.WriteString(target)
|
|
|
|
}
|
|
|
|
s.WriteString(config.KvSpaceSeparator)
|
|
|
|
s.WriteString(kv.String())
|
2019-12-20 17:47:14 -05:00
|
|
|
count--
|
|
|
|
if count > 0 {
|
|
|
|
s.WriteString(config.KvNewline)
|
|
|
|
}
|
2019-12-04 18:32:37 -05:00
|
|
|
}
|
2019-11-27 12:36:08 -05:00
|
|
|
}
|
2019-10-23 01:59:13 -04:00
|
|
|
|
2020-04-25 01:36:48 -04:00
|
|
|
password := cred.SecretKey
|
2019-12-04 18:32:37 -05:00
|
|
|
econfigData, err := madmin.EncryptData(password, []byte(s.String()))
|
2019-10-23 01:59:13 -04:00
|
|
|
if err != nil {
|
|
|
|
writeErrorResponseJSON(ctx, w, toAdminAPIErr(ctx, err), r.URL)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
writeSuccessResponseJSON(w, econfigData)
|
|
|
|
}
|