containertool: Read default username and password from the environment #119
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
The
--username
and--password
options allow default credentials to be defined. These are used if a corresponding entry cannot be found in.netrc
, or if the--disable-netrc
flag is set. (--username
and--password
should possibly be renamed to--default-username
and--default-password
to make this clearer.)Specifying passwords as command line arguments is generally discouraged because they will then be visible in the the output of tools such as
ps
andtop
. Providing credentials in environment variables avoids this problem, although there may still be other ways for users on the same machine to discover their values.Environment variables are also more convenient than
.netrc
when uploading to registries which use short-lived credentials, such as ECR:In the example above, if .netrc contains credentials for 123456789012.dkr.ecr.us-west-2.amazonaws.com they will be used in preference to the credentials in the environment variables. To avoid this, credentials which are not intended to be used should be removed from .netrc.
Modifications
If the
--username
or--password
flags are not present on the command line, use the values of theCONTAINERTOOL_USERNAME
orCONTAINERTOOL_PASSWORD
environment variables - if defined - as the default credentials.Result
.netrc
frequently.Fixes #105
Test Plan
All existing tests continue to pass.
Tested manually with a registry using short-lived credentials.