Skip to content

Commit 552e970

Browse files
fix(core): update casbin policy to allow authorization service (#1041)
This adds authorization service rpc to `org-admin` and `admin` role. It also adds kas `rewrap` to the unknown role. --------- Co-authored-by: Jake Van Vorhis <[email protected]>
1 parent 1be04f6 commit 552e970

File tree

4 files changed

+22
-31
lines changed

4 files changed

+22
-31
lines changed

service/internal/auth/authn.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ var (
4949
// KAS Public Key Endpoints
5050
"/kas.AccessService/PublicKey",
5151
"/kas.AccessService/LegacyPublicKey",
52+
"/kas.AccessService/Info",
5253
"/kas/kas_public_key",
5354
"/kas/v2/kas_public_key",
5455
// HealthZ

service/internal/auth/authn_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,7 @@ type FakeAccessServiceServer struct {
5757
kas.UnimplementedAccessServiceServer
5858
}
5959

60-
func (f *FakeAccessServiceServer) Info(ctx context.Context, _ *kas.InfoRequest) (*kas.InfoResponse, error) {
61-
if md, ok := metadata.FromIncomingContext(ctx); ok {
62-
f.accessToken = md.Get("authorization")
63-
f.dpopKey = GetJWKFromContext(ctx)
64-
}
65-
60+
func (f *FakeAccessServiceServer) Info(context.Context, *kas.InfoRequest) (*kas.InfoResponse, error) {
6661
return &kas.InfoResponse{}, nil
6762
}
6863

@@ -74,7 +69,11 @@ func (f *FakeAccessServiceServer) LegacyPublicKey(context.Context, *kas.LegacyPu
7469
return &wrapperspb.StringValue{}, nil
7570
}
7671

77-
func (f *FakeAccessServiceServer) Rewrap(context.Context, *kas.RewrapRequest) (*kas.RewrapResponse, error) {
72+
func (f *FakeAccessServiceServer) Rewrap(ctx context.Context, _ *kas.RewrapRequest) (*kas.RewrapResponse, error) {
73+
if md, ok := metadata.FromIncomingContext(ctx); ok {
74+
f.accessToken = md.Get("authorization")
75+
f.dpopKey = GetJWKFromContext(ctx)
76+
}
7877
return &kas.RewrapResponse{}, nil
7978
}
8079

@@ -454,7 +453,7 @@ func (s *AuthSuite) TestDPoPEndToEnd_GRPC() {
454453

455454
client := kas.NewAccessServiceClient(conn)
456455

457-
_, err = client.Info(context.Background(), &kas.InfoRequest{})
456+
_, err = client.Rewrap(context.Background(), &kas.RewrapRequest{})
458457
s.Require().NoError(err)
459458
s.NotNil(fakeServer.dpopKey)
460459
dpopJWKFromRequest, ok := fakeServer.dpopKey.(jwk.RSAPublicKey)

service/internal/auth/casbin.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,35 @@ var defaultPolicy = `
4545
## gRPC routes
4646
p, role:org-admin, policy.*, *, allow
4747
p, role:org-admin, kasregistry.*, *, allow
48-
p, role:org-admin, kas.AccessService/Rewrap, *, allow
48+
p, role:org-admin, kas.AccessService/Rewrap, *, allow
49+
p, role:org-admin, authorization.*, *, allow
4950
## HTTP routes
5051
p, role:org-admin, /attributes*, *, allow
5152
p, role:org-admin, /namespaces*, *, allow
5253
p, role:org-admin, /subject-mappings*, *, allow
5354
p, role:org-admin, /resource-mappings*, *, allow
5455
p, role:org-admin, /key-access-servers*, *, allow
55-
p, role:org-admin, /kas/v2/rewrap, *, allow
56-
p, role:org-admin, /unsafe*, *, allow
56+
p, role:org-admin, /kas/v2/rewrap, *, allow
57+
p, role:org-admin, /unsafe*, *, allow
5758
5859
# Role: Admin
5960
## gRPC routes
60-
p, role:admin, policy.*, *, allow
61-
p, role:admin, kasregistry.*, *, allow
62-
p, role:admin, kas.AccessService/Info, *, allow
63-
p, role:admin, kas.AccessService/Rewrap, *, allow
61+
p, role:admin, policy.*, *, allow
62+
p, role:admin, kasregistry.*, *, allow
63+
p, role:admin, kas.AccessService/Rewrap, *, allow
64+
p, role:admin, authorization.*, *, allow
6465
## HTTP routes
6566
p, role:admin, /attributes*, *, allow
6667
p, role:admin, /namespaces*, *, allow
6768
p, role:admin, /subject-mappings*, *, allow
6869
p, role:admin, /resource-mappings*, *, allow
6970
p, role:admin, /key-access-servers*, *, allow
70-
p, role:admin, /kas/v2/rewrap, *, allow
71+
p, role:admin, /kas/v2/rewrap, *, allow
7172
7273
## Role: Standard
7374
## gRPC routes
7475
p, role:standard, policy.*, read, allow
7576
p, role:standard, kasregistry.*, read, allow
76-
p, role:standard, kas.AccessService/Info, *, allow
7777
p, role:standard, kas.AccessService/Rewrap, *, allow
7878
## HTTP routes
7979
p, role:standard, /attributes*, read, allow
@@ -87,10 +87,13 @@ p, role:standard, /entityresolution/resolve, write, allow
8787
# Public routes
8888
## gRPC routes
8989
## for ERS, right now we don't care about requester role, just that a valid jwt is provided when the OPA engine calls (enforced in the ERS itself, not casbin)
90-
p, role:unknown, entityresolution.EntityResolutionService.ResolveEntities, write, allow
90+
p, role:unknown, entityresolution.EntityResolutionService.ResolveEntities, write, allow
91+
p, role:unknown, kas.AccessService/Rewrap, write, allow
9192
## HTTP routes
9293
## for ERS, right now we don't care about requester role, just that a valid jwt is provided when the OPA engine calls (enforced in the ERS itself, not casbin)
93-
p, role:unknown, /entityresolution/resolve, write, allow
94+
p, role:unknown, /entityresolution/resolve, write, allow
95+
p, role:unknown, /kas/v2/rewrap, write, allow
96+
9497
`
9598

9699
var defaultModel = `

service/internal/auth/casbin_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -260,18 +260,6 @@ func (s *AuthnCasbinSuite) Test_Enforcement() {
260260
resource: "non-existent",
261261
action: "read",
262262
},
263-
{
264-
allowed: true,
265-
roles: standard,
266-
resource: "/kas/kas_public_key",
267-
action: "read",
268-
},
269-
{
270-
allowed: true,
271-
roles: standard,
272-
resource: "/kas/v2/kas_public_key",
273-
action: "read",
274-
},
275263
{
276264
allowed: true,
277265
roles: standard,

0 commit comments

Comments
 (0)