Skip to content

Commit 3f26da0

Browse files
committed
ING-1363: Make client cert checks failed when disabled on cluster
1 parent 67fa47c commit 3f26da0

File tree

4 files changed

+57
-9
lines changed

4 files changed

+57
-9
lines changed

cbauthx/cbauth.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ func (a *CbAuth) handleAuthCheckErr(
452452
) (UserInfo, error) {
453453
if errors.Is(err, ErrInvalidAuth) {
454454
return UserInfo{}, ErrInvalidAuth
455+
} else if errors.Is(err, ErrCertAuthDisabled) {
456+
return UserInfo{}, ErrCertAuthDisabled
455457
}
456458

457459
a.logger.Debug("failed to check user with cbauth", zap.Error(err))

cbauthx/cbauthclient.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ type CbAuthClient struct {
3232
lastCommTs atomic.Int64
3333
heartbeatTimer *time.Timer
3434

35-
lock sync.Mutex
36-
nodeUuid string
37-
clusterUuid string
38-
authVersion string
39-
clientCertAuthVersion string
35+
lock sync.Mutex
36+
nodeUuid string
37+
clusterUuid string
38+
authVersion string
39+
clientCertAuthDisabled bool
40+
clientCertAuthVersion string
4041

4142
initOpts *UpdateDBExtOptions
4243
initSigCh chan struct{}
@@ -294,6 +295,8 @@ func (c *CbAuthClient) rpcUpdateDBExt(opts *UpdateDBExtOptions) (bool, error) {
294295
}
295296
}
296297

298+
c.clientCertAuthDisabled = opts.ClientCertAuthState == "disable"
299+
297300
// If the client wasn't marked as initialized yet. Lets signal that.
298301
if c.initOpts == nil {
299302
c.initOpts = opts
@@ -364,6 +367,13 @@ func (a *CbAuthClient) getCertCache(_ context.Context) (*CertCheckCached, error)
364367
}
365368

366369
func (a *CbAuthClient) CheckCertificate(ctx context.Context, clientCert *x509.Certificate) (UserInfo, error) {
370+
// The endpoint we use to extract the user from the cert still works when
371+
// client cert auth has been disabled so we need to explicitly fail the
372+
// cert check.
373+
if a.clientCertAuthDisabled {
374+
return UserInfo{}, ErrCertAuthDisabled
375+
}
376+
367377
certCache, err := a.getCertCache(ctx)
368378
if err != nil {
369379
return UserInfo{}, err

cbauthx/errors.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import (
77
)
88

99
var (
10-
ErrNoCert = errors.New("no cert specified")
11-
ErrInvalidAuth = errors.New("invalid auth")
12-
ErrClosed = errors.New("already closed")
13-
ErrLivenessTimeout = errors.New("cache is stale")
10+
ErrNoCert = errors.New("no cert specified")
11+
ErrCertAuthDisabled = errors.New("cert auth disabled")
12+
ErrInvalidAuth = errors.New("invalid auth")
13+
ErrClosed = errors.New("already closed")
14+
ErrLivenessTimeout = errors.New("cache is stale")
1415
)
1516

1617
type contextualError struct {

cbmgmtx/mgmt.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,41 @@ func (h Management) ConfigureAutoFailover(ctx context.Context, req *ConfigureAut
11611161
return nil
11621162
}
11631163

1164+
type Prefix struct {
1165+
Path string `json:"path"`
1166+
Prefix string `json:"prefix"`
1167+
Delimiter string `json:"delimiter"`
1168+
}
1169+
1170+
type ConfigureClientCertAuthRequest struct {
1171+
State string `json:"state"`
1172+
Prefixes []Prefix `json:"prefixes"`
1173+
}
1174+
1175+
func (h Management) ConfigureClientCertAuth(ctx context.Context, req *ConfigureClientCertAuthRequest) error {
1176+
jsonBytes, err := json.Marshal(req)
1177+
if err != nil {
1178+
return err
1179+
}
1180+
1181+
resp, err := h.Execute(
1182+
ctx,
1183+
"POST",
1184+
"/settings/clientCertAuth",
1185+
"application/json", nil, bytes.NewReader(jsonBytes))
1186+
if err != nil {
1187+
return err
1188+
}
1189+
1190+
if resp.StatusCode != 202 {
1191+
return h.DecodeCommonError(resp)
1192+
}
1193+
1194+
_ = resp.Body.Close()
1195+
1196+
return nil
1197+
}
1198+
11641199
// AuthDomain specifies the user domain of a specific user
11651200
type AuthDomain string
11661201

0 commit comments

Comments
 (0)