Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Bug: CreateGroup via PAT creates an orphan group row

Abierto
#1,645 0 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@AmanGIT07 ya está trabajando en esto.

Desde el 25/5/2026.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

bug

Summary

When CreateGroup is called by a PAT-authenticated principal, the Postgres groups row is written but the SpiceDB hierarchy links and owner policy are never wired. The row is left as an orphan.

Reproduction

  1. Authenticate as a PAT scoped to an org with the create-group permission.
  2. Call CreateGroup.
  3. Observe: response carries an error; a row exists in groups for the requested name; SpiceDB has no group#org / org#member@group relations and no owner policy in policies.

Root cause

  1. core/group/service.go:72-74 — s.repository.Create(ctx, grp) writes the Postgres row first.
  2. core/group/service.go:77 — s.membershipService.OnGroupCreated(ctx, newGroup.ID, newGroup.OrganizationID, principal.ID, principal.Type) passes the raw principal. For PAT auth this is (<pat-id>, "app/pat").
  3. core/membership/service.go:1302 — OnGroupCreated calls SetGroupMemberRole(..., creatorID, creatorType, schema.GroupOwnerRole).
  4. core/membership/service.go:1402-1420 — validateGroupPrincipal switches on principal type and accepts only app/user; everything else returns ErrInvalidPrincipalType.
  5. The error propagates back to the group Create caller, but repository.Create is not rolled back.

Impact

  • Orphan rows accumulate in groups on each failed PAT-driven CreateGroup call.
  • The orphan has no hierarchy in SpiceDB, no owner policy in Postgres, and is unreachable through normal listing (membership-based listing won't surface it either, since there's no policy row).

Suggested fix

Resolve the PAT to its underlying user before invoking OnGroupCreated, mirroring the pattern in CreateProject at core/project/service.go:113:

principal, err := s.authnService.GetPrincipal(ctx)
if err != nil {
    return Group{}, fmt.Errorf("%w: %s", authenticate.ErrInvalidID, err.Error())
}
...
subjectID, subjectType := principal.ResolveSubject()  // PAT → user
if err = s.membershipService.OnGroupCreated(ctx, newGroup.ID, newGroup.OrganizationID, subjectID, subjectType); err != nil {
    return Group{}, err
}

Two-line change. Independent of the ListByUser → List migration in #1643 (this bug pre-dates that work).

Cleanup

Existing orphan rows should be identified and either backfilled with hierarchy + owner or deleted. Candidate query: groups whose id has no matching row in policies with resource_type = 'app/group'.

How surfaced

Found while testing the group listing migration in #1643 with PAT-authenticated calls. The listing bug there was fixed in 42a5c508; this write-side bug is independent.

Lenguaje dominante
Go
Estrellas
344
Forks
48
Merge medio
1 d 22 h
PR fusionados (30 d)
38

Preparar el entorno

  • Incluye un Dockerfile o un archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de raystack/frontier

Todos los issues de raystack/frontier

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.