Skip to content

Configuration: no longer hardcode mesh certs#12189

Merged
rshriram merged 12 commits intoistio:masterfrom
drichelson:configurableMeshCerts
Mar 10, 2019
Merged

Configuration: no longer hardcode mesh certs#12189
rshriram merged 12 commits intoistio:masterfrom
drichelson:configurableMeshCerts

Conversation

@drichelson
Copy link
Copy Markdown
Contributor

@drichelson drichelson commented Mar 1, 2019

Addresses #11984

Follow-on to #12142 (closed)

…Discovery: no longer hardcode Envoy listener cert paths.
@istio-testing
Copy link
Copy Markdown
Collaborator

Hi @drichelson. Thanks for your PR.

I'm waiting for a istio member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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.

path.Join(model.AuthCertsPath, model.KeyFilename),
path.Join(model.AuthCertsPath, model.RootCertFilename),
}
if role.Type == model.Ingress {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@rshriram mentioned that we probably don't need this. Can this be confirmed? if not I'd prefer to remove it in a separate PR in case it needs to be reverted.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

keep it for now


// setupFilterChains sets up filter chains based on authentication policy.
func setupFilterChains(authnPolicy *authn.Policy, sdsUdsPath string, sdsUseTrustworthyJwt, sdsUseNormalJwt bool, meta map[string]string) []plugin.FilterChain {
func setupFilterChains(authnPolicy *authn.Policy, serverCertPaths *meshconfig.ServerCertPaths, sdsUdsPath string, sdsUseTrustworthyJwt, sdsUseNormalJwt bool, meta map[string]string) []plugin.FilterChain {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

line is 204 characters (from lll)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

port := in.ServiceInstance.Endpoint.ServicePort
authnPolicy := model.GetConsolidateAuthenticationPolicy(in.Env.IstioConfigStore, in.ServiceInstance.Service, port)
return setupFilterChains(authnPolicy, in.Env.Mesh.SdsUdsPath, in.Env.Mesh.EnableSdsTokenMount, in.Env.Mesh.SdsUseK8SSaJwt, in.Node.Metadata)
return setupFilterChains(authnPolicy, in.Env.Mesh.MeshTrafficServerCertPaths, in.Env.Mesh.SdsUdsPath, in.Env.Mesh.EnableSdsTokenMount, in.Env.Mesh.SdsUseK8SSaJwt, in.Node.Metadata)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

line is 181 characters (from lll)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

}
for _, c := range cases {
if got := setupFilterChains(c.in, c.sdsUdsPath, c.useTrustworthyJwt, c.useNormalJwt, map[string]string{}); !reflect.DeepEqual(got, c.expected) {
if got := setupFilterChains(c.in, c.serverCertPaths, c.sdsUdsPath, c.useTrustworthyJwt, c.useNormalJwt, map[string]string{}); !reflect.DeepEqual(got, c.expected) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

line is 165 characters (from lll)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

@rshriram
Copy link
Copy Markdown
Member

rshriram commented Mar 4, 2019

/ok-to-test

@istio-testing istio-testing added ok-to-test Set this label allow normal testing to take place for a PR not submitted by an Istio org member. and removed needs-ok-to-test labels Mar 4, 2019
@rshriram
Copy link
Copy Markdown
Member

rshriram commented Mar 4, 2019

You are missing changes to cluster.go (istio mtls setting client side)

@drichelson
Copy link
Copy Markdown
Contributor Author

@rshriram

You are missing changes to cluster.go (istio mtls setting client side)
I've updated the PR comments noting that this only covers TLSSettings_MUTUAL mode.

Based on my reading of cluster.go: when in TLSSettings_MUTUAL mode we always pull mTLS client cert paths from DestinationRules. Based on this the client certs are already configurable, so we're covered.

Only in when in TLSSettings_ISTIO_MUTUAL mode do we use the hardcoded client certs when building clusters.

Does this make sense? It looks like wiring in the client cert paths for ISTIO_MUTUAL mode will be a bit more gnarly.

NodeMetadataDNSDomains = "DNS_DOMAINS"

// NodeMetadataTlsServerCertChain is the absolute path to server cert-chain file
NodeMetadataTlsServerCertChain = "TLS_SERVER_CERT_CHAIN"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

const NodeMetadataTlsServerCertChain should be NodeMetadataTLSServerCertChain (from golint)

NodeMetadataTlsServerCertChain = "TLS_SERVER_CERT_CHAIN"

// NodeMetadataTlsServerKey is the absolute path to server private key file
NodeMetadataTlsServerKey = "TLS_SERVER_KEY"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

const NodeMetadataTlsServerKey should be NodeMetadataTLSServerKey (from golint)

NodeMetadataTlsServerKey = "TLS_SERVER_KEY"

// NodeMetadataTlsServerRootCert is the absolute path to server root cert file
NodeMetadataTlsServerRootCert = "TLS_SERVER_ROOT_CERT"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

const NodeMetadataTlsServerRootCert should be NodeMetadataTLSServerRootCert (from golint)

NodeMetadataTlsServerRootCert = "TLS_SERVER_ROOT_CERT"

// NodeMetadataTlsClientCertChain is the absolute path to client cert-chain file
NodeMetadataTlsClientCertChain = "TLS_CLIENT_CERT_CHAIN"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

const NodeMetadataTlsClientCertChain should be NodeMetadataTLSClientCertChain (from golint)

NodeMetadataTlsClientCertChain = "TLS_CLIENT_CERT_CHAIN"

// NodeMetadataTlsClientKey is the absolute path to client private key file
NodeMetadataTlsClientKey = "TLS_CLIENT_KEY"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

const NodeMetadataTlsClientKey should be NodeMetadataTLSClientKey (from golint)

NodeMetadataTlsClientKey = "TLS_CLIENT_KEY"

// NodeMetadataTlsClientRootCert is the absolute path to client root cert file
NodeMetadataTlsClientRootCert = "TLS_CLIENT_ROOT_CERT"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

const NodeMetadataTlsClientRootCert should be NodeMetadataTLSClientRootCert (from golint)

role.TrustDomain = spiffe.GetTrustDomain()
log.Infof("Proxy role: %#v", role)

// Add cert paths as node metadata only if they differ from defaults
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should we always set the metadata? we handle the absence of these fields properly in Pilot-discovery.

@costinm
Copy link
Copy Markdown
Contributor

costinm commented Mar 5, 2019

Do you need to customize the names of the files, or just the directory ? I can see the use case for using a different dir - that's why we have the base dir. ( and watching the base dir is indeed needed - again, the base was mostly intended for local testing - with the plan to move to SDS ).

It feels far too complicated for something that will soon be dead code - and our tradition of paying technical debt and removing dead code is not so great. In general the entire watching business has
major problems - it would be much better to just spend less effort writing a small SDS server that watches files, which will address the reload-without-restart problem as well.

@drichelson
Copy link
Copy Markdown
Contributor Author

drichelson commented Mar 5, 2019

@costinm

Do you need to customize the names of the files, or just the directory ?

We need the path to each cert/key to be custom. This includes separate keys/certs for client and server connections.

I can see the use case for using a different dir - that's why we have the base dir. ( and watching the > base dir is indeed needed - again, the base was mostly intended for local testing - with the plan to > move to SDS ).

It feels far too complicated for something that will soon be dead code - and our tradition of paying technical debt and removing dead code is not so great. In general the entire watching business has
major problems -

it would be much better to just spend less effort writing a small SDS server that watches files, which will address the reload-without-restart problem as well.

A small SDS server makes sense to simplify Pilot-Agent and envoy hot restarts. The changes I made here to watcher code and agent config will be useful and needed for our use case if/when that happens.

@drichelson
Copy link
Copy Markdown
Contributor Author

@rshriram any thoughts on these changes?

tls *networking.TLSSettings,
serviceAccounts []string,
sni string,
metadata map[string]string,
Copy link