Skip to content

Dockerng appears to not be using docker registries pillar data #32829

Closed

Description

@tyhunt99

Description of Issue/Question

I am writing a state to pull docker images from AWS ECR registry. The way the credentials passed out by AWS are only valid for 12 hours, so I wrote a custom python pillar to run the proper awscli commands to fetch the credentials and build the pillar data for the registry. Assuming the pillar data is refreshed and with valid credentials for the run the minion still fails with an execption.

The problem is fixed by manually going onto the minion and running docker login, so I would guess it sees the configured auth credentials from a previous docker login and uses them even if they are invalid.

Setup

Here are the relevant salt files for the issue (w/ private info redacted)
This build the docker-registries pillar data

#!py

import subprocess
import re

def run():
    '''
    builds the data structure used by docker states
    '''

    docker = {
        'docker-pkg': {
            'lookup': {
                'version': '1.9.1-0~'+__grains__['oscodename'],
                'config': ['DOCKER_OPTS=" --host=unix:///var/run/docker.sock --storage-driver=aufs"']
            }
        },
        'docker-registries': {
            'https://xxxxxxxxxxxx.dkr.ecr.us-east-1.amazonaws.com': {
                'email': 'none',
                'password': fetchAWSECRCreds(),
                'username': 'AWS'
            }           
        },
        'install_docker_py': True
    }

    return docker

#fetches aws credentials for ecr
#requires awscli to be installed and configured with valid credentials
def fetchAWSECRCreds():
    r = subprocess.Popen(["aws","ecr","get-login"],stdout=subprocess.PIPE)
    p = re.compile(ur'-p (.*) -e')
    test_str = r.stdout.read()
    return re.search(p,test_str).group(1)

Steps to Reproduce Issue

Easiest method to reproduce (using AWS ECR):

  1. Setup pillar data to login with valid credentials and do dockerng.pull (works fine)
  2. Invalidate credentials and try pull again (fails as expected)
  3. Update the credentials making sure to refresh pillar data
  4. Try to pull again and it should fail with the following message

minion log

2016-04-25 15:37:25,231 [requests.packages.urllib3.connectionpool][DEBUG   ][19156] "GET /v1.21/images/json?only_ids=0&all=1 HTTP/1.1" 200 None
2016-04-25 15:37:25,318 [docker.auth.auth ][DEBUG   ][19156] Looking for auth entry for '364535168108.dkr.ecr.us-east-1.amazonaws.com'
2016-04-25 15:37:25,319 [docker.auth.auth ][DEBUG   ][19156] Found u'https://364535168108.dkr.ecr.us-east-1.amazonaws.com'
2016-04-25 15:37:25,319 [docker.api.image ][DEBUG   ][19156] Looking for auth config
2016-04-25 15:37:25,319 [docker.auth.auth ][DEBUG   ][19156] Looking for auth entry for '364535168108.dkr.ecr.us-east-1.amazonaws.com'
2016-04-25 15:37:25,320 [docker.auth.auth ][DEBUG   ][19156] Found u'https://364535168108.dkr.ecr.us-east-1.amazonaws.com'
2016-04-25 15:37:25,320 [docker.api.image ][DEBUG   ][19156] Found auth config
2016-04-25 15:37:25,449 [requests.packages.urllib3.connectionpool][DEBUG   ][19156] "POST /v1.21/images/create?tag=search_alpha&fromImage=364535168108.dkr.ecr.us-east-1.amazonaws.com%2Fjs-sessions HTTP/1.1" 200 None
2016-04-25 15:37:25,467 [salt.minion      ][WARNING ][19156] The minion function caused an exception
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/salt/minion.py", line 1071, in _thread_return
    return_data = func(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/salt/modules/dockerng.py", line 3865, in pull
    _error_detail(errors, item)
  File "/usr/local/lib/python2.7/dist-packages/salt/modules/dockerng.py", line 1058, in _error_detail
    item['errorDetail']['message'],
IndexError: tuple index out of range

Versions Report

Salt Version:
           Salt: 2015.8.7

Dependency Versions:
         Jinja2: 2.8
       M2Crypto: 0.21.1
           Mako: 0.9.1
         PyYAML: 3.11
          PyZMQ: 15.2.0
         Python: 2.7.6 (default, Jun 22 2015, 17:58:13)
           RAET: Not Installed
        Tornado: 4.3
            ZMQ: 4.1.2
           cffi: 1.5.0
       cherrypy: 3.2.2
       dateutil: 2.4.2
          gitdb: 0.5.4
      gitpython: 0.3.2 RC1
          ioflo: Not Installed
        libgit2: 0.23.4
        libnacl: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.7
   mysql-python: 1.2.3
      pycparser: 2.14
       pycrypto: 2.6.1
         pygit2: 0.23.1
   python-gnupg: Not Installed
          smmap: 0.8.2
        timelib: Not Installed

System Versions:
           dist: Ubuntu 14.04 trusty
        machine: x86_64
        release: 3.13.0-71-generic
         system: Ubuntu 14.04 trusty

Activity

  1. tyhunt99 commented on Apr 25, 2016

    @tyhunt99
    Author

    Upon further investigation it appears the exception is unique to AWS ECR repos because they return a special response back when credentials are invalid.

    It also appears the same method can be used for any repository. I tested against a dockerhub repo and it failed under same conditions although the output it returned was not useful. None is always returned with no apparent error. The minion log for this case where I change my docker hub credentials and then update the pillar with new valid credentials follows:

    2016-04-25 17:12:49,857 [salt.minion      ][INFO    ][25465] User sudo_thunt Executing command dockerng.pull with jid 20160425171249852964
    2016-04-25 17:12:49,857 [salt.minion      ][DEBUG   ][25465] Command details {'tgt_type': 'glob', 'jid': '20160425171249852964', 'tgt': 'dev', 'ret': '', 'user': 'sudo_thunt', 'arg': ['index.docker.io/tyhunt99/test:evennewer'], 'fun': 'dockerng.pull'}
    2016-04-25 17:12:49,943 [salt.minion      ][INFO    ][5758] Starting a new job with PID 5758
    2016-04-25 17:12:49,962 [salt.utils       ][TRACE   ][5758] 'nsenter' could not be found in the following search path: ['/usr/local/sbin', '/usr/local/bin', '/usr/bin', '/usr/sbin', '/sbin', '/bin']
    2016-04-25 17:12:49,966 [docker.auth.auth ][DEBUG   ][5758] Found 'auths' section
    2016-04-25 17:12:49,966 [docker.auth.auth ][DEBUG   ][5758] Found entry (registry=u'https://364535168108.dkr.ecr.us-east-1.amazonaws.com', username=u'AWS')
    2016-04-25 17:12:49,966 [docker.auth.auth ][DEBUG   ][5758] Found entry (registry=u'https://index.docker.io/v1/', username=u'tyhunt99')
    2016-04-25 17:12:49,970 [requests.packages.urllib3.connectionpool][DEBUG   ][5758] "GET /version HTTP/1.1" 200 191
    2016-04-25 17:12:49,972 [requests.packages.urllib3.connectionpool][DEBUG   ][5758] "GET /v1.21/version HTTP/1.1" 200 191
    2016-04-25 17:12:49,973 [salt.utils.lazy  ][DEBUG   ][5758] LazyLoaded dockerng.pull
    2016-04-25 17:12:52,140 [requests.packages.urllib3.connectionpool][DEBUG   ][5758] "GET /v1.21/images/json?only_ids=0&all=1 HTTP/1.1" 200 None
    2016-04-25 17:12:52,192 [docker.auth.auth ][DEBUG   ][5758] Looking for auth entry for '364535168108.dkr.ecr.us-east-1.amazonaws.com'
    2016-04-25 17:12:52,192 [docker.auth.auth ][DEBUG   ][5758] Found u'https://364535168108.dkr.ecr.us-east-1.amazonaws.com'
    2016-04-25 17:12:52,192 [docker.auth.auth ][DEBUG   ][5758] Looking for auth entry for 'docker.io'
    2016-04-25 17:12:52,193 [docker.auth.auth ][DEBUG   ][5758] Found u'https://index.docker.io/v1/'
    2016-04-25 17:12:52,193 [docker.api.image ][DEBUG   ][5758] Looking for auth config
    2016-04-25 17:12:52,193 [docker.auth.auth ][DEBUG   ][5758] Looking for auth entry for 'docker.io'
    2016-04-25 17:12:52,193 [docker.auth.auth ][DEBUG   ][5758] Found u'https://index.docker.io/v1/'
    2016-04-25 17:12:52,194 [docker.api.image ][DEBUG   ][5758] Found auth config
    2016-04-25 17:12:52,251 [requests.packages.urllib3.connectionpool][DEBUG   ][5758] "POST /v1.21/images/create?tag=evennewer&fromImage=index.docker.io%2Ftyhunt99%2Ftest HTTP/1.1" 200 None
    2016-04-25 17:12:52,701 [requests.packages.urllib3.connectionpool][DEBUG   ][5758] "GET /v1.21/images/index.docker.io%2Ftyhunt99%2Ftest%3Aevennewer/json HTTP/1.1" 200 1150
    2016-04-25 17:12:52,702 [salt.minion      ][DEBUG   ][5758] Minion return retry timer set to 8 seconds (randomized)
    2016-04-25 17:12:52,702 [salt.minion      ][INFO    ][5758] Returning information for job: 20160425171249852964
    

    Not sure if it is relevant but using the docker cli tool with invalid credentials simply returns no image found even when the image exists.

  2. tyhunt99 commented on Apr 25, 2016

    @tyhunt99
    Author

    Even further investigation seems to indicate if there is not a .docker/config file present then it will use the credentials stored in the pillar data, otherwise it will use whatever is in the config file without a way to force an override.

  3. added
    bug
    severity-medium
    P3
    Platform
    on Apr 26, 2016
  4. added this to the Approved milestone on Apr 26, 2016
  5. jfindlay commented on Apr 26, 2016

    @jfindlay
    Contributor

    @tyhunt99, thanks for the excellent investigative work here.

  6. rallytime commented on Apr 26, 2016

    @rallytime
    Contributor

    @ticosax This might be one you're interested in.

  7. ticosax commented on Apr 26, 2016

    @ticosax
    Contributor

    @rallytime Yes, I saw that issue, but it is not my priority at the moment, as I'm not affected by that bug.
    So if someone is in need of an immediate fix, better you grab it yourself.
    I'll let a comment here once I'll start working on it.

  8. rallytime commented on Apr 26, 2016

    @rallytime
    Contributor

    No problem. I knew you'd been working on some of these. Thanks for the update!

  9. tyhunt99 commented on Aug 23, 2016

    @tyhunt99
    Author

    I have a super simple fix which solves the problem but I am not sure if it valid for all cases. If you simply pass reauth=True to the docker-py login function it will always use the credentials passed in.

    This seems valid to me because you are using the credentials passed in via pillar data which need to always be valid anyways for it to work.

    But I can also see a possible use case of maybe having one thing ensure the .docker/config file exists and then rely on that for further calls.

    If it is the former it is super easy and quick to implement a fix. The latter will require a little more though and design

  10. added a commit that references this issue on Oct 13, 2016
    39cd3ca
  11. added a commit that references this issue on Nov 23, 2016
    5b0c11a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Execution-ModuleP3PillarPlatformbugseverity-medium

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions