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

Expand proxy detection support to Dex and support proxy configuration #3636

Merged
merged 2 commits into from
Dec 11, 2024

Conversation

pasanw
Copy link
Contributor

@pasanw pasanw commented Dec 6, 2024

Description

This PR expands the support for proxy detection to Dex, and adds support for users to specify a proxy that the Operator will set on Guardian and Dex containers.

The proxy detection logic will always be used to render policy, in case the user has used both the proxy configuration and a mutating admission webhook to set the proxy environment variables.

For PR author

  • Tests for change.
  • If changing pkg/apis/, run make gen-files
  • If changing versions, run make gen-versions

For PR reviewers

A note for code reviewers - all pull requests must have the following:

  • Milestone set according to targeted release.
  • Appropriate labels:
    • kind/bug if this is a bugfix.
    • kind/enhancement if this is a a new feature.
    • enterprise if this PR applies to Calico Enterprise only.

Comment on lines +314 to +385
// Determine the current deployment availability.
var currentAvailabilityTransition metav1.Time
var currentlyAvailable bool
dexDeployment := v1.Deployment{}
err = r.client.Get(ctx, client.ObjectKey{Name: render.DexObjectName, Namespace: render.DexNamespace}, &dexDeployment)
if err != nil && !errors.IsNotFound(err) {
r.status.SetDegraded(oprv1.ResourceReadError, "Failed to read the deployment status of Dex", err, reqLogger)
return reconcile.Result{}, nil
} else if err == nil {
for _, condition := range dexDeployment.Status.Conditions {
if condition.Type == v1.DeploymentAvailable {
currentAvailabilityTransition = condition.LastTransitionTime
if condition.Status == corev1.ConditionTrue {
currentlyAvailable = true
}
break
}
}
}

// Resolve the proxies used by each Dex pod. We only update the resolved proxies if the availability of the
// Dex deployment has changed since our last reconcile and the deployment is currently available. We restrict
// the resolution of pod proxies in this way to limit the number of pod queries we make.
if !currentAvailabilityTransition.Equal(&r.lastAvailabilityTransition) && currentlyAvailable {
// Query dex pods.
labelSelector := labels.SelectorFromSet(map[string]string{
"app.kubernetes.io/name": render.DexObjectName,
})
pods := corev1.PodList{}
err := r.client.List(ctx, &pods, &client.ListOptions{
LabelSelector: labelSelector,
Namespace: render.DexNamespace,
})
if err != nil {
r.status.SetDegraded(oprv1.ResourceReadError, "Failed to list the pods of the Dex deployment", err, reqLogger)
return reconcile.Result{}, nil
}

// Resolve the proxy config for each pod. Pods without a proxy will have a nil proxy config value.
var podProxies []*httpproxy.Config
for _, pod := range pods.Items {
for _, container := range pod.Spec.Containers {
if container.Name == render.DexObjectName {
var podProxyConfig *httpproxy.Config
var httpProxy, httpsProxy, noProxy string
for _, env := range container.Env {
switch env.Name {
case "http_proxy", "HTTP_PROXY":
httpProxy = env.Value
case "https_proxy", "HTTPS_PROXY":
httpsProxy = env.Value
case "no_proxy", "NO_PROXY":
noProxy = env.Value
}
}
if httpProxy != "" || httpsProxy != "" || noProxy != "" {
podProxyConfig = &httpproxy.Config{
HTTPProxy: httpProxy,
HTTPSProxy: httpsProxy,
NoProxy: noProxy,
}
}

podProxies = append(podProxies, podProxyConfig)
}
}
}

r.resolvedPodProxies = podProxies
}
r.lastAvailabilityTransition = currentAvailabilityTransition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For context, this logic is a mirror of what is found in the cluster connection controller

@pasanw pasanw marked this pull request as ready for review December 6, 2024 21:32
@pasanw pasanw requested a review from a team as a code owner December 6, 2024 21:32
@pasanw pasanw changed the title Expand proxy support to Dex and support proxy configuration Expand proxy detection support to Dex and support proxy configuration Dec 6, 2024
@@ -18,6 +18,9 @@ import (
"context"
"fmt"

"golang.org/x/net/http/httpproxy"
Copy link
Member

Choose a reason for hiding this comment

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

nit: the imports in this file are a bit of a mess

Copy link
Member

@rene-dekker rene-dekker left a comment

Choose a reason for hiding this comment

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

lgtm

// HTTPSProxy defines the value of the HTTPS_PROXY environment variable that will be set on Tigera containers that connect to
// destinations outside the cluster.
// +optional
HTTPSProxy string `json:"httpsProxy,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Not to throw a wrench into things, but since these vars can take a separated list of items should we make them lists in our API?

httpsProxy:
- foo.com
- bar.org

and combine them? Or nah?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

httpProxy and httpsProxy should always be a single value, not a list AFAIK. noProxy can be a list of exempted destinations, but it's expected that this is a comma-separated list. If we ask for an array, it will likely be an inconvenience for the user IMO - they've likely been passing a comma-separated list elsewhere

Copy link
Member

Choose a reason for hiding this comment

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

ah right, it was noProxy I was thinking about. I'm fine with the stance that it should just be the same as the env var.

@pasanw pasanw merged commit 65f3256 into tigera:master Dec 11, 2024
5 checks passed
@pasanw pasanw deleted the ev-5319 branch December 11, 2024 20:13
@pasanw pasanw mentioned this pull request Dec 20, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants