Skip to content

feat: adding support for ext auth and backend mtls#3441

Merged
guydc merged 6 commits intoenvoyproxy:mainfrom
alexwo:upstream_mtls
May 24, 2024
Merged

feat: adding support for ext auth and backend mtls#3441
guydc merged 6 commits intoenvoyproxy:mainfrom
alexwo:upstream_mtls

Conversation

@alexwo
Copy link
Copy Markdown
Contributor

@alexwo alexwo commented May 20, 2024

What this PR does / why we need it:
This enables the use of a shared client certificate with Envoy proxies when accessing external services or backends.

Approach:
We introduce the capability to associate a TLS client certificate with the global configuration of an Envoy proxy. When configured, this client certificate will be used by the proxies when connecting to specified backends or external services.

Which issue(s) this PR fixes:
#2536

@alexwo alexwo requested a review from a team as a code owner May 20, 2024 18:01
@codecov
Copy link
Copy Markdown

codecov bot commented May 20, 2024

Codecov Report

Attention: Patch coverage is 67.36842% with 31 lines in your changes are missing coverage. Please review.

Project coverage is 67.18%. Comparing base (2880a55) to head (5edafcd).

Files Patch % Lines
internal/xds/translator/translator.go 15.00% 14 Missing and 3 partials ⚠️
internal/provider/kubernetes/controller.go 23.52% 13 Missing ⚠️
internal/gatewayapi/backendtlspolicy.go 97.91% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3441      +/-   ##
==========================================
+ Coverage   67.15%   67.18%   +0.02%     
==========================================
  Files         166      166              
  Lines       19463    19544      +81     
==========================================
+ Hits        13071    13131      +60     
- Misses       5447     5469      +22     
+ Partials      945      944       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alexwo
Copy link
Copy Markdown
Contributor Author

alexwo commented May 20, 2024

@alexwo Thanks for working on this!

Could you please add e2e tests to this PR directly? This is not a very large PR, incorporating these tests would not be a burden for reviewers.

Hi @zhaohuabing ,

Sure, I have added the e2e tests as part of this PR.

@alexwo
Copy link
Copy Markdown
Contributor Author

alexwo commented May 21, 2024

/retest

2 similar comments
@alexwo
Copy link
Copy Markdown
Contributor Author

alexwo commented May 21, 2024

/retest

@alexwo
Copy link
Copy Markdown
Contributor Author

alexwo commented May 21, 2024

/retest

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.

According to the API comment, should the namespace of the client secret be the same as the EnvoyProxy resource?

This secret should be located within the same namespace as the Envoy proxy resource that references it.

Copy link
Copy Markdown
Contributor Author

@alexwo alexwo May 22, 2024

Choose a reason for hiding this comment

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

Suggested change
ns := ptr.Deref(resources.EnvoyProxy.Spec.BackendTLS.ClientCertificateRef.Namespace, "")
ns := ptr.Deref(resources.EnvoyProxy.Spec.BackendTLS.ClientCertificateRef.Namespace, "")

Yes, was actually unsure if we should restrict this, perhaps the we should just allow any namespace. For now i have removed this comment. let me know incase you think thats interesting.

Copy link
Copy Markdown
Member

@zhaohuabing zhaohuabing May 22, 2024

Choose a reason for hiding this comment

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

IMO, It makes sense to create the secret in the same namespace because it's only used by the EnvoyProxy resource, and the other EG API does the similar.

Copy link
Copy Markdown
Contributor Author

@alexwo alexwo May 23, 2024

Choose a reason for hiding this comment

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

Great, I had similar thoughts. I have just added it back, with a restriction.

@alexwo
Copy link
Copy Markdown
Contributor Author

alexwo commented May 22, 2024

/retest

4 similar comments
@alexwo
Copy link
Copy Markdown
Contributor Author

alexwo commented May 22, 2024

/retest

@alexwo
Copy link
Copy Markdown
Contributor Author

alexwo commented May 22, 2024

/retest

@alexwo
Copy link
Copy Markdown
Contributor Author

alexwo commented May 22, 2024

/retest

@alexwo
Copy link
Copy Markdown
Contributor Author

alexwo commented May 22, 2024

/retest

alexwo added 3 commits May 23, 2024 08:26
Signed-off-by: Alexander Volchok <alex.volchok@sap.com>
Signed-off-by: Alexander Volchok <alex.volchok@sap.com>
Signed-off-by: Alexander Volchok <alex.volchok@sap.com>
@alexwo
Copy link
Copy Markdown
Contributor Author

alexwo commented May 23, 2024

/retest

Signed-off-by: Alexander Volchok <alex.volchok@sap.com>
@alexwo
Copy link
Copy Markdown
Contributor Author

alexwo commented May 23, 2024

/retest

alexwo added 2 commits May 23, 2024 12:13
Signed-off-by: Alexander Volchok <alex.volchok@sap.com>
Signed-off-by: Alexander Volchok <alex.volchok@sap.com>
Copy link
Copy Markdown
Contributor

@arkodg arkodg left a comment

Choose a reason for hiding this comment

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

LGTM thanks !

@arkodg arkodg requested review from a team and zhaohuabing May 23, 2024 22:57
Copy link
Copy Markdown
Contributor

@guydc guydc left a comment

Choose a reason for hiding this comment

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

Thanks, this looks great overall, some comments around testing mostly. Can be fixed in a follow-up PR.

}
}

// process envoy gateway secret refs
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.

Should we also update predicates.go, indexers.go to make sure that a change in the secret triggers a reconcile and lookup is efficient?

ConformanceTests = append(ConformanceTests, UpstreamTLSSettingsTest)
}

var UpstreamTLSSettingsTest = suite.ConformanceTest{
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.

nit: maybe use Backend instead of Upstream for all names here??

port: 443
targetPort: 8443
---
apiVersion: apps/v1
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.

maybe use a different name for the deployment, secrets, etc. to make sure that this doesn't conflict with other tests from conformance/e2e suites

certificateRefs:
- group: ""
kind: Secret
name: backend-tls-certificate
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.

Do we really need this? We can have HTTP => HTTPS upgrade in backend TLS tests..

MaxVersion: ptr.To(v1alpha1.TLSv12),
Ciphers: []string{"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"},
}
err = UpdateProxyConfig(suite.Client, proxyNN, config)
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.

Can we maybe create multiple EP resources as part of the test data and just change the reference from the GWC?

t.Error(err)
}
expectedRes.TLS.Version = "TLSv1.2"
expectedRes.TLS.CipherSuite = "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"
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.

maybe another yaml here for the expected result?

TLS TLSInfo `json:"tls"`
}

type TLSInfo struct {
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.

Can we somehow reuse the gateway-api test util structs by extending them here?

return hasAllFieldsAndValuesRecursive(reflect.ValueOf(obj1), reflect.ValueOf(obj2))
}

func hasAllFieldsAndValuesRecursive(v1, v2 reflect.Value) (bool, error) {
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.

can we use go-cmp here to make these comparisons?

gatewayapi.KindEnvoyProxy,
*certRef); err != nil {
r.log.Error(err,
"failed to process TLS SecretRef for gateway",
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.

for GatewayClass

return tlsBundle, policy
}

func (t *Translator) applyEnvoyProxyBackendTLSSetting(policy *gwapiv1a3.BackendTLSPolicy, tlsBundle *ir.TLSUpstreamConfig, resources *Resources, parent gwapiv1a2.ParentReference) *ir.TLSUpstreamConfig {
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.

nit: maybe rename tlsBundle to tlsConfig here? It used to be just a cert bundle, but now contains much more settings,

@guydc guydc merged commit e3439f6 into envoyproxy:main May 24, 2024
@guydc
Copy link
Copy Markdown
Contributor

guydc commented May 24, 2024

@alexwo - can you maybe make some of the suggested test improvements in a follow-up PR?

@guydc guydc mentioned this pull request May 24, 2024
@alexwo
Copy link
Copy Markdown
Contributor Author

alexwo commented May 24, 2024

@alexwo - can you maybe make some of the suggested test improvements in a follow-up PR?

yes sounds good! , thanks for the quick review & feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants