Skip to content
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

Support for buildkit --secret option #785

Closed
ehengao opened this issue Mar 23, 2020 · 11 comments
Closed

Support for buildkit --secret option #785

ehengao opened this issue Mar 23, 2020 · 11 comments

Comments

@ehengao
Copy link

ehengao commented Mar 23, 2020

Expected Behaviour

When use docker buildkit to build the function images, there is a feature to use --secret option to create a safer build enviroment, the typical usecase would be when user has a private pypi repository or private gitlab repository which require senstive access information to download in order to install these packages as part of dependency for the function. Currently, the faas-cli build command does not have any option to pass in the secret arguments.

Current Behaviour

Currently, the faas-cli build only have build-arg and build-options that pass sepecific key, value arguements for docker build api. Do not have a way to pass the --secret options and its arguments to the docker build api when buildkit is enabled.

Possible Solution

Add another flags "--buildkit-extra" to pass in the addtional arguments to the docker buildkit.
And this options only applicable when user has enabled DOCKER_BUILDKIT=1.

Steps to Reproduce (for bugs)

Context

Your Environment

  • FaaS-CLI version ( Full output from: faas-cli version ):0.12.1

  • Docker version ( Full output from: docker version ):19.03.8

  • Are you using Docker Swarm (FaaS-swarm ) or Kubernetes (FaaS-netes)? faas-swarm

  • Operating System and version (e.g. Linux, Windows, MacOS): Linux

  • Link to your project or a code example to reproduce issue: N/A

@alexellis
Copy link
Member

Thanks for raising your request @ehengao

I'm pinging @LucasRoesler, we're talking about how to support it in the context of #773

@LucasRoesler
Copy link
Member

LucasRoesler commented Mar 31, 2020

In context of #773, we descussed the idea of having the ability to pass through arbitrary flags

Perhaps with #773 , we can extend

type BuildConfig struct {
	BuildArgs map[string]string `yaml:"build_args"`
}

to have be

type BuildConfig struct {
	BuildArgs map[string]string `yaml:"build_args"`
	BuildFlags []PassThroughFlag `yaml:"build_flags"`
}

type PassThroughFlag struct {
	Name string
	Value string
}

in yaml, for this secret flag it would look like

build_config:
    build_flags:
    - name: secret
      value: id=mysecret,src=mysecret.txt

the corresponding CLI flag would be a repeatable

faas-cli build --build-flag secret=id=mysecret,src=mysecret.txt

For long flags we would probably just split on the first =. I am not sure it would cleanly support short flags though.

These flags can be passed directly to the builder.

@ehengao
Copy link
Author

ehengao commented Apr 10, 2020

@LucasRoesler, one question, are we supporting putting environment variable into the yaml file?

build_config:
    build_flags:
    - name: secret
      value: id=netrc,src=${HOME}/.netrc

It would be nice to have to resolve the environmnets during runtime, so the yml file is pretty documented for build environment.

@LucasRoesler
Copy link
Member

This is already supported

@talhof8
Copy link

talhof8 commented Oct 17, 2020

Any news?

@LucasRoesler
Copy link
Member

#842 is related, in wanting to access other flags on the builder. I think #785 (comment) would allow us to solve both cases, if we decide to add direct support for additional flags to the cli/stack

@goncalo-oliveira
Copy link

Using sensitive information on a build process is somewhat common if you're not working with open source. I think most scenarios would be using private package/source registries, although I'm sure there are others. ARGS are not suitable to pass through this sensitive information, as it is retained in the image history, making it vulnerable to anyone with access to the build cache or the built layers.
BuildKit support for secrets is a safe alternative, supported since Docker 18.09 (I think) and it would be nice to have a way to integrate with it directly from the faas-cli.

As to how it should be done, I think I would rather see a --secret or --build-secret flag explicitly for this, even if that worked as an alias for the mentioned --build-flags, though, that's just my opinion.

As a workaround, I'm using --shrinkwrap followed by a docker build.

@alexellis
Copy link
Member

Given that buildkit's secrets mechanism is not compatible with other container builders such as kaniko, podman and cloud builders, coupling to this solution may exclude a bunch of users.

What would make --shrinkwrap + DOCKER_BUILDKIT=1 docker build easier to use as a solution here?

@goncalo-oliveira
Copy link

Given that buildkit's secrets mechanism is not compatible with other container builders such as kaniko, podman and cloud builders, coupling to this solution may exclude a bunch of users.

Makes sense. In that case, I think the best option would be #785 (comment). That way, the solution is builder-agnostic.

@alexellis
Copy link
Member

This feature will be available for OpenFaaS Pro customers.

If you're a customer, please get in touch for instructions on how to use it with our supported templates.

@alexellis
Copy link
Member

/lock: resolved

@derek derek bot locked and limited conversation to collaborators Oct 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants