Documentation
¶
Overview ¶
Package proxy implements a programmable proxy for rclone serve
Index ¶
- Variables
- type Options
- type Provider
- type Proxy
- func (p *Proxy) Call(user, auth string, isPublicKey bool, remoteAddr string) (VFS *vfs.VFS, vfsKey string, err error)
- func (p *Proxy) CallAccessKey(accessKeyID, remoteAddr string, refresh bool) (VFS *vfs.VFS, secret string, err error)
- func (p *Proxy) Get(key string) *vfs.VFS
- func (p *Proxy) Pin(key string)
- func (p *Proxy) Shutdown()
- func (p *Proxy) Unpin(key string)
Constants ¶
This section is empty.
Variables ¶
var Help = strings.ReplaceAll(`### Auth Proxy
If you supply the parameter |--auth-proxy /path/to/program| then
rclone will use that program to generate backends on the fly which
then are used to authenticate incoming requests. This uses a simple
JSON based protocol with input on STDIN and output on STDOUT.
**PLEASE NOTE:** |--auth-proxy| and |--authorized-keys| cannot be used
together, if |--auth-proxy| is set the authorized keys option will be
ignored.
There is an example program
[bin/test_proxy.py](https://github.com/rclone/rclone/blob/master/bin/test_proxy.py)
in the rclone source code.
The program's job is to take a |user| and |pass| on the input and turn
those into the config for a backend on STDOUT in JSON format. This
config will have any default parameters for the backend added, but it
won't use configuration from environment variables or command line
options - it is the job of the proxy program to make a complete
config.
This config generated must have this extra parameter
- |_root| - root to use for the backend
And it may have these parameters
- |_obscure| - comma separated strings for parameters to obscure
- |_secret_access_key| - the secret for S3 access key auth (see below)
If password authentication was used by the client, input to the proxy
process (on STDIN) would look similar to this:
|||json
{
"user": "me",
"pass": "mypassword",
"client_ip": "192.168.1.1"
}
|||
If public-key authentication was used by the client, input to the
proxy process (on STDIN) would look similar to this:
|||json
{
"user": "me",
"public_key": "AAAAB3NzaC1yc2EAAAADAQABAAABAQDuwESFdAe14hVS6omeyX7edc...JQdf",
"client_ip": "192.168.1.1"
}
|||
If the client authenticated with an S3 access key (|rclone serve s3|),
the client never sends its secret, only a signature made with it, so
the input contains just the access key ID as the |user| with no |pass|
or |public_key|:
|||json
{
"user": "AKIAIOSFODNN7EXAMPLE",
"client_ip": "192.168.1.1"
}
|||
In this case the program must look up the secret access key for that
access key ID and return it in the |_secret_access_key| field of the
output. Rclone then uses that secret to verify the signature on the
request, refusing the request if it does not match. This means the
proxy program is the source of truth for both the credentials and the
backend they map to. If the program does not return
|_secret_access_key| or returns it empty the request is refused.
The program's answer for an access key ID is cached (see below) but
is checked with the program again after 5 minutes even if the access
key ID is in constant use, so revoking an access key ID in the
program takes effect within 5 minutes. A rotated secret takes effect
on the first request signed with it.
The |client_ip| key holds the IP address the client connected from,
without a port number. It can be used to restrict logins to certain
networks, or to log authentication attempts centrally. It is omitted if
the client has no IP address, for example when connecting over a unix
socket. Note that if rclone is behind a reverse proxy this will be the
address of the reverse proxy and not the original client.
And as an example return this on STDOUT
|||json
{
"type": "sftp",
"_root": "",
"_obscure": "pass",
"user": "me",
"pass": "mypassword",
"host": "sftp.example.com"
}
|||
This would mean that an SFTP backend would be created on the fly for
the |user| and |pass|/|public_key| returned in the output to the host given. Note
that since |_obscure| is set to |pass|, rclone will obscure the |pass|
parameter before creating the backend (which is required for sftp
backends).
The program can manipulate the supplied |user| in any way, for example
to make proxy to many different sftp backends, you could make the
|user| be |user@example.com| and then set the |host| to |example.com|
in the output and the user to |user|. For security you'd probably want
to restrict the |host| to a limited list.
An internal cache of backends is keyed on the |user|, a hash of the
|pass| or |public_key|, and the |client_ip|. This means that if a
user's password or public-key changes, the client connects from a new IP
address, or the proxy returns different config parameters (eg a rotated
|api_key|), a fresh backend will be created on the next request rather
than the cached one being reused.
This can be used to build general purpose proxies to any kind of
backend that rclone supports.
`, "|", "`")
Help contains text describing how to use the proxy
var OptionsInfo = fs.Options{{ Name: "auth_proxy", Default: "", Help: "A program to use to create the backend from the auth", }}
OptionsInfo descripts the Options in use
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
AuthProxy string `config:"auth_proxy"`
}
Options is options for creating the proxy
var Opt Options
Opt is the default options
type Provider ¶ added in v1.75.1
type Provider struct {
// contains filtered or unexported fields
}
Provider hands out VFS instances, either a fixed one or per-user via an auth proxy.
func NewProvider ¶ added in v1.75.1
func NewProvider(ctx context.Context, f fs.Fs, vfsOpt *vfscommon.Options, proxyOpt *Options) *Provider
NewProvider creates a Provider. If proxyOpt.AuthProxy is set it creates an auth proxy; otherwise it creates a fixed VFS from f and vfsOpt.
func (*Provider) Get ¶ added in v1.75.1
Get returns the VFS for the current request context. For fixed-VFS providers it returns the single VFS. For proxy providers it reads the VFS from the request's auth context.
func (*Provider) Proxy ¶ added in v1.75.1
Proxy returns the Proxy instance, or nil if not using an auth proxy.
func (*Provider) Shutdown ¶ added in v1.75.1
func (p *Provider) Shutdown()
Shutdown tears down the provider: shuts down the fixed VFS or flushes all proxy cache entries.
type Proxy ¶
type Proxy struct {
Opt Options
// contains filtered or unexported fields
}
Proxy represents a proxy to turn auth requests into a VFS
func New ¶
New creates a new proxy with the Options passed in
Any VFS are created with the vfsOpt passed in.
func (*Proxy) Call ¶
func (p *Proxy) Call(user, auth string, isPublicKey bool, remoteAddr string) (VFS *vfs.VFS, vfsKey string, err error)
Call runs the auth proxy with the username and password/public key provided returning a *vfs.VFS and the key used in the VFS cache.
remoteAddr is the address of the client as returned by net.Addr.String(). It may be empty if the client has no IP address, for example when connecting over a unix socket.
func (*Proxy) CallAccessKey ¶ added in v1.75.1
func (p *Proxy) CallAccessKey(accessKeyID, remoteAddr string, refresh bool) (VFS *vfs.VFS, secret string, err error)
CallAccessKey runs the auth proxy for an S3 access key ID returning a *vfs.VFS and the secret access key the proxy supplied for it.
The caller must verify the request's signature against the returned secret - the proxy only maps the access key ID to a backend and secret, it cannot authenticate the client itself.
If refresh is true the proxy is consulted rather than using a cached answer, unless it was consulted for this access key ID less than accessKeyRefreshInterval ago. A refresh never shuts down a cached backend, even if the proxy returns a different secret, so this is safe to do when a signature fails to verify in case the secret has been rotated.
A cached answer older than accessKeyRevalidateInterval is always checked with the proxy so a revoked access key ID is refused even if it is in constant use.
remoteAddr is the address of the client as returned by net.Addr.String().
func (*Proxy) Pin ¶ added in v1.75.1
Pin pins the cache entry for key so it won't be evicted by expire
Directories
¶
| Path | Synopsis |
|---|---|
|
Package proxyflags implements command line flags to set up a proxy
|
Package proxyflags implements command line flags to set up a proxy |