Skip to content

Commit

Permalink
Check owner permissions in resolvers (#291)
Browse files Browse the repository at this point in the history
* check permissions against ownerID, rather than resource

Signed-off-by: Matt Siwiec <[email protected]>

* establish permissions auth-relationship in ports

Signed-off-by: Matt Siwiec <[email protected]>

---------

Signed-off-by: Matt Siwiec <[email protected]>
  • Loading branch information
rizzza authored Dec 18, 2023
1 parent 627379f commit 6bb9a56
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 34 deletions.
1 change: 1 addition & 0 deletions internal/ent/schema/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (Port) Fields() []ent.Field {
Annotations(
entgql.Type("ID"),
entgql.Skip(entgql.SkipWhereInput, entgql.SkipMutationUpdateInput),
pubsubinfo.EventsHookAdditionalSubject("loadbalancer"),
),
}
}
Expand Down
26 changes: 13 additions & 13 deletions internal/graphapi/loadbalancer.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions internal/graphapi/origin.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 14 additions & 13 deletions internal/graphapi/pool.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions internal/graphapi/port.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions internal/manualhooks/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,11 @@ func PortHooks() []ent.Hook {
})
}

relationships = append(relationships, events.AuthRelationshipRelation{
Relation: "loadbalancer",
SubjectID: load_balancer_id,
})

msg := events.ChangeMessage{
EventType: eventType(m.Op()),
SubjectID: objID,
Expand Down Expand Up @@ -1089,6 +1094,11 @@ func PortHooks() []ent.Hook {
additionalSubjects = append(additionalSubjects, dbObj.Edges.LoadBalancer.OwnerID)
additionalSubjects = append(additionalSubjects, dbObj.Edges.LoadBalancer.ProviderID)

relationships = append(relationships, events.AuthRelationshipRelation{
Relation: "loadbalancer",
SubjectID: dbObj.LoadBalancerID,
})

// we have all the info we need, now complete the mutation before we process the event
retValue, err := next.Mutate(ctx, m)
if err != nil {
Expand Down

0 comments on commit 6bb9a56

Please sign in to comment.