Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,10 @@ server:
map:
standard: opentdf-standard
admin: opentdf-admin
org-admin: opentdf-org-admin

## Custom policy (see examples https://github.com/casbin/casbin/tree/master/examples)
csv: |
p, role:org-admin, policy:attributes, *, *, allow
p, role:org-admin, policy:subject-mappings, *, *, allow
p, role:org-admin, policy:resource-mappings, *, *, allow
p, role:org-admin, policy:kas-registry, *, *, allow
p, role:org-admin, policy:unsafe, *, *, allow
p, role:admin, policy:attributes, read, allow
p, role:admin, policy:subject-mappings, read, allow
p, role:admin, policy:resource-mappings, read, allow
p, role:admin, policy:kas-registry, read, allow
p, role:admin, *, *, allow
p, role:standard, policy:attributes, read, allow
p, role:standard, policy:subject-mappings, read, allow
p, role:standard, policy:resource-mappings, read, allow
Expand Down
14 changes: 5 additions & 9 deletions lib/fixtures/keycloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func SetupKeycloak(ctx context.Context, kcConnectParams KeycloakConnectParams) e

opentdfClientID := "opentdf"
opentdfSdkClientID := "opentdf-sdk"
opentdfOrgAdminRoleName := "opentdf-org-admin"
opentdfAdminRoleName := "opentdf-admin"
opentdfStandardRoleName := "opentdf-standard"
testingOnlyRoleName := "opentdf-testing-role"
Expand Down Expand Up @@ -155,7 +154,7 @@ func SetupKeycloak(ctx context.Context, kcConnectParams KeycloakConnectParams) e
}

// Create Roles
roles := []string{opentdfOrgAdminRoleName, opentdfAdminRoleName, opentdfStandardRoleName, testingOnlyRoleName}
roles := []string{opentdfAdminRoleName, opentdfStandardRoleName, testingOnlyRoleName}
for _, role := range roles {
_, err := client.CreateRealmRole(ctx, token.AccessToken, kcConnectParams.Realm, gocloak.Role{
Name: gocloak.StringP(role),
Expand All @@ -173,8 +172,7 @@ func SetupKeycloak(ctx context.Context, kcConnectParams KeycloakConnectParams) e
}

// Get the roles
var opentdfOrgAdminRole *gocloak.Role
// var opentdfAdminRole *gocloak.Role
var opentdfAdminRole *gocloak.Role
var opentdfStandardRole *gocloak.Role
var testingOnlyRole *gocloak.Role
realmRoles, err := client.GetRealmRoles(ctx, token.AccessToken, kcConnectParams.Realm, gocloak.GetRoleParams{
Expand All @@ -187,10 +185,8 @@ func SetupKeycloak(ctx context.Context, kcConnectParams KeycloakConnectParams) e
slog.Info(fmt.Sprintf("✅ Roles found: %d", len(realmRoles))) // , slog.String("roles", fmt.Sprintf("%v", realmRoles))
for _, role := range realmRoles {
switch *role.Name {
case opentdfOrgAdminRoleName:
opentdfOrgAdminRole = role
// case opentdfAdminRoleName:
// opentdfAdminRole = role
case opentdfAdminRoleName:
opentdfAdminRole = role
case opentdfStandardRoleName:
opentdfStandardRole = role
case testingOnlyRoleName:
Expand All @@ -207,7 +203,7 @@ func SetupKeycloak(ctx context.Context, kcConnectParams KeycloakConnectParams) e
ClientAuthenticatorType: gocloak.StringP("client-secret"),
Secret: gocloak.StringP("secret"),
ProtocolMappers: &protocolMappers,
}, []gocloak.Role{*opentdfOrgAdminRole}, nil)
}, []gocloak.Role{*opentdfAdminRole}, nil)
if err != nil {
return err
}
Expand Down
7 changes: 1 addition & 6 deletions opentdf-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,10 @@ server:
map:
# standard: opentdf-standard
# admin: opentdf-admin
# org-admin: opentdf-org-admin

## Custom policy (see examples https://github.com/casbin/casbin/tree/master/examples)
csv: #|
# p, role:org-admin, policy:attributes, *, *, allow
# p, role:org-admin, policy:subject-mappings, *, *, allow
# p, role:org-admin, policy:resource-mappings, *, *, allow
# p, role:org-admin, policy:kas-registry, *, *, allow
# p, role:org-admin, policy:unsafe, *, *, allow
# p, role:admin, *, *, allow

## Custom model (see https://casbin.org/docs/syntax-for-models/)
model: #|
Expand Down
7 changes: 1 addition & 6 deletions opentdf-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,10 @@ server:
map:
# standard: opentdf-standard
# admin: opentdf-admin
# org-admin: opentdf-org-admin

## Custom policy (see examples https://github.com/casbin/casbin/tree/master/examples)
csv: #|
# p, role:org-admin, policy:attributes, *, *, allow
# p, role:org-admin, policy:subject-mappings, *, *, allow
# p, role:org-admin, policy:resource-mappings, *, *, allow
# p, role:org-admin, policy:kas-registry, *, *, allow
# p, role:org-admin, policy:unsafe, *, *, allow
# p, role:admin, *, *, allow
## Custom model (see https://casbin.org/docs/syntax-for-models/)
model: #|
# [request_definition]
Expand Down
7 changes: 1 addition & 6 deletions opentdf-with-hsm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,9 @@ server:
map:
# standard: opentdf-standard
# admin: opentdf-admin
# org-admin: opentdf-org-admin
## Custom policy (see examples https://github.com/casbin/casbin/tree/master/examples)
csv: #|
# p, role:org-admin, policy:attributes, *, *, allow
# p, role:org-admin, policy:subject-mappings, *, *, allow
# p, role:org-admin, policy:resource-mappings, *, *, allow
# p, role:org-admin, policy:kas-registry, *, *, allow
# p, role:org-admin, policy:unsafe, *, *, allow
# p, role:admin, *, *, allow
## Custom model (see https://casbin.org/docs/syntax-for-models/)
model: #|
# [request_definition]
Expand Down
5 changes: 2 additions & 3 deletions service/cmd/keycloak_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ realms:
realm: opentdf
enabled: true
custom_realm_roles:
- name: opentdf-org-admin
- name: opentdf-admin
- name: opentdf-standard
custom_client_roles:
Expand All @@ -35,7 +34,7 @@ realms:
protocolMappers:
- *customAudMapper
sa_realm_roles:
- opentdf-org-admin
- opentdf-admin
- client:
clientID: opentdf-sdk
enabled: true
Expand Down Expand Up @@ -98,7 +97,7 @@ realms:
groups:
- mygroup
realmRoles:
- opentdf-org-admin
- opentdf-admin
clientRoles:
realm-management:
- view-clients
Expand Down
57 changes: 10 additions & 47 deletions service/internal/auth/casbin.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ var (
var defaultRoleClaim = "realm_access.roles"

var defaultRoleMap = map[string]string{
"standard": "opentdf-standard",
"admin": "opentdf-admin",
"org-admin": "opentdf-org-admin",
"standard": "opentdf-standard",
"admin": "opentdf-admin",
}

var defaultPolicy = `
## Roles (prefixed with role:)
# org-admin - organization admin
# admin - admin
# standard - standard
# unknown - unknown role or no role
Expand All @@ -46,70 +44,35 @@ var defaultPolicy = `
# delete - delete the resource
# unsafe - unsafe actions

# Role: Org-Admin
## gRPC routes
p, role:org-admin, policy.*, *, allow
p, role:org-admin, kasregistry.*, *, allow
p, role:org-admin, kas.AccessService/Rewrap, *, allow
p, role:org-admin, authorization.*, *, allow
## HTTP routes
p, role:org-admin, /attributes*, *, allow
p, role:org-admin, /namespaces*, *, allow
p, role:org-admin, /subject-mappings*, *, allow
p, role:org-admin, /resource-mappings*, *, allow
p, role:org-admin, /key-access-servers*, *, allow
p, role:org-admin, /kas/v2/rewrap, *, allow
p, role:org-admin, /unsafe*, *, allow
p, role:org-admin, /v1/entitlements, *, allow
p, role:org-admin, /v1/authorization, *, allow
p, role:org-admin, /v1/token/authorization, *, allow

# Role: Admin
## gRPC routes
p, role:admin, policy.*, read, allow
p, role:admin, policy.*, write, allow
p, role:admin, policy.*, delete, allow
p, role:admin, kasregistry.*, *, allow
p, role:admin, kas.AccessService/Rewrap, *, allow
p, role:admin, authorization.*, *, allow
## HTTP routes
p, role:admin, /attributes*, *, allow
p, role:admin, /namespaces*, *, allow
p, role:admin, /subject-mappings*, *, allow
p, role:admin, /resource-mappings*, *, allow
p, role:admin, /key-access-servers*, *, allow
p, role:admin, /kas/v2/rewrap, *, allow
p, role:admin, /v1/entitlements, *, allow
p, role:admin, /v1/authorization, *, allow
p, role:admin, /v1/token/authorization, *, allow

## gRPC and HTTP routes
p, role:admin, *, *, allow

## Role: Standard
## gRPC routes
p, role:standard, policy.*, read, allow
p, role:standard, kasregistry.*, read, allow
p, role:standard, kas.AccessService/Rewrap, *, allow
p, role:standard, authorization.AuthorizationService/GetDecisions, read, allow
p, role:standard, authorization.AuthorizationService/GetDecisionsByToken, read, allow
p, role:standard, kas.AccessService/Rewrap, *, allow
p, role:standard, authorization.AuthorizationService/GetDecisions, read, allow
p, role:standard, authorization.AuthorizationService/GetDecisionsByToken, read, allow

## HTTP routes
p, role:standard, /attributes*, read, allow
p, role:standard, /namespaces*, read, allow
p, role:standard, /subject-mappings*, read, allow
p, role:standard, /resource-mappings*, read, allow
p, role:standard, /key-access-servers*, read, allow
p, role:standard, /kas/v2/rewrap, write, allow
p, role:standard, /entityresolution/resolve, write, allow
p, role:standard, /v1/authorization, write, allow
p, role:standard, /v1/token/authorization, write, allow
p, role:standard, /v1/authorization, write, allow
p, role:standard, /v1/token/authorization, write, allow

# Public routes
## gRPC routes
## 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)
p, role:unknown, entityresolution.EntityResolutionService.ResolveEntities, write, allow
p, role:unknown, kas.AccessService/Rewrap, *, allow
## HTTP routes
## 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)
p, role:unknown, /entityresolution/resolve, write, allow
p, role:unknown, /kas/v2/rewrap, *, allow

`
Expand Down
Loading
Loading