Skip to content

Commit 66a34da

Browse files
objstorage: adjust remote.Locator to support redactability
This patch adjusts `remote.Locator` to support redaction by changing the underlying type from a raw string to a `redact.RedactableString`. This puts the responsibility on the constructor of a `remote.Locator` to insert the necessary markers if redaction is required.
1 parent a3b8dfe commit 66a34da

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

event.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (i DataCorruptionInfo) String() string {
7373
func (i DataCorruptionInfo) SafeFormat(w redact.SafePrinter, _ rune) {
7474
w.Printf("on-disk corruption: %s", redact.Safe(i.Path))
7575
if i.IsRemote {
76-
w.Printf(" (remote locator %q)", redact.Safe(i.Locator))
76+
w.Printf(" (remote locator %q)", i.Locator)
7777
}
7878
w.Printf("; bounds: %s; details: %+v", i.Bounds.String(), i.Details)
7979
}

objstorage/objstorageprovider/remote.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/cockroachdb/pebble/objstorage/objstorageprovider/remoteobjcat"
2020
"github.com/cockroachdb/pebble/objstorage/objstorageprovider/sharedcache"
2121
"github.com/cockroachdb/pebble/objstorage/remote"
22+
"github.com/cockroachdb/redact"
2223
)
2324

2425
// remoteSubsystem contains the provider fields related to remote storage.
@@ -276,7 +277,8 @@ func (p *provider) sharedSync() error {
276277

277278
func (p *provider) remotePath(meta objstorage.ObjectMetadata) string {
278279
if meta.Remote.Locator != "" {
279-
return fmt.Sprintf("remote-%s://%s", meta.Remote.Locator, remoteObjectName(meta))
280+
return fmt.Sprintf("remote-%s://%s",
281+
redact.Sprint(meta.Remote.Locator).Redact(), remoteObjectName(meta))
280282
}
281283
return "remote://" + remoteObjectName(meta)
282284
}

objstorage/remote/storage.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ import (
1313

1414
// Locator is an opaque string identifying a remote.Storage implementation.
1515
//
16-
// The Locator must not contain secrets (like authentication keys). Locators are
17-
// stored on disk in the shared object catalog and are passed around as part of
18-
// RemoteObjectBacking; they can also appear in error messages.
19-
type Locator string
16+
// Locators are stored on disk in the shared object catalog and are passed around as part of
17+
// RemoteObjectBacking. They can also appear in error messages.
18+
// As such, if a Locator contains secrets, the constructor must ensure that the necessary redaction
19+
// is implemented.
20+
type Locator redact.RedactableString
2021

2122
// SafeFormat implements redact.SafeFormatter.
22-
func (l Locator) SafeFormat(w redact.SafePrinter, _ rune) {
23-
w.Printf("%s", redact.SafeString(l))
23+
func (l Locator) SafeFormat(w redact.SafePrinter, r rune) {
24+
redact.RedactableString(l).SafeFormat(w, r)
2425
}
2526

2627
// StorageFactory is used to return Storage implementations based on locators. A

0 commit comments

Comments
 (0)