Skip to content

Commit

Permalink
MG-2456 - Refactor auth (absmach#2409)
Browse files Browse the repository at this point in the history
- Set/Unset parent Group for Things and Channels (absmach#2486)
- Move groups out of pkg (absmach#2493)
- Separate Things authn and Channels authz (absmach#2496)

Signed-off-by: Arvindh <[email protected]>

NOISSUE - Add Publish/Subscribe to channels (absmach#2497)

Signed-off-by: Arvindh <[email protected]>

MG-2457 - Update auth tests (absmach#2503)

Signed-off-by: Felix Gateru <[email protected]>

MG-2477 - Replace Things with Clients (absmach#2508)

Signed-off-by: Dusan Borovcanin <[email protected]>

NOISSUE - Rename Things to Clients

Signed-off-by: Felix Gateru <[email protected]>
Signed-off-by: Arvindh <[email protected]>
  • Loading branch information
arvindh123 authored and nyagamunene committed Nov 26, 2024
1 parent 6760115 commit 0a5f883
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion api/openapi/auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tags:
externalDocs:
description: Find out more about domains
url: https://docs.magistrala.abstractmachines.fr/

- name: Health
description: Service health check endpoint.
externalDocs:
Expand Down
13 changes: 8 additions & 5 deletions api/openapi/clients.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1100,9 +1100,12 @@ components:
"bb7edb32-2eac-4aad-aebe-ed96fe073879",
]
relation:
type: string
example: "editor"
description: Policy relation.
type: array
minItems: 0
items:
type: string
example: ["m_write", "g_add"]
description: Policy relations.
required:
- user_ids
- relation
Expand All @@ -1123,7 +1126,7 @@ components:
]
relation:
type: string
example: "editor"
example: "m_write"
description: Policy relations.
member_kind:
type: string
Expand All @@ -1150,7 +1153,7 @@ components:
]
relation:
type: string
example: "editor"
example: "m_write"
description: Policy relations.
required:
- users_ids
Expand Down
6 changes: 3 additions & 3 deletions cmd/auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import (
authgrpcapi "github.com/absmach/magistrala/auth/api/grpc/auth"
tokengrpcapi "github.com/absmach/magistrala/auth/api/grpc/token"
httpapi "github.com/absmach/magistrala/auth/api/http"
"github.com/absmach/magistrala/auth/bolt"
"github.com/absmach/magistrala/auth/hasher"
"github.com/absmach/magistrala/auth/jwt"
apostgres "github.com/absmach/magistrala/auth/postgres"
"github.com/absmach/magistrala/auth/tracing"
boltclient "github.com/absmach/magistrala/internal/clients/bolt"
grpcAuthV1 "github.com/absmach/magistrala/internal/grpc/auth/v1"
grpcTokenV1 "github.com/absmach/magistrala/internal/grpc/token/v1"
mglog "github.com/absmach/magistrala/logger"
"github.com/absmach/magistrala/auth/bolt"
"github.com/absmach/magistrala/auth/hasher"
"github.com/absmach/magistrala/pkg/jaeger"
"github.com/absmach/magistrala/pkg/policies/spicedb"
"github.com/absmach/magistrala/pkg/postgres"
Expand Down Expand Up @@ -244,7 +244,7 @@ func newService(_ context.Context, db *sqlx.DB, tracer trace.Tracer, cfg config,

t := jwt.New([]byte(cfg.SecretKey))

svc := auth.New(keysRepo,patsRepo, hasher, idProvider, t, pEvaluator, pService, cfg.AccessDuration, cfg.RefreshDuration, cfg.InvitationDuration)
svc := auth.New(keysRepo, patsRepo, hasher, idProvider, t, pEvaluator, pService, cfg.AccessDuration, cfg.RefreshDuration, cfg.InvitationDuration)
svc = api.LoggingMiddleware(svc, logger)
counter, latency := prometheus.MakeMetrics("auth", "api")
svc = api.MetricsMiddleware(svc, counter, latency)
Expand Down
1 change: 0 additions & 1 deletion docker/nginx/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ fi
envsubst '
${MG_NGINX_SERVER_NAME}
${MG_DOMAINS_HTTP_PORT}
${MG_AUTH_HTTP_PORT}
${MG_GROUPS_HTTP_PORT}
${MG_USERS_HTTP_PORT}
${MG_CLIENTS_HTTP_PORT}
Expand Down
2 changes: 1 addition & 1 deletion docker/nginx/nginx-key.conf
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ http {
location ~ ^/(domains|keys|pats) {
include snippets/proxy-headers.conf;
add_header Access-Control-Expose-Headers Location;
proxy_pass http://auth:${MG_AUTH_HTTP_PORT};
proxy_pass http://domains:${MG_DOMAINS_HTTP_PORT};
}

# Proxy pass to users service
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ require (
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
github.com/sqids/sqids-go v0.4.1
github.com/stretchr/testify v1.10.0
github.com/sqids/sqids-go v0.4.1
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.57.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0
go.opentelemetry.io/otel v1.32.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
Expand Down
10 changes: 5 additions & 5 deletions pkg/sdk/go/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
"github.com/absmach/magistrala"
"github.com/absmach/magistrala/bootstrap/api"
bmocks "github.com/absmach/magistrala/bootstrap/mocks"
chmocks "github.com/absmach/magistrala/channels/mocks"
climocks "github.com/absmach/magistrala/clients/mocks"
mglog "github.com/absmach/magistrala/logger"
authnmocks "github.com/absmach/magistrala/pkg/authn/mocks"
authzmocks "github.com/absmach/magistrala/pkg/authz/mocks"
"github.com/absmach/magistrala/pkg/errors"
sdk "github.com/absmach/magistrala/pkg/sdk/go"
readersapi "github.com/absmach/magistrala/readers/api"
readersmocks "github.com/absmach/magistrala/readers/mocks"
thmocks "github.com/absmach/magistrala/things/mocks"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -135,10 +135,10 @@ func setupMinimalBootstrap() *httptest.Server {

func setupMinimalReader() *httptest.Server {
repo := new(readersmocks.MessageRepository)
authz := new(authzmocks.Authorization)
channels := new(chmocks.ChannelsServiceClient)
authn := new(authnmocks.Authentication)
things := new(thmocks.ThingsServiceClient)
clients := new(climocks.ClientsServiceClient)

mux := readersapi.MakeHandler(repo, authn, authz, things, "test", "")
mux := readersapi.MakeHandler(repo, authn, clients, channels, "test", "")
return httptest.NewServer(mux)
}

0 comments on commit 0a5f883

Please sign in to comment.