Skip to content

Commit f81cd7d

Browse files
committed
serve s3: make errors in --s3-auth-key fatal - fixes rclone#9044
Previously if auth keys were provided without a comma then rclone would only log an INFO message which could mean it went on to serve without any auth. The parsing for environment variables was changed in v1.70.0 to make them work properly with multiple inputs. This means the input is treated like a mini CSV file which works well except in this case when the input has commas. This meant `user,auth` without quotes is treated as two key pairs `user` and `quote`. The correct syntax is `"user,auth"`. This updates the documentation accordingly.
1 parent 1a0a462 commit f81cd7d

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

cmd/serve/s3/serve_s3.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,26 @@ docs](https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html)).
1313
`--auth-key` is not provided then `serve s3` will allow anonymous
1414
access.
1515

16+
Like all rclone flags `--auth-key` can be set via environment
17+
variables, in this case `RCLONE_AUTH_KEY`. Since this flag can be
18+
repeated, the input to `RCLONE_AUTH_KEY` is CSV encoded. Because the
19+
`accessKey,secretKey` has a comma in, this means it needs to be in
20+
quotes.
21+
22+
```console
23+
export RCLONE_AUTH_KEY='"user,pass"'
24+
rclone serve s3 ...
25+
```
26+
27+
Or to supply multiple identities:
28+
29+
```console
30+
export RCLONE_AUTH_KEY='"user1,pass1","user2,pass2"'
31+
rclone serve s3 ...
32+
```
33+
34+
Setting this variable without quotes will produce an error.
35+
1636
Please note that some clients may require HTTPS endpoints. See [the
1737
SSL docs](#tls-ssl) for more information.
1838

cmd/serve/s3/server.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,19 @@ func newServer(ctx context.Context, f fs.Fs, opt *Options, vfsOpt *vfscommon.Opt
7070
w.s3Secret = getAuthSecret(opt.AuthKey)
7171
}
7272

73+
authList, err := authlistResolver(opt.AuthKey)
74+
if err != nil {
75+
return nil, fmt.Errorf("parsing auth list failed: %q", err)
76+
}
77+
7378
var newLogger logger
7479
w.faker = gofakes3.New(
7580
newBackend(w),
7681
gofakes3.WithHostBucket(!opt.ForcePathStyle),
7782
gofakes3.WithLogger(newLogger),
7883
gofakes3.WithRequestID(rand.Uint64()),
7984
gofakes3.WithoutVersioning(),
80-
gofakes3.WithV4Auth(authlistResolver(opt.AuthKey)),
85+
gofakes3.WithV4Auth(authList),
8186
gofakes3.WithIntegrityCheck(true), // Check Content-MD5 if supplied
8287
)
8388

@@ -92,7 +97,7 @@ func newServer(ctx context.Context, f fs.Fs, opt *Options, vfsOpt *vfscommon.Opt
9297
w._vfs = vfs.New(f, vfsOpt)
9398

9499
if len(opt.AuthKey) > 0 {
95-
w.faker.AddAuthKeys(authlistResolver(opt.AuthKey))
100+
w.faker.AddAuthKeys(authList)
96101
}
97102
}
98103

cmd/serve/s3/utils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package s3
33
import (
44
"context"
55
"encoding/hex"
6+
"errors"
67
"io"
78
"os"
89
"path"
@@ -125,15 +126,14 @@ func rmdirRecursive(p string, VFS *vfs.VFS) {
125126
}
126127
}
127128

128-
func authlistResolver(list []string) map[string]string {
129+
func authlistResolver(list []string) (map[string]string, error) {
129130
authList := make(map[string]string)
130131
for _, v := range list {
131132
parts := strings.Split(v, ",")
132133
if len(parts) != 2 {
133-
fs.Infof(nil, "Ignored: invalid auth pair %s", v)
134-
continue
134+
return nil, errors.New("invalid auth pair: expecting a single comma")
135135
}
136136
authList[parts[0]] = parts[1]
137137
}
138-
return authList
138+
return authList, nil
139139
}

0 commit comments

Comments
 (0)