You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
problems registry 2.0 with S3 backend and IAM instance profiles #701
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:
Setting REGISTRY_STORAGE_S3_SECRETKEY and REGISTRY_STORAGE_S3_ACCESSKEY variables to empty
Setting accesskey and secretkey to empty in the config file
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.
@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.
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):
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.
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.
@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.
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).
@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.
Activity
stevvooe commentedon Jul 16, 2015
@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
AndreyKostov commentedon Jul 16, 2015
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?
BrianBland commentedon Jul 16, 2015
It's possible that setting the access key and secret key as empty config variables or environment variables makes them
nilvalued in the driver parameters map. On this line, they would then be converted to the string value"<nil>", so we might want to handlenilmore 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):
And to retrieve a credentials pair, you can then hit the endpoint for that role name:
tiadobatima commentedon Jul 16, 2015
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.
BrianBland commentedon Jul 16, 2015
To diagnose this environment variable issue, I added the following line to the very beginning of
s3.FromParameters():Then, I tweaked the default config file so that the storage section is:
With no provided environment variables, I see the parameters as defined in the config file:
I then added the bucket and region environment variables:
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.
tiadobatima commentedon Jul 16, 2015
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
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.
stevvooe commentedon Jul 17, 2015
@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.
tiadobatima commentedon Jul 17, 2015
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! :)
stevvooe commentedon Jul 17, 2015
@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!