Skip to content

Commit b147ab9

Browse files
craig[bot]souravcrl
andcommitted
Merge #150476
150476: provisioning: add usability counters for enabling ldap provisioning r=pritesh-lahoti a=souravcrl fixes #148876 Epic CRDB-21590 Release note (security): The following provisioning usability metric counters were added for ldap based user provisioning. * An enablement tracking counter for organizations enabling ldap provisioning (`auth.provisioning.ldap.enable`) * A counter for number of organizations & tenants which have enabled ldap to auto-provision users(`auth.provisioning.ldap.begin`). * A counter for the number of auto-provisioned users (`auth.provisioning.ldap.success`). * A telemetry counter for number of logins performed by provisioned users (`auth.provisioning.login_success`). Co-authored-by: souravcrl <[email protected]>
2 parents cd4d33e + 4f2cf60 commit b147ab9

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

pkg/security/provisioning/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ go_library(
99
importpath = "github.com/cockroachdb/cockroach/pkg/security/provisioning",
1010
visibility = ["//visibility:public"],
1111
deps = [
12+
"//pkg/server/telemetry",
1213
"//pkg/settings",
1314
"//pkg/settings/cluster",
1415
"@com_github_cockroachdb_errors//:errors",

pkg/security/provisioning/settings.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
package provisioning
77

88
import (
9+
"context"
10+
11+
"github.com/cockroachdb/cockroach/pkg/server/telemetry"
912
"github.com/cockroachdb/cockroach/pkg/settings"
1013
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
1114
)
@@ -16,6 +19,22 @@ const (
1619
testSupportedAuthMethodCertPassword = "cert-password"
1720
baseProvisioningSettingName = "security.provisioning."
1821
ldapProvisioningEnableSettingName = baseProvisioningSettingName + "ldap.enabled"
22+
23+
baseCounterPrefix = "auth.provisioning."
24+
ldapCounterPrefix = baseCounterPrefix + "ldap."
25+
26+
beginLDAPProvisionCounterName = ldapCounterPrefix + "begin"
27+
provisionLDAPSuccessCounterName = ldapCounterPrefix + "success"
28+
enableLDAPProvisionCounterName = ldapCounterPrefix + "enable"
29+
30+
provisionedUserLoginSuccessCounterName = baseCounterPrefix + "login_success"
31+
)
32+
33+
var (
34+
BeginLDAPProvisionUseCounter = telemetry.GetCounterOnce(beginLDAPProvisionCounterName)
35+
ProvisionLDAPSuccessCounter = telemetry.GetCounterOnce(provisionLDAPSuccessCounterName)
36+
enableLDAPProvisionCounter = telemetry.GetCounterOnce(enableLDAPProvisionCounterName)
37+
ProvisionedUserLoginSuccessCounter = telemetry.GetCounterOnce(provisionedUserLoginSuccessCounterName)
1938
)
2039

2140
// UserProvisioningConfig allows for customization of automatic user
@@ -59,7 +78,13 @@ func (c clusterProvisioningConfig) Enabled(authMethod string) bool {
5978
}
6079

6180
// ClusterProvisioningConfig creates a UserProvisioningConfig backed by the
62-
// given cluster settings.
81+
// given cluster settings. It also installs a callback for changes to cluster
82+
// setting related to enablement of provisioning for different auth methods.
6383
func ClusterProvisioningConfig(settings *cluster.Settings) UserProvisioningConfig {
64-
return clusterProvisioningConfig{settings}
84+
ldapProvisioningEnabled.SetOnChange(&settings.SV, func(_ context.Context) {
85+
if ldapProvisioningEnabled.Get(&settings.SV) {
86+
telemetry.Inc(enableLDAPProvisionCounter)
87+
}
88+
})
89+
return clusterProvisioningConfig{settings: settings}
6590
}

pkg/sql/pgwire/auth.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import (
1515

1616
"github.com/cockroachdb/cockroach/pkg/clusterversion"
1717
"github.com/cockroachdb/cockroach/pkg/security"
18+
"github.com/cockroachdb/cockroach/pkg/security/provisioning"
1819
"github.com/cockroachdb/cockroach/pkg/security/username"
20+
"github.com/cockroachdb/cockroach/pkg/server/telemetry"
1921
"github.com/cockroachdb/cockroach/pkg/sql"
2022
"github.com/cockroachdb/cockroach/pkg/sql/lexbase"
2123
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/hba"
@@ -151,7 +153,7 @@ func (c *conn) handleAuthentication(
151153

152154
// Check that the requested user exists and retrieve the hashed
153155
// password in case password authentication is needed.
154-
exists, canLoginSQL, _, canUseReplicationMode, isSuperuser, defaultSettings, roleSubject, _, pwRetrievalFn, err :=
156+
exists, canLoginSQL, _, canUseReplicationMode, isSuperuser, defaultSettings, roleSubject, provisioningSource, pwRetrievalFn, err :=
155157
sql.GetUserSessionInitInfo(
156158
ctx,
157159
execCfg,
@@ -173,7 +175,7 @@ func (c *conn) handleAuthentication(
173175
ac.LogAuthFailed(ctx, eventpb.AuthFailReason_PROVISIONING_ERROR, err)
174176
return connClose, c.sendError(ctx, pgerror.WithCandidateCode(err, pgcode.InvalidAuthorizationSpecification))
175177
}
176-
exists, canLoginSQL, _, canUseReplicationMode, isSuperuser, defaultSettings, roleSubject, _, pwRetrievalFn, err =
178+
exists, canLoginSQL, _, canUseReplicationMode, isSuperuser, defaultSettings, roleSubject, provisioningSource, pwRetrievalFn, err =
177179
sql.GetUserSessionInitInfo(
178180
ctx,
179181
execCfg,
@@ -266,6 +268,11 @@ func (c *conn) handleAuthentication(
266268
}
267269
}
268270

271+
// If user has PROVISIONSRC set, increment the login success counter
272+
if provisioningSource != nil {
273+
telemetry.Inc(provisioning.ProvisionedUserLoginSuccessCounter)
274+
}
275+
269276
// Compute the authentication latency needed to serve a SQL query.
270277
// The metric published is based on the authentication type.
271278
duration := timeutil.Since(authStartTime).Nanoseconds()

pkg/sql/pgwire/auth_methods.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/cockroachdb/cockroach/pkg/security/provisioning"
2020
"github.com/cockroachdb/cockroach/pkg/security/sessionrevival"
2121
"github.com/cockroachdb/cockroach/pkg/security/username"
22+
"github.com/cockroachdb/cockroach/pkg/server/telemetry"
2223
"github.com/cockroachdb/cockroach/pkg/settings"
2324
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
2425
"github.com/cockroachdb/cockroach/pkg/sql"
@@ -1055,6 +1056,7 @@ func AuthLDAP(
10551056

10561057
b.SetProvisioner(func(ctx context.Context) error {
10571058
c.LogAuthInfof(ctx, "LDAP authentication succeeded; attempting to provision user")
1059+
telemetry.Inc(provisioning.BeginLDAPProvisionUseCounter)
10581060
// Provision the user in the system.
10591061
idpString := entry.Method.String() + ":" + entry.GetOption("ldapserver")
10601062
provisioningSource, err := provisioning.ParseProvisioningSource(idpString)
@@ -1069,6 +1071,8 @@ func AuthLDAP(
10691071
c.LogAuthFailed(ctx, eventpb.AuthFailReason_PROVISIONING_ERROR, err)
10701072
return err
10711073
}
1074+
1075+
telemetry.Inc(provisioning.ProvisionLDAPSuccessCounter)
10721076
return nil
10731077
})
10741078

0 commit comments

Comments
 (0)