Skip to content

Commit b7796cd

Browse files
authored
feat(policy): register unsafe service in platform (#1066)
Relates to #115 Closes #115 Drives authorization with existing casbin action definition matching logic: https://github.com/opentdf/platform/blob/main/service/internal/auth/authn.go#L289-L290 Middleware casbin tests (with local `test-admin` client given the `admin` role for validation): ```shell time=2024-07-01T17:16:31.618-07:00 level=INFO msg="enforcing policy" subject=role:admin resource=policy.unsafe.UnsafeService/UnsafeUpdateNamespace action=unsafe time=2024-07-01T17:16:31.618-07:00 level=WARN msg="permission denied" azp=b007dc27-e9a5-493b-8d2d-b26a92a6752c error="permission denied" ``` ```shell time=2024-07-01T17:18:08.028-07:00 level=INFO msg="enforcing policy" subject=role:standard resource=policy.unsafe.UnsafeService/UnsafeUpdateNamespace action=unsafe time=2024-07-01T17:18:08.028-07:00 level=WARN msg="permission denied" azp=d8949062-977b-498a-a640-61865d633121 error="permission denied" ``` ```shell time=2024-07-01T17:18:30.518-07:00 level=INFO msg="enforcing policy" subject=role:org-admin resource=policy.unsafe.UnsafeService/UnsafeUpdateNamespace action=unsafe time=2024-07-01T17:18:30.519-07:00 level=DEBUG msg=sql sql="SELECT opentdf_policy.attribute_namespaces.id, opentdf_policy.attribute_namespaces.name, opentdf_policy.attribute_namespaces.active, JSON_STRIP_NULLS(JSON_BUILD_OBJECT('labels', metadata->'labels', 'created_at', created_at, 'updated_at', updated_at)) AS metadata, opentdf_policy.attribute_fqns.fqn FROM opentdf_policy ..... ```
1 parent 10138d2 commit b7796cd

File tree

9 files changed

+267
-254
lines changed

9 files changed

+267
-254
lines changed

opentdf-dev.yaml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ services:
3333
entityresolution:
3434
enabled: true
3535
url: http://localhost:8888/auth
36-
clientid: "tdf-entity-resolution"
37-
clientsecret: "secret"
38-
realm: "opentdf"
36+
clientid: 'tdf-entity-resolution'
37+
clientsecret: 'secret'
38+
realm: 'opentdf'
3939
legacykeycloak: true
4040
server:
4141
auth:
4242
enabled: true
4343
enforceDPoP: false
44-
audience: "http://localhost:8080"
44+
audience: 'http://localhost:8080'
4545
issuer: http://localhost:8888/auth/realms/opentdf
4646
policy:
4747
## Default policy for all requests
@@ -61,6 +61,7 @@ server:
6161
# p, role:org-admin, policy:subject-mappings, *, *, allow
6262
# p, role:org-admin, policy:resource-mappings, *, *, allow
6363
# p, role:org-admin, policy:kas-registry, *, *, allow
64+
# p, role:org-admin, policy:unsafe, *, *, allow
6465

6566
## Custom model (see https://casbin.org/docs/syntax-for-models/)
6667
model: #|
@@ -81,8 +82,8 @@ server:
8182
cors:
8283
enabled: false
8384
# '*' to allow any origin or a specific domain like 'https://yourdomain.com'
84-
allowedorigins:
85-
- "*"
85+
allowedorigins:
86+
- '*'
8687
# List of methods. Examples: 'GET,POST,PUT'
8788
allowedmethods:
8889
- GET

opentdf-example.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ server:
5252
# p, role:org-admin, policy:subject-mappings, *, *, allow
5353
# p, role:org-admin, policy:resource-mappings, *, *, allow
5454
# p, role:org-admin, policy:kas-registry, *, *, allow
55+
# p, role:org-admin, policy:unsafe, *, *, allow
5556
## Custom model (see https://casbin.org/docs/syntax-for-models/)
5657
model: #|
5758
# [request_definition]

opentdf-with-hsm.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ server:
5757
# p, role:org-admin, policy:subject-mappings, *, *, allow
5858
# p, role:org-admin, policy:resource-mappings, *, *, allow
5959
# p, role:org-admin, policy:kas-registry, *, *, allow
60+
# p, role:org-admin, policy:unsafe, *, *, allow
6061
## Custom model (see https://casbin.org/docs/syntax-for-models/)
6162
model: #|
6263
# [request_definition]

protocol/go/policy/unsafe/unsafe.pb.go

Lines changed: 250 additions & 234 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/buf.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ breaking:
99
- PACKAGE
1010
- WIRE_JSON
1111
- WIRE
12-
ignore:
13-
- policy/unsafe/unsafe.proto
1412
lint:
1513
allow_comment_ignores: true
1614
use:

service/internal/auth/casbin.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ p, role:org-admin, /unsafe*, *, allow
5959
6060
# Role: Admin
6161
## gRPC routes
62-
p, role:admin, policy.*, *, allow
62+
p, role:admin, policy.*, read, allow
63+
p, role:admin, policy.*, write, allow
64+
p, role:admin, policy.*, delete, allow
6365
p, role:admin, kasregistry.*, *, allow
6466
p, role:admin, kas.AccessService/Rewrap, *, allow
6567
p, role:admin, authorization.*, *, allow
@@ -73,7 +75,6 @@ p, role:admin, /kas/v2/rewrap, *, allow
7375
7476
## Role: Standard
7577
## gRPC routes
76-
p, role:standard, policy.unsafe.*, *, deny
7778
p, role:standard, policy.*, read, allow
7879
p, role:standard, kasregistry.*, read, allow
7980
p, role:standard, kas.AccessService/Rewrap, *, allow

service/policy/db/namespaces.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,7 @@ func (c PolicyDBClient) GetNamespace(ctx context.Context, id string) (*policy.Na
111111
return nil, err
112112
}
113113

114-
n, err := hydrateNamespaceItem(row, opts)
115-
if err != nil {
116-
return nil, err
117-
}
118-
119-
return n, nil
114+
return hydrateNamespaceItem(row, opts)
120115
}
121116

122117
func listNamespacesSQL(opts namespaceSelectOptions) (string, []interface{}, error) {

service/policy/policy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/opentdf/platform/service/policy/namespaces"
1111
"github.com/opentdf/platform/service/policy/resourcemapping"
1212
"github.com/opentdf/platform/service/policy/subjectmapping"
13-
// "github.com/opentdf/platform/service/policy/unsafe"
13+
"github.com/opentdf/platform/service/policy/unsafe"
1414
)
1515

1616
var Migrations *embed.FS
@@ -33,7 +33,7 @@ func NewRegistrations() []serviceregistry.Registration {
3333
resourcemapping.NewRegistration(),
3434
subjectmapping.NewRegistration(),
3535
kasregistry.NewRegistration(),
36-
// unsafe.NewRegistration(),
36+
unsafe.NewRegistration(),
3737
} {
3838
r.Namespace = namespace
3939
r.DB = dbRegister

service/policy/unsafe/unsafe.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ message UnsafeUpdateNamespaceRequest {
1919
(buf.validate.field).string.max_len = 253,
2020
(buf.validate.field).cel = {
2121
id: "namespace_name_format",
22-
message: "Namespace name must be an alphanumeric string, allowing hyphens and underscores but not as the first or last character. The stored namespace name will be normalized to lower case.",
23-
expression: "this.matches('^[a-zA-Z0-9](?:[a-zA-Z0-9_-]*[a-zA-Z0-9])?$')"
22+
message: "Namespace must be a valid hostname. It should include at least one dot, with each segment (label) starting and ending with an alphanumeric character. Each label must be 1 to 63 characters long, allowing hyphens but not as the first or last character. The top-level domain (the last segment after the final dot) must consist of at least two alphabetic characters. The stored namespace will be normalized to lower case.",
23+
expression: "this.matches('^([a-zA-Z0-9]([a-zA-Z0-9\\\\-]{0,61}[a-zA-Z0-9])?\\\\.)+[a-zA-Z]{2,}$')"
2424
}
2525
];
2626
}

0 commit comments

Comments
 (0)