Skip to content

Add AllowPrivateIPs flag to OIDC and OAuth2 upstream configs for in-cluster providers #5614

Closed

Description

@tgrunnagle

Problem

When an OIDC or OAuth2 upstream provider runs inside a Kubernetes cluster (e.g. dex, Keycloak, or a custom token server as a ClusterIP service), requests to that provider are blocked because newHTTPClientForHost() in upstream/oauth2.go sets WithPrivateIPs(false) for any non-localhost host:

func newHTTPClientForHost(host string) (*http.Client, error) {
    allowInsecure := networking.IsLocalhost(host) ||
        strings.EqualFold(os.Getenv("INSECURE_DISABLE_URL_VALIDATION"), "true")
    return networking.NewHttpClientBuilder().
        WithInsecureAllowHTTP(allowInsecure).
        WithPrivateIPs(allowInsecure).  // false for ClusterIPs like 10.96.x.x
        Build()
}

For OIDC providers this fails at startup during OIDC discovery:

failed to discover OIDC endpoints: dial tcp 10.96.161.59:5556:
the provided URL redirects to a private IP address, which is not allowed

For OAuth2 providers (no discovery step) this fails at runtime during token exchange, since NewOAuth2Provider builds its HTTP client from the same function using the token endpoint host (tokenURL.Host). The config validation (networking.ValidateEndpointURL) passes for HTTPS endpoints regardless of IP range, so the failure only surfaces when a token exchange is first attempted.

Both failures block in-cluster deployments.

Root cause

newHTTPClientForHost() is called by both NewOIDCProvider() (upstream/oidc.go) and newBaseOAuth2Provider() (upstream/oauth2.go) with no caller-controlled way to opt into allowing private IP ranges.

Proposed change

Add a serializable boolean flag — AllowPrivateIPs — to both OIDCUpstreamRunConfig and OAuth2UpstreamRunConfig, and thread it through to newHTTPClientForHost.

Key design point: AllowPrivateIPs widens only the private-IP gate, not the HTTP-scheme gate

The two are orthogonal security properties. An in-cluster provider at https://10.96.x.x:5556 should be reachable (private IP allowed, HTTPS still required), but the flag must not grant HTTP access to non-localhost hosts. The correct form of the updated function is:

func newHTTPClientForHost(host string, allowPrivateIPs bool) (*http.Client, error) {
    allowInsecure := networking.IsLocalhost(host) ||
        strings.EqualFold(os.Getenv("INSECURE_DISABLE_URL_VALIDATION"), "true")
    return networking.NewHttpClientBuilder().
        WithInsecureAllowHTTP(allowInsecure).           // unchanged: HTTP only for localhost
        WithPrivateIPs(allowInsecure || allowPrivateIPs). // widened by flag
        Build()
}

This ensures AllowPrivateIPs: true permits https://10.96.x.x:5556 but still rejects http://10.96.x.x:5556.

Full set of changes

config.go — add to OIDCUpstreamRunConfig and OAuth2UpstreamRunConfig:

// AllowPrivateIPs permits the upstream provider's HTTP client to connect to
// private IP ranges (RFC-1918, link-local). Use only when the upstream is
// hosted inside the same cluster and has no public endpoint. HTTP-scheme
// restrictions are unchanged — HTTPS is still required for non-localhost hosts.
// Defaults to false.
AllowPrivateIPs bool `json:"allow_private_ips,omitempty" yaml:"allow_private_ips,omitempty"`

upstream/types.go — add to OIDCConfig and OAuth2Config:

AllowPrivateIPs bool

runner/embeddedauthserver.go — propagate in buildOIDCConfig() and buildPureOAuth2Config():

AllowPrivateIPs: rc.OIDCConfig.AllowPrivateIPs,   // or rc.OAuth2Config.AllowPrivateIPs

upstream/oauth2.go — update signature of newHTTPClientForHost as shown above, and update all callers to pass the flag through from their config.

Scope of change

Component Effect
OIDC discovery HTTP client Private IPs allowed when flag is set; HTTP scheme restriction unchanged
OAuth2 token exchange HTTP client Private IPs allowed when flag is set; HTTP scheme restriction unchanged
Connector HTTP traffic Unaffected — separate client stack
All other upstreams Unaffected — flag defaults to false

Existing pattern

Follows the serializable security-override flag convention already used for Redis TLS in storage/config.go (InsecureSkipVerify bool).

YAML example

upstreams:
  - name: in-cluster-oidc
    type: oidc
    oidc_config:
      issuer_url: https://dex.my-namespace.svc.cluster.local:5556
      client_id: my-client
      client_secret_file: /var/run/secrets/client_secret
      allow_private_ips: true

  - name: in-cluster-oauth2
    type: oauth2
    oauth2_config:
      authorization_endpoint: https://auth.my-namespace.svc.cluster.local:8443/authorize
      token_endpoint: https://auth.my-namespace.svc.cluster.local:8443/token
      client_id: my-client
      client_secret_file: /var/run/secrets/oauth2_secret
      allow_private_ips: true

Activity

  1. added
    needs-triage
    on Jun 24, 2026
  2. changed the title [-]Allow configuring a trusted HTTP client for in-cluster OIDC upstream discovery[/-] [+]Export the WithHTTPClient option on OIDCProviderImpl[/+] on Jun 24, 2026
  3. self-assigned this
    on Jun 24, 2026
  4. changed the title [-]Export the WithHTTPClient option on OIDCProviderImpl[/-] [+]Add AllowPrivateIPsForDiscovery flag to OIDCUpstreamRunConfig for in-cluster OIDC providers[/+] on Jun 24, 2026
  5. changed the title [-]Add AllowPrivateIPsForDiscovery flag to OIDCUpstreamRunConfig for in-cluster OIDC providers[/-] [+]Add AllowPrivateIPs flag to OIDC and OAuth2 upstream configs for in-cluster providers[/+] on Jun 24, 2026
  6. removed
    needs-triage
    on Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions