Skip to content

Commit b19be1b

Browse files
committed
Implement client-side mTLS support settings
1 parent b4b1322 commit b19be1b

7 files changed

Lines changed: 68 additions & 0 deletions

File tree

apis/ingress/v1/pomerium_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ type PomeriumSpec struct {
243243
// +optional
244244
CASecrets []string `json:"caSecrets"`
245245

246+
// ClientCASecret is a list of secrets of type Opaque to use for client-side mTLS.
247+
// Specify the corresponding CRL with the ca.crl key
248+
// +optional
249+
ClientCASecrets []string `json:"clientCASecrets"`
250+
246251
// Secrets references a Secret with Pomerium bootstrap parameters.
247252
//
248253
// <p>

apis/ingress/v1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/ingress.pomerium.io_pomerium.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ spec:
7676
items:
7777
type: string
7878
type: array
79+
clientCASecrets:
80+
description: Client CAs is a list of secrets of type Opaque to use
81+
for client-side mTLS. Specify the corresponding CRL with the ca.crl
82+
key
83+
items:
84+
type: string
85+
type: array
7986
cookie:
8087
description: Cookie defines Pomerium session cookie options.
8188
properties:

controllers/settings/fetch.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ func fetchConfigSecrets(ctx context.Context, client client.Client, cfg *model.Co
111111
}
112112
return nil
113113
},
114+
func() error {
115+
for _, clientCASecret := range s.ClientCASecrets {
116+
secret, err := get(clientCASecret)()
117+
if err != nil {
118+
return fmt.Errorf("ca: %w", err)
119+
}
120+
cfg.ClientCASecrets = append(cfg.ClientCASecrets, secret)
121+
}
122+
return nil
123+
},
114124
func() error {
115125
if s.IdentityProvider == nil {
116126
return nil

model/ingress_config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ const (
4545
StorageConnectionStringKey = "connection"
4646
// CAKey is certificate authority secret key
4747
CAKey = "ca.crt"
48+
// CAKey is certificate authority CRL
49+
CRLKey = "ca.crl"
4850
)
4951

5052
// StorageSecrets is a convenience grouping of storage-related secrets
@@ -84,6 +86,8 @@ type Config struct {
8486
CASecrets []*corev1.Secret
8587
// Certs are fetched certs from settings.Certificates
8688
Certs map[types.NamespacedName]*corev1.Secret
89+
// ClientCASecrets are fetched certs and crls from settings.ClientCASecrets
90+
ClientCASecrets []*corev1.Secret
8791
// RequestParams is a secret from Settings.IdentityProvider.RequestParams
8892
RequestParams *corev1.Secret
8993
// IdpSecret is Settings.IdentityProvider.Secret

pomerium/config.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func applyConfig(ctx context.Context, p *pb.Config, c *model.Config) error {
3434

3535
opts := []applyOpt{
3636
{"ca", applyCertificateAuthority},
37+
{"client ca", applyClientCertificate},
3738
{"certs", applyCerts},
3839
{"authenticate", applyAuthenticate},
3940
{"cookie", applyCookie},
@@ -132,6 +133,26 @@ func applyCertificateAuthority(_ context.Context, p *pb.Config, c *model.Config)
132133
return nil
133134
}
134135

136+
func applyClientCertificate(_ context.Context, p *pb.Config, c *model.Config) error {
137+
if len(c.ClientCASecrets) == 0 {
138+
return nil
139+
}
140+
141+
var crtBuf bytes.Buffer
142+
var crlBuf bytes.Buffer
143+
144+
for _, secret := range c.ClientCASecrets {
145+
crtBuf.Write(secret.Data[model.CAKey])
146+
crtBuf.WriteRune('\n')
147+
crlBuf.Write(secret.Data[model.CRLKey])
148+
crlBuf.WriteRune('\n')
149+
}
150+
151+
p.Settings.ClientCa = proto.String(base64.StdEncoding.EncodeToString(crtBuf.Bytes()))
152+
p.Settings.ClientCrl = proto.String(base64.StdEncoding.EncodeToString(crlBuf.Bytes()))
153+
return nil
154+
}
155+
135156
func applyCerts(_ context.Context, p *pb.Config, c *model.Config) error {
136157
if len(c.Certs) != len(c.Spec.Certificates) {
137158
return fmt.Errorf("expected %d cert secrets, only %d was fetched. this is a bug", len(c.Spec.Certificates), len(c.Certs))

reference.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,22 @@ PomeriumSpec defines Pomerium-specific configuration parameters.
7575
</td>
7676
</tr>
7777

78+
<tr>
79+
<td>
80+
<p>
81+
<code>clientCASecrets</code>&#160;&#160;
82+
83+
<strong>[]string</strong>&#160;
84+
85+
</p>
86+
<p>
87+
88+
Client CAs is a list of secrets of type TLS to use for client-side mTLS. Specify the corresponding CRL with the ca.crl key
89+
</p>
90+
91+
</td>
92+
</tr>
93+
7894
<tr>
7995
<td>
8096
<p>

0 commit comments

Comments
 (0)