Add support for restoring SSE-C encrypted objects (#4456)
This commit is contained in:
+16
-7
@@ -57,7 +57,7 @@ var ilmRestoreCmd = cli.Command{
|
||||
Action: mainILMRestore,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(ilmRestoreFlags, globalFlags...),
|
||||
Flags: append(append(ilmRestoreFlags, ioFlags...), globalFlags...),
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
@@ -84,6 +84,9 @@ EXAMPLES:
|
||||
|
||||
4. Restore all objects with all versions under a specific prefix
|
||||
{{.Prompt}} {{.HelpName}} --recursive --versions myminio/mybucket/dir/
|
||||
|
||||
5. Restore an SSE-C encrypted object.
|
||||
{{.Prompt}} {{.HelpName}} --encrypt-key "myminio/mybucket/=MzJieXRlc2xvbmdzZWNyZWFiY2RlZmcJZ2l2ZW5uMjE=" myminio/mybucket/myobject.txt
|
||||
`,
|
||||
}
|
||||
|
||||
@@ -153,14 +156,17 @@ func sendRestoreRequests(ctx context.Context, targetAlias, targetURL, targetVers
|
||||
}
|
||||
|
||||
// Wait until an object which receives restore request is completely restored in the fast tier
|
||||
func waitRestoreObject(ctx context.Context, targetAlias, targetURL, versionID string) *probe.Error {
|
||||
func waitRestoreObject(ctx context.Context, targetAlias, targetURL, versionID string, encKeyDB map[string][]prefixSSEPair) *probe.Error {
|
||||
clnt, err := newClientFromAlias(targetAlias, targetURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for {
|
||||
opts := StatOptions{versionID: versionID}
|
||||
opts := StatOptions{
|
||||
versionID: versionID,
|
||||
sse: getSSE(targetAlias+clnt.GetURL().Path, encKeyDB[targetAlias]),
|
||||
}
|
||||
st, err := clnt.Stat(ctx, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -177,7 +183,7 @@ func waitRestoreObject(ctx context.Context, targetAlias, targetURL, versionID st
|
||||
}
|
||||
|
||||
// Check and wait the restore status of one or more objects one by one.
|
||||
func checkRestoreStatus(ctx context.Context, targetAlias, targetURL, targetVersionID string, recursive, applyOnVersions bool, restoreStatus chan *probe.Error) {
|
||||
func checkRestoreStatus(ctx context.Context, targetAlias, targetURL, targetVersionID string, recursive, applyOnVersions bool, encKeyDB map[string][]prefixSSEPair, restoreStatus chan *probe.Error) {
|
||||
defer close(restoreStatus)
|
||||
|
||||
client, err := newClientFromAlias(targetAlias, targetURL)
|
||||
@@ -187,7 +193,7 @@ func checkRestoreStatus(ctx context.Context, targetAlias, targetURL, targetVersi
|
||||
}
|
||||
|
||||
if !recursive {
|
||||
restoreStatus <- waitRestoreObject(ctx, targetAlias, targetURL, targetVersionID)
|
||||
restoreStatus <- waitRestoreObject(ctx, targetAlias, targetURL, targetVersionID, encKeyDB)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -202,7 +208,7 @@ func checkRestoreStatus(ctx context.Context, targetAlias, targetURL, targetVersi
|
||||
continue
|
||||
}
|
||||
|
||||
err := waitRestoreObject(ctx, targetAlias, content.URL.String(), content.VersionID)
|
||||
err := waitRestoreObject(ctx, targetAlias, content.URL.String(), content.VersionID, encKeyDB)
|
||||
if err != nil {
|
||||
restoreStatus <- err
|
||||
continue
|
||||
@@ -305,6 +311,9 @@ func mainILMRestore(cliCtx *cli.Context) (cErr error) {
|
||||
includeVersions := cliCtx.Bool("versions")
|
||||
days := cliCtx.Int("days")
|
||||
|
||||
encKeyDB, err := getEncKeys(cliCtx)
|
||||
fatalIf(err, "Unable to parse encryption keys.")
|
||||
|
||||
targetAlias, targetURL, _ := mustExpandAlias(aliasedURL)
|
||||
if targetAlias == "" {
|
||||
fatalIf(errDummy().Trace(), "Unable to restore the given URL")
|
||||
@@ -320,7 +329,7 @@ func mainILMRestore(cliCtx *cli.Context) (cErr error) {
|
||||
}()
|
||||
|
||||
sendRestoreRequests(ctx, targetAlias, targetURL, versionID, recursive, includeVersions, days, restoreReqStatus)
|
||||
checkRestoreStatus(ctx, targetAlias, targetURL, versionID, recursive, includeVersions, restoreStatus)
|
||||
checkRestoreStatus(ctx, targetAlias, targetURL, versionID, recursive, includeVersions, encKeyDB, restoreStatus)
|
||||
|
||||
// Wait until the UI printed all the status
|
||||
<-done
|
||||
|
||||
Reference in New Issue
Block a user