CLI: Introduced identity command to fetch tls-certificates for a pod - #5408
Conversation
|
This is so awesome. 😱 Can't wait to test this out |
|
@adleong, did you get the chance to review/test this? |
|
@jimil749 I had a chance to run some basic tests and this looks good! Thanks for your hard work. One thing that I noticed is that the command doesn't write any output when Linkerd isn't installed in the cluster. I had a new kind cluster running without Linkerd installed, and when I ran the In contrast, the $ linkerd stat deploy
Cannot find Linkerd: configmaps "linkerd-config" not found
Validate the install with: linkerd checkWhat do you think about adding a check to make sure that linkerd is installed? |
|
@cpretzer, thanks for the feedback, I'll do the needful. :) |
Signed-off-by: Jimil Desai <jimildesai42@gmail.com>
Signed-off-by: Jimil Desai <jimildesai42@gmail.com>
Signed-off-by: Jimil Desai <jimildesai42@gmail.com>
linkerd#4459) Modified and added a new cli command, which initiates a sni-tls session to the proxy's admin port and returns the certificate. Usage: - linkerd identity pod/<pod-name> : fetches certificate from the specified pod - linkerd identity -n emojivoto : fetches certificate from all pods in the emojivoto namespace - linkerd identity -l app=svc/emoji : fetches certificate from all pods with label app=svc/emoji Signed-off-by: Jimil Desai <jimildesai42@gmail.com>
Signed-off-by: Jimil Desai <jimildesai42@gmail.com>
|
👍 |
|
@cpretzer I think the reason we aren't getting any output is because we do not have the proxy sidecar container injected. The |
Signed-off-by: Jimil Desai <jimildesai42@gmail.com>
|
@cpretzer, Sorry for the delayed response, but I've added the check for the linkerd control plane but I wasn't able to test the command entirely, because I am having an error in installing the control plane in my cluster after fetching the latest commit, which I think is because of this, I am getting the same error as in this comment. Not a 100% sure, but is that the reason the tests are failing? |
|
hi @jimil749 thanks for adding the check for the namespace. We're working on getting the build fixed, and once it is, we can run the tests again. |
adleong
left a comment
There was a problem hiding this comment.
I played with this a little bit and it's pretty great.
I like the linkerd identity (pod-name) mode, though I think we should drop the resource type or at least make it optional since only pods are supported. i.e. instead of linkerd identity pod/linkerd-destination-6887bb8f49-h8qvr it should be linkerd identity linkerd-destination-6887bb8f49-h8qvr
I also like the -l selector mode.
I found the third mode where it prints all certificates in a namespace to be confusing and I think we can remove that.
I also looked into certificate formatting a bit more and found https://github.com/smallstep/certinfo. I think we should use this library for formatting the certificates.
Yeah, makes sense. Will do the necessary changes!
The reason to do was this comment, where it is mentioned that a command like
I will take a look at the library. 👍 |
Summary of changes: - Fetching the certificates in series rather than parallel. - URL trim using `strings.Trim` for `tls.Dial()` - Dropped the resource type from `linkerd identity` command - Removed the `linkerd -n ns` subcommand, which used to fetch certificates for all pods in the provided ns - Used `grantae/certinfo` library to print the certificates in a format similar to OpenSSL - Removed RootCAs field from tls.Dial Signed-off-by: Jimil Desai <jimildesai42@gmail.com>
|
@adleong, I've addressed the changes proposed, here's the summary of the changes:
|
Signed-off-by: Jimil Desai <jimildesai42@gmail.com>
adleong
left a comment
There was a problem hiding this comment.
This is so awesome! I'm really excited for this to land. 😻
- Added check for un-meshed pod - Print pod name for multiple certificates - Removed control-plane check and PEM encoding Signed-off-by: Jimil Desai <jimildesai42@gmail.com>
|
@adleong, I made the changes as suggested. But I was not sure of what exact error message to print out when no certificates are returned. Maybe you could suggest a better message to output? |
kleimkuhler
left a comment
There was a problem hiding this comment.
@jimil749 This is super cool thanks for getting this change up!
I've left a few smaller comments focused around formatting help text and such.
There are a few comments though that are more significant. Let me know if you have any questions about those I'd be glad to clarify a little more!
| if len(arg) > 0 { | ||
| pod, err := clientset.CoreV1().Pods(namespace).Get(ctx, arg[0], metav1.GetOptions{}) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return []corev1.Pod{*pod}, nil | ||
| } |
There was a problem hiding this comment.
So I run the command linkerd identity -n linkerd linkerd-identity-xyz linkerd-destination-xyz.
My expectation for the output would be two certificate outputs, but with only getting the pod arg[0] I only see one.
I think if there len(arg) > 0, then we would want to loop through arg (whether it's 1 or greater) and return that slice of pods.
There was a problem hiding this comment.
Oh alright. To be honest, I had not thought about such a situation, I was under the impression that we just want to fetch cert for a single pod. I will make the required changes! :)
| for _, c := range pod.Spec.Containers { | ||
| for _, p := range c.Ports { | ||
| if p.Name == portName { | ||
| containers = append(containers, c) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
We expect the admin port to be on a linkerd-proxy container right? Can we loop through the containers until we have a container name that matches linkerd-proxy (k8s.ProxyContainerName) and then loop through the ports?
Also, once we have the port we're looking for we can stop looping through both the containers and then ports. We have something similar to this that you can look at here!
Signed-off-by: Jimil Desai <jimildesai42@gmail.com>
|
@kleimkuhler, I've made the required changes! |
kleimkuhler
left a comment
There was a problem hiding this comment.
This looks great! I have one more suggestion to just make sure errors are printing as expected.
After that it should be good. Sorry I did not catch this in the previous review!
Signed-off-by: Jimil Desai <jimildesai42@gmail.com>
|
Thanks for addressing all these reviews @jimil749! |
CLI: Introduced
identitycommand to fetch tls-certificates for a pod (#4459)Modified and added a new cli command, which initiates a sni-tls session to the proxy's admin port and returns the certificate.
Usage:
linkerd identity pod/<pod-name>: fetches certificate from the specified podlinkerd identity -n emojivoto: fetches certificate from all pods in the emojivoto namespacelinkerd identity -l app=svc/emoji: fetches certificate from all pods with label app=svc/emojiCurrently, I am not a 100% sure of the way I am outputting the certificates, I'll change that if needed, but overall these commands do fetch the required certificates.
Screenshot:
I would be happy to work upon any changes suggested