Skip to content

feat: sync profile pictures from OIDC claims - #2704

Open
Guibi1 wants to merge 22 commits into
opencloud-eu:mainfrom
Guibi1:oidc-profile-picture
Open

Guibi1 wants to merge 22 commits into
opencloud-eu:mainfrom
Guibi1:oidc-profile-picture

Conversation

@Guibi1

@Guibi1 Guibi1 commented May 2, 2026 •

Copy link
Copy Markdown

Description

Sync a user's profile picture from an OIDC claim when a new session starts. The proxy emits a sync request; the Graph event consumer downloads and stores the picture asynchronously, then publishes an update event. Account auto-provisioning is not required.

Configuration:

  • PROXY_OIDC_PICTURE_CLAIM selects the picture URL claim (default: picture). Set it to an empty string to disable syncing. Each new login downloads the picture again and replaces any stored photo, including one uploaded locally.
  • GRAPH_PROFILE_PICTURE_URL_ALLOWLIST restricts HTTP(S) download URLs. When empty, it permits the OIDC issuer scheme and host without its path (OC_OIDC_ISSUER, or GRAPH_OIDC_ISSUER to override it; defaults to OC_URL). Patterns support host globs and an optional exact path or trailing path wildcard. Paths are URL-decoded and cleaned of dot segments before matching. Redirects are not followed. * permits all HTTP(S) URLs and should only be used with an IdP trusted to provide safe URLs.
  • GRAPH_PROFILE_PICTURE_INSECURE controls TLS certificate verification for picture downloads independently from event-bus TLS settings.

Downloads have a 10 MiB size limit and a 10-second timeout. Four workers process sync requests through a queue of 32; a full queue applies backpressure instead of starting more downloads. Failed or cancelled syncs do not publish picture update events. Local profile picture editing remains available.

Related issue

Fixes #1499

Validation

  • Manual testing reported during initial implementation.
  • Ginkgo/Gomega coverage for claim defaults and overrides, account-resolver event emission, URL allowlists, HTTP/TLS behavior, download limits, asynchronous processing, cancellation, and consumer shutdown.
  • Passed all four affected packages with the race detector:
nix-shell -p gcc --run 'go test -race ./services/graph/pkg/service/events ./services/graph/pkg/service/v0 ./services/proxy/pkg/config/defaults ./services/proxy/pkg/middleware'

Checklist

  • Code changes
  • Unit tests added
  • Acceptance tests added
  • Configuration settings documented in config annotations

Copilot AI left a comment

Copy link
Copy Markdown

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 support in the proxy service to (a) sync a user’s profile photo from a configurable OIDC claim on login, and (b) optionally forbid local profile-photo updates via the Graph “me/photo/$value” endpoint for OIDC-authenticated requests.

Changes:

  • Add PROXY_OIDC_PROFILE_PICTURE_CLAIM to fetch a profile-photo URL from OIDC claims and sync it on new sessions.
  • Add PROXY_OIDC_PROFILE_PICTURE_DISABLE_LOCAL_CHANGES to block PUT/PATCH/DELETE to /graph/v1.0/me/photo/$value for OIDC-authenticated requests.
  • Introduce proxy wiring for internal Graph calls (service discovery + separate backend HTTP client).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
services/proxy/pkg/middleware/options.go Extends middleware options with backend HTTP client, internal service selector, and OIDC profile-picture config.
services/proxy/pkg/middleware/account_resolver.go Implements profile-picture fetch + Graph update on new session; optionally blocks local photo mutations.
services/proxy/pkg/config/defaults/defaultconfig.go Adds default values for the new oidc_profile_picture config section.
services/proxy/pkg/config/config.go Introduces OIDCProfilePicture config and env vars for claim + local-change disable.
services/proxy/pkg/command/server.go Wires new config into middleware and creates a dedicated backend HTTP client for internal calls.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread services/proxy/pkg/config/config.go Resolved
Comment thread services/proxy/pkg/command/server.go Resolved
@dschmidt

dschmidt commented May 8, 2026

Copy link
Copy Markdown
Contributor

First of all: Thanks for the effort, @Guibi1!

I think this might entangle two separate concerns too tightly:

  1. Use profile pictures from oidc claims
  2. Disable profile picture updates for the user

I have a feeling the proxy is not the right place to handle the second concern. To me the route handling is crossing service domains in an unfortunate way.
IMHO it's the graph service which should be responsible for ultimately deciding this - and the frontend should be made aware of this, to hide the upload option etc.

When moving this responsibility to the graph service, this leaves us with the question of how to update the profile picture from the proxy (handling it at all there seems to be the right call as the proxy deals with all claims anyway), as the Graph HTTP Api now rejects updates.

Two possibilities from my view:

  1. Emit an event in the proxy and let the graph service consume it. This is rather easy and auditable, but it loses user auth. Again two possibilities:
    1.1 attach the image data to the event, limited by event bus config and feels a bit awkward
    1.2 have no user auth for fetching the image (is this really needed in reality? I haven't seen this in the wild anyway)
  2. Add a gRPC interface to the graph service: less auditable, but we can pass on user auth or bigger image data

It might be easier to discuss separate concerns in separate PRs - unfortunately they are heavily influencing each other...

@Guibi1

Guibi1 commented May 12, 2026

Copy link
Copy Markdown
Author

Agreed! For simplicity (and because i really want this merged), I straight up removed the second concern.
However, using a gRPC interface sounds like the best option, as long as there is already one on the graph service, it would be weird to have one just for this.

@sonarqubecloud

Copy link
Copy Markdown

@dschmidt

Copy link
Copy Markdown
Contributor

afaik there is none - personally I don't think it's too bad adding it, we're not coming up with a new pattern in this code base.

But ultimately not up for me to decide.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.

Comment thread services/proxy/pkg/command/server.go Resolved
Comment thread services/proxy/pkg/config/config.go Resolved
Comment thread services/proxy/pkg/config/config.go Resolved
Comment thread services/proxy/pkg/command/server.go Resolved
@codacy-production

codacy-production Bot commented May 12, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 159 complexity

Metric Results
Complexity 159

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@codacy-production codacy-production Bot left a comment

Copy link
Copy Markdown

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 cannot be merged in its current state due to high-severity logic and security issues.

Critical Findings

  • Compilation Errors: The code references options.AutoProvisionClaims and cfg.OIDCProfilePicture, neither of which exists in the provided configuration or middleware structs.
  • Security Risk: The fetchProfilePicture function lacks host validation, exposing the system to SSRF (Server-Side Request Forgery) by allowing requests to arbitrary URLs provided in OIDC claims.
  • Requirement Gaps: The setting PROXY_OIDC_PROFILE_PICTURE_DISABLE_LOCAL_CHANGES promised in the description is not implemented in the code.
  • Performance Concerns: Synchronizing profile pictures is handled synchronously within the middleware, which will block the login flow and increase latency for users during their first request.

About this PR

  • The account resolver middleware has high complexity and significant new logic for fetching and updating profile pictures, yet no unit tests or integration tests have been provided. This is particularly concerning given the identified logic errors.
  • There is a significant naming mismatch between the PR description ('PROXY_OIDC_PROFILE_PICTURE_CLAIM') and the code ('PROXY_AUTOPROVISION_CLAIM_PROFILE_PICTURE'). Furthermore, the OIDCProfilePicture type used in options.go and server.go appears to be undefined or incorrectly replaced by a string field in the configuration diff.

Test suggestions

  • Missing: Successful profile picture sync on new session with valid claim and URL
  • Missing: Skip profile picture sync if the session is not a new OIDC session
  • Missing: Reject profile picture sync if the URL scheme is not http or https
  • Missing: Reject profile picture if the response size exceeds 10MB limit
  • Missing: Verify Authorization header is only attached to image fetch requests if the host matches the OIDC issuer
  • Missing: Verify Graph API update request includes the correct CS3 token and content type
  • Missing: Verify local changes are disabled when PROXY_OIDC_PROFILE_PICTURE_DISABLE_LOCAL_CHANGES is true
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Missing: Successful profile picture sync on new session with valid claim and URL
2. Missing: Skip profile picture sync if the session is not a new OIDC session
3. Missing: Reject profile picture sync if the URL scheme is not http or https
4. Missing: Reject profile picture if the response size exceeds 10MB limit
5. Missing: Verify Authorization header is only attached to image fetch requests if the host matches the OIDC issuer
6. Missing: Verify Graph API update request includes the correct CS3 token and content type
7. Missing: Verify local changes are disabled when PROXY_OIDC_PROFILE_PICTURE_DISABLE_LOCAL_CHANGES is true

TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback

Comment thread services/proxy/pkg/command/server.go Resolved
Comment thread services/proxy/pkg/config/config.go Resolved
Comment thread services/proxy/pkg/command/server.go Resolved

@codacy-production codacy-production Bot left a comment

Copy link
Copy Markdown

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 introduces OIDC-based profile picture synchronization and the ability to disable local profile updates. While the implementation aligns with the stated goals via new configuration flags, there is a total lack of automated test coverage for these features.

Codacy analysis indicates the PR is technically up to standards regarding code style; however, the account_resolver.go and options.go files have seen a large increase in complexity (101 and 61 respectively) without any new tests to mitigate regression risk. It is recommended to address the missing test scenarios before merging.

About this PR

  • This PR lacks unit and acceptance tests for the core logic. Specifically, the mapping of the OIDC claim to the user profile and the logic to block graph API updates remain unverified. Automated tests are required to ensure the OIDC claim parsing handles various formats (URL vs. binary) correctly.
  • Multiple files (account_resolver.go, options.go, server.go, defaultconfig.go) have undergone significant complexity increases without being covered by tests. This creates a high risk of long-term maintenance issues and hidden bugs in the proxy middleware.

Test suggestions

  • Verify that the profile picture is correctly mapped from the OIDC claim specified in PROXY_OIDC_PROFILE_PICTURE_CLAIM.
  • Verify that attempts to update the profile picture via the graph endpoint return an error or are blocked when PROXY_OIDC_PROFILE_PICTURE_DISABLE_LOCAL_CHANGES is true.
  • Unit tests for new logic in services/proxy/pkg/middleware/account_resolver.go (Complexity: 101, Coverage: 0%).
  • Unit tests for new logic in services/proxy/pkg/middleware/options.go (Complexity: 61, Coverage: 0%).
  • Unit tests for new logic in services/proxy/pkg/command/server.go (Complexity: 28, Coverage: 0%).
  • Unit tests for new logic in services/proxy/pkg/config/defaults/defaultconfig.go (Complexity: 27, Coverage: 0%).
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Verify that the profile picture is correctly mapped from the OIDC claim specified in PROXY_OIDC_PROFILE_PICTURE_CLAIM.
2. Verify that attempts to update the profile picture via the graph endpoint return an error or are blocked when PROXY_OIDC_PROFILE_PICTURE_DISABLE_LOCAL_CHANGES is true.
3. Unit tests for new logic in services/proxy/pkg/middleware/account_resolver.go (Complexity: 101, Coverage: 0%).
4. Unit tests for new logic in services/proxy/pkg/middleware/options.go (Complexity: 61, Coverage: 0%).
5. Unit tests for new logic in services/proxy/pkg/command/server.go (Complexity: 28, Coverage: 0%).
6. Unit tests for new logic in services/proxy/pkg/config/defaults/defaultconfig.go (Complexity: 27, Coverage: 0%).

TIP Improve review quality by adding custom instructions
TIP How was this review? Give us feedback

@dschmidt

dschmidt commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

I've been thinking about this for a bit and came to a few conclusions:
(It's still not up for me to decide whether you should do it like this and if this gets merged at all, but here's how I would approach this problem)

First of all: This feature is more demanding to get right than it might seem at first sight. Sorry you have to go through this in your first contribution :)

Token forwarding

I don't think we should forward the token to the photo source. In OIDC every token has an audience and the token we receive in the proxy is for OpenCloud - not for the image source, that's conceptually a weird thing to forward it and a security nightmare.
Does your photo source/IdP need it? Can you point me/us to the documentation?

ProfilePicture claim

https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims

picture is a standard claim with well defined semantics. Let's use Picture as property in AutoProvisionClaims /variable name and also let it default to picture?
I think if the IdP provides it, we should use it by default - we can override it to empty to opt out?

Graph communication

I think the way you're setting up an http client for talking to the graph service is much too complicated.

I still see two approaches:

  1. You make it analogous to group syncing: add a method to the UserBackend, use the standard way of setting up a libregraph client (just with the user context instead of a service user). This would still be sync and also would make it hard to disable manual uploads in the graph service. We'd need a way to update it even if it's disabled for users (maybe add a new endpoint that allows service users/admins to update avatars for other users but ... meh)
    This has the additional annoyance that the libre graph client currently needs an *os.File to update the picture ... (refactor: map binary params to io.Reader in Go client libre-graph-api#47)

  2. You make it an event and consume it in graph itself. You agreed to the ai review that it might be good to make the download async. Then firing an event in the proxy and handling it in the graph service would be the natural approach imho.
    You could for example modify the UserSignedIn event and attach the picture url. That event is already consumed in graph and is emitted exactly when you are currently updating the profile picture.
    Alternatively you can introduce a new more specific event.
    While at it I would introduce a new event for when the picture has been successfully updated. That one we can use later to update the web ui as soon as the picture is available.
    (Personally I think it leaves a bad first impression if I have to reload the page after first login so my avatar becomes visible)
    The graph service itself controls the picture storage via cs3. We can easily disable the endpoints in graph, while it still handles the events.

You might have guessed: I strongly prefer the second approach.

Http Client configuration

If you agree / the team agrees with me that graph should handle it through an event, we can get rid of the http client setup in the proxy - but the image fetcher needs the same kind of config for insecure mode etc. Not sure we have a useful pattern/example to copy.
I'm a bit torn how we want to handle allowed urls. Default to only the IdP host? allow all urls because the IdP MUST provide us with safe urls (convenient, but :-\ )?

@Guibi1

Guibi1 commented May 16, 2026

Copy link
Copy Markdown
Author

Thanks for all that, i'm really not familiar enough with the codebase to have thought about it that way.
Being opt-out and using events sounds good!
Of the urls, we could default to idP host only and have an unsafe option to allow all? I feel like someone could have a setup where their idP acts as a proxy in front of Active Directory for exemple, and where the picture url is just relayed.

@dschmidt

Copy link
Copy Markdown
Contributor

Maybe allow a glob pattern like https://*.cdn.mydomain.com?
That would also allow for *for all hosts (although that's only a good idea if the IdP takes care of managing secure urls only)
Default to IdP url without path sounds fine to me :)

@dschmidt dschmidt 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.

Did you forget to commit the actual photo service? I don't see it.
Also I don't see how you instantiate it and if you always just use the default http client.

We probably need to setup a configurable client like in the proxy for talking to the IdP:

	oidcHTTPClient := &http.Client{
		Transport: &http.Transport{
			TLSClientConfig: &tls.Config{
				MinVersion:         tls.VersionTLS12,
				InsecureSkipVerify: cfg.OIDC.Insecure, //nolint:gosec
			},
			DisableKeepAlives: true,
		},
		Timeout: time.Second * 10,
	}

Anyhow I really like where this is going! Good job

Comment thread services/graph/pkg/config/config.go Resolved
Comment thread services/graph/pkg/config/config.go Resolved
Comment thread services/graph/pkg/service/v0/option.go Resolved
Comment thread services/proxy/pkg/command/server.go Resolved
@Guibi1
Guibi1 force-pushed the oidc-profile-picture branch from 53fb6fb to b5074d8 Compare June 29, 2026 21:15
@Guibi1
Guibi1 requested a review from dschmidt June 29, 2026 21:22

@dschmidt dschmidt 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.

Great, I'm pretty happy with this now :)

unfortunately it's ultimately not up to me to decide

Comment thread pkg/events/events.go Resolved

@rhafer rhafer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Guibi1 Thanks a lot for you effort on this pull request.

I haven't looked through all of the code yet. Especially I still need to get through the changes in the proxy. But in general I like it. I've added some comments and questions on the parts that I already reviewed.

Comment thread services/graph/pkg/config/config.go Resolved
Comment thread pkg/events/events.go Resolved
Comment thread services/proxy/pkg/config/config.go Resolved
@Guibi1
Guibi1 force-pushed the oidc-profile-picture branch from b5074d8 to d91900f Compare October 23, 2026 16:28
@Guibi1
Guibi1 requested review from dschmidt and rhafer October 23, 2026 16:36
@dschmidt

Copy link
Copy Markdown
Contributor

I will look more closely soon, but could you port your tests to ginkgo already?

@Guibi1 Guibi1 changed the title Feat: Pull users' Profile Picture from the OIDC claims feat: sync profile pictures from OIDC claims Nov 1, 2026
@Guibi1

Guibi1 commented Nov 1, 2026 •

Copy link
Copy Markdown
Author

@dschmidt Ported all six profile-picture test files to Ginkgo/Gomega in 39196ad, including suite entry points for the events and proxy defaults packages. The async tests now use Gomega channel assertions for completion and cancellation. I also adjusted the HTTP fixtures flagged by Codacy and updated the PR description to match the current configuration and event-based implementation.

All four affected packages pass with the race detector:

nix-shell -p gcc --run 'go test -race ./services/graph/pkg/service/events ./services/graph/pkg/service/v0 ./services/proxy/pkg/config/defaults ./services/proxy/pkg/middleware'

Ready for another look when you have time.

CI note: Require Pull Request Labels is action_required before any jobs start. The PR already has Type:Enhancement, which satisfies its label rule. Could a maintainer approve the pending fork workflow run? Its label job is configured to skip fork PRs. Codacy has passed on the new head.
This migration was made with help from GPT 6.1 Sol.

@dschmidt

dschmidt commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

My agent says:

A few things from a full pass:

Default allowlist. We agreed on "default to the IdP URL without path", the code defaults to OC_URL. With an external IdP (the Authentik case from the issue) nothing syncs until GRAPH_PROFILE_PICTURE_URL_ALLOWLIST is set. Either default to the OIDC issuer host, or keep OC_URL and say so clearly in the env description so admins know they have to add their IdP.

oidcIssuer in api_users_user_profile_photo.go and WithProfilePictureSync still carries that name although it's fed the OpenCloud URL (@rhafer flagged this). defaultOrigin or similar.

profile_picture_config.go: misnamed, nothing in here is config, it's the storage + HTTP client wiring for UsersUserProfilePhotoService. Also "picture" vs. "photo" (the rest of the package). Fold it into api_users_user_profile_photo.go next to the constructor, or users_user_profile_photo_service.go.

Mock: mocks/users_user_profile_photo_provider.go was regenerated with mockery v2, all other graph mocks use v3 (template: testify), so most of that hunk is churn. Please regenerate with the repo's mockery.

Tests: the for _, tt := range loops emitting It should be DescribeTable, that's what the rest of the repo uses. The bare top-level var _ = It( in the events and proxy defaults specs need a Describe. The two new v0 specs should dot-import ginkgo like their siblings. fakePhotoService in v0/profile_picture_test.go is unused.

Path patterns: https://h/avatars/* is a plain prefix on EscapedPath, so https://h/avatars/../etc passes. Clean the path (path.Clean) before matching, or drop path patterns and keep it host-only.

Concurrency: go syncProfilePicture per event is unbounded, a login burst means N parallel 10 MiB downloads. A small semaphore (or errgroup.SetLimit) would do.

Overwrite semantics: every login re-downloads and overwrites whatever is stored, including a picture the user uploaded locally. That's fine given the issue wants central management, but it should be stated in the env description of PROXY_OIDC_PICTURE_CLAIM, since local editing stays enabled.

Smaller: the "no profile picture claim" log line still has no user info; the SyncPhotoFromURL doc is duplicated on interface and impl, maxProfilePhotoBytes is commented twice, and the three-line "always enabled" comment in the wiring belongs in the PR, not the file.

Commit messages don't follow conventional commits, but that's moot if we squash with the PR title.

Apart from that:
OpenCloud is doing a QA sprint right now and this is obviously an enhancement, so it's probably a few more weeks before there's even a chance someone is really looking into this

@Guibi1

Guibi1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Author

Done in 94350d9. The allowlist now defaults to the IdP origin, paths are cleaned before matching, and downloads are limited to four workers.

I also updated the mock and test style, moved the service wiring, and addressed the smaller points. The setting now makes it clear that logging in replaces any locally uploaded photo.

@Guibi1

Guibi1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Author

Could someone rerun the antivirus job? It failed on a truncated settings response (use of closed network connection in the proxy log). Looks unrelated to this PR.

@LarsArtmann

Copy link
Copy Markdown

+1; I would like to see this get merged :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Qualification

Development

Successfully merging this pull request may close these issues.

[FR] Tell Opencloud OIDC where to find the Profile Picture

6 participants