Skip to content

Commit 151ea0e

Browse files
authored
add support for route idp_client_id and idp_client_secret (#1283)
## Summary Add support for route `idp_client_id` and `idp_client_secret`. This is done with an annotation like: ```yaml ingress.pomerium.io/identity_provider_secret: idp-secret ``` And a corresponding secret: ```yaml apiVersion: v1 kind: Secret type: Opaque data: client_id: '' client_secret: '' metadata: name: idp-secret namespace: pomerium ``` ## Related issues - pomerium/pomerium#5954 ## Checklist - [x] reference any related issues - [ ] updated docs - [x] updated unit tests - [ ] updated UPGRADING.md - [x] add appropriate tag (`improvement` / `bug` / etc) - [x] ready for review
1 parent 174cc1d commit 151ea0e

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

model/ingress_config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ const (
7474
MCPServerUpstreamOAuth2ClientIDKey = "client_id"
7575
// MCPServerUpstreamOAuth2ClientSecretKey defines the key within the OAuth2 secret that contains the client secret
7676
MCPServerUpstreamOAuth2ClientSecretKey = "client_secret"
77+
// IdentityProviderSecret defines a secret to set the idp_client_id and idp_client_secret from.
78+
IdentityProviderSecret = "identity_provider_secret"
79+
// IdentityProviderClientIDKey is the client id key in the IdentityProviderSecret.
80+
IdentityProviderClientIDKey = "client_id"
81+
// IdentityProviderClientSecretKey is the client secret key in the IdentityProviderSecret.
82+
IdentityProviderClientSecretKey = "client_secret"
7783
)
7884

7985
// SSHSecrets is a grouping of ssh-related secrets.

pomerium/ingress_annotations.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ var (
7878
model.SetRequestHeadersSecret,
7979
model.SetResponseHeadersSecret,
8080
model.MCPServerUpstreamOAuth2Secret,
81+
model.IdentityProviderSecret,
8182
})
8283
mcpServerAnnotations = boolMap([]string{
8384
model.MCPServer,
@@ -356,6 +357,25 @@ func applySecretAnnotations(
356357
server.UpstreamOauth2.ClientSecret = string(clientSecret)
357358
}
358359

360+
return nil
361+
},
362+
},
363+
model.IdentityProviderSecret: {
364+
corev1.SecretTypeOpaque,
365+
func(data map[string][]byte) error {
366+
// client id and client secret are both optional
367+
// if not set the global will be used
368+
369+
clientID, hasClientID := data[model.IdentityProviderClientIDKey]
370+
if hasClientID {
371+
r.IdpClientId = proto.String(string(clientID))
372+
}
373+
374+
clientSecret, hasClientSecret := data[model.IdentityProviderClientSecretKey]
375+
if hasClientSecret {
376+
r.IdpClientSecret = proto.String(string(clientSecret))
377+
}
378+
359379
return nil
360380
},
361381
},

pomerium/ingress_annotations_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func TestAnnotations(t *testing.T) {
5555
"a/host_path_regex_rewrite_substitution": "rewrite-sub",
5656
"a/host_rewrite_header": "rewrite-header",
5757
"a/host_rewrite": "rewrite",
58+
"a/identity_provider_secret": "identity_provider_secret",
5859
"a/idle_timeout": `60s`,
5960
"a/idp_access_token_allowed_audiences": `["x","y","z"]`,
6061
"a/kubernetes_service_account_token_secret": "k8s_token",
@@ -121,6 +122,13 @@ func TestAnnotations(t *testing.T) {
121122
},
122123
Type: corev1.SecretTypeOpaque,
123124
},
125+
{Name: "identity_provider_secret", Namespace: "test"}: {
126+
Data: map[string][]byte{
127+
"client_id": []byte("CLIENT_ID"),
128+
"client_secret": []byte("CLIENT_SECRET"),
129+
},
130+
Type: corev1.SecretTypeOpaque,
131+
},
124132
},
125133
}
126134
require.NoError(t, applyAnnotations(r, ic))
@@ -201,6 +209,8 @@ func TestAnnotations(t *testing.T) {
201209
LogoUrl: "LOGO_URL",
202210
BearerTokenFormat: pb.BearerTokenFormat_BEARER_TOKEN_FORMAT_IDP_ACCESS_TOKEN.Enum(),
203211
IdpAccessTokenAllowedAudiences: &pb.Route_StringList{Values: []string{"x", "y", "z"}},
212+
IdpClientId: proto.String("CLIENT_ID"),
213+
IdpClientSecret: proto.String("CLIENT_SECRET"),
204214
DependsOn: []string{"foo.example.com", "bar.example.com", "baz.example.com"},
205215
CircuitBreakerThresholds: &pb.CircuitBreakerThresholds{
206216
MaxConnections: proto.Uint32(1),

0 commit comments

Comments
 (0)