Skip to content

problems registry 2.0 with S3 backend and IAM instance profiles  #701

Closed

Description

@tiadobatima

According to a comment in the S3 driver, instance profiles should work, but this I'm having problems with it.

The driver config and environment variable overrides are pretty finicky, but I managed to get it working if I set the access/secret keys in REGISTRY_STORAGE_S3_SECRETKEY and REGISTRY_STORAGE_S3_ACCESSKEY. Finicky because it looks like for s3 to work, bucket and region must be set with the config file only (env variable override doesn't seem to work fully).

Anyways, the goal is to use instance profiles, so I tried not setting access and secret key in a variety of ways:

  1. Setting REGISTRY_STORAGE_S3_SECRETKEY and REGISTRY_STORAGE_S3_ACCESSKEY variables to empty
  2. Setting accesskey and secretkey to empty in the config file
  3. Unsetting REGISTRY_STORAGE_S3_ACCESSKEY and REGISTRY_STORAGE_S3_ACCESSKEY. Ie, removing them from the environment.

In cases 1 and 2 I get this error:

panic: The AWS Access Key Id you provided does not exist in our records.

In case 3 I get:

panic: Access Denied

This is the bash history for each of these cases.

Thanks :)

Activity

  1. stevvooe commented on Jul 16, 2015

    @stevvooe
    Collaborator

    @tiadobatima The correct configuration for this is to not set the environment variables or the configuration values. Either way, if they are empty, they will be resolved through the instance credentials. These are checked on startup with a round trip to the backend, which is why we see a panic.

    I would recommend that you check to ensure the instance profiles are accessible from the registry. The code that resolves this is GetInstanceProfiles. If that seems normal, double check your s3 configuration and access keys in another tool to see if they are working correctly.

    cc @BrianBland @AndreyKostov

  2. AndreyKostov commented on Jul 16, 2015

    @AndreyKostov
    Contributor

    Hey guys, so this line:
    https://github.com/docker/distribution/blob/master/registry/storage/driver/s3/s3.go#L202
    should properly get an auth token if either the secret key or the access key is empty.
    Here's the GetAuth code that does this
    https://github.com/AdRoll/goamz/blob/b0a456ecbd5367f922900045462906715ca794a5/aws/aws.go#L346
    if you look at it, you'll notice that it has to reach that line and it will do so if either access key or secret key are empty strings. My guess then is that in the s3 driver code, the secret key and access key parameter are somehow not empty strings, even when you go out of your way not to set them. Maybe trace the code for how they get there see what they are at the s3 driver level in debug mode?

  3. BrianBland commented on Jul 16, 2015

    @BrianBland
    Contributor

    It's possible that setting the access key and secret key as empty config variables or environment variables makes them nil valued in the driver parameters map. On this line, they would then be converted to the string value "<nil>", so we might want to handle nil more gracefully.

    Given your scenario 3, I'd definitely recommend validating that the instance has valid role credentials.
    The following command should output the role name associated with the instance (if any):

    curl http://169.254.169.254/latest/meta-data/iam/security-credentials/

    And to retrieve a credentials pair, you can then hit the endpoint for that role name:

    curl http://169.254.169.254/latest/meta-data/iam/security-credentials/<role_name>
  4. tiadobatima commented on Jul 16, 2015

    @tiadobatima
    Author

    Thanks guys!

    From the 3 scenarios I described just 1 and 2 are actually valid (and related). As @BrianBland mentioned, it indeed looks like a nil type of problem... python loads empty yaml dict keys as None, so I imagine go must do something similar.

    It would be more user friendly to fallback to IAM instance credentials if the environment variables or the config keys exist but are empty. Or at least update the docs for now.

    The 3rd scenario was a problem with my IAM instance profile policies (I was just giving list permissions to the folder).

    Regarding the problem with overriding the default config with the environment variables, it looks like I'm not the only one:
    REGISTRY_STORAGE_S3_BUCKET and REGISTRY_STORAGE_S3_REGION don't seem to be overriding the config, and we have to end up mounting a config file for S3 to work.

    Thank you very much for looking into this guys.

  5. BrianBland commented on Jul 16, 2015

    @BrianBland
    Contributor

    To diagnose this environment variable issue, I added the following line to the very beginning of s3.FromParameters():

    fmt.Printf("Params: %+v\n", parameters)

    Then, I tweaked the default config file so that the storage section is:

    storage:
        cache:
            blobdescriptor: redis
        s3:
            rootdirectory: /var/lib/registry
            bucket: bad
            region: us-west-2
        maintenance:
            uploadpurging:
                enabled: false

    With no provided environment variables, I see the parameters as defined in the config file:

    $ ./bin/registry cmd/registry/config.yml
    Params: map[region:us-west-2 rootdirectory:/var/lib/registry bucket:bad]

    I then added the bucket and region environment variables:

    $ REGISTRY_STORAGE_S3_BUCKET=bukkit REGISTRY_STORAGE_S3_REGION=us-east-1 ./bin/registry cmd/registry/config.yml
    Params: map[rootdirectory:/var/lib/registry bucket:bukkit region:us-east-1]

    tl;dr I can't reproduce this, but I'd like to fix it if you can give me an example repro.

    For clarification, this test was done on the current master branch.

  6. tiadobatima commented on Jul 16, 2015

    @tiadobatima
    Author

    Good documentation here. Never used go before, and was able to test this in just over half an hour!

    Anyways... As @BrianBland demonstrated, it works just fine when the storage is already set to s3 in the config.

    But the storage in the default config (cmd/registry/config.yml) is filesystem, so in order to override that to s3, we must set REGISTRY_STORAGE=s3, as well as the other keys underneath it (ie REGISTRY_STORAGE_S3_BUCKET, REGISTRY_STORAGE_S3_REGION...)

    I did read the note in the registry docs, but to me it kindda sounds like by specifying the full nested env variable (eg REGISTRY_STORAGE_S3_BUCKET), the storage dictionary would be automatically overridden

    Note: If an environment variable changes a map value into a string, such as replacing the storage driver type with REGISTRY_STORAGE=filesystem, then all sub-fields will be erased. As such, specifying the storage type in the environment will remove all parameters related to the old storage configuration.
    

    Maybe the doc should be more explicit... I imagine most people use S3 as backend. In any case, it's nice that we don't have to do mounts to get this going.

    Thank you very much for the help!
    g.

  7. stevvooe commented on Jul 17, 2015

    @stevvooe
    Collaborator

    @tiadobatima Generally, we don't recommend configuring the entire instance with environment variables. The configuration is hierarchical and the mapping to environment variables is flaky. Effectively, there is no way "delete" the filesytem driver which is default. If you're running in production, it's worth the small amount of time it takes to define a Dockerfile with a different configuration file. It will save a lot of headache. We may make this easier, but it is a low priority.

    From your last message, it sounds like we can close this. Let us know if you have further issues.

  8. tiadobatima commented on Jul 17, 2015

    @tiadobatima
    Author

    Good to know that @stevvooe

    I'm trying to get saltstack formula for docker in a better state, and the environment variables are sure a nice way of configuring it. But if they aren't to be trusted, maybe we should mount the generated config file onto the path of the default config (cmd/registry/config.yml).

    What do you think of this solution?

    Thanks! :)

  9. stevvooe commented on Jul 17, 2015

    @stevvooe
    Collaborator

    @tiadobatima I understand the desire to use env variables but the current configuration system is designed to use these to tweak a mostly complete configuration rather than replace the default.

    Mounting is a sufficient solution.

    Thanks for your understanding!

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions