# Drone 1.0 and AWS ECR going forward

**URL:** <https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074>\
**Category:** Drone Support\
**Created:** [November 26, 2018, 7:47pm UTC](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074 "2018-11-26T19:47:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidbyttow](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/davidbyttow/32/4537_2.png) [@davidbyttow](https://drone.discourse.group/u/davidbyttow)\
**Post date:** [November 26, 2018, 7:47pm UTC](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074/1 "2018-11-26T19:47:10Z")

</div>

This has discussed before and there are several solutions out there, but they all seem hacky/brittle.

Because AWS ECR requires login via a short-lived token, it’s not possible to bake in long-term credentials. awslabs created a Docker credential store that can be used with docker config.json, however it seems that while drone agent supports config.json location, it doesn’t seem to play well with credHelpers.

So, to solve this, I’ve had to boot EC2 worker instances with a cron that periodically invokes “aws ecr get-login” to update the /.docker/config.json with the latest token, and mount that directory in order for the docker agent to get access to it, as described here: [How do you authenticate with and pull from an ECR registry?](http://discuss.harness.io/t/how-do-you-authenticate-with-and-pull-from-an-ecr-registry/967/8?u=davidbyttow)

This feels quite brittle. Is there some sort of configuration plugin/service we can devise for drone agents prior to pulling an image? Or give agents support for credHelpers and a way to mount the executable that it will invoke for specific repos? E.g.,

```auto
{
  "credHelpers": {
    "xxxxxxxx.dkr.ecr.us-east-1.amazonaws.com/repo:tag": "ecr-login",
  }
}

```

This would invoke docker-credential-ecr-login, which can be built from this: [https://github.com/awslabs/amazon-ecr-credential-helper](https://github.com/awslabs/amazon-ecr-credential-helper)

---

<div class="post-metadata">

**Author:** ![bradrydzewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bradrydzewski/32/3513_2.png) [@bradrydzewski](https://drone.discourse.group/u/bradrydzewski)\
**Post date:** [November 26, 2018, 8:10pm UTC](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074/2 "2018-11-26T20:10:17Z")

</div>

yes, 1.0 supports registry credentials extensions although I haven’t had the chance to document or provide a starter project yet. I was planning to provide an official ecr extension at some point.

extensions are microservices (communicate via rest) so you would pass the following variables to your drone agents, which would instruct them to fetch credentials from the plugin.

```auto
DRONE_REGISTRY_ENDPOINT=https://your.drone.microservice
DRONE_REGISTRY_SECRET=some-shared-secret

```

the api request would then return the following response, in json format:

```auto
[{
  "address": "docker.io",
  "username": "octocat",
  "password": "correct-horse-battery-staple"
}]

```

there is actually a helper library for this: [https://github.com/drone/drone-go/tree/master/plugin/registry](https://github.com/drone/drone-go/tree/master/plugin/registry)

I will try and see if I can put together a sample plugin early next week. These extensions tend to be quite easy to implement, especially when using the helper library. I’m currently at re-invent, but would be happy to touch base next week regarding extensions, and help you get setup / answer any questions you have.

---

<div class="post-metadata">

**Author:** ![davidbyttow](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/davidbyttow/32/4537_2.png) [@davidbyttow](https://drone.discourse.group/u/davidbyttow)\
**Post date:** [November 26, 2018, 8:20pm UTC](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074/3 "2018-11-26T20:20:18Z")

</div>

Oh nice, and this should work today? If so, I can just switch to that. I already am successfully using the Secret and Jsonnet plugins in a similar way.

---

<div class="post-metadata">

**Author:** ![davidbyttow](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/davidbyttow/32/4537_2.png) [@davidbyttow](https://drone.discourse.group/u/davidbyttow)\
**Post date:** [November 26, 2018, 8:20pm UTC](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074/4 "2018-11-26T20:20:48Z")

</div>

Also, is the source code for 1.0 anywhere? I couldn’t find it, and that would be super helpful with respect to digging on these sorts of issues. I’ve been looking at older code.

---

<div class="post-metadata">

**Author:** ![bradrydzewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bradrydzewski/32/3513_2.png) [@bradrydzewski](https://drone.discourse.group/u/bradrydzewski)\
**Post date:** [November 26, 2018, 8:22pm UTC](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074/5 "2018-11-26T20:22:13Z")

</div>

awesome, yes it should work, with the caveat that I have only tested registry plugins with unit tests. Usually I write a sample / starter plugin so that I can test in my integration environment, but that is still a pending task in my todo

---

<div class="post-metadata">

**Author:** ![jccguimaraes](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/jccguimaraes/32/5589_2.png) [@jccguimaraes](https://drone.discourse.group/u/jccguimaraes)\
**Post date:** [November 27, 2018, 2:24pm UTC](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074/6 "2018-11-27T14:24:28Z")

</div>

Hi, I am really keen on understanding what changes is needed for 1.0.0 to create an image in ECR. Any help? Thanks

---

<div class="post-metadata">

**Author:** ![jccguimaraes](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/jccguimaraes/32/5589_2.png) [@jccguimaraes](https://drone.discourse.group/u/jccguimaraes)\
**Post date:** [November 27, 2018, 2:40pm UTC](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074/7 "2018-11-27T14:40:58Z")

</div>

doing this

```
steps:
- name: ecr
  image: plugins/docker
  environment:
    AWS_ACCOUNT_ID:
      from_secret: aws_account_id
    AWS_REGION:
      from_secret: aws_region
  settings:
    repo: ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${DRONE_REPO_NAME}
    registry: ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com

```

gives me

```
+ /usr/local/bin/dockerd -g /var/lib/docker
Registry credentials not provided. Guest mode enabled.
+ /usr/local/bin/docker version
Client:
 Version:	17.12.0-ce
 API version:	1.35
 Go version:	go1.9.2
 Git commit:	c97c6d6
 Built:	Wed Dec 27 20:05:38 2017
 OS/Arch:	linux/amd64
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
time="2018-11-27T14:33:37Z" level=fatal msg="exit status 1"
```

---

<div class="post-metadata">

**Author:** ![davidbyttow](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/davidbyttow/32/4537_2.png) [@davidbyttow](https://drone.discourse.group/u/davidbyttow)\
**Post date:** [November 27, 2018, 4:25pm UTC](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074/8 "2018-11-27T16:25:25Z")

</div>

You need to mount the docker volume still here, as per the docs.

---

<div class="post-metadata">

**Author:** ![bradrydzewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bradrydzewski/32/3513_2.png) [@bradrydzewski](https://drone.discourse.group/u/bradrydzewski)\
**Post date:** [November 27, 2018, 4:25pm UTC](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074/9 "2018-11-27T16:25:53Z")

</div>

@jccguimaraes for reference, you can look at the [ecr documentation](http://plugins.drone.io/drone-plugins/drone-ecr/) which shows examples for using the plugin with the 1.0 format. There are a few different issues that I see that I will walk through below, which will hopefully clear things up 🙂

First is that you are using the wrong docker image:

```auto
steps:
  - name: ecr
- image: plugins/docker
+ image: plugins/ecr

```

Second is that you should be providing the access key and access key secret:

```auto
  settings:
    access_key:
      from_secret: aws_access_key_id
    secret_key:
      from_secret: aws_secret_access_key

```

The third issue is that the secrets should passed via the settings section. Normally this syntax would be allowed (for legacy reasons) but the docker and ecr plugins restrict passing environment variables directly.

```diff
steps:
  - name: publish  
    image: plugins/ecr
- environment:
- AWS_ACCOUNT_ID:
- from_secret: aws_account_id
- AWS_REGION:
- from_secret: aws_region
    settings:
      access_key:
        from_secret: aws_access_key_id
      secret_key:
        from_secret: aws_secret_access_key

```

The fourth issue is that you are trying to use bash variable substitution (e.g. `${AWS_ACCOUNT_ID}.dkr.ecr...` in your yaml file. The `repo` and `registry` attributes are unmarshaled into Go string literals. They are not processed by bash a bash interpreter, which means substitution will not work here.

```auto
  settings:
    repo: ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/${DRONE_REPO_NAME}
    registry: ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com

```

---

<div class="post-metadata">

**Author:** ![davidbyttow](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/davidbyttow/32/4537_2.png) [@davidbyttow](https://drone.discourse.group/u/davidbyttow)\
**Post date:** [November 27, 2018, 5:49pm UTC](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074/10 "2018-11-27T17:49:48Z")

</div>

FYI, I started a little plugin here, not fully tested yet – doing so in real time now. [https://github.com/davidbyttow/drone-ecr-registry-plugin](https://github.com/davidbyttow/drone-ecr-registry-plugin)

---

<div class="post-metadata">

**Author:** ![bradrydzewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bradrydzewski/32/3513_2.png) [@bradrydzewski](https://drone.discourse.group/u/bradrydzewski)\
**Post date:** [November 27, 2018, 6:20pm UTC](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074/11 "2018-11-27T18:20:34Z")

</div>

awesome! one thing you might find super helpful is that we’ve been adding commands to the CLI that allow you to test plugins. For example:

```nohighlight
$ drone plugins secret get secret/data/docker username
$ drone plugins secret get secret/data/docker password

```

If you are looking for a good way to test registry credentials plugins, the CLI would be a good option. Unfortunately I’m flying out to aws:reinvent in a couple of hours and won’t have time to add a command today, but if you look at the [`drone secret get`](https://github.com/drone/drone-cli/tree/master/drone/plugins/secret) implementation, it is a small amount of code and could really save you some time if you end up needing to debug.

---

<div class="post-metadata">

**Author:** ![bradrydzewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bradrydzewski/32/3513_2.png) [@bradrydzewski](https://drone.discourse.group/u/bradrydzewski)\
**Post date:** [November 27, 2018, 6:58pm UTC](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074/12 "2018-11-27T18:58:36Z")

</div>

**update:** I published a `drone plugins registry list` command that can be used for testing registry plugins. I tagged a v1.0.3 binary that can be downloaded from GitHub or can be built from source.

---

<div class="post-metadata">

**Author:** ![jccguimaraes](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/jccguimaraes/32/5589_2.png) [@jccguimaraes](https://drone.discourse.group/u/jccguimaraes)\
**Post date:** [November 27, 2018, 7:17pm UTC](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074/13 "2018-11-27T19:17:08Z")

</div>

hey!  
thank you both for the help. turns out that the only way I could make the plugin work is with

```
image: plugins/ecr
  settings:
    access_key:
      from_secret: aws_access_key_id
    secret_key:
      from_secret: aws_secret_acess_key
    region:
      from_secret: aws_region
    repo: name-of-repository-in-ecs
```

---

<div class="post-metadata">

**Author:** ![c2h5oh](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/c2h5oh/32/4487_2.png) [@c2h5oh](https://drone.discourse.group/u/c2h5oh)\
**Post date:** [May 7, 2019, 7:16pm UTC](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074/14 "2019-05-07T19:16:30Z")

</div>

This approach is a fix if you have access to both ECR and [hub.docker.com/another](http://hub.docker.com/another) registry that uses login/pass that can be stored in Drone secrets.

It doesn’t help when you’re limited to ECR only - any idea how to solve that case?

---

<div class="post-metadata">

**Author:** ![bradrydzewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bradrydzewski/32/3513_2.png) [@bradrydzewski](https://drone.discourse.group/u/bradrydzewski)\
**Post date:** [May 7, 2019, 7:57pm UTC](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074/15 "2019-05-07T19:57:17Z")

</div>

This is handled by registry credential extensions. See the following:

> [@On another topic](https://drone.discourse.group/t/3071/10):
>
> [GitHub - davidbyttow/drone-ecr-registry-plugin](https://github.com/davidbyttow/drone-ecr-registry-plugin)

---

<div class="post-metadata">

**Author:** ![ScOut3R](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/scout3r/32/5318_2.png) [@ScOut3R](https://drone.discourse.group/u/ScOut3R)\
**Post date:** [December 9, 2019, 3:10am UTC](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074/16 "2019-12-09T03:10:49Z")

</div>

@bradrydzewski @davidbyttow

The [https://github.com/davidbyttow/drone-ecr-registry-plugin](https://github.com/davidbyttow/drone-ecr-registry-plugin) seems to have stopped working with the docker runner.

I have just upgraded my autoscalers from 1.4.4 to 1.5.0 and though the new docker runner receives the credentials from the plugin (based on network tracing) it fails to pull images from ECR. The runner container does not log any error.

Is there any information I could provide to enable you assisting me in resolving this issue?

---

<div class="post-metadata">

**Author:** ![staffanselander](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/staffanselander/32/4396_2.png) [@staffanselander](https://drone.discourse.group/u/staffanselander)\
**Post date:** [May 18, 2020, 4:48pm UTC](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074/17 "2020-05-18T16:48:37Z")

</div>

@bradrydzewski

I was looking into creating a registry plugin for gcr like the one for ecr.  
There is a deprecation notice on the Registry struct here [https://github.com/drone/drone-go/blob/master/drone/types.go#L175](https://github.com/drone/drone-go/blob/master/drone/types.go#L175).  
Is the registry struct something that i should avoid?

---

<div class="post-metadata">

**Author:** ![bradrydzewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bradrydzewski/32/3513_2.png) [@bradrydzewski](https://drone.discourse.group/u/bradrydzewski)\
**Post date:** [May 18, 2020, 5:31pm UTC](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074/18 "2020-05-18T17:31:50Z")

</div>

Thanks for brining this to my attention, I will remove the comment from the Registry structure to avoid causing confusion 🙂. You can continue to use registry extensions as documented [here](https://docs.drone.io/extensions/registry/). We recommend using our [starter project](https://docs.drone.io/extensions/registry/#starter-project) when creating a new extension.

However, you may not need to create an extension for GCR. The reason an extension was required for ECR is AWS does not provide long-lived credentials which means they need to be constantly refreshed. With GCR, you can create long lived credentials using [JSON key](https://cloud.google.com/container-registry/docs/advanced-authentication#json-key) authentication. You can [provide](https://docs.drone.io/pipeline/docker/syntax/images/#pulling-private-images) these long-lived credentials to Drone by storing them as secrets [1][2] and referencing in your yaml.

We also provide a registry credentials plugin [3] that works with standard docker username and password authentication, which would also work with JSON key authentication. The main difference between using secrets vs extensions is that extensions do not require any additional yaml configuration.

With that being said, if you want to use your access token to generate short lived GCR credentials, an extensions is your best option. Hope that helps!

[1] [https://docs.drone.io/secret/repository/](https://docs.drone.io/secret/repository/)  
[2] [https://docs.drone.io/secret/organization/](https://docs.drone.io/secret/organization/)  
[3] [https://github.com/drone/drone-registry-plugin](https://github.com/drone/drone-registry-plugin)

---

<div class="post-metadata">

**Author:** ![Gowiem](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/gowiem/32/2739_2.png) [@Gowiem](https://drone.discourse.group/u/Gowiem)\
**Post date:** [October 21, 2020, 8:17pm UTC](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074/19 "2020-10-21T20:17:44Z")

</div>

@bradrydzewski @davidbyttow is drone-ecr-registry-plugin still the best and proper way to setup using / pulling private repositories from ECR? I’m looking to add this without needing to do manual ECR logins as I have 20+ drone files and a handful of plugins I’m managing for a client.

Bear with me as I’m a bit confused on this subject, but if it is still the best way to handle access to ECR, is the below the correct approach to get it working in a Kubernetes cluster?

1. Setup [amazon-ecr-credential-helper](https://github.com/awslabs/amazon-ecr-credential-helper) on all k8s nodes so they have access to ECR.
2. Or should I possibly just be ensuring my cluster has access to ECR via EKS IAM service accounts role?
3. Run [drone-ecr-registry-plugin](https://github.com/davidbyttow/drone-ecr-registry-plugin) as a simple, single Deployment / Pod.
4. Configure the drone agents to use the `DRONE_REGISTRY_ENDPOINT`, `DRONE_REGISTRY_SECRET`, and `DRONE_REGISTRY_VERIFY="false"` parameters to point to the new ecr-registry-plugin address.

Is it that simple? In the above, is `DRONE_REGISTRY_SECRET` any random value and it doesn’t matter what it is as long as the ecr-registry-plugins’ value matches the agents’ configured value? Or does that need to be something like the `DRONE_RPC_SECRET`?

Also, the Drone docs on registry plugins seem to mention `DRONE_REGISTRY_PLUGIN_ENDPOINT` and `DRONE_REGISTRY_PLUGIN_TOKEN`. Are these needed?

Thanks for the direction gents – Appreciate any help!

---

<div class="post-metadata">

**Author:** ![bradrydzewski](https://yyz1.discourse-cdn.com/flex003/user_avatar/drone.discourse.group/bradrydzewski/32/3513_2.png) [@bradrydzewski](https://drone.discourse.group/u/bradrydzewski)\
**Post date:** [October 21, 2020, 9:20pm UTC](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074/20 "2020-10-21T21:20:37Z")

</div>

I recommend installing the following registry extension:

> **[drone/drone-registry-plugin](https://github.com/drone/drone-registry-plugin)**
>
> Registry extension for backward compatibility with 0.8 global registry credentials. - drone/drone-registry-plugin

This extension handles generating the docker username and password for ECR registries, as well as refreshing the username and password which otherwise expire every few hours.  
You can install this extension on a single machine, and then you configure each of your runners to point to this extension.

[Next page](https://drone.discourse.group/t/drone-1-0-and-aws-ecr-going-forward/11074.md?page=2)
