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

Enable TLS for connect-inject #181

Merged
merged 6 commits into from
Dec 18, 2019
Merged

Enable TLS for connect-inject #181

merged 6 commits into from
Dec 18, 2019

Conversation

ishustava
Copy link
Contributor

@ishustava ishustava commented Dec 17, 2019

  • Add new flag -consul-ca-cert
  • Make Consul addresses use HTTPS if CA is provided
  • Provide CA certificate to the init and both sidecar containers,
    so that service registration and envoy bootstrapping
    can use TLS.

This PR has a slightly different approach to what was proposed in #30 and assumes the implementation in the hashicorp/consul-helm#313.

Fixes #79

* Add new flag -consul-ca-cert
* Make Consul addresses use HTTPS if CA is provided
* Provide CA certificate to the init and both sidecar containers,
  so that service registration and envoy bootstrapping
  can use TLS.
@ishustava ishustava requested a review from a team December 17, 2019 18:56
@ishustava ishustava added theme/tls About running Consul with TLS area/connect Related to Connect service mesh, e.g. injection labels Dec 17, 2019
subcommand/inject-connect/command.go Outdated Show resolved Hide resolved
export CONSUL_GRPC_ADDR="https://${HOST_IP}:8502"
export CONSUL_CACERT=/consul/connect-inject/consul-ca.pem
cat <<EOF >/consul/connect-inject/consul-ca.pem
{{ .ConsulCACert }}
Copy link
Member

Choose a reason for hiding this comment

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

Why do this instead of mounting in the same volume in the initContainer?

Copy link
Member

Choose a reason for hiding this comment

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

We talked offline and this makes sense to me now based on the tradeoffs. It's nicer than mounting in a secret and fits with the pattern we're following where everything lives in that directory (like the acl token file)

Co-Authored-By: Luke Kysow <1034429+lkysow@users.noreply.github.com>
Copy link
Member

@lkysow lkysow left a comment

Choose a reason for hiding this comment

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

Looks good. I think it's okay to merge after my comments are addressed but lmk if you want another review

@@ -14,6 +14,12 @@ func (h *Handler) lifecycleSidecar(pod *corev1.Pod) corev1.Container {
if h.AuthMethod != "" {
command = append(command, "-token-file=/consul/connect-inject/acl-token")
}
if h.ConsulCACert != "" {
command = append(command, "-http-addr", "https://${HOST_IP}:8501")
command = append(command, "-ca-file", "/consul/connect-inject/consul-ca.pem")
Copy link
Member

Choose a reason for hiding this comment

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

Lets make this a constant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm ok, I think we should make acl token an env variable too to keep it consistent.

@@ -28,12 +34,6 @@ func (h *Handler) lifecycleSidecar(pod *corev1.Pod) corev1.Container {
FieldRef: &corev1.ObjectFieldSelector{FieldPath: "status.hostIP"},
},
},
// Kubernetes will interpolate HOST_IP when creating this environment
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to keep that comment, maybe on lines 18 and 21?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added this back!

subcommand/inject-connect/command.go Outdated Show resolved Hide resolved
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestHandlerContainerSidecar(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

this is now "envoySidecar" I thnk

Copy link
Member

Choose a reason for hiding this comment

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

and this file should be renamed IIRC

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep yep! thank you!

}, nil
}
if h.ConsulCACert != "" {
caCertEnvVar := corev1.EnvVar{
Copy link
Member

Choose a reason for hiding this comment

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

I don't personally see the benefit of these extra vars, but personal preference

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed so that preStop command will succeed.

connect-inject/handler.go Outdated Show resolved Hide resolved
subcommand/inject-connect/command.go Outdated Show resolved Hide resolved
ishustava and others added 4 commits December 18, 2019 12:41
Co-Authored-By: Luke Kysow <1034429+lkysow@users.noreply.github.com>
Co-Authored-By: Luke Kysow <1034429+lkysow@users.noreply.github.com>
Co-Authored-By: Luke Kysow <1034429+lkysow@users.noreply.github.com>
@ishustava ishustava merged commit dbc5157 into master Dec 18, 2019
@ishustava ishustava deleted the enable-tls-connect-inject branch December 18, 2019 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/connect Related to Connect service mesh, e.g. injection theme/tls About running Consul with TLS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

consul-k8s Connect inject does not support consul with TLS enabled and HTTP disabled.
2 participants