s3

package
v1.72.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2025 License: MIT Imports: 63 Imported by: 33

README

Adding a new s3 provider

It is quite easy to add a new S3 provider to rclone.

You'll then need to do add the following (optional tags are in [] and do not get displayed in rclone config if empty):

The process is as follows: Create yaml -> add docs -> run tests -> adjust yaml until tests pass.

All tags can be found in backend/s3/providers.go Provider Struct. Looking through a few of the yaml files as examples should make things clear. AWS.yaml as the most config. pasting.

YAML

In backend/s3/provider/YourProvider.yaml

  • name

  • description

    • More like the full name often "YourProvider + Object Storage"
  • [Region]

    • Any regions your provider supports or the defaults (use region: {} for this)
      • Example from AWS.yaml:

        region:
          us-east-1: |-
            The default endpoint - a good choice if you are unsure.
            US Region, Northern Virginia, or Pacific Northwest.
            Leave location constraint empty.
        
      • The defaults (as seen in Rclone.yaml):

        region:
          "": |-
            Use this if unsure.
            Will use v4 signatures and an empty region.
          other-v2-signature: |-
            Use this only if v4 signatures don't work.
            E.g. pre Jewel/v10 CEPH.
        
  • [Endpoint]

    • Any endpoints your provider supports

      • Example from Mega.yaml

          endpoint:
            s3.eu-central-1.s4.mega.io: Mega S4 eu-central-1 (Amsterdam)
        
  • [Location Constraint]

    • The Location Constraint of your remote, often same as region.
      • Example from AWS.yaml

        location_constraint:
          "": Empty for US Region, Northern Virginia, or Pacific Northwest
          us-east-2: US East (Ohio) Region
        
  • [ACL]

    • Identical across most providers. Select the default with acl: {}
      • Example from AWS.yaml

        acl:
          private: |-
            Owner gets FULL_CONTROL.
            No one else has access rights (default).
          public-read: |-
            Owner gets FULL_CONTROL.
            The AllUsers group gets READ access.
          public-read-write: |-
            Owner gets FULL_CONTROL.
            The AllUsers group gets READ and WRITE access.
            Granting this on a bucket is generally not recommended.
          authenticated-read: |-
            Owner gets FULL_CONTROL.
            The AuthenticatedUsers group gets READ access.
          bucket-owner-read: |-
            Object owner gets FULL_CONTROL.
            Bucket owner gets READ access.
            If you specify this canned ACL when creating a bucket, Amazon S3 ignores it.
          bucket-owner-full-control: |-
            Both the object owner and the bucket owner get FULL_CONTROL over the object.
            If you specify this canned ACL when creating a bucket, Amazon S3 ignores it.
        
  • [Storage Class]

    • Identical across most providers.
      • Defaults from AWS.yaml

        storage_class:
          "": Default
          STANDARD: Standard storage class
          REDUCED_REDUNDANCY: Reduced redundancy storage class
          STANDARD_IA: Standard Infrequent Access storage class
          ONEZONE_IA: One Zone Infrequent Access storage class
          GLACIER: Glacier Flexible Retrieval storage class
          DEEP_ARCHIVE: Glacier Deep Archive storage class
          INTELLIGENT_TIERING: Intelligent-Tiering storage class
          GLACIER_IR: Glacier Instant Retrieval storage class
        
  • [Server Side Encryption]

    • Not common, identical across most providers.
      • Defaults from AWS.yaml

          server_side_encryption:
            "": None
            AES256: AES256
            aws:kms: aws:kms
        
  • [Advanced Options]

    • All advanced options are Boolean - if true the configurator asks about that value, if not it doesn't:

      BucketACL             bool `yaml:"bucket_acl,omitempty"`
      DirectoryBucket       bool `yaml:"directory_bucket,omitempty"`
      LeavePartsOnError     bool `yaml:"leave_parts_on_error,omitempty"`
      RequesterPays         bool `yaml:"requester_pays,omitempty"`
      SSECustomerAlgorithm  bool `yaml:"sse_customer_algorithm,omitempty"`
      SSECustomerKey        bool `yaml:"sse_customer_key,omitempty"`
      SSECustomerKeyBase64  bool `yaml:"sse_customer_key_base64,omitempty"`
      SSECustomerKeyMd5     bool `yaml:"sse_customer_key_md5,omitempty"`
      SSEKmsKeyID           bool `yaml:"sse_kms_key_id,omitempty"`
      STSEndpoint           bool `yaml:"sts_endpoint,omitempty"`
      UseAccelerateEndpoint bool `yaml:"use_accelerate_endpoint,omitempty"`
      
      • Example from AWS.yaml:

        bucket_acl: true
        directory_bucket: true
        leave_parts_on_error: true
        requester_pays: true
        sse_customer_algorithm: true
        sse_customer_key: true
        sse_customer_key_base64: true
        sse_customer_key_md5: true
        sse_kms_key_id: true
        sts_endpoint: true
        use_accelerate_endpoint: true
        
  • Quirks

    • Quirks are discovered through documentation and running the tests as seen below.
      • Most quirks are *bool as to have 3 values, true, false and dont care.

        type Quirks struct {
            ListVersion           *int   `yaml:"list_version,omitempty"`     // 1 or 2
            ForcePathStyle        *bool  `yaml:"force_path_style,omitempty"` // true = path-style
            ListURLEncode         *bool  `yaml:"list_url_encode,omitempty"`
            UseMultipartEtag      *bool  `yaml:"use_multipart_etag,omitempty"`
            UseAlreadyExists      *bool  `yaml:"use_already_exists,omitempty"`
            UseAcceptEncodingGzip *bool  `yaml:"use_accept_encoding_gzip,omitempty"`
            MightGzip             *bool  `yaml:"might_gzip,omitempty"`
            UseMultipartUploads   *bool  `yaml:"use_multipart_uploads,omitempty"`
            UseUnsignedPayload    *bool  `yaml:"use_unsigned_payload,omitempty"`
            UseXID                *bool  `yaml:"use_x_id,omitempty"`
            SignAcceptEncoding    *bool  `yaml:"sign_accept_encoding,omitempty"`
            CopyCutoff            *int64 `yaml:"copy_cutoff,omitempty"`
            MaxUploadParts        *int   `yaml:"max_upload_parts,omitempty"`
            MinChunkSize          *int64 `yaml:"min_chunk_size,omitempty"`
        }
        
        • Example from AWS.yaml

          quirks:
            might_gzip: false # Never auto gzips objects
            use_unsigned_payload: false # AWS has trailer support
          

Note that if you omit a section, eg region then the user won't be asked that question, and if you add an empty section e.g. region: {} then the defaults from the Other.yaml will be used.

DOCS

  • docs/content/s3.md
    • Add the provider at the top of the page.
    • Add a section about the provider linked from there.
      • Make sure this is in alphabetical order in the Providers section.
    • Add a transcript of a trial rclone config session
      • Edit the transcript to remove things which might change in subsequent versions
    • Do not alter or add to the autogenerated parts of s3.md
      • Rule of thumb: don't edit anything not mentioned above.
    • Do not run make backenddocs or bin/make_backend_docs.py s3
      • This will make autogenerated changes!
  • README.md - this is the home page in github
    • Add the provider and a link to the section you wrote in docs/contents/s3.md
  • docs/content/_index.md - this is the home page of rclone.org
    • Add the provider and a link to the section you wrote in docs/contents/s3.md
  • Once you've written the docs, run make serve and check they look OK in the web browser and the links (internal and external) all work.

TESTS

Once you've written the code, test rclone config works to your satisfaction and looks correct, and check the integration tests work go test -v -remote NewS3Provider:. You may need to adjust the quirks to get them to pass. Some providers just can't pass the tests with control characters in the names so if these fail and the provider doesn't support urlEncodeListings in the quirks then ignore them.

Documentation

Overview

Package s3 provides an interface to Amazon S3 object storage

Index

Constants

This section is empty.

Variables

View Source
var NewYamlMap = orderedmap.New[string, string]

NewYamlMap creates a new ordered map

Functions

func NewFs

func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, error)

NewFs constructs an Fs from the path, bucket:path

Types

type Authenticator added in v1.70.0

type Authenticator interface {
	GetToken() (string, error)
}

Authenticator defines an interface for obtaining an IAM token.

type Fs

type Fs struct {
	// contains filtered or unexported fields
}

Fs represents a remote s3 server

func (*Fs) CleanUp added in v1.53.0

func (f *Fs) CleanUp(ctx context.Context) (err error)

CleanUp removes all pending multipart uploads older than 24 hours

func (*Fs) CleanUpHidden added in v1.60.0

func (f *Fs) CleanUpHidden(ctx context.Context) error

CleanUpHidden deletes all the hidden files.

func (*Fs) Command added in v1.53.0

func (f *Fs) Command(ctx context.Context, name string, arg []string, opt map[string]string) (out any, err error)

Command the backend to run a named command

The command run is name args may be used to read arguments from opts may be used to read optional arguments from

The result should be capable of being JSON encoded If it is a string or a []string it will be shown to the user otherwise it will be JSON encoded and shown to the user like that

func (*Fs) Copy

func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, error)

Copy src to this remote using server-side copy operations.

This is stored with the remote path given.

It returns the destination Object and a possible error.

Will only be called if src.Fs().Name() == f.Name()

If it isn't possible then return fs.ErrorCantCopy

func (*Fs) Features

func (f *Fs) Features() *fs.Features

Features returns the optional features of this Fs

func (*Fs) Hashes

func (f *Fs) Hashes() hash.Set

Hashes returns the supported hash sets.

func (*Fs) List

func (f *Fs) List(ctx context.Context, dir string) (entries fs.DirEntries, err error)

List the objects and directories in dir into entries. The entries can be returned in any order but should be for a complete directory.

dir should be "" to list the root, and should not have trailing slashes.

This should return ErrDirNotFound if the directory isn't found.

func (*Fs) ListP added in v1.70.0

func (f *Fs) ListP(ctx context.Context, dir string, callback fs.ListRCallback) error

ListP lists the objects and directories of the Fs starting from dir non recursively into out.

dir should be "" to start from the root, and should not have trailing slashes.

This should return ErrDirNotFound if the directory isn't found.

It should call callback for each tranche of entries read. These need not be returned in any particular order. If callback returns an error then the listing will stop immediately.

func (*Fs) ListR

func (f *Fs) ListR(ctx context.Context, dir string, callback fs.ListRCallback) (err error)

ListR lists the objects and directories of the Fs starting from dir recursively into out.

dir should be "" to start from the root, and should not have trailing slashes.

This should return ErrDirNotFound if the directory isn't found.

It should call callback for each tranche of entries read. These need not be returned in any particular order. If callback returns an error then the listing will stop immediately.

Don't implement this unless you have a more efficient way of listing recursively than doing a directory traversal.

func (*Fs) Mkdir

func (f *Fs) Mkdir(ctx context.Context, dir string) error

Mkdir creates the bucket if it doesn't exist

func (*Fs) Name

func (f *Fs) Name() string

Name of the remote (as passed into NewFs)

func (*Fs) NewObject

func (f *Fs) NewObject(ctx context.Context, remote string) (fs.Object, error)

NewObject finds the Object at remote. If it can't be found it returns the error fs.ErrorObjectNotFound.

func (*Fs) OpenChunkWriter added in v1.64.0

func (f *Fs) OpenChunkWriter(ctx context.Context, remote string, src fs.ObjectInfo, options ...fs.OpenOption) (info fs.ChunkWriterInfo, writer fs.ChunkWriter, err error)

OpenChunkWriter returns the chunk size and a ChunkWriter

Pass in the remote and the src object You can also use options to hint at the desired chunk size

func (*Fs) Precision

func (f *Fs) Precision() time.Duration

Precision of the remote

func (f *Fs) PublicLink(ctx context.Context, remote string, expire fs.Duration, unlink bool) (link string, err error)

PublicLink generates a public link to the remote path (usually readable by anyone)

func (*Fs) Purge added in v1.60.0

func (f *Fs) Purge(ctx context.Context, dir string) error

Purge deletes all the files and directories including the old versions.

func (*Fs) Put

func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error)

Put the Object into the bucket

func (*Fs) PutStream

func (f *Fs) PutStream(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (fs.Object, error)

PutStream uploads to the remote path with the modTime given of indeterminate size

func (*Fs) Rmdir

func (f *Fs) Rmdir(ctx context.Context, dir string) error

Rmdir deletes the bucket if the fs is at the root

Returns an error if it isn't empty

func (*Fs) Root

func (f *Fs) Root() string

Root of the remote (as passed into NewFs)

func (*Fs) String

func (f *Fs) String() string

String converts this Fs to a string

type IbmIamSigner added in v1.70.0

type IbmIamSigner struct {
	APIKey     string
	InstanceID string
	Auth       Authenticator
}

IbmIamSigner is a structure for signing requests using IBM IAM. Requeres APIKey and Resource InstanceID

func (*IbmIamSigner) SignHTTP added in v1.70.0

func (signer *IbmIamSigner) SignHTTP(ctx context.Context, credentials aws.Credentials, req *http.Request, payloadHash string, service string, region string, signingTime time.Time, optFns ...func(*v4signer.SignerOptions)) error

SignHTTP signs requests using IBM IAM token.

type NoOpCredentialsProvider added in v1.70.0

type NoOpCredentialsProvider struct{}

NoOpCredentialsProvider is needed since S3 SDK requires having credentials, even though authentication is happening via IBM IAM.

func (*NoOpCredentialsProvider) IsExpired added in v1.70.0

func (n *NoOpCredentialsProvider) IsExpired() bool

IsExpired always returns false

func (*NoOpCredentialsProvider) Retrieve added in v1.70.0

Retrieve returns mock credentials for the NoOpCredentialsProvider.

type Object

type Object struct {
	// contains filtered or unexported fields
}

Object describes a s3 object

func (*Object) Fs

func (o *Object) Fs() fs.Info

Fs returns the parent Fs

func (*Object) GetTier added in v1.49.4

func (o *Object) GetTier() string

GetTier returns storage class as string

func (*Object) Hash

func (o *Object) Hash(ctx context.Context, t hash.Type) (string, error)

Hash returns the Md5sum of an object returning a lowercase hex string

func (*Object) Metadata added in v1.59.0

func (o *Object) Metadata(ctx context.Context) (metadata fs.Metadata, err error)

Metadata returns metadata for an object

It should return nil if there is no Metadata

func (*Object) MimeType

func (o *Object) MimeType(ctx context.Context) string

MimeType of an Object if known, "" otherwise

func (*Object) ModTime

func (o *Object) ModTime(ctx context.Context) time.Time

ModTime returns the modification time of the object

It attempts to read the objects mtime and if that isn't present the LastModified returned in the http headers

func (*Object) Open

func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.ReadCloser, err error)

Open an object for read

func (*Object) Remote

func (o *Object) Remote() string

Remote returns the remote path

func (*Object) Remove

func (o *Object) Remove(ctx context.Context) error

Remove an object

func (*Object) SetModTime

func (o *Object) SetModTime(ctx context.Context, modTime time.Time) error

SetModTime sets the modification time of the local fs object

func (*Object) SetTier added in v1.49.4

func (o *Object) SetTier(tier string) (err error)

SetTier performs changing storage class

func (*Object) Size

func (o *Object) Size() int64

Size returns the size of an object in bytes

func (*Object) Storable

func (o *Object) Storable() bool

Storable raturns a boolean indicating if this object is storable

func (*Object) String

func (o *Object) String() string

Return a string version

func (*Object) Update

func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) error

Update the Object from in with modTime and size

type Options

type Options struct {
	Provider                    string               `config:"provider"`
	EnvAuth                     bool                 `config:"env_auth"`
	AccessKeyID                 string               `config:"access_key_id"`
	SecretAccessKey             string               `config:"secret_access_key"`
	Region                      string               `config:"region"`
	Endpoint                    string               `config:"endpoint"`
	STSEndpoint                 string               `config:"sts_endpoint"`
	UseDualStack                bool                 `config:"use_dual_stack"`
	LocationConstraint          string               `config:"location_constraint"`
	ACL                         string               `config:"acl"`
	BucketACL                   string               `config:"bucket_acl"`
	RequesterPays               bool                 `config:"requester_pays"`
	ServerSideEncryption        string               `config:"server_side_encryption"`
	SSEKMSKeyID                 string               `config:"sse_kms_key_id"`
	SSECustomerAlgorithm        string               `config:"sse_customer_algorithm"`
	SSECustomerKey              string               `config:"sse_customer_key"`
	SSECustomerKeyBase64        string               `config:"sse_customer_key_base64"`
	SSECustomerKeyMD5           string               `config:"sse_customer_key_md5"`
	StorageClass                string               `config:"storage_class"`
	UploadCutoff                fs.SizeSuffix        `config:"upload_cutoff"`
	CopyCutoff                  fs.SizeSuffix        `config:"copy_cutoff"`
	ChunkSize                   fs.SizeSuffix        `config:"chunk_size"`
	MaxUploadParts              int                  `config:"max_upload_parts"`
	DisableChecksum             bool                 `config:"disable_checksum"`
	SharedCredentialsFile       string               `config:"shared_credentials_file"`
	Profile                     string               `config:"profile"`
	SessionToken                string               `config:"session_token"`
	UploadConcurrency           int                  `config:"upload_concurrency"`
	ForcePathStyle              bool                 `config:"force_path_style"`
	V2Auth                      bool                 `config:"v2_auth"`
	UseAccelerateEndpoint       bool                 `config:"use_accelerate_endpoint"`
	UseARNRegion                bool                 `config:"use_arn_region"`
	LeavePartsOnError           bool                 `config:"leave_parts_on_error"`
	ListChunk                   int32                `config:"list_chunk"`
	ListVersion                 int                  `config:"list_version"`
	ListURLEncode               fs.Tristate          `config:"list_url_encode"`
	NoCheckBucket               bool                 `config:"no_check_bucket"`
	NoHead                      bool                 `config:"no_head"`
	NoHeadObject                bool                 `config:"no_head_object"`
	Enc                         encoder.MultiEncoder `config:"encoding"`
	DisableHTTP2                bool                 `config:"disable_http2"`
	DownloadURL                 string               `config:"download_url"`
	DirectoryMarkers            bool                 `config:"directory_markers"`
	UseMultipartEtag            fs.Tristate          `config:"use_multipart_etag"`
	UsePresignedRequest         bool                 `config:"use_presigned_request"`
	UseDataIntegrityProtections fs.Tristate          `config:"use_data_integrity_protections"`
	Versions                    bool                 `config:"versions"`
	VersionAt                   fs.Time              `config:"version_at"`
	VersionDeleted              bool                 `config:"version_deleted"`
	Decompress                  bool                 `config:"decompress"`
	MightGzip                   fs.Tristate          `config:"might_gzip"`
	UseAcceptEncodingGzip       fs.Tristate          `config:"use_accept_encoding_gzip"`
	NoSystemMetadata            bool                 `config:"no_system_metadata"`
	UseAlreadyExists            fs.Tristate          `config:"use_already_exists"`
	UseMultipartUploads         fs.Tristate          `config:"use_multipart_uploads"`
	UseUnsignedPayload          fs.Tristate          `config:"use_unsigned_payload"`
	SDKLogMode                  sdkLogMode           `config:"sdk_log_mode"`
	DirectoryBucket             bool                 `config:"directory_bucket"`
	IBMAPIKey                   string               `config:"ibm_api_key"`
	IBMInstanceID               string               `config:"ibm_resource_instance_id"`
	UseXID                      fs.Tristate          `config:"use_x_id"`
	SignAcceptEncoding          fs.Tristate          `config:"sign_accept_encoding"`
}

Options defines the configuration for this backend

type Provider added in v1.72.0

type Provider struct {
	Name                 string  `yaml:"name,omitempty"`
	Description          string  `yaml:"description,omitempty"`
	Region               YamlMap `yaml:"region,omitempty"`
	Endpoint             YamlMap `yaml:"endpoint,omitempty"`
	LocationConstraint   YamlMap `yaml:"location_constraint,omitempty"`
	ACL                  YamlMap `yaml:"acl,omitempty"`
	StorageClass         YamlMap `yaml:"storage_class,omitempty"`
	ServerSideEncryption YamlMap `yaml:"server_side_encryption,omitempty"`

	// other
	IBMApiKey             bool `yaml:"ibm_api_key,omitempty"`
	IBMResourceInstanceID bool `yaml:"ibm_resource_instance_id,omitempty"`

	// advanced
	BucketACL             bool `yaml:"bucket_acl,omitempty"`
	DirectoryBucket       bool `yaml:"directory_bucket,omitempty"`
	LeavePartsOnError     bool `yaml:"leave_parts_on_error,omitempty"`
	RequesterPays         bool `yaml:"requester_pays,omitempty"`
	SSECustomerAlgorithm  bool `yaml:"sse_customer_algorithm,omitempty"`
	SSECustomerKey        bool `yaml:"sse_customer_key,omitempty"`
	SSECustomerKeyBase64  bool `yaml:"sse_customer_key_base64,omitempty"`
	SSECustomerKeyMd5     bool `yaml:"sse_customer_key_md5,omitempty"`
	SSEKmsKeyID           bool `yaml:"sse_kms_key_id,omitempty"`
	STSEndpoint           bool `yaml:"sts_endpoint,omitempty"`
	UseAccelerateEndpoint bool `yaml:"use_accelerate_endpoint,omitempty"`

	Quirks Quirks `yaml:"quirks,omitempty"`
}

Provider defines the configurable data in each provider.yaml

type Quirks added in v1.72.0

type Quirks struct {
	ListVersion                 *int   `yaml:"list_version,omitempty"`     // 1 or 2
	ForcePathStyle              *bool  `yaml:"force_path_style,omitempty"` // true = path-style
	ListURLEncode               *bool  `yaml:"list_url_encode,omitempty"`
	UseMultipartEtag            *bool  `yaml:"use_multipart_etag,omitempty"`
	UseAlreadyExists            *bool  `yaml:"use_already_exists,omitempty"`
	UseAcceptEncodingGzip       *bool  `yaml:"use_accept_encoding_gzip,omitempty"`
	UseDataIntegrityProtections *bool  `yaml:"use_data_integrity_protections,omitempty"`
	MightGzip                   *bool  `yaml:"might_gzip,omitempty"`
	UseMultipartUploads         *bool  `yaml:"use_multipart_uploads,omitempty"`
	UseUnsignedPayload          *bool  `yaml:"use_unsigned_payload,omitempty"`
	UseXID                      *bool  `yaml:"use_x_id,omitempty"`
	SignAcceptEncoding          *bool  `yaml:"sign_accept_encoding,omitempty"`
	CopyCutoff                  *int64 `yaml:"copy_cutoff,omitempty"`
	MaxUploadParts              *int   `yaml:"max_upload_parts,omitempty"`
	MinChunkSize                *int64 `yaml:"min_chunk_size,omitempty"`
}

Quirks defines all the S3 provider quirks

type YamlMap added in v1.72.0

type YamlMap = *orderedmap.OrderedMap[string, string]

YamlMap is converted to YAML in the correct order

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL