2022-06-02 12:24:31 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2022-08-17 10:22:05 +00:00
|
|
|
"errors"
|
2022-06-02 12:24:31 +00:00
|
|
|
"time"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
internalclient "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/client"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
|
|
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
2023-08-18 14:44:17 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
2022-06-02 12:24:31 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2022-08-17 10:22:05 +00:00
|
|
|
var flagVarsSetEACL struct {
|
2022-09-02 07:57:23 +00:00
|
|
|
noPreCheck bool
|
2022-08-17 10:23:48 +00:00
|
|
|
|
|
|
|
srcPath string
|
2022-08-17 10:22:05 +00:00
|
|
|
}
|
|
|
|
|
2022-06-02 12:24:31 +00:00
|
|
|
var setExtendedACLCmd = &cobra.Command{
|
|
|
|
Use: "set-eacl",
|
|
|
|
Short: "Set new extended ACL table for container",
|
|
|
|
Long: `Set new extended ACL table for container.
|
|
|
|
Container ID in EACL table will be substituted with ID from the CLI.`,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
id := parseContainerID(cmd)
|
2022-08-17 10:23:48 +00:00
|
|
|
eaclTable := common.ReadEACL(cmd, flagVarsSetEACL.srcPath)
|
2022-06-02 12:24:31 +00:00
|
|
|
|
2022-10-20 09:40:33 +00:00
|
|
|
tok := getSession(cmd)
|
2022-06-02 12:24:31 +00:00
|
|
|
|
|
|
|
eaclTable.SetCID(id)
|
|
|
|
|
|
|
|
pk := key.GetOrGenerate(cmd)
|
|
|
|
cli := internalclient.GetSDKClientByFlag(cmd, pk, commonflags.RPC)
|
|
|
|
|
2022-09-02 07:57:23 +00:00
|
|
|
if !flagVarsSetEACL.noPreCheck {
|
2022-08-17 10:22:05 +00:00
|
|
|
cmd.Println("Checking the ability to modify access rights in the container...")
|
|
|
|
|
2023-05-24 13:51:57 +00:00
|
|
|
extendable, err := internalclient.IsACLExtendable(cmd.Context(), cli, id)
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "Extensibility check failure: %w", err)
|
2022-08-17 10:22:05 +00:00
|
|
|
|
|
|
|
if !extendable {
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "", errors.New("container ACL is immutable"))
|
2022-08-17 10:22:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Println("ACL extension is enabled in the container, continue processing.")
|
|
|
|
}
|
|
|
|
|
2023-08-21 16:11:43 +00:00
|
|
|
setEACLPrm := internalclient.SetEACLPrm{
|
|
|
|
Client: cli,
|
|
|
|
ClientParams: client.PrmContainerSetEACL{
|
|
|
|
Table: eaclTable,
|
|
|
|
Session: tok,
|
|
|
|
},
|
2022-06-22 10:55:31 +00:00
|
|
|
}
|
|
|
|
|
2023-05-24 13:51:57 +00:00
|
|
|
_, err := internalclient.SetEACL(cmd.Context(), setEACLPrm)
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
|
2022-06-02 12:24:31 +00:00
|
|
|
|
|
|
|
if containerAwait {
|
|
|
|
exp, err := eaclTable.Marshal()
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "broken EACL table: %w", err)
|
2022-06-02 12:24:31 +00:00
|
|
|
|
|
|
|
cmd.Println("awaiting...")
|
|
|
|
|
2023-08-18 14:44:17 +00:00
|
|
|
getEACLPrm := internalclient.EACLPrm{
|
|
|
|
Client: cli,
|
|
|
|
ClientParams: client.PrmContainerEACL{
|
|
|
|
ContainerID: &id,
|
|
|
|
},
|
|
|
|
}
|
2022-06-02 12:24:31 +00:00
|
|
|
|
|
|
|
for i := 0; i < awaitTimeout; i++ {
|
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
|
2023-05-24 13:51:57 +00:00
|
|
|
res, err := internalclient.EACL(cmd.Context(), getEACLPrm)
|
2022-06-02 12:24:31 +00:00
|
|
|
if err == nil {
|
|
|
|
// compare binary values because EACL could have been set already
|
2022-08-22 11:04:00 +00:00
|
|
|
table := res.EACL()
|
|
|
|
got, err := table.Marshal()
|
2022-06-02 12:24:31 +00:00
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if bytes.Equal(exp, got) {
|
|
|
|
cmd.Println("EACL has been persisted on sidechain")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "", errSetEACLTimeout)
|
2022-06-02 12:24:31 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func initContainerSetEACLCmd() {
|
|
|
|
commonflags.Init(setExtendedACLCmd)
|
|
|
|
|
|
|
|
flags := setExtendedACLCmd.Flags()
|
2022-10-18 11:43:04 +00:00
|
|
|
flags.StringVar(&containerID, commonflags.CIDFlag, "", commonflags.CIDFlagUsage)
|
2022-08-17 10:23:48 +00:00
|
|
|
flags.StringVar(&flagVarsSetEACL.srcPath, "table", "", "path to file with JSON or binary encoded EACL table")
|
2022-06-02 12:24:31 +00:00
|
|
|
flags.BoolVar(&containerAwait, "await", false, "block execution until EACL is persisted")
|
2022-09-02 07:57:23 +00:00
|
|
|
flags.BoolVar(&flagVarsSetEACL.noPreCheck, "no-precheck", false, "do not pre-check the extensibility of the container ACL")
|
2022-06-02 12:24:31 +00:00
|
|
|
}
|