-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand build argument from environment when no value specified #993
Expand build argument from environment when no value specified #993
Conversation
@cvgw As promised... Do I need to add integration test? |
Thank you so much for your contribution! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this addresses the primary use case which is secrets
won't docker -e SOME_SECRET=secret-value run ....
output the value of the secret to the log/shell history?
I think we need a solution that won't be logged out. We also need to audit the logs in kaniko and make sure this value will never be logged. Infact, we should probably write an integration tests that checks the logs to make sure a known secret value is never logged
At least that part can be solved via a .env file. I.e.
with
Granted, that file would need to be written to disk first, but this is a common way to pass along environment variables without exposing them via the command line. |
@tejal29 you're welcome |
@@ -206,6 +207,17 @@ func resolveDockerfilePath() error { | |||
return errors.New("please provide a valid path to a Dockerfile within the build context with --dockerfile") | |||
} | |||
|
|||
// resolveEnvironmentBuildArgs replace build args without value by the same named environment variable | |||
func resolveEnvironmentBuildArgs(arguments []string, resolver func(string) string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this will take an argument like FOO
and replace it with FOO=FOO
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cvgw this will take the argument array such as [ "foo=bar", "EnvVariable" ]
crawl through it and replace any argument without =
with "EnvVariable=EnvValue"
if a value was returned by resolver
function (os.Getenv
in prod code, mocked function in tests). If zero length value returned, it will be replaced with "EnvVariable="
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explaining, cheers
|
||
// Checks if argument are not printed in output. | ||
// Argument may be passed through --build-arg key=value manner or --build-arg key with key in environment | ||
func checkArgsNotPrinted(dockerfile string, out []byte) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this checks to make sure the value of none of the build args are logged? It makes no distinction between whether they were added as literals or expanded from the env?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cvgw I could have make the distinction in the test, however I could not find any way to make the distinction in the code as env like variable (env, arg and meta arg ) are used everywhere as a mere string key=value
and could not make the distinction without breaking everything.
Do you want I change the test? Or everything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No changes needed. Was just clarifying for my owner understanding. I think it's reasonable to not log any ARG values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really nice, just a couple questions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cvgw Thank you for the feed back. I answered .
@@ -206,6 +207,17 @@ func resolveDockerfilePath() error { | |||
return errors.New("please provide a valid path to a Dockerfile within the build context with --dockerfile") | |||
} | |||
|
|||
// resolveEnvironmentBuildArgs replace build args without value by the same named environment variable | |||
func resolveEnvironmentBuildArgs(arguments []string, resolver func(string) string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cvgw this will take the argument array such as [ "foo=bar", "EnvVariable" ]
crawl through it and replace any argument without =
with "EnvVariable=EnvValue"
if a value was returned by resolver
function (os.Getenv
in prod code, mocked function in tests). If zero length value returned, it will be replaced with "EnvVariable="
@@ -206,6 +207,17 @@ func resolveDockerfilePath() error { | |||
return errors.New("please provide a valid path to a Dockerfile within the build context with --dockerfile") | |||
} | |||
|
|||
// resolveEnvironmentBuildArgs replace build args without value by the same named environment variable | |||
func resolveEnvironmentBuildArgs(arguments []string, resolver func(string) string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explaining, cheers
@cvgw something went wrong with kaniko. However, things went well in Travis 🤔... What went wrong? |
@antechrestos i triggered a rebuilt. Previous failure was a flake. |
@tejal29 thanks |
@tejal29 I have rebased my branch. I am not sure it might change anything 🤔 |
@antechrestos The travis test passed, so i am going to merge this in! |
@tejal29 at our own risk 😊 |
THANK YOU! ❤️ |
Thanks this is so helpful (albeit undocumented) feature |
Fixes #713
Description
This change adds the feature of getting value of build argument from environment when build argument is specified as follows
/kaniko/executor .... --build-arg MY_ARGUMENT ...
Submitter Checklist
Reviewer Notes
Release Notes