fix(postgres): confine identity writes and GetPrincipal to the caller's org

Issue: archie-core-wkey2
This commit is contained in:
sam committed 2026-10-13 15:07:48 +11:00
1 parent 25face6d04
commit 1b561402cf
2 files changed
+8 -3

No files matched your search

@@ -154,7 +154,7 @@ func (s *Store) Apply(ctx context.Context, id identity.IdentityID, expectedVersi
defer func() { _ = tx.Rollback(ctx) }()
q := postgresdb.New(tx)
current, err := q.GetIdentity(ctx, string(id))
current, err := q.GetVisibleIdentity(ctx, postgresdb.GetVisibleIdentityParams{ID: string(id), ScopeOrg: memberScope(ctx)})
if errors.Is(err, pgx.ErrNoRows) {
return identity.Identity{}, identity.ErrNotFound
}
@@ -268,7 +268,7 @@ func (s *Store) BindSubject(ctx context.Context, id identity.IdentityID, subject
defer func() { _ = tx.Rollback(ctx) }()
q := postgresdb.New(tx)
current, err := q.GetIdentity(ctx, string(id))
current, err := q.GetVisibleIdentity(ctx, postgresdb.GetVisibleIdentityParams{ID: string(id), ScopeOrg: memberScope(ctx)})
if errors.Is(err, pgx.ErrNoRows) {
return identity.ErrNotFound
}
@@ -317,7 +317,7 @@ func (s *Store) UnbindSubject(ctx context.Context, id identity.IdentityID, subje
}
return pgx.BeginFunc(ctx, s.pool, func(tx pgx.Tx) error {
q := postgresdb.New(tx)
current, err := q.GetIdentity(ctx, string(id))
current, err := q.GetVisibleIdentity(ctx, postgresdb.GetVisibleIdentityParams{ID: string(id), ScopeOrg: memberScope(ctx)})
if errors.Is(err, pgx.ErrNoRows) {
return identity.ErrNotFound
}
@@ -72,6 +72,11 @@ func (s *server) GetPrincipal(ctx context.Context, request *pb.GetPrincipalReque
if s.deps.Principals == nil {
return nil, status.Error(codes.Unavailable, "identity store unavailable")
}
if s.deps.Identities != nil {
if _, err := s.deps.Identities.Get(ctx, identity.IdentityID(request.IdentityId)); err != nil {
return nil, identityStatus(err)
}
}
value, err := s.deps.Principals.PrincipalFor(ctx, identity.IdentityID(request.IdentityId))
if err != nil {
return nil, identityStatus(err)