Skip to content

Commit e326022

Browse files
authored
[#10962] feat(authn): Add built-in IDP metadata schema (#10969)
### What changes were proposed in this pull request? This PR adds the local IdP metadata schema for H2, MySQL, and PostgreSQL by introducing `idp_user_meta`, `idp_group_meta`, and `idp_group_user_rel` to both the full schema scripts and the 1.2.0-to-1.3.0 upgrade scripts. The change is limited to JDBC SQL scripts only. ### Why are the changes needed? The local authenticator needs dedicated metadata tables to persist built-in IdP users, groups, and group memberships with soft-delete support. Fix: #10962 ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? ``` ./gradlew --no-daemon :core:test --tests org.apache.gravitino.storage.TestSQLScripts ``` Note: the current `TestSQLScripts` coverage does not execute `upgrade-*-to-*.sql` scripts, so upgrade scripts are not in the test scope here.
1 parent d9e8724 commit e326022

6 files changed

Lines changed: 250 additions & 0 deletions

scripts/h2/schema-1.3.0-h2.sql

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,40 @@ CREATE TABLE IF NOT EXISTS `group_role_rel` (
248248
KEY `idx_gid` (`group_id`)
249249
) ENGINE=InnoDB;
250250

251+
CREATE TABLE IF NOT EXISTS `idp_user_meta` (
252+
`user_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'idp user id',
253+
`user_name` VARCHAR(128) NOT NULL COMMENT 'idp username',
254+
`password_hash` VARCHAR(1024) NOT NULL COMMENT 'idp user password hash',
255+
`current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp user current version',
256+
`last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp user last version',
257+
`deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'idp user deleted at',
258+
PRIMARY KEY (`user_id`),
259+
CONSTRAINT `uk_iun_del` UNIQUE (`user_name`, `deleted_at`)
260+
) ENGINE=InnoDB;
261+
262+
CREATE TABLE IF NOT EXISTS `idp_group_meta` (
263+
`group_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'idp group id',
264+
`group_name` VARCHAR(128) NOT NULL COMMENT 'idp group name',
265+
`current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp group current version',
266+
`last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp group last version',
267+
`deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'idp group deleted at',
268+
PRIMARY KEY (`group_id`),
269+
CONSTRAINT `uk_ign_del` UNIQUE (`group_name`, `deleted_at`)
270+
) ENGINE=InnoDB;
271+
272+
CREATE TABLE IF NOT EXISTS `idp_group_user_rel` (
273+
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
274+
`group_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'idp group id',
275+
`user_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'idp user id',
276+
`current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp relation current version',
277+
`last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp relation last version',
278+
`deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'idp relation deleted at',
279+
PRIMARY KEY (`id`),
280+
CONSTRAINT `uk_igiu_del` UNIQUE (`group_id`, `user_id`, `deleted_at`),
281+
KEY `idx_iug_gid` (`group_id`),
282+
KEY `idx_iug_uid` (`user_id`)
283+
) ENGINE=InnoDB;
284+
251285
CREATE TABLE IF NOT EXISTS `tag_meta` (
252286
`tag_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'tag id',
253287
`tag_name` VARCHAR(128) NOT NULL COMMENT 'tag name',

scripts/h2/upgrade-1.2.0-to-1.3.0-h2.sql

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,37 @@ CREATE TABLE IF NOT EXISTS `view_version_info` (
6464
KEY `idx_vvcid` (`catalog_id`),
6565
KEY `idx_vvsid` (`schema_id`)
6666
) ENGINE=InnoDB;
67+
68+
CREATE TABLE IF NOT EXISTS `idp_user_meta` (
69+
`user_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'idp user id',
70+
`user_name` VARCHAR(128) NOT NULL COMMENT 'idp username',
71+
`password_hash` VARCHAR(1024) NOT NULL COMMENT 'idp user password hash',
72+
`current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp user current version',
73+
`last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp user last version',
74+
`deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'idp user deleted at',
75+
PRIMARY KEY (`user_id`),
76+
CONSTRAINT `uk_iun_del` UNIQUE (`user_name`, `deleted_at`)
77+
) ENGINE=InnoDB;
78+
79+
CREATE TABLE IF NOT EXISTS `idp_group_meta` (
80+
`group_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'idp group id',
81+
`group_name` VARCHAR(128) NOT NULL COMMENT 'idp group name',
82+
`current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp group current version',
83+
`last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp group last version',
84+
`deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'idp group deleted at',
85+
PRIMARY KEY (`group_id`),
86+
CONSTRAINT `uk_ign_del` UNIQUE (`group_name`, `deleted_at`)
87+
) ENGINE=InnoDB;
88+
89+
CREATE TABLE IF NOT EXISTS `idp_group_user_rel` (
90+
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
91+
`group_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'idp group id',
92+
`user_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'idp user id',
93+
`current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp relation current version',
94+
`last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp relation last version',
95+
`deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'idp relation deleted at',
96+
PRIMARY KEY (`id`),
97+
CONSTRAINT `uk_igiu_del` UNIQUE (`group_id`, `user_id`, `deleted_at`),
98+
KEY `idx_iug_gid` (`group_id`),
99+
KEY `idx_iug_uid` (`user_id`)
100+
) ENGINE=InnoDB;

scripts/mysql/schema-1.3.0-mysql.sql

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,40 @@ CREATE TABLE IF NOT EXISTS `group_role_rel` (
239239
KEY `idx_rid` (`group_id`)
240240
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'group role relation';
241241

242+
CREATE TABLE IF NOT EXISTS `idp_user_meta` (
243+
`user_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'idp user id',
244+
`user_name` VARCHAR(128) NOT NULL COMMENT 'idp username',
245+
`password_hash` VARCHAR(1024) NOT NULL COMMENT 'idp user password hash',
246+
`current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp user current version',
247+
`last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp user last version',
248+
`deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'idp user deleted at',
249+
PRIMARY KEY (`user_id`),
250+
UNIQUE KEY `uk_iun_del` (`user_name`, `deleted_at`)
251+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'local IdP user metadata';
252+
253+
CREATE TABLE IF NOT EXISTS `idp_group_meta` (
254+
`group_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'idp group id',
255+
`group_name` VARCHAR(128) NOT NULL COMMENT 'idp group name',
256+
`current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp group current version',
257+
`last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp group last version',
258+
`deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'idp group deleted at',
259+
PRIMARY KEY (`group_id`),
260+
UNIQUE KEY `uk_ign_del` (`group_name`, `deleted_at`)
261+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'local IdP group metadata';
262+
263+
CREATE TABLE IF NOT EXISTS `idp_group_user_rel` (
264+
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
265+
`group_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'idp group id',
266+
`user_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'idp user id',
267+
`current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp relation current version',
268+
`last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp relation last version',
269+
`deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'idp relation deleted at',
270+
PRIMARY KEY (`id`),
271+
UNIQUE KEY `uk_igiu_del` (`group_id`, `user_id`, `deleted_at`),
272+
KEY `idx_iug_gid` (`group_id`),
273+
KEY `idx_iug_uid` (`user_id`)
274+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'local IdP group user relation';
275+
242276
CREATE TABLE IF NOT EXISTS `tag_meta` (
243277
`tag_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'tag id',
244278
`tag_name` VARCHAR(128) NOT NULL COMMENT 'tag name',

scripts/mysql/upgrade-1.2.0-to-1.3.0-mysql.sql

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,37 @@ CREATE TABLE IF NOT EXISTS `view_version_info` (
7878
KEY `idx_vvcid` (`catalog_id`),
7979
KEY `idx_vvsid` (`schema_id`)
8080
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'view version info';
81+
82+
CREATE TABLE IF NOT EXISTS `idp_user_meta` (
83+
`user_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'idp user id',
84+
`user_name` VARCHAR(128) NOT NULL COMMENT 'idp username',
85+
`password_hash` VARCHAR(1024) NOT NULL COMMENT 'idp user password hash',
86+
`current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp user current version',
87+
`last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp user last version',
88+
`deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'idp user deleted at',
89+
PRIMARY KEY (`user_id`),
90+
UNIQUE KEY `uk_iun_del` (`user_name`, `deleted_at`)
91+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'local IdP user metadata';
92+
93+
CREATE TABLE IF NOT EXISTS `idp_group_meta` (
94+
`group_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'idp group id',
95+
`group_name` VARCHAR(128) NOT NULL COMMENT 'idp group name',
96+
`current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp group current version',
97+
`last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp group last version',
98+
`deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'idp group deleted at',
99+
PRIMARY KEY (`group_id`),
100+
UNIQUE KEY `uk_ign_del` (`group_name`, `deleted_at`)
101+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'local IdP group metadata';
102+
103+
CREATE TABLE IF NOT EXISTS `idp_group_user_rel` (
104+
`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'auto increment id',
105+
`group_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'idp group id',
106+
`user_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'idp user id',
107+
`current_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp relation current version',
108+
`last_version` INT UNSIGNED NOT NULL DEFAULT 1 COMMENT 'idp relation last version',
109+
`deleted_at` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 COMMENT 'idp relation deleted at',
110+
PRIMARY KEY (`id`),
111+
UNIQUE KEY `uk_igiu_del` (`group_id`, `user_id`, `deleted_at`),
112+
KEY `idx_iug_gid` (`group_id`),
113+
KEY `idx_iug_uid` (`user_id`)
114+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT 'local IdP group user relation';

scripts/postgresql/schema-1.3.0-postgresql.sql

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,63 @@ COMMENT ON COLUMN group_role_rel.current_version IS 'relation current version';
427427
COMMENT ON COLUMN group_role_rel.last_version IS 'relation last version';
428428
COMMENT ON COLUMN group_role_rel.deleted_at IS 'relation deleted at';
429429

430+
CREATE TABLE IF NOT EXISTS idp_user_meta (
431+
user_id BIGINT NOT NULL,
432+
user_name VARCHAR(128) NOT NULL,
433+
password_hash VARCHAR(1024) NOT NULL,
434+
current_version INT NOT NULL DEFAULT 1,
435+
last_version INT NOT NULL DEFAULT 1,
436+
deleted_at BIGINT NOT NULL DEFAULT 0,
437+
PRIMARY KEY (user_id),
438+
UNIQUE (user_name, deleted_at)
439+
);
440+
COMMENT ON TABLE idp_user_meta IS 'local IdP user metadata';
441+
442+
COMMENT ON COLUMN idp_user_meta.user_id IS 'idp user id';
443+
COMMENT ON COLUMN idp_user_meta.user_name IS 'idp username';
444+
COMMENT ON COLUMN idp_user_meta.password_hash IS 'idp user password hash';
445+
COMMENT ON COLUMN idp_user_meta.current_version IS 'idp user current version';
446+
COMMENT ON COLUMN idp_user_meta.last_version IS 'idp user last version';
447+
COMMENT ON COLUMN idp_user_meta.deleted_at IS 'idp user deleted at';
448+
449+
CREATE TABLE IF NOT EXISTS idp_group_meta (
450+
group_id BIGINT NOT NULL,
451+
group_name VARCHAR(128) NOT NULL,
452+
current_version INT NOT NULL DEFAULT 1,
453+
last_version INT NOT NULL DEFAULT 1,
454+
deleted_at BIGINT NOT NULL DEFAULT 0,
455+
PRIMARY KEY (group_id),
456+
UNIQUE (group_name, deleted_at)
457+
);
458+
COMMENT ON TABLE idp_group_meta IS 'local IdP group metadata';
459+
460+
COMMENT ON COLUMN idp_group_meta.group_id IS 'idp group id';
461+
COMMENT ON COLUMN idp_group_meta.group_name IS 'idp group name';
462+
COMMENT ON COLUMN idp_group_meta.current_version IS 'idp group current version';
463+
COMMENT ON COLUMN idp_group_meta.last_version IS 'idp group last version';
464+
COMMENT ON COLUMN idp_group_meta.deleted_at IS 'idp group deleted at';
465+
466+
CREATE TABLE IF NOT EXISTS idp_group_user_rel (
467+
id BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY,
468+
group_id BIGINT NOT NULL,
469+
user_id BIGINT NOT NULL,
470+
current_version INT NOT NULL DEFAULT 1,
471+
last_version INT NOT NULL DEFAULT 1,
472+
deleted_at BIGINT NOT NULL DEFAULT 0,
473+
PRIMARY KEY (id),
474+
UNIQUE (group_id, user_id, deleted_at)
475+
);
476+
CREATE INDEX IF NOT EXISTS idp_group_user_rel_idx_group_id ON idp_group_user_rel (group_id);
477+
CREATE INDEX IF NOT EXISTS idp_group_user_rel_idx_user_id ON idp_group_user_rel (user_id);
478+
COMMENT ON TABLE idp_group_user_rel IS 'local IdP group user relation';
479+
480+
COMMENT ON COLUMN idp_group_user_rel.id IS 'auto increment id';
481+
COMMENT ON COLUMN idp_group_user_rel.group_id IS 'idp group id';
482+
COMMENT ON COLUMN idp_group_user_rel.user_id IS 'idp user id';
483+
COMMENT ON COLUMN idp_group_user_rel.current_version IS 'idp relation current version';
484+
COMMENT ON COLUMN idp_group_user_rel.last_version IS 'idp relation last version';
485+
COMMENT ON COLUMN idp_group_user_rel.deleted_at IS 'idp relation deleted at';
486+
430487
CREATE TABLE IF NOT EXISTS tag_meta (
431488
tag_id BIGINT NOT NULL,
432489
tag_name VARCHAR(128) NOT NULL,

scripts/postgresql/upgrade-1.2.0-to-1.3.0-postgresql.sql

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,60 @@ COMMENT ON COLUMN view_version_info.default_schema IS 'default schema for view S
9191
COMMENT ON COLUMN view_version_info.representations IS 'view representations (JSON array)';
9292
COMMENT ON COLUMN view_version_info.audit_info IS 'view version audit info';
9393
COMMENT ON COLUMN view_version_info.deleted_at IS 'view version deleted at';
94+
95+
CREATE TABLE IF NOT EXISTS idp_user_meta (
96+
user_id BIGINT NOT NULL,
97+
user_name VARCHAR(128) NOT NULL,
98+
password_hash VARCHAR(1024) NOT NULL,
99+
current_version INT NOT NULL DEFAULT 1,
100+
last_version INT NOT NULL DEFAULT 1,
101+
deleted_at BIGINT NOT NULL DEFAULT 0,
102+
PRIMARY KEY (user_id),
103+
UNIQUE (user_name, deleted_at)
104+
);
105+
COMMENT ON TABLE idp_user_meta IS 'local IdP user metadata';
106+
107+
COMMENT ON COLUMN idp_user_meta.user_id IS 'idp user id';
108+
COMMENT ON COLUMN idp_user_meta.user_name IS 'idp username';
109+
COMMENT ON COLUMN idp_user_meta.password_hash IS 'idp user password hash';
110+
COMMENT ON COLUMN idp_user_meta.current_version IS 'idp user current version';
111+
COMMENT ON COLUMN idp_user_meta.last_version IS 'idp user last version';
112+
COMMENT ON COLUMN idp_user_meta.deleted_at IS 'idp user deleted at';
113+
114+
CREATE TABLE IF NOT EXISTS idp_group_meta (
115+
group_id BIGINT NOT NULL,
116+
group_name VARCHAR(128) NOT NULL,
117+
current_version INT NOT NULL DEFAULT 1,
118+
last_version INT NOT NULL DEFAULT 1,
119+
deleted_at BIGINT NOT NULL DEFAULT 0,
120+
PRIMARY KEY (group_id),
121+
UNIQUE (group_name, deleted_at)
122+
);
123+
COMMENT ON TABLE idp_group_meta IS 'local IdP group metadata';
124+
125+
COMMENT ON COLUMN idp_group_meta.group_id IS 'idp group id';
126+
COMMENT ON COLUMN idp_group_meta.group_name IS 'idp group name';
127+
COMMENT ON COLUMN idp_group_meta.current_version IS 'idp group current version';
128+
COMMENT ON COLUMN idp_group_meta.last_version IS 'idp group last version';
129+
COMMENT ON COLUMN idp_group_meta.deleted_at IS 'idp group deleted at';
130+
131+
CREATE TABLE IF NOT EXISTS idp_group_user_rel (
132+
id BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY,
133+
group_id BIGINT NOT NULL,
134+
user_id BIGINT NOT NULL,
135+
current_version INT NOT NULL DEFAULT 1,
136+
last_version INT NOT NULL DEFAULT 1,
137+
deleted_at BIGINT NOT NULL DEFAULT 0,
138+
PRIMARY KEY (id),
139+
UNIQUE (group_id, user_id, deleted_at)
140+
);
141+
CREATE INDEX IF NOT EXISTS idp_group_user_rel_idx_group_id ON idp_group_user_rel (group_id);
142+
CREATE INDEX IF NOT EXISTS idp_group_user_rel_idx_user_id ON idp_group_user_rel (user_id);
143+
COMMENT ON TABLE idp_group_user_rel IS 'local IdP group user relation';
144+
145+
COMMENT ON COLUMN idp_group_user_rel.id IS 'auto increment id';
146+
COMMENT ON COLUMN idp_group_user_rel.group_id IS 'idp group id';
147+
COMMENT ON COLUMN idp_group_user_rel.user_id IS 'idp user id';
148+
COMMENT ON COLUMN idp_group_user_rel.current_version IS 'idp relation current version';
149+
COMMENT ON COLUMN idp_group_user_rel.last_version IS 'idp relation last version';
150+
COMMENT ON COLUMN idp_group_user_rel.deleted_at IS 'idp relation deleted at';

0 commit comments

Comments
 (0)