This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 101
Lightning: Changed data-source-dir to use StorageBackend to prevent leaking secret access key to JSON output #1392
Open
kennytm
wants to merge
6
commits into
pingcap:master
Choose a base branch
from
kennytm:secret-source-dir
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2b9132d
storage: remove SkipCheckPath handling from storage itself
kennytm 970ce2a
storage: ensure a consistent '/' handling on windows...
kennytm 23f0675
lightning/restore: added asJSON checker to simplify debugging
kennytm 19ea4e3
lightning/config: introduced SourceDir type to hold parsed data-sourc…
kennytm 2d7feb2
lightning/*: changed the SourceDir field from string to SourceDir
kennytm 7b0758f
lightning: fix unit test
kennytm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2021 PingCAP, Inc. Licensed under Apache-2.0. | ||
|
||
package config | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
"github.com/pingcap/errors" | ||
backuppb "github.com/pingcap/kvproto/pkg/backup" | ||
|
||
"github.com/pingcap/br/pkg/storage" | ||
) | ||
|
||
// SourceDir is the parsed data source directory. It hides the "access-key" and | ||
// "secret-access-key" when dumped as JSON. | ||
type SourceDir struct { | ||
*backuppb.StorageBackend | ||
} | ||
|
||
// String implements fmt.Stringer | ||
func (sd SourceDir) String() string { | ||
// need the intermediate variable to avoid "cannot call pointer method" compiler error. | ||
u := storage.FormatBackendURL(sd.StorageBackend) | ||
return u.String() | ||
} | ||
|
||
func (sd *SourceDir) UnmarshalText(text []byte) error { | ||
var err error | ||
sd.StorageBackend, err = storage.ParseBackend(string(text), nil) | ||
return errors.Trace(err) | ||
} | ||
|
||
func (sd SourceDir) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(sd.String()) | ||
} | ||
|
||
// NewStorage creates a new external storage interface from the storage backend | ||
// URL. It is basically a wrapper around `storage.New()` function. | ||
func (sd SourceDir) NewStorage(ctx context.Context, checkPermissions []storage.Permission) (storage.ExternalStorage, error) { | ||
return storage.New( | ||
ctx, sd.StorageBackend, | ||
&storage.ExternalStorageOptions{CheckPermissions: checkPermissions}, | ||
) | ||
} | ||
|
||
// NewSourceDirFromPath creates a SourceDir from a file path. | ||
// This should only be used in test. | ||
func NewSourceDirFromPath(path string) SourceDir { | ||
return SourceDir{ | ||
StorageBackend: &backuppb.StorageBackend{ | ||
Backend: &backuppb.StorageBackend_Local{Local: &backuppb.Local{Path: path}}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,6 +259,15 @@ func (l *Lightning) run(taskCtx context.Context, taskCfg *config.Config, g glue. | |
} | ||
}() | ||
|
||
storagePermissions := []storage.Permission{storage.ListObjects, storage.GetObject} | ||
if !taskCfg.App.CheckRequirements { | ||
storagePermissions = nil | ||
} | ||
s, err := taskCfg.Mydumper.SourceDir.NewStorage(ctx, storagePermissions) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this replaces the |
||
if err != nil { | ||
return errors.Annotatef(err, "cannot open storage at '%s'", taskCfg.Mydumper.SourceDir) | ||
} | ||
|
||
// initiation of default glue should be after RegisterMySQL, which is ready to be called after taskCfg.Adjust | ||
// and also put it here could avoid injecting another two SkipRunTask failpoint to caller | ||
if g == nil { | ||
|
@@ -269,15 +278,6 @@ func (l *Lightning) run(taskCtx context.Context, taskCfg *config.Config, g glue. | |
g = glue.NewExternalTiDBGlue(db, taskCfg.TiDB.SQLMode) | ||
} | ||
|
||
u, err := storage.ParseBackend(taskCfg.Mydumper.SourceDir, nil) | ||
if err != nil { | ||
return errors.Annotate(err, "parse backend failed") | ||
} | ||
s, err := storage.New(ctx, u, &storage.ExternalStorageOptions{}) | ||
if err != nil { | ||
return errors.Annotate(err, "create storage failed") | ||
} | ||
|
||
loadTask := log.L().Begin(zap.InfoLevel, "load data source") | ||
var mdl *mydump.MDLoader | ||
mdl, err = mydump.NewMyDumpLoaderWithStore(ctx, taskCfg, s) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this check-and-adjust does several things:
common.IsDirExists
it. this is going to be replaced by the ListObjects permission check.storage.ParseBackend
.