Skip to content

Commit 19c4ba0

Browse files
committed
Create "Trusted Publishing" database tables
1 parent 2f2755f commit 19c4ba0

File tree

5 files changed

+158
-13
lines changed

5 files changed

+158
-13
lines changed

crates/crates_io_database/src/schema.patch

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--- original
22
+++ patched
3-
@@ -21,9 +21,7 @@
3+
@@ -14,9 +14,7 @@
44
/// The `pg_catalog.tsvector` SQL type
55
///
66
/// (Automatically generated by Diesel.)
@@ -9,9 +9,9 @@
99
- pub struct Tsvector;
1010
+ pub use diesel_full_text_search::Tsvector;
1111
}
12-
12+
1313
diesel::table! {
14-
@@ -74,9 +72,9 @@
14+
@@ -67,9 +65,9 @@
1515
/// (Automatically generated by Diesel.)
1616
revoked -> Bool,
1717
/// NULL or an array of crate scope patterns (see RFC #2947)
@@ -23,7 +23,7 @@
2323
/// The `expired_at` column of the `api_tokens` table.
2424
///
2525
/// Its SQL type is `Nullable<Timestamptz>`.
26-
@@ -180,12 +178,6 @@
26+
@@ -175,12 +173,6 @@
2727
///
2828
/// (Automatically generated by Diesel.)
2929
created_at -> Timestamptz,
@@ -35,8 +35,8 @@
3535
- path -> Ltree,
3636
}
3737
}
38-
39-
@@ -476,7 +468,7 @@
38+
39+
@@ -483,7 +475,7 @@
4040
/// Its SQL type is `Array<Nullable<Text>>`.
4141
///
4242
/// (Automatically generated by Diesel.)
@@ -45,9 +45,9 @@
4545
/// The `target` column of the `dependencies` table.
4646
///
4747
/// Its SQL type is `Nullable<Varchar>`.
48-
@@ -703,6 +695,24 @@
48+
@@ -710,6 +702,24 @@
4949
}
50-
50+
5151
diesel::table! {
5252
+ /// Representation of the `recent_crate_downloads` view.
5353
+ ///
@@ -70,7 +70,7 @@
7070
/// Representation of the `reserved_crate_names` table.
7171
///
7272
/// (Automatically generated by Diesel.)
73-
@@ -1018,7 +1028,8 @@
73+
@@ -1094,7 +1104,8 @@
7474
diesel::joinable!(crate_downloads -> crates (crate_id));
7575
diesel::joinable!(crate_owner_invitations -> crates (crate_id));
7676
diesel::joinable!(crate_owners -> crates (crate_id));
@@ -80,19 +80,19 @@
8080
diesel::joinable!(crates_categories -> categories (category_id));
8181
diesel::joinable!(crates_categories -> crates (crate_id));
8282
diesel::joinable!(crates_keywords -> crates (crate_id));
83-
@@ -1031,6 +1042,7 @@
83+
@@ -1110,6 +1121,7 @@
8484
diesel::joinable!(publish_limit_buckets -> users (user_id));
8585
diesel::joinable!(publish_rate_overrides -> users (user_id));
8686
diesel::joinable!(readme_renderings -> versions (version_id));
8787
+diesel::joinable!(recent_crate_downloads -> crates (crate_id));
88+
diesel::joinable!(trustpub_configs_github -> crates (crate_id));
8889
diesel::joinable!(version_downloads -> versions (version_id));
8990
diesel::joinable!(version_owner_actions -> api_tokens (api_token_id));
90-
diesel::joinable!(version_owner_actions -> users (user_id));
91-
@@ -1058,6 +1070,7 @@
91+
@@ -1140,6 +1152,7 @@
9292
publish_limit_buckets,
9393
publish_rate_overrides,
9494
readme_renderings,
9595
+ recent_crate_downloads,
9696
reserved_crate_names,
9797
teams,
98-
users,
98+
trustpub_configs_github,

crates/crates_io_database/src/schema.rs

+56
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,58 @@ diesel::table! {
765765
}
766766
}
767767

768+
diesel::table! {
769+
/// Trusted Publisher configuration for GitHub Actions
770+
trustpub_configs_github (id) {
771+
/// Unique identifier of the `trustpub_configs_github` row
772+
id -> Int4,
773+
/// Date and time when the configuration was created
774+
created_at -> Timestamptz,
775+
/// Unique identifier of the crate that this configuration is for
776+
crate_id -> Int4,
777+
/// GitHub name of the user or organization that owns the repository
778+
repository_owner -> Varchar,
779+
/// GitHub ID of the user or organization that owns the repository
780+
repository_owner_id -> Int4,
781+
/// Name of the repository that this configuration is for
782+
repository_name -> Varchar,
783+
/// Name of the workflow file inside the repository that will be used to publish the crate
784+
workflow_filename -> Varchar,
785+
/// GitHub Actions environment that will be used to publish the crate (if `NULL` the environment is unrestricted)
786+
environment -> Nullable<Varchar>,
787+
}
788+
}
789+
790+
diesel::table! {
791+
/// Temporary access tokens for Trusted Publishing
792+
trustpub_tokens (id) {
793+
/// Unique identifier of the `trustpub_tokens` row
794+
id -> Int8,
795+
/// Date and time when the token was created
796+
created_at -> Timestamptz,
797+
/// Date and time when the token will expire
798+
expires_at -> Timestamptz,
799+
/// SHA256 hash of the token that can be used to publish the crate
800+
hashed_token -> Bytea,
801+
/// Unique identifier of the crate that can be published using this token
802+
crate_ids -> Array<Nullable<Int4>>,
803+
}
804+
}
805+
806+
diesel::table! {
807+
/// Used JWT IDs to prevent token reuse in the Trusted Publishing flow
808+
trustpub_used_jtis (id) {
809+
/// Unique identifier of the `trustpub_used_jtis` row
810+
id -> Int8,
811+
/// JWT ID from the OIDC token
812+
jti -> Varchar,
813+
/// Date and time when the JWT was used
814+
used_at -> Timestamptz,
815+
/// Date and time when the JWT would expire
816+
expires_at -> Timestamptz,
817+
}
818+
}
819+
768820
diesel::table! {
769821
/// Representation of the `users` table.
770822
///
@@ -1070,6 +1122,7 @@ diesel::joinable!(publish_limit_buckets -> users (user_id));
10701122
diesel::joinable!(publish_rate_overrides -> users (user_id));
10711123
diesel::joinable!(readme_renderings -> versions (version_id));
10721124
diesel::joinable!(recent_crate_downloads -> crates (crate_id));
1125+
diesel::joinable!(trustpub_configs_github -> crates (crate_id));
10731126
diesel::joinable!(version_downloads -> versions (version_id));
10741127
diesel::joinable!(version_owner_actions -> api_tokens (api_token_id));
10751128
diesel::joinable!(version_owner_actions -> users (user_id));
@@ -1102,6 +1155,9 @@ diesel::allow_tables_to_appear_in_same_query!(
11021155
recent_crate_downloads,
11031156
reserved_crate_names,
11041157
teams,
1158+
trustpub_configs_github,
1159+
trustpub_tokens,
1160+
trustpub_used_jtis,
11051161
users,
11061162
version_downloads,
11071163
version_owner_actions,

crates/crates_io_database_dump/src/dump-db.toml

+25
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,31 @@ name = "public"
188188
avatar = "public"
189189
org_id = "public"
190190

191+
[trustpub_configs_github]
192+
dependencies = ["crates"]
193+
[trustpub_configs_github.columns]
194+
id = "private"
195+
created_at = "private"
196+
crate_id = "private"
197+
repository_owner = "private"
198+
repository_owner_id = "private"
199+
repository_name = "private"
200+
workflow_filename = "private"
201+
environment = "private"
202+
203+
[trustpub_tokens.columns]
204+
id = "private"
205+
created_at = "private"
206+
expires_at = "private"
207+
hashed_token = "private"
208+
crate_ids = "private"
209+
210+
[trustpub_used_jtis.columns]
211+
id = "private"
212+
jti = "private"
213+
used_at = "private"
214+
expires_at = "private"
215+
191216
[users]
192217
filter = """
193218
id in (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
drop table trustpub_configs_github;
2+
drop table trustpub_tokens;
3+
drop table trustpub_used_jtis;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
create table trustpub_configs_github
2+
(
3+
id serial primary key,
4+
created_at timestamptz not null default now(),
5+
crate_id int not null references crates on delete cascade,
6+
repository_owner varchar not null,
7+
repository_owner_id int not null,
8+
repository_name varchar not null,
9+
workflow_filename varchar not null,
10+
environment varchar
11+
);
12+
13+
comment on table trustpub_configs_github is 'Trusted Publisher configuration for GitHub Actions';
14+
comment on column trustpub_configs_github.id is 'Unique identifier of the `trustpub_configs_github` row';
15+
comment on column trustpub_configs_github.created_at is 'Date and time when the configuration was created';
16+
comment on column trustpub_configs_github.crate_id is 'Unique identifier of the crate that this configuration is for';
17+
comment on column trustpub_configs_github.repository_owner is 'GitHub name of the user or organization that owns the repository';
18+
comment on column trustpub_configs_github.repository_owner_id is 'GitHub ID of the user or organization that owns the repository';
19+
comment on column trustpub_configs_github.repository_name is 'Name of the repository that this configuration is for';
20+
comment on column trustpub_configs_github.workflow_filename is 'Name of the workflow file inside the repository that will be used to publish the crate';
21+
comment on column trustpub_configs_github.environment is 'GitHub Actions environment that will be used to publish the crate (if `NULL` the environment is unrestricted)';
22+
23+
-------------------------------------------------------------------------------
24+
25+
create table trustpub_tokens
26+
(
27+
id bigserial primary key,
28+
created_at timestamptz not null default now(),
29+
expires_at timestamptz not null,
30+
hashed_token bytea not null,
31+
crate_ids int[] not null
32+
);
33+
34+
comment on table trustpub_tokens is 'Temporary access tokens for Trusted Publishing';
35+
comment on column trustpub_tokens.id is 'Unique identifier of the `trustpub_tokens` row';
36+
comment on column trustpub_tokens.created_at is 'Date and time when the token was created';
37+
comment on column trustpub_tokens.expires_at is 'Date and time when the token will expire';
38+
comment on column trustpub_tokens.hashed_token is 'SHA256 hash of the token that can be used to publish the crate';
39+
comment on column trustpub_tokens.crate_ids is 'Unique identifiers of the crates that can be published using this token';
40+
41+
create unique index trustpub_tokens_hashed_token_uindex
42+
on trustpub_tokens (hashed_token);
43+
44+
-------------------------------------------------------------------------------
45+
46+
create table trustpub_used_jtis
47+
(
48+
id bigserial primary key,
49+
jti varchar not null,
50+
used_at timestamptz not null default now(),
51+
expires_at timestamptz not null
52+
);
53+
54+
comment on table trustpub_used_jtis is 'Used JWT IDs to prevent token reuse in the Trusted Publishing flow';
55+
comment on column trustpub_used_jtis.id is 'Unique identifier of the `trustpub_used_jtis` row';
56+
comment on column trustpub_used_jtis.jti is 'JWT ID from the OIDC token';
57+
comment on column trustpub_used_jtis.used_at is 'Date and time when the JWT was used';
58+
comment on column trustpub_used_jtis.expires_at is 'Date and time when the JWT would expire';
59+
60+
create unique index trustpub_used_jtis_jti_uindex
61+
on trustpub_used_jtis (jti);

0 commit comments

Comments
 (0)