2016-09-29 19:21:06 +00:00
---
description: Explains how to use the S3 storage drivers
2016-11-10 19:54:25 +00:00
keywords: registry, service, driver, images, storage, S3
2016-09-29 19:21:06 +00:00
title: S3 storage driver
---
2016-09-28 21:46:28 +00:00
2016-11-04 22:38:40 +00:00
An implementation of the `storagedriver.StorageDriver` interface which uses
Amazon S3 or S3 compatible services for object storage.
2016-09-28 21:46:28 +00:00
## Parameters
< table >
< tr >
< th > Parameter< / th >
< th > Required< / th >
< th > Description< / th >
< / tr >
< tr >
< td >
< code > accesskey< / code >
< / td >
< td >
2017-02-16 01:35:05 +00:00
no
2016-09-28 21:46:28 +00:00
< / td >
< td >
2017-02-16 01:35:05 +00:00
Your AWS Access Key. If you use [IAM roles ](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html ), omit to fetch temporary credentials from IAM.
2016-09-28 21:46:28 +00:00
< / td >
< / tr >
< tr >
< td >
< code > secretkey< / code >
< / td >
< td >
2017-02-16 01:35:05 +00:00
no
2016-09-28 21:46:28 +00:00
< / td >
< td >
2017-02-16 01:35:05 +00:00
Your AWS Secret Key. If you use [IAM roles ](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html ), omit to fetch temporary credentials from IAM.
2016-09-28 21:46:28 +00:00
< / td >
< / tr >
< tr >
< td >
< code > region< / code >
< / td >
< td >
yes
< / td >
< td >
The AWS region in which your bucket exists. For the moment, the Go AWS
library in use does not use the newer DNS based bucket routing.
< / td >
< / tr >
< tr >
< td >
< code > regionendpoint< / code >
< / td >
< td >
no
< / td >
< td >
Endpoint for S3 compatible storage services (Minio, etc)
< / td >
< / tr >
< tr >
< td >
< code > bucket< / code >
< / td >
< td >
yes
< / td >
< td >
The bucket name in which you want to store the registry's data.
< / td >
< / tr >
< tr >
< td >
< code > encrypt< / code >
< / td >
< td >
no
< / td >
< td >
Specifies whether the registry stores the image in encrypted format or
not. A boolean value. The default is false.
< / td >
< / tr >
< tr >
< td >
< code > keyid< / code >
< / td >
< td >
no
< / td >
< td >
Optional KMS key ID to use for encryption (encrypt must be true, or this
2018-01-26 01:37:23 +00:00
parameter is ignored). The default is none.
2016-09-28 21:46:28 +00:00
< / td >
< / tr >
< tr >
< td >
< code > secure< / code >
< / td >
< td >
no
< / td >
< td >
Indicates whether to use HTTPS instead of HTTP. A boolean value. The
default is < code > true< / code > .
< / td >
< / tr >
< tr >
< td >
< code > v4auth< / code >
< / td >
< td >
no
< / td >
< td >
Indicates whether the registry uses Version 4 of AWS's authentication.
2017-01-03 14:33:05 +00:00
By default, this is < code > true< / code > .
2016-09-28 21:46:28 +00:00
< / td >
< / tr >
< tr >
< td >
< code > chunksize< / code >
< / td >
< td >
no
< / td >
< td >
The S3 API requires multipart upload chunks to be at least 5MB. This value
should be a number that is larger than 5*1024*1024.
< / td >
< / tr >
< tr >
< td >
< code > rootdirectory< / code >
< / td >
< td >
no
< / td >
< td >
2018-01-26 01:37:23 +00:00
This is a prefix that is applied to all S3 keys to allow you to segment data in your bucket if necessary.
2016-09-28 21:46:28 +00:00
< / td >
< / tr >
< tr >
< td >
< code > storageclass< / code >
< / td >
< td >
no
< / td >
< td >
The S3 storage class applied to each registry file. The default value is STANDARD.
< / td >
< / tr >
2019-01-21 19:00:58 +00:00
< tr >
< td >
< code > s3accelerate< / code >
< / td >
< td >
no
< / td >
< td >
Specifies whether the registry should use S3 Transfer Acceleration. You must enable acceleration
endpoint on a bucket before using this option. A boolean value. The default is < code > false< / code > .
< / td >
< / tr >
2016-09-28 21:46:28 +00:00
< / table >
`accesskey` : Your aws access key.
`secretkey` : Your aws secret key.
2017-02-16 01:35:05 +00:00
> **Note** You can provide empty strings for your access and secret keys to run the driver
2018-01-26 01:37:23 +00:00
> on an ec2 instance and handles authentication with the instance's credentials. If you
2017-02-16 01:35:05 +00:00
> use [IAM roles](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html),
> omit these keys to fetch temporary credentials from IAM.
2016-09-28 21:46:28 +00:00
`region` : The name of the aws region in which you would like to store objects (for example `us-east-1` ). For a list of regions, you can look at http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html
`regionendpoint` : (optional) Endpoint URL for S3 compatible APIs. This should not be provided when using Amazon S3.
`bucket` : The name of your S3 bucket where you wish to store objects. The bucket must exist prior to the driver initialization.
`encrypt` : (optional) Whether you would like your data encrypted on the server side (defaults to false if not specified).
2018-01-26 01:37:23 +00:00
`keyid` : (optional) Whether you would like your data encrypted with this KMS key ID (defaults to none if not specified, is ignored if encrypt is not true).
2016-09-28 21:46:28 +00:00
2018-01-26 01:37:23 +00:00
`secure` : (optional) Whether you would like to transfer data to the bucket over ssl or not. Defaults to true (meaning transferring over ssl) if not specified. While setting this to false improves performance, it is not recommended due to security concerns.
2016-09-28 21:46:28 +00:00
2018-01-26 01:37:23 +00:00
`v4auth` : (optional) Whether you would like to use aws signature version 4 with your requests. This defaults to `false` if not specified. The `eu-central-1` region does not work with version 2 signatures, so the driver errors out if initialized with this region and v4auth set to `false` .
2016-09-28 21:46:28 +00:00
2018-01-26 01:37:23 +00:00
`chunksize` : (optional) The default part size for multipart uploads (performed by WriteStream) to S3. The default is 10 MB. Keep in mind that the minimum part size for S3 is 5MB. Depending on the speed of your connection to S3, a larger chunk size may result in better performance; faster connections benefit from larger chunk sizes.
2016-09-28 21:46:28 +00:00
2018-01-26 01:37:23 +00:00
`rootdirectory` : (optional) The root directory tree in which all registry files are stored. Defaults to the empty string (bucket root).
2016-09-28 21:46:28 +00:00
`storageclass` : (optional) The storage class applied to each registry file. Defaults to STANDARD. Valid options are STANDARD and REDUCED_REDUNDANCY.
2019-01-21 19:00:58 +00:00
`s3accelerate` : (optional) Whether you would like to use accelerate endpoint for communication with S3. You must enable acceleration on a bucket before using this option. See https://docs.aws.amazon.com/AmazonS3/latest/dev/transfer-acceleration.html on how to use enable option.
2016-09-28 21:46:28 +00:00
## S3 permission scopes
2016-12-06 22:46:12 +00:00
The following AWS policy is required by the registry for push and pull. Make sure to replace `S3_BUCKET_NAME` with the name of your bucket.
2016-09-28 21:46:28 +00:00
```
2016-12-06 22:46:12 +00:00
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:GetBucketLocation",
"s3:ListBucketMultipartUploads"
],
"Resource": "arn:aws:s3:::S3_BUCKET_NAME"
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject",
"s3:ListMultipartUploadParts",
"s3:AbortMultipartUpload"
],
"Resource": "arn:aws:s3:::S3_BUCKET_NAME/*"
}
]
}
2016-09-28 21:46:28 +00:00
```
2016-12-06 22:46:12 +00:00
See [the S3 policy documentation ](http://docs.aws.amazon.com/AmazonS3/latest/dev/mpuAndPermissions.html ) for more details.
2016-09-28 21:46:28 +00:00
# CloudFront as Middleware with S3 backend
## Use Case
2016-11-04 22:38:40 +00:00
Adding CloudFront as a middleware for your S3 backed registry can dramatically
2018-01-26 01:37:23 +00:00
improve pull times. Your registry can retrieve your images
2016-11-04 22:38:40 +00:00
from edge servers, rather than the geographically limited location of your S3
2018-01-26 01:37:23 +00:00
bucket. The farther your registry is from your bucket, the more improvements are
possible. See [Amazon CloudFront ](https://aws.amazon.com/cloudfront/details/ ).
2016-09-28 21:46:28 +00:00
2019-01-21 19:00:58 +00:00
An alternative method for CloudFront that requires less configuration and will use
the same edge servers is [S3 Transfer Acceleration ](https://docs.aws.amazon.com/AmazonS3/latest/dev/transfer-acceleration.html ).
Please check acceleration [Requirements ](https://docs.aws.amazon.com/AmazonS3/latest/dev/transfer-acceleration.html#transfer-acceleration-requirements )
to see whether you need CloudFront or S3 Transfer Acceleration.
2016-09-28 21:46:28 +00:00
## Configuring CloudFront for Distribution
2016-11-04 22:38:40 +00:00
If you are unfamiliar with creating a CloudFront distribution, see [Getting
Started with
Cloudfront](http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/GettingStarted.html).
2016-09-28 21:46:28 +00:00
Defaults can be kept in most areas except:
### Origin:
2018-01-09 22:31:37 +00:00
- The CloudFront distribution must be created such that the `Origin Path` is set
to the directory level of the root "docker" key in S3. If your registry exists
on the root of the bucket, this path should be left blank.
- For private S3 buckets, you must set `Restrict Bucket Access` to `Yes` . See
the [CloudFront documentation ](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html ).
2016-09-28 21:46:28 +00:00
### Behaviors:
- Viewer Protocol Policy: HTTPS Only
- Allowed HTTP Methods: GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE
- Cached HTTP Methods: OPTIONS (checked)
- Restrict Viewer Access (Use Signed URLs or Signed Cookies): Yes
- Trusted Signers: Self (Can add other accounts as long as you have access to CloudFront Key Pairs for those additional accounts)
## Registry configuration
2016-11-04 22:38:40 +00:00
Here the `middleware` option is used. It is still important to keep the
2018-01-26 01:37:23 +00:00
`storage` option, because CloudFront only handles `pull` actions; `push` actions
2016-11-04 22:38:40 +00:00
are still directly written to S3.
2016-09-28 21:46:28 +00:00
2018-01-26 01:37:23 +00:00
The following example shows a minimum configuration:
2016-10-03 23:05:09 +00:00
2016-09-28 21:46:28 +00:00
```
...
storage:
s3:
region: us-east-1
bucket: docker.myregistry.com
middleware:
storage:
- name: cloudfront
options:
baseurl: https://abcdefghijklmn.cloudfront.net/
privatekey: /etc/docker/cloudfront/pk-ABCEDFGHIJKLMNOPQRST.pem
keypairid: ABCEDFGHIJKLMNOPQRST
...
```
## CloudFront Key-Pair
2016-11-04 22:38:40 +00:00
A CloudFront key-pair is required for all AWS accounts needing access to your
2018-01-26 01:37:23 +00:00
CloudFront distribution. You must have access to your AWS account's root credentials to create the required Cloudfront keypair. For information, see [Creating CloudFront Key
2017-01-03 14:33:05 +00:00
Pairs](http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-trusted-signers.html#private-content-creating-cloudfront-key-pairs).