Repository navigation
Conversation
…date Add a new setting OCIS_LDAP_UPDATE_LAST_SIGNIN_DATE / GRAPH_LDAP_UPDATE_LAST_SIGNIN_DATE (default true) to disable maintaining the 'oCLastSignInTimestamp' LDAP attribute on user sign-in. When set to false the graph service no longer listens for UserSignedIn events and does not write the attribute, without having to disable all LDAP writes or the events consumer. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
I'm fine with the quick fix, but the last sign-in is something people might be interested in. We should research alternative solutions. I don't know how much work it is, but having a specific cache for the last sign-in, with the cache being close to the LDAP server might be worthy to check. The tricky part is where to place the cache and how to use it effectively. Anyone requesting directly or indirectly the last sign-in should receive the cached and updated data, not the data stored in the LDAP server. |
dj4oC
left a comment
There was a problem hiding this comment.
Adds UpdateUserLastSignInDate (OCIS_LDAP_UPDATE_LAST_SIGNIN_DATE/GRAPH_LDAP_UPDATE_LAST_SIGNIN_DATE, default true) so operators can stop the graph service from writing the oCLastSignInTimestamp LDAP attribute on every sign-in, reducing LDAP write load.
Findings
Security: No blocking findings. The flag is operator-only (loaded via the same env/yaml ParseConfig path as every other LDAP field — not attacker-reachable). One non-blocking note, CWE-778 (Insufficient Logging)-adjacent: disabling this removes the only signal ocis keeps for dormant-account/forensic purposes, and that trade-off is only mentioned as a load-reduction feature in the changelog/desc, not called out as a security-relevant trade-off; consider bumping the "disabled" log line from Info to Warn and adding a one-line security note to the changelog. No existing audit subsystem covers UserSignedIn today, so this isn't a regression of existing audit coverage.
Stability: No findings. Purely additive — the new check sits after the existing nil-consumer guard, default true preserves current behavior exactly, and UserSignedIn has exactly one publisher/consumer pair in the codebase, so no other service assumes this registration always happens. Compatible with single-binary, docker-compose, and k8s topologies; doesn't introduce or remove any assumption about Keycloak/LDAP/NATS/Traefik/S3/NFS. Minor wording nit: the field desc says it "requires OCIS_LDAP_SERVER_WRITE_ENABLED to be true," but the two settings are actually independent at the code level — worth rewording so it doesn't read as a hard dependency.
Performance: No findings. Confirmed this is a true unsubscribe (no dangling NATS consumer, no discarded dispatch) rather than a post-receive filter, and the check is evaluated once at service construction, not per sign-in.
Test coverage — gap, not blocking security/stability but below this org's 85% threshold. This diff adds no test, and StartListenForLogonEvents/UserSignedIn registration has no pre-existing test coverage in services/graph/pkg/service/v0/ either — the new conditional is entirely unexercised. I wrote and verified (compiled + passed against this PR's diff applied to a local checkout) a Ginkgo test covering both branches. Proposing as a new file, services/graph/pkg/service/v0/logon_events_test.go:
package svc_test
import (
"context"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/owncloud/ocis/v2/ocis-pkg/log"
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
"github.com/owncloud/ocis/v2/services/graph/pkg/config/defaults"
identitymocks "github.com/owncloud/ocis/v2/services/graph/pkg/identity/mocks"
service "github.com/owncloud/ocis/v2/services/graph/pkg/service/v0"
mevents "go-micro.dev/v4/events"
)
// fakeConsumer observes whether StartListenForLogonEvents registers for logon events.
type fakeConsumer struct{ calls int }
func (f *fakeConsumer) Consume(_ string, _ ...mevents.ConsumeOption) (<-chan mevents.Event, error) {
f.calls++
return make(chan mevents.Event), nil
}
var _ = Describe("StartListenForLogonEvents", func() {
var (
ctx context.Context
identityBackend *identitymocks.Backend
consumer *fakeConsumer
)
BeforeEach(func() {
ctx = context.Background()
identityBackend = &identitymocks.Backend{}
consumer = &fakeConsumer{}
})
It("does not register for UserSignedIn events when UpdateUserLastSignInDate is disabled", func() {
cfg := defaults.FullDefaultConfig()
cfg.Identity.LDAP.CACert = ""
cfg.Commons = &shared.Commons{}
cfg.GRPCClientTLS = &shared.GRPCClientTLS{}
cfg.Identity.LDAP.UpdateUserLastSignInDate = false
svc, err := service.NewService(
service.Config(cfg), service.Context(ctx), service.Logger(log.NewLogger()),
service.WithIdentityBackend(identityBackend), service.EventsConsumer(consumer),
)
Expect(err).ToNot(HaveOccurred())
Expect(svc.StartListenForLogonEvents(ctx, log.NewLogger())).To(Succeed())
Expect(consumer.calls).To(Equal(0), "Consume must not be called when UpdateUserLastSignInDate is false")
})
It("registers for UserSignedIn events when UpdateUserLastSignInDate is enabled (default)", func() {
cfg := defaults.FullDefaultConfig()
cfg.Identity.LDAP.CACert = ""
cfg.Commons = &shared.Commons{}
cfg.GRPCClientTLS = &shared.GRPCClientTLS{}
cfg.Identity.LDAP.UpdateUserLastSignInDate = true
svc, err := service.NewService(
service.Config(cfg), service.Context(ctx), service.Logger(log.NewLogger()),
service.WithIdentityBackend(identityBackend), service.EventsConsumer(consumer),
)
Expect(err).ToNot(HaveOccurred())
Expect(svc.StartListenForLogonEvents(ctx, log.NewLogger())).To(Succeed())
Expect(consumer.calls).To(BeNumerically(">=", 1), "Consume must be called when UpdateUserLastSignInDate is true")
})
})CI: all-acceptance-tests and apiSearch2 are currently failing; all other ~65 check runs (including apiGraph) are green. Neither failing suite looks related to this graph/LDAP config change — please confirm they're pre-existing/flaky before merge.
Deployment topology check
Compatible — per-process config flag, no co-location assumption, no new PVC/RBAC, no change to Keycloak/LDAP/NATS dependency expectations.
Verdict
Commenting — no security or stability blockers, but not approving short of the coverage gate; please add the proposed test (or your own) for the new branch, and confirm the two red CI jobs are unrelated.
🤖 Automated review by Claude Code (security · stability · performance · coverage)
Generated by Claude Code
🤖 Automated review by Claude Code (security · stability · performance · coverage) Generated by Claude Code |
| UseServerUUID bool `yaml:"use_server_uuid" env:"GRAPH_LDAP_SERVER_UUID" desc:"If set to true, rely on the LDAP Server to generate a unique ID for users and groups, like when using 'entryUUID' as the user ID attribute." introductionVersion:"pre5.0"` | ||
| UsePasswordModExOp bool `yaml:"use_password_modify_exop" env:"GRAPH_LDAP_SERVER_USE_PASSWORD_MODIFY_EXOP" desc:"Use the 'Password Modify Extended Operation' for updating user passwords." introductionVersion:"pre5.0"` | ||
| WriteEnabled bool `yaml:"write_enabled" env:"OCIS_LDAP_SERVER_WRITE_ENABLED;GRAPH_LDAP_SERVER_WRITE_ENABLED" desc:"Allow creating, modifying and deleting LDAP users via the GRAPH API. This can only be set to 'true' when keeping default settings for the LDAP user and group attribute types (the 'OCIS_LDAP_USER_SCHEMA_* and 'OCIS_LDAP_GROUP_SCHEMA_* variables)." introductionVersion:"pre5.0"` | ||
| UpdateUserLastSignInDate bool `yaml:"update_user_last_sign_in_date" env:"OCIS_LDAP_UPDATE_LAST_SIGNIN_DATE;GRAPH_LDAP_UPDATE_LAST_SIGNIN_DATE" desc:"Update the 'oCLastSignInTimestamp' LDAP attribute of a user when the user signs in. This requires 'OCIS_LDAP_SERVER_WRITE_ENABLED' to be 'true'. Set this to 'false' to avoid an LDAP write on every sign-in, e.g. when the last sign-in timestamp is not needed or the LDAP write load should be reduced." introductionVersion:"NEXT"` |
There was a problem hiding this comment.
Consider:
If this will be part of the upcoming 8.2 release, set the introduction version to 8.2.0
Leave it as it is otherwise.
|
@jvillafanez OPS is already working on storing and retrieving the timestamp from keycloak. oCIS will probably not have to worry any longer. |
- Add unit test covering both branches of StartListenForLogonEvents (subscribes when UpdateUserLastSignInDate is enabled, not when disabled). - Set introductionVersion to 8.2.0. - Reword the config description: the two settings are independent, the timestamp is only persisted when OCIS_LDAP_SERVER_WRITE_ENABLED is enabled rather than the toggle requiring it. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR adds a configuration gate in the Graph service to optionally stop consuming UserSignedIn events, thereby preventing updates to the LDAP oCLastSignInTimestamp attribute and reducing LDAP write load when that timestamp is not needed.
Changes:
- Add
OCIS_LDAP_UPDATE_LAST_SIGNIN_DATE/GRAPH_LDAP_UPDATE_LAST_SIGNIN_DATE(defaulttrue) to control whether Graph listens for logon events and updatesoCLastSignInTimestamp. - Short-circuit
StartListenForLogonEventswhen the new setting is disabled. - Add a small Ginkgo test covering the enabled/disabled subscription behavior and a changelog entry.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| services/graph/pkg/service/v0/service.go | Adds an early-return gate to skip subscribing to logon events when last sign-in updates are disabled. |
| services/graph/pkg/service/v0/logon_events_test.go | Adds tests to ensure subscription is skipped/enabled based on the new config flag. |
| services/graph/pkg/config/defaults/defaultconfig.go | Sets the new LDAP config flag default to true to preserve existing behavior. |
| services/graph/pkg/config/config.go | Introduces the new LDAP config field with env var bindings and documentation metadata. |
| changelog/unreleased/graph-disable-last-signin-timestamp.md | Documents the new setting and its effect on event consumption and LDAP writes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address Copilot review: NewService already calls StartListenForLogonEvents during initialization, so assert the subscription behavior right after constructing the service instead of calling it again. Use a cancelable context and cancel it in AfterEach so the dispatch goroutine does not leak. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…imestamp update (#12531) feat(graph): allow disabling the last sign-in timestamp update (#12522) * feat(graph): [OCISDEV-1022] allow disabling last sign-in timestamp update Add a new setting OCIS_LDAP_UPDATE_LAST_SIGNIN_DATE / GRAPH_LDAP_UPDATE_LAST_SIGNIN_DATE (default true) to disable maintaining the 'oCLastSignInTimestamp' LDAP attribute on user sign-in. When set to false the graph service no longer listens for UserSignedIn events and does not write the attribute, without having to disable all LDAP writes or the events consumer. * docs(changelog): [OCISDEV-1022] fix PR link to 12522 * test(graph): [OCISDEV-1022] cover last sign-in toggle; address review - Add unit test covering both branches of StartListenForLogonEvents (subscribes when UpdateUserLastSignInDate is enabled, not when disabled). - Set introductionVersion to 8.2.0. - Reword the config description: the two settings are independent, the timestamp is only persisted when OCIS_LDAP_SERVER_WRITE_ENABLED is enabled rather than the toggle requiring it. --------- (cherry picked from commit 49c897e) Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: Martin <[email protected]>
I think the agent is right. It found zero BLOCKING findings but: One non-blocking note, CWE-778 (Insufficient Logging)-adjacent: disabling this removes the only signal ocis keeps for dormant-account/forensic purposes, and that trade-off is only mentioned as a load-reduction feature in the changelog/desc, not called out as a security-relevant trade-off; consider bumping the "disabled" log line from Info to Warn and adding a one-line security note to the changelog. No existing audit subsystem covers UserSignedIn today, so this isn't a regression of existing audit coverage. |
…imestamp update (#12532) * feat(graph): allow disabling the last sign-in timestamp update (#12522) * feat(graph): [OCISDEV-1022] allow disabling last sign-in timestamp update Add a new setting OCIS_LDAP_UPDATE_LAST_SIGNIN_DATE / GRAPH_LDAP_UPDATE_LAST_SIGNIN_DATE (default true) to disable maintaining the 'oCLastSignInTimestamp' LDAP attribute on user sign-in. When set to false the graph service no longer listens for UserSignedIn events and does not write the attribute, without having to disable all LDAP writes or the events consumer. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * docs(changelog): [OCISDEV-1022] fix PR link to 12522 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * test(graph): [OCISDEV-1022] cover last sign-in toggle; address review - Add unit test covering both branches of StartListenForLogonEvents (subscribes when UpdateUserLastSignInDate is enabled, not when disabled). - Set introductionVersion to 8.2.0. - Reword the config description: the two settings are independent, the timestamp is only persisted when OCIS_LDAP_SERVER_WRITE_ENABLED is enabled rather than the toggle requiring it. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: Martin <[email protected]> (cherry picked from commit 49c897e) * chore: bump go-git * chore: bump crypto --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: Martin <[email protected]> Co-authored-by: Michal Klos <[email protected]>
Description
The graph service maintains the
oCLastSignInTimestampLDAP attribute of a user on every sign-in (when the LDAP identity backend has write access, introduced in #9942). This can cause significant LDAP write load, especially when the proxy's OIDC userinfo cache has a short TTL andUserSignedInevents are emitted frequently.This adds a new setting
OCIS_LDAP_UPDATE_LAST_SIGNIN_DATE/GRAPH_LDAP_UPDATE_LAST_SIGNIN_DATE(defaulttrue, preserving current behavior) to disable this update independently — without having to disable all Graph→LDAP writes (OCIS_LDAP_SERVER_WRITE_ENABLED) or the graph events consumer (which would also stop graph event publishing used by search/audit).When set to
false, the graph service no longer listens forUserSignedInevents and does not write theoCLastSignInTimestampattribute.UserSignedInis the only event this listener handles, so gating the whole listener has no other side effects.How Has This Been Tested?
go build ./services/graph/...StartListenForLogonEventsTypes of changes
Checklist
Relates to #9942
🤖 Generated with Claude Code