Skip to content

feat(graph): allow disabling the last sign-in timestamp update - #12522

Merged
mmattel merged 5 commits into
owncloud:masterfrom
kobergj:feat/OCISDEV-1022-disable-last-signin-timestamp
Jul 9, 2026
Merged

mmattel merged 5 commits into
owncloud:masterfrom
kobergj:feat/OCISDEV-1022-disable-last-signin-timestamp

Conversation

@kobergj

@kobergj kobergj commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Description

The graph service maintains the oCLastSignInTimestamp LDAP 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 and UserSignedIn events are emitted frequently.

This adds a new setting OCIS_LDAP_UPDATE_LAST_SIGNIN_DATE / GRAPH_LDAP_UPDATE_LAST_SIGNIN_DATE (default true, 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 for UserSignedIn events and does not write the oCLastSignInTimestamp attribute. UserSignedIn is 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/...
  • Manual review of the gate in StartListenForLogonEvents

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist

  • Code changes
  • Changelog
  • Documentation ETA (env var reference is auto-generated)

Relates to #9942

🤖 Generated with Claude Code

…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]>
@kobergj
kobergj requested a review from a team as a code owner July 8, 2026 16:15
@kw-security

kw-security commented Jul 8, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues
✅ Code Security 0 0 0 0 0 issues

💻 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]>
@jvillafanez

Copy link
Copy Markdown
Member

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.
Before writing the data in the LDAP server, the data is cached for 1 hour, for example. If someone requests that data, it's checked against the cache first. After a while, 1 hour of inactivity for the user, for example, the data is persisted in LDAP.
Ideally, the continuous logins from a user (from refreshing the access token for example) will be cached and won't hit the LDAP server. Only the last one after a period of inactivity will be saved.

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 dj4oC left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

dj4oC commented Jul 8, 2026

Copy link
Copy Markdown
Contributor
  • Security: 1 finding — see review
  • Stability: 1 finding — see review
  • Performance: no findings
  • Test coverage: below 85% — tests proposed in review
  • TODOs found: none
  • Dependency touched: no
  • CI status: failing: all-acceptance-tests, apiSearch2 (appear unrelated — confirm before merge)
  • Stale review: no

🤖 Automated review by Claude Code (security · stability · performance · coverage)


Generated by Claude Code

Comment thread services/graph/pkg/config/config.go Outdated
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"`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kobergj

kobergj commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

@jvillafanez OPS is already working on storing and retrieving the timestamp from keycloak. oCIS will probably not have to worry any longer.
@dj4oC your comment says no finding in security/stability. Your summary says 1 finding in security and 1 in stability. Please update agent to verify its claims before posting.

@mzner
mzner self-requested a review July 9, 2026 07:25
mzner
mzner previously approved these changes Jul 9, 2026
- 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]>
mzner
mzner previously approved these changes Jul 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (default true) to control whether Graph listens for logon events and updates oCLastSignInTimestamp.
  • Short-circuit StartListenForLogonEvents when 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.

mmattel and others added 2 commits July 9, 2026 11:16
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]>
@mmattel
mmattel enabled auto-merge (squash) July 9, 2026 09:32
@mmattel
mmattel merged commit 49c897e into owncloud:master Jul 9, 2026
67 checks passed
@kobergj
kobergj deleted the feat/OCISDEV-1022-disable-last-signin-timestamp branch July 9, 2026 10:49
kobergj added a commit that referenced this pull request Jul 9, 2026
…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]>
@dj4oC

dj4oC commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

@dj4oC your comment says no finding in security/stability. Your summary says 1 finding in security and 1 in stability. Please update agent to verify its claims before posting.

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.

kobergj added a commit that referenced this pull request Jul 13, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants