Skip to content

exchange login identifiers for a stable internal user id in the proxy #4173

Backlog

Description

@butonic

Is your feature request related to a problem? Please describe.

Changing OC_URL or switching to a different IdP breaks all existing shares: #4170

The proxy writes the OIDC issuer into the CS3 user id of every internal user:

https://github.com/opencloud-eu/opencloud/blob/0629702ecf4/services/proxy/pkg/user/backend/cs3.go#L502-L506

That idp ends up in the share manager (owner, creator, grantee) and in the storage (owner xattrs), and reva compares it when checking who created a share or who it was granted to:

https://github.com/opencloud-eu/reva/blob/02d5d9ba9a18/pkg/share/share.go#L151-L159

which uses https://github.com/opencloud-eu/reva/blob/02d5d9ba9a18/pkg/utils/utils.go#L220-L223

// UserEqual returns whether two users have the same field values.
func UserEqual(u, v *userpb.UserId) bool {
	return u != nil && v != nil && u.Idp == v.Idp && UserIDEqual(u, v)
}

When the issuer changes, the same user suddenly has a different id. Owners still see their shares, but IsCreatedByUser fails, so they cannot delete them (404). Grantees lose access.

We already stopped comparing the idp in decomposedfs grants in 2022 (cs3org/reva#3266, which introduced UserIDEqual). The share manager and the owner checks in decomposedfs were left behind. That inconsistency is what #4170 runs into.

The same issuer also leaks into the OCM addresses we send to other instances, see #3783 and the OCM section below.

This is not new. I have been annoyed by this since 2019:

All of them were closed as stale or outdated. None of them were fixed.

Describe the solution you'd like

Distinguish two kinds of identifiers:

  • login identifier: what the user authenticates with, e.g. sub@iss, a username, an email address, a public link token, an OCM address. It can change, and a user can have several of them. In the graph api these are the identities of a user.
  • unique identifier: stable, internal, persistent and non-reassignable. Rolled by us, or by the LDAP under our control, in the openCloudUUID attribute. Not an entryUUID or objectGUID of an LDAP we do not control: they change when users are reimported. Internally we only ever use this one.

The proxy exchanges the login identifier for the unique identifier right after authentication. Most of that already happens: the proxy looks up the user and mints a reva token for the internal user. What changes is that we stop stamping the issuer into the id, and that we look users up by their identities (sub@iss) instead of by username or email. Everything behind the proxy (gateway, share manager, storage providers, search, activitylog, ...) only sees the unique identifier. The idp of internal users is no longer part of the id, and internal user shares must not compare it.

The CS3 requests behind the proxy do not need the claims of the initial identity. A storage provider needs an id it can persist and check grants against ... not the login identifier. That is why reva once supported looking up numeric uid and gid from LDAP. That CS3 requests to the storage provider carry a grant with the full user id object, including the idp, may have led to the current implementation.

Grants should be an internal thing. To create a grant you need an internal user id, and no issuer is part of that identifier. The user manager allows looking up users, and creating federated users for OCM shares. The unique id that is created in the process is what we persist in grants. We could add a displayname and email to the grant to let end users identify the grantee ... but we can also query the grantee data on the fly when listing a directory, so it never gets stale.

Changing the IdP then becomes an admin task that does not touch any share or file: add an identity for the new IdP to the user, migrate the IdP, remove the old identity. Rewriting all shares and grants is not an option.

I'd go one step further and do this exchange regardless of the type of user:

  • internal users
  • CS3 guest users
  • email users (the new guest links)
  • OCM users, see below
  • public links: currently the public share auth manager impersonates the creator of the link and adds a scope: https://github.com/opencloud-eu/reva/blob/02d5d9ba9a18/pkg/auth/manager/publicshares/publicshares.go#L133-L180 A technical user per link reflects that better. We could move authenticating via the public link token into the auth middlewares. The request then gets a public link identity, scoped to the resource with the permissions of the link. We still need a link manager for the token, password, expiry and name, but the scope checks and the public storage provider could mostly go away. Uploads via a link would then belong to the link user instead of the creator.

Reusing the same grant mechanism for internal shares, public links and OCM shares should make the code a lot slimmer: one authorization path instead of grants plus public link scopes plus OCM share scopes.

It also opens the door to requiring a stronger authentication for some spaces, e.g. a session with a second factor (acr/amr claims). That is a different identity of the same user, with the same unique identifier, so it can be handled by dynamically reauthenticating the user when the space requires it. The open question is which IdPs support the required level.

OCM

OCM is a backend protocol with its own credentials. We never forward the access token of the IdP or of the proxy. The receiving side sends the shared secret of the share as a bearer token: https://github.com/opencloud-eu/reva/blob/02d5d9ba9a18/pkg/ocm/storage/received/ocm.go#L207 The sending side looks up the share by that secret and authenticates the request as the accepted federated user, with an OCM share scope: https://github.com/opencloud-eu/reva/blob/02d5d9ba9a18/pkg/auth/manager/ocmshares/ocmshares.go

So a federated user is just another identity: the issuer is the remote OCM Server Address, the issuer assigned id is the remote identifier. We map it to an internal unique identifier and persist grants for that. The shared secret is per share, not per user, so the request must stay restricted to the resource of that one share ... the same pattern as a public link identity.

The issuer of an OCM address is the OCM server, not the IdP. The OCM spec (https://github.com/cs3org/OCM-API/blob/472387058c/IETF-OCM.md#L151-L184) says:

OCM Address - identifies a user or group "at" an OCM Server. The OCM Address contains a server specific Party identifier, a host locating the OCM Server and an optional port.

ocm-address = identifier "@" host [ ":" port]

and identifiers are compared byte for byte:

OCM Addresses use this comparison for their server part and compare identifiers byte for byte.

We already put the OCM provider domain into the host part, but our internal idp is the issuer URL, so the identifier becomes <uuid>@<issuer>: https://github.com/opencloud-eu/reva/blob/02d5d9ba9a18/internal/grpc/services/ocmshareprovider/ocmshareprovider.go#L304-L305 The addresses we send look like <uuid>@https://idp.example.com@cloud.example.com. When our issuer changes, every OCM address of our users changes, and a remote instance has to treat them as different users. With internal ids without issuer they become <uuid>@cloud.example.com, which also fixes #3783. Incoming shares already ignore the nested issuer and look up the local user by opaque id only: https://github.com/opencloud-eu/reva/blob/02d5d9ba9a18/internal/http/services/ocmd/shares.go#L127-L134

The spec even anticipates identities: the userID exchanged in the invite flow "does not need to match" the username, "a different userID could be given out to each contact, to avoid correlation of identities", and implementers "MAY support linking of the two identities belonging to that same user". With an identities mechanism, pairwise ids are just more identities of the same user.

Describe alternatives you've considered

  • a) rewrite all shares and grants when the issuer changes. Every service that persists a user id needs to take part, and it has to happen for every IdP change. Not an option IMO.
  • b) keep a history of previous sub@iss ids per user and check all of them (Keep track of previous userids owncloud/ocis#51). Only defers the rewrite, and adding an entry to the history grants access to all data of that user, so only admins could be allowed to do it.
  • c) only stop comparing the idp for internal users. Fixes All internal shares are broken after a domain change #4170 quickly, but leaves the other user types with their own id handling. A good first step though.

Additional context

Existing data still contains the old issuer as idp. If we stop comparing it for internal users, existing shares keep working without a migration, as long as the opaque ids of the different user types cannot collide. Today OCM ids are <remote id>@<remote domain>, public link ids are the token and internal ids are uuids. They are unlikely to collide, but only by accident. The user manager should mint a uuid for every user type.

Remote OCM instances will see a different address for our users after the switch, because they stored the old <uuid>@<issuer>@<domain> form. That is a one time change, but it belongs in the changelog.

  • stop comparing the idp of internal users in share and permission checks
  • stop stamping the issuer into internal user ids in the proxy
  • look up users by their identities in the proxy
  • document how to migrate to a different IdP using the graph api identities
  • only accept internal user ids (without issuer) when creating grants, resolve grantee display data when listing
  • same for guest and email users
  • OCM users as identities, send <uuid>@<ocm domain> as OCM address
  • public links as technical users, authenticated in the auth middlewares
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions