Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MG-2301 - Verify connections during adding of bootstrap config #2371

Open
wants to merge 52 commits into
base: main
Choose a base branch
from

Conversation

nyagamunene
Copy link
Contributor

@nyagamunene nyagamunene commented Aug 1, 2024

What type of PR is this?

This is a bug fix because it fixes the following issue: #2301

What does this do?

It adds verify connections in the add method in bootstrap.

Which issue(s) does this PR fix/relate to?

Have you included tests for your changes?

Yes

Did you document any new/modified feature?

N/A

Notes

@nyagamunene nyagamunene changed the title MG-2301 - Verify connections during creation of bootstrap MG-2301 - Verify connections during adding of bootstrap config Aug 1, 2024
@nyagamunene nyagamunene self-assigned this Aug 2, 2024
@nyagamunene nyagamunene marked this pull request as ready for review August 7, 2024 18:47
things/things.go Outdated
@@ -33,6 +33,9 @@ type Service interface {
// the provided key.
ListClientsByGroup(ctx context.Context, token, groupID string, pm clients.Page) (clients.MembersPage, error)

// VerifyConnections verifies if a list of channels is connected to a list of channels.
VerifyConnections(ctx context.Context, token string, thingID, groupID []string) (clients.ConnectionsPage, error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of thingID groupID we can have like thingIDs and groupIDs, since they are slice

bootstrap/events/producer/streams_test.go Show resolved Hide resolved
auth/service.go Outdated
Comment on lines 1073 to 1121
func (svc service) VerifyConnections(ctx context.Context, thingsId, channelsId []string) (ConnectionsPage, error) {
uniqueThings := getUniqueValues(thingsId)
uniqueChannels := getUniqueValues(channelsId)

cp := ConnectionsPage{}
totalConnectionsCount := len(uniqueChannels) * len(uniqueThings)
totalConnectedCount := 0

cp.Connections = make([]ConnectionStatus, 0, totalConnectionsCount)

for _, th := range uniqueThings {
for _, ch := range uniqueChannels {
err := svc.agent.CheckPolicy(ctx, PolicyReq{
Subject: ch,
SubjectType: GroupType,
Permission: GroupRelation,
Object: th,
ObjectType: ThingType,
})
var status string
switch {
case err == nil:
status = connected
totalConnectedCount++
case errors.Contains(err, svcerr.ErrAuthorization):
status = disconnected
default:
return ConnectionsPage{}, errors.Wrap(svcerr.ErrMalformedEntity, err)
}

cp.Connections = append(cp.Connections, ConnectionStatus{
ThingId: th,
ChannelId: ch,
Status: status,
})
}
}

switch {
case totalConnectedCount == totalConnectionsCount:
cp.Status = allConn
case totalConnectedCount == 0:
cp.Status = allDisConn
default:
cp.Status = partConn
}

return cp, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can have this logic in Things service,
Like things service will verify connection via auth gRPC connection.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be inefficent if we move this logic to things service, but in future we can have direct grpc connection to spiceDB from things service.

Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Bootstrap config state could not change, where thing and channel connected before config creation
2 participants