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

Add support for file based secret #1007

Closed
wants to merge 5 commits into from

Conversation

hangyan
Copy link
Contributor

@hangyan hangyan commented May 15, 2018

related to #296

Notes:

  1. External secret is not supported
  2. may have conflict with Add support for Config, endpoint_mode and 3.3 support #994
  3. import a new package cast(https://github.com/spf13/cast)

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 15, 2018
@hangyan hangyan requested review from cdrage, ngtuna and kadel and removed request for cdrage and ngtuna May 15, 2018 03:24
@hangyan
Copy link
Contributor Author

hangyan commented May 15, 2018

/assign cdrage
/assign kadel

@cdrage
Copy link
Member

cdrage commented May 15, 2018

@hangyan Please separate the commits between code change and vendor update so we can review!

@hangyan
Copy link
Contributor Author

hangyan commented May 16, 2018

@cdrage Done. Thanks!

Copy link
Member

@cdrage cdrage left a comment

Choose a reason for hiding this comment

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

Hey @hangyan I see some still work-in-progress code, is this ready for review?

@@ -117,6 +117,7 @@ func parseV3(files []string) (kobject.KomposeObject, error) {
}
}
}
log.Debugf("fuck %+v", config)
Copy link
Member

Choose a reason for hiding this comment

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

I think this needs to be removed 🤣

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cdrage So sorry for this , totally forgot this debug info.

type OldSecretConfig struct {
File string
}
*/
Copy link
Member

Choose a reason for hiding this comment

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

Remove commented out code

}

}*/

Copy link
Member

Choose a reason for hiding this comment

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

Remove commented out code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cdrage This is ready for review. But i have started too long ago and forgot to remove some useless code before this review. Sorry about that! Will be more carefully about this in the future

Copy link
Member

Choose a reason for hiding this comment

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

Since this code is no longer needed, please remove the commented out code 👍 @hangyan

@hangyan hangyan force-pushed the secret-support branch 2 times, most recently from 80648b6 to 75855dc Compare May 16, 2018 13:30
Copy link
Member

@cdrage cdrage left a comment

Choose a reason for hiding this comment

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

I will have to test this out, but other than a few comments, the code is great!

Just add more comments please to the code so future programmers can better understand what is happening, otherwise, looks amazing to me!

}

}*/

Copy link
Member

Choose a reason for hiding this comment

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

Since this code is no longer needed, please remove the commented out code 👍 @hangyan

if config.File != "" {
data, err := GetSecretDataFromFile(config.File, k.Opt)
if err != nil {
log.Fatal("unable to read secret from file:", config.File)
Copy link
Member

Choose a reason for hiding this comment

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

add spacing after "file:"

}
objects = append(objects, secret)
} else {
log.Warnf("External secrets %s is not supported by now - ignoring", name)
Copy link
Member

Choose a reason for hiding this comment

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

small grammar mistake, should be "is not currently supported"

}
}
return volumeMounts, volumes
}
Copy link
Member

Choose a reason for hiding this comment

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

Are you able to comment on some of the code above as to what's happening?

if komposeObject.Secrets != nil {
secrets, err := k.CreateSecrets(komposeObject)
if err != nil {
return nil, errors.Wrapf(err, "create secrets error")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add something different such as "Unable to create secrets" or something more descriptive? Not too sure what type of error message to add.

@@ -449,6 +531,10 @@ func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) (
useHostPath = true
}

secretsVolumeMounts, secretsVolumes := k.ConfigSecretVolumes(name, service)
Copy link
Member

Choose a reason for hiding this comment

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

Add comment above here explaining that we are adding secrets to volumes

@cdrage
Copy link
Member

cdrage commented Jul 24, 2018

Progress @hangyan ?

@hangyan
Copy link
Contributor Author

hangyan commented Jul 25, 2018

@cdrage Sorry, been very busy these days on my work. Working on this now.

@hangyan
Copy link
Contributor Author

hangyan commented Jul 26, 2018

@cdrage Updated

@hangyan
Copy link
Contributor Author

hangyan commented Aug 2, 2018

conflict resolved

@jvitor83
Copy link
Contributor

@cdrage is this good? will be merged?
I need that feature.


volMount := api.VolumeMount{
Name: vol.Name,
MountPath: "/run/secrets",
Copy link
Contributor

Choose a reason for hiding this comment

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

@hangyan
This shouldn't be MountPath: "/run/secrets/" + vol.Name, ???

Because without the MountPath targeting to the secret, it gives a error:

RunContainerError: failed to start container "f97d9e9354548939d15acae70758347538426fbb05c80f2a5cd316dc67e7bf58": 

Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "process_linux.go:359: 

container init caused \"rootfs_linux.go:54: 
mounting \\\"/opt/rke/var/lib/kubelet/pods/516c135b-bce8-11e8-8714-005056ae708d/volumes/kubernetes.io~secret/default-token-khnzc\\\" 
to rootfs \\\"/var/lib/docker/overlay/60fb5d9a4007bf8e1889898df737b275cb77431351b9168ab4d629fbcdf065b5/merged\\\" 
at \\\"/var/lib/docker/overlay/60fb5d9a4007bf8e1889898df737b275cb77431351b9168ab4d629fbcdf065b5/merged/run/secrets/kubernetes.io/serviceaccount\\\" 
caused \\\"mkdir /var/lib/docker/overlay/60fb5d9a4007bf8e1889898df737b275cb77431351b9168ab4d629fbcdf065b5/merged/run/secrets/kubernetes.io: read-only file system\\\"\""

Just like in this issue: kubernetes/kubernetes#65835

And concating the secret name, it work!

Copy link
Contributor

@jvitor83 jvitor83 Sep 21, 2018

Choose a reason for hiding this comment

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

With some research i discover that:

kubernetes

kubectl create secret generic my_secret --from-literal=my_secret_key_1=my_secret_value_1 --from-literal=my_secret_key_2=my_secret_value_2

it create a file /run/secrets/my_secret/my_secret_key_1 (with the content my_secret_value_1)

docker-compose/swarm

  • with short syntax:
...
    secrets:
      - my_secret
secrets:
  my_secret:
    file: my_secret.txt

it create a file /run/secrets/my_secret

don't allow to be compatible with kubernetes

  • with long syntax:
...
    secrets:
      - source: some_secret
        target: my_secret/my_secret_key
secrets:
  some_secret:
    file: my_secret.txt

it create a file /run/secrets/my_secret/my_secret_key

allow to be compatible with kubernetes


I believe that this PR:

  • shouldn't allow to use short-syntax, or if allow, to at least concat the secret name as directory (as my previous comment suggest to avoid the error).
  • only allow long-syntax if has at least inside one directory to be compatible with kubernetes, or at least concat the secret name as directory

Maybe concat the secret name as directory (by default) for the path can be the solution!?!

Copy link
Contributor Author

@hangyan hangyan Oct 2, 2018

Choose a reason for hiding this comment

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

@jvitor83 Sorry about the late response. I have re-checked the document of kubernetes and docker. I have different opinion on this problem. kompose is meant to translate compose to kubernetes as precision as possible. Because docker mount the secret to /run/secrets/<secret-name>, so this path should be the same in kubernetes, not /run/secrets/<secret-name>/<key>. I believe the right choice is to use subPath ( you can see a example in the issues link you provide)

Copy link
Contributor

Choose a reason for hiding this comment

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

I get it that "kompose is meant to translate compose to kubernetes as precision as possible", but it didn't work with the k8s generated!
The generated mapping gives error (mentioned before) and the pod didn't start!

By my understanding, the generated files should work in first place to then keep the translation as precise as possible.

I guess we should remove the short syntax once it is incompatible and don't allow to get the file at the same path.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue link you provide has a solution in the end:subPath. I think it's a better solution, i haven't test it out, but I think it should work

Copy link
Contributor

@jvitor83 jvitor83 Oct 4, 2018

Choose a reason for hiding this comment

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

@hangyan
I am not understanding what you mean.

The thing is that this PR is generating:

        volumeMounts:
        - name: secret-name
          mountPath: "/run/secrets"

which gives the error reported.
The issue (kubernetes/kubernetes#65835) was solved not because it put the subPath, but because the directory was added to the mountPath. (I think the issue author have been mistaken)
If the kompose generate the k8s without the mountPath with a directory (with secret using short-syntax), it will give error on start. I have tested it with openjdk, dotnet and others. All gives the same error.

What you are suggesting to do?
If is to: "modify the code to add the subPath", it will continue to give the error.

I think we have to at least put some warning saying that secrets with short-syntax is not recommended and can gives error.

@jvitor83
Copy link
Contributor

jvitor83 commented Sep 25, 2018

@hangyan , i create a PR ( https://github.com/hangyan/kompose/pull/3/files ) to your secret-support branch (PR) which:

@hangyan
Copy link
Contributor Author

hangyan commented Sep 27, 2018

@jvitor83 Great. Thanks very much. I will review this again ASAP. But since there are not so many active maintainers for this project, this PR may take a long time to be merged in. I'm afraid of you will have to build the binary yourself based on this branch.

@jvitor83
Copy link
Contributor

I'm afraid of you will have to build the binary yourself based on this branch.

Already did it!
Thanks for the feedback.

@cdrage
Copy link
Member

cdrage commented Oct 1, 2018

@hangyan if you want @jvitor83 you can always do a branch of this PR, push your changes and open a new PR. I don't think @hangyan would mind if you continue on his awesome work 👍

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To fully approve this pull request, please assign additional approvers.
We suggest the following additional approver: cdrage

If they are not already assigned, you can assign the PR to them by writing /assign @cdrage in a comment when ready.

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 28, 2019
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Feb 27, 2019
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closed this PR.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@hangyan hangyan deleted the secret-support branch December 27, 2019 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants