Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Add secrets to runtime configuration #1169

Merged

Conversation

sepetrov
Copy link
Contributor

@sepetrov sepetrov commented Sep 8, 2020

Issue Ref: None

Description:

Adds support for using secrets via mounted volumes.

Extends the runtime-images structure in kubeless-config configmap to allow using secrets in the init containers of function deployments, in a similar way as providing environment variables.

Usage:

Manifest for github-token secret.

apiVersion: v1
kind: Secret
metadata:
  name: github-token
type: Opaque
stringData:
  token: foobar

Manifest for kubeless-config configmap

...
data:
  runtime-images: |
    [
        {
            "ID": "go",
            "depName": "go.mod",
            "fileNameSuffix": ".go",
            "versions": [
                {
                    "imagePullSecrets": [{"ImageSecret": "docker-registry"}],
                    "images": [
                        {
                            "command": "docker-entrypoint",
                            "env": {
                                "GITHUB_TOKEN_SECRET_FILE": "/var/run/secrets/kubeless.io/github-token/token",
                                "GOCACHE": "$(KUBELESS_INSTALL_VOLUME)/.cache",
                                "GOPRIVATE": "github.com/acme/*"
                            },
                            "image": "quay.io/acme/kubeless-runtime:go-1.14",
                            "phase": "compilation",
                            "secrets": [{"name": "github-token"}]
                        },
                        {
                            "image": "kubeless/go@sha256:55759228714d7080b3dd858e56530d4e1f539d071906e88d88b454ee3b3c9b16",
                            "phase": "runtime"
                        }
                    ],
                    "name": "go1.14",
                    "version": "1.14"
                }
            ]
        }
    ]
...

The above runtime configuration specified custom image for Go 1.14 runtime with a secret github-token shared with the container as a volume mounted at /var/run/secrets/kubeless.io/{{secret.name}} (/var/run/secrets/kubeless.io/github-token in this example). Now the container can read the GitHub token secret from the filesystem and use it to download private Go packages.

TODOs:

  • Ready to review
  • Automated Tests
  • Docs

@sepetrov sepetrov force-pushed the add-secrets-to-runtime-images branch 2 times, most recently from 05ec2a6 to 3996a76 Compare September 8, 2020 09:42
@sepetrov sepetrov force-pushed the add-secrets-to-runtime-images branch from 3996a76 to 8f25eb8 Compare September 8, 2020 10:27
Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feature! I have a couple of minor comments.

result.InitContainers[i].VolumeMounts = append(result.InitContainers[i].VolumeMounts, v1.VolumeMount{
Name: secret.Name,
ReadOnly: true,
MountPath: "/" + secret.Name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to use an unused subpath like "/etc/secrets/" + secret.Name so you avoid issues with people using as secret name var or run

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @andresmgot , I agree completely, mounting in the root is not ideal - I went for it as a first iteration + AFAIK serverless-kubeless plugin is using this approach.

I am thinking of the following options:

  1. /var/run/secrets/{{secret.name}}
  2. /var/run/secrets/kubeless.io/{{secret.name}}
  3. /opt/secrets/{{secret.name}}
  4. /opt/secrets/kubeless.io/{{secret.name}}

My choice would be 2. Seems consistent with what I see as mounted volumes with secrets in kubernetes.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed mount path to /var/run/secrets/kubeless.io/{{secret.name}}.

- Name: Unique ID of the runtime. It should contain the runtime name and version.
- Version: Major and minor version of the runtime.
- Runtime Image: Image used to execute the function.
- Init Image: Image used for installing the function and/or dependencies.
- (Optional) Image Pull Secrets: Secret required to pull the image in case the repository is private.
- (Optional) Environment variables.
- (Optional) Secrets: Shared with the container as mounted volumes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add here the path in which the secrets are mounted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes!

@andresmgot andresmgot merged commit 25d6376 into vmware-archive:master Sep 9, 2020
@sepetrov sepetrov deleted the add-secrets-to-runtime-images branch September 9, 2020 10:14
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 this pull request may close these issues.

2 participants