yuqi1129 commented on code in PR #13957:
URL: https://github.com/apache/gravitino/pull/13957#discussion_r4638117331
##########
scripts/mysql/schema-2.0.0-mysql.sql:
##########
@@ -425,6 +425,18 @@ CREATE TABLE IF NOT EXISTS `policy_tag_relation_meta` (
KEY `policy_tag_relation_meta_idx_tag_id` (`tag_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'policy
tag relation';
+CREATE TABLE IF NOT EXISTS `policy_role_relation_meta` (
+ `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment
id',
+ `policy_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'policy id',
+ `role_name` VARCHAR(128) NOT NULL COMMENT 'role name referenced by the
policy content',
Review Comment:
[Important] What guarantees that a policy cannot silently apply to a
different role that reuses this name? On H2 I created role `analyst` and policy
`reader` referencing it, deleted the role, and created another `analyst`. The
new role had a different ID. The original reference row kept its ID, and
`listByRoleName` still returned `reader`. This reproduces the storage behavior.
Policy evaluation is outside this PR.
A name index makes sense for finding policies whose content mentions a role.
OQ-3 also requires deletion to fail while any policy references that role.
Could we make this guarantee a prerequisite for enabling evaluation, and
specify how operators should reconcile policies written before the guard
exists? Once a name has been reused, the policy JSON and this row alone cannot
identify which role its author intended. Storing a role ID only in this derived
table would leave the same ambiguity when rebuilding from JSON. [OQ-3
decision](https://github.com/apache/gravitino/blob/8a26a2c53c53f2033924b8835ccef47b5197ee47/design-docs/tag-based-access-control.md#oq-3--deleting-a-referenced-role)
##########
core/src/main/java/org/apache/gravitino/storage/relational/service/PolicyMetaService.java:
##########
@@ -429,6 +450,70 @@ private void insertPolicyWithoutCommit(
updatePolicyRootWithVersion(observedIdentifier, existingPolicyPO,
replacementPolicyPO);
insertPolicyVersionIfAllocated(existingPolicyPO, replacementPolicyPO);
afterUpdate(storedPolicy);
+ return replacementPolicyPO.getPolicyId();
+ }
+
+ /**
+ * Brings the role references derived from a policy's content in line with
that content.
+ *
+ * <p>The references are written only here and never by a caller, so {@code
content} stays the one
+ * authority on which roles a policy names.
+ *
+ * <p>Only the difference is written: a reference the content still names
keeps its row, so a
+ * policy edit that leaves {@code applicableRoles} alone writes no reference
rows at all.
+ *
+ * <p>A reference the content drops is deleted rather than soft-deleted, so
no edit leaves a
+ * tombstone behind. Removing a role, naming it again, and removing it once
more therefore cannot
+ * collide on the table's uniqueness over (policy, role, deleted_at), which
the two removals would
+ * otherwise share whenever they read the same millisecond from the database
clock.
+ */
+ private void updateRoleRelationsWithoutCommit(long policyId, PolicyEntity
policyEntity) {
+ List<PolicyRoleRelPO> desired =
POConverters.initializePolicyRoleRelPOs(policyId, policyEntity);
Review Comment:
[Important] How will a policy write and role deletion serialize across
server instances? This transaction can add a reference without checking that
the named role exists. Adding an existence check on this side and a separate
reference lookup on the delete side would still allow this ordering: the policy
writer sees the role, the deleter sees no committed reference and deletes it,
then the writer commits the reference.
Could we track a two-transaction regression test with both commit orders? If
the policy write wins, single and bulk deletion should refuse the referenced
role. If deletion wins, creating a policy or adding the role to an existing
policy should fail without committing the new content or reference. One
implementation would resolve and lock the same live role row on both paths,
recheck its identity, and hold the lock through commit. This can land with
lifecycle enforcement, provided evaluation depends on it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]