@@ -51,6 +51,12 @@ type manager struct {
5151 httpClient * http.Client
5252}
5353
54+ type primaryUser struct {
55+ username string
56+ uid_number int64
57+ gid_number int64
58+ }
59+
5460func (manager ) RevaPlugin () reva.PluginInfo {
5561 return reva.PluginInfo {
5662 ID : "grpc.services.userprovider.drivers.indigo-iam" ,
@@ -75,6 +81,14 @@ type config struct {
7581 UserFetchInterval int `mapstructure:"user_fetch_interval" docs:"3600"`
7682 UserGroupsCacheExpiration int `mapstructure:"user_groups_cache_expiration" docs:"5"`
7783 PageSize int `mapstructure:"page_size" docs:"100"`
84+
85+ // PrimaryUsers maps an IAM account UUID to an internal user with the given
86+ // username, uid and gid, and marks that user as USER_TYPE_PRIMARY. Every other
87+ // user is treated as USER_TYPE_LIGHTWEIGHT. This is needed because IAM
88+ // has no native concept of primary vs. lightweight accounts: by default
89+ // every account looks the same, so an explicit allowlist is required to
90+ // recognize the subset of "real" organization members.
91+ PrimaryUsers map [string ]primaryUser `mapstructure:"primary_users" docs:"{}"`
7892}
7993
8094func (c * config ) ApplyDefaults () {
@@ -261,10 +275,17 @@ func (m *manager) fetchAllUserAccounts(ctx context.Context) error {
261275 if ! acc .Active {
262276 continue
263277 }
264- u := m .accountToProto (acc )
278+ u , remapped := m .accountToProto (acc )
265279 if err := m .cache .StoreUser (u ); err != nil {
266280 log .Error ().Err (err ).Str ("uuid" , acc .ID ).Msg ("indigoiam user: cache error" )
267281 }
282+ // Only the exceptional, remapped case needs a reverse-index
283+ // entry; lightweight users already have OpaqueId == IAM UUID.
284+ if remapped {
285+ if err := m .cache .StoreIAMUUID (u .Id .OpaqueId , acc .ID ); err != nil {
286+ log .Error ().Err (err ).Str ("uuid" , acc .ID ).Msg ("indigoiam user: failed to cache IAM UUID mapping" )
287+ }
288+ }
268289 }
269290
270291 nextStart := startIndex + list .ItemsPerPage
@@ -276,17 +297,36 @@ func (m *manager) fetchAllUserAccounts(ctx context.Context) error {
276297 return nil
277298}
278299
279- func (m * manager ) accountToProto (acc * iamAccount ) * userpb.User {
300+ // accountToProto converts an iamAccount to the CS3 userpb.User type.
301+ // If acc.ID is a key in conf.PrimaryUsers, the OpaqueId is replaced by the
302+ // mapped value and the user is marked PRIMARY; otherwise the user is
303+ // LIGHTWEIGHT and keeps its original IAM UUID as OpaqueId.
304+ func (m * manager ) accountToProto (acc * iamAccount ) (* userpb.User , bool ) {
305+ opaqueID := acc .ID
306+ userType := userpb .UserType_USER_TYPE_LIGHTWEIGHT
307+ uid := int64 (0 )
308+ gid := int64 (0 )
309+ remapped := false
310+
311+ if mapped , remapped := m .conf .PrimaryUsers [acc .ID ]; remapped {
312+ opaqueID = mapped .username
313+ uid = int64 (mapped .uid_number )
314+ gid = int64 (mapped .gid_number )
315+ userType = userpb .UserType_USER_TYPE_PRIMARY
316+ }
317+
280318 return & userpb.User {
281319 Id : & userpb.UserId {
282- OpaqueId : acc . ID ,
320+ OpaqueId : opaqueID ,
283321 Idp : m .conf .IDProvider ,
284- Type : userpb . UserType_USER_TYPE_PRIMARY ,
322+ Type : userType ,
285323 },
286324 Username : acc .UserName ,
287325 Mail : acc .primaryEmail (),
288326 DisplayName : acc .DisplayName ,
289- }
327+ UidNumber : uid ,
328+ GidNumber : gid ,
329+ }, remapped
290330}
291331
292332// ---------------------------------------------------------------------------
@@ -364,7 +404,15 @@ func (m *manager) GetUserGroups(ctx context.Context, uid *userpb.UserId) ([]stri
364404 return cached , nil
365405 }
366406
367- url := fmt .Sprintf ("%s/iam/account/%s/groups" , m .conf .IAMBaseURL , uid .OpaqueId )
407+ iamUUID , err := m .cache .GetIAMUUID (ctx , uid .OpaqueId )
408+ if err != nil {
409+ // No mapping found — assume the OpaqueId is already the IAM UUID
410+ // (this is always true for lightweight users, since they are never
411+ // remapped).
412+ iamUUID = uid .OpaqueId
413+ }
414+
415+ url := fmt .Sprintf ("%s/iam/account/%s/groups" , m .conf .IAMBaseURL , iamUUID )
368416 var list iamGroupList
369417 if err := m .iamGET (ctx , url , & list ); err != nil {
370418 return nil , err
0 commit comments