kanidmd_lib/constants/mod.rs
1// Re-export as needed
2
3pub mod entries;
4pub mod uuids;
5pub mod values;
6
7pub use self::{entries::*, uuids::*, values::*};
8
9use std::time::Duration;
10
11// This value no longer requires incrementing during releases. It only
12// serves as a "once off" marker so that we know when the initial db
13// index is performed on first-run.
14//
15// It's also useful if we need to force a reindex due to a bug though :)
16pub const SYSTEM_INDEX_VERSION: i64 = 32;
17
18/*
19 * domain functional levels
20 *
21 * The idea here is to allow topology wide upgrades to be performed. We have to
22 * assume that across multiple kanidm instances there may be cases where we have version
23 * N and version N minus 1 as upgrades are rolled out.
24 *
25 * Imagine we set up a new cluster. Machine A and B both have level 1 support.
26 * We upgrade machine A. It has support up to level 2, but machine B does not.
27 * So the overall functional level is level 1. Then we upgrade B, which supports
28 * up to level 2. We still don't do the upgrade! The topology is still level 1
29 * unless an admin at this point *intervenes* and forces the update. OR what
30 * happens we we update machine A again and it now supports up to level 3, with
31 * a target level of 2. So we update machine A now to level 2, and that can
32 * still replicate to machine B since it also supports level 2.
33 *
34 * effectively it means that "some features" may be a "release behind" for users
35 * who don't muck with the levels, but it means that we can do mixed version
36 * upgrades.
37 */
38pub type DomainVersion = u32;
39
40/// Domain level 0 - this indicates that this instance
41/// is a new install and has never had a domain level
42/// previously.
43pub const DOMAIN_LEVEL_0: DomainVersion = 0;
44
45/// The domain's patch level - this is used for emergency migrations
46/// within a release cycle, and should not be changed otherwise.
47pub const PATCH_LEVEL_2: u32 = 2;
48
49/// Domain Level introduced with 1.6.0.
50/// Deprecated as of 1.8.0
51pub const DOMAIN_LEVEL_10: DomainVersion = 10;
52
53/// Domain Level introduced with 1.7.0.
54/// Deprecated as of 1.9.0
55pub const DOMAIN_LEVEL_11: DomainVersion = 11;
56
57/// Domain Level introduced with 1.8.0.
58/// Deprecated as of 1.10.0
59pub const DOMAIN_LEVEL_12: DomainVersion = 12;
60
61/// Domain Level introduced with 1.9.0.
62/// Deprecated as of 1.11.0
63pub const DOMAIN_LEVEL_13: DomainVersion = 13;
64
65/// Domain Level introduced with 1.10.0.
66/// Deprecated as of 1.12.0
67pub const DOMAIN_LEVEL_14: DomainVersion = 14;
68
69/// Domain Level introduced with 1.11.0.
70/// Deprecated as of 1.13.0
71pub const DOMAIN_LEVEL_1_11: DomainVersion = 15;
72
73/// Domain Level introduced with 1.12.0.
74/// Deprecated as of 1.14.0
75pub const DOMAIN_LEVEL_1_12: DomainVersion = 16;
76
77/// Domain Level introduced with 1.13.0.
78/// Deprecated as of 1.15.0
79pub const DOMAIN_LEVEL_1_13: DomainVersion = 17;
80
81/// Domain Level introduced with 1.14.0.
82/// Deprecated as of 1.16.0
83pub const DOMAIN_LEVEL_1_14: DomainVersion = 18;
84
85// The target supported domain functional level. During development this is
86// the NEXT level that users will upgrade too. In other words if we are
87// developing 1.6.0-dev, then we need to set TGT_LEVEL to 10 which is
88// the corresponding level.
89pub const DOMAIN_TGT_LEVEL: DomainVersion = DOMAIN_LEVEL_1_13;
90// The current patch level if any out of band fixes are required.
91pub const DOMAIN_TGT_PATCH_LEVEL: u32 = PATCH_LEVEL_2;
92
93// The maximum supported domain functional level. This generally
94// represents a *future* version of the server which doesn't exist
95// yet.
96pub const DOMAIN_MAX_LEVEL: DomainVersion = DOMAIN_LEVEL_1_14;
97
98// This is the LOWEST level of database we can recreate. This is important for testing,
99// but we don't actually expect it to be used.
100pub const DOMAIN_MIN_CREATION_LEVEL: DomainVersion = DOMAIN_LEVEL_12;
101
102// The previous releases domain functional level
103pub const DOMAIN_PREVIOUS_TGT_LEVEL: DomainVersion = DOMAIN_TGT_LEVEL - 1;
104// The target domain functional level for the SUBSEQUENT release/dev cycle.
105pub const DOMAIN_TGT_NEXT_LEVEL: DomainVersion = DOMAIN_TGT_LEVEL + 1;
106
107// What domain level is the "one before" we could do a valid upgrade. We need to be able
108// to create this database, then attempt (and fail) to upgrade from it during tests. So
109// that technically means we have to keep one-extra migration level.
110pub const DOMAIN_MIGRATION_FROM_INVALID: DomainVersion = DOMAIN_MIN_CREATION_LEVEL;
111
112// What is the MINIMUM domain level we *could* allow migration from? This has to be
113// one greater than our minimum so we can test this, and in releases it's one version prior.
114#[cfg(test)]
115pub const DOMAIN_MIGRATION_FROM_MIN: DomainVersion = DOMAIN_MIN_CREATION_LEVEL + 1;
116#[cfg(not(test))]
117pub const DOMAIN_MIGRATION_FROM_MIN: DomainVersion = DOMAIN_PREVIOUS_TGT_LEVEL;
118
119// The minimum level that we can re-migrate from. Remember, this
120// means we should be able to move from min level to the next level. It doesn't mean
121// we have to be able to *create* this level. Generally this means it's "off by one"
122// to migration-from-min.
123#[cfg(test)]
124pub const DOMAIN_MIN_REMIGRATION_LEVEL: DomainVersion = DOMAIN_MIN_CREATION_LEVEL;
125#[cfg(not(test))]
126pub const DOMAIN_MIN_REMIGRATION_LEVEL: DomainVersion = DOMAIN_PREVIOUS_TGT_LEVEL - 1;
127
128// The minimum supported domain functional level (for replication)
129pub const DOMAIN_MINIMUM_REPLICATION_LEVEL: DomainVersion = DOMAIN_TGT_LEVEL;
130// The minimum supported domain functional level (for replication)
131pub const DOMAIN_MAXIMUM_REPLICATION_LEVEL: DomainVersion = DOMAIN_TGT_LEVEL;
132
133// On test builds define to 60 seconds
134#[cfg(test)]
135pub const PURGE_FREQUENCY: u64 = 60;
136// For production 10 minutes.
137#[cfg(not(test))]
138pub const PURGE_FREQUENCY: u64 = 600;
139
140/// The duration for which messages will be retained after their send_after time. Defaults to
141/// 7 days
142pub const DEFAULT_MESSAGE_RETENTION: Duration = Duration::from_secs(86400 * 7);
143
144/// The duration for an account signup request to be processed before it is removed. Defaults
145/// to 1 day
146pub const DEFAULT_ACCOUNT_SIGNUP_RETENTION: Duration = Duration::from_secs(86400);
147
148/// The number of delayed actions to consider per write transaction. Higher
149/// values allow more coalescing to occur, but may consume more ram and cause
150/// some latency while dequeuing and writing those operations.
151pub const DELAYED_ACTION_BATCH_SIZE: usize = 256;
152
153/// The amount of time to wait to acquire a database ticket before timing out.
154/// Higher values allow greater operation queuing but can cause feedback
155/// loops where operations will stall for long periods.
156pub const DB_LOCK_ACQUIRE_TIMEOUT_MILLIS: u64 = 5000;
157
158#[cfg(test)]
159/// In test, we limit the changelog to 10 minutes.
160pub const CHANGELOG_MAX_AGE: u64 = 600;
161#[cfg(not(test))]
162/// A replica may be up to 7 days out of sync before being denied updates.
163pub const CHANGELOG_MAX_AGE: u64 = 7 * 86400;
164
165#[cfg(test)]
166/// In test, we limit the recyclebin to 5 minutes.
167pub const RECYCLEBIN_MAX_AGE: u64 = 300;
168#[cfg(not(test))]
169/// In production we allow 1 week
170pub const RECYCLEBIN_MAX_AGE: u64 = 7 * 86400;
171
172// 5 minute auth session window.
173pub const AUTH_SESSION_TIMEOUT: u64 = 300;
174// 5 minute mfa reg window
175pub const MFAREG_SESSION_TIMEOUT: u64 = 300;
176
177// Maximum - Sessions have no upper bound.
178pub const MAXIMUM_AUTH_SESSION_EXPIRY: u32 = u32::MAX;
179// Default - sessions last for 1 day
180pub const DEFAULT_AUTH_SESSION_EXPIRY: u32 = 86400;
181// Maximum - privileges last for 1 hour.
182pub const MAXIMUM_AUTH_PRIVILEGE_EXPIRY: u32 = 3600;
183// Default - privileges last for 10 minutes.
184pub const DEFAULT_AUTH_PRIVILEGE_EXPIRY: u32 = 600;
185// Default - directly privileged sessions only last 1 hour.
186pub const DEFAULT_AUTH_SESSION_LIMITED_EXPIRY: u32 = 3600;
187// Default - oauth refresh tokens last for 16 hours.
188pub const OAUTH_REFRESH_TOKEN_EXPIRY: u32 = 3600 * 16;
189
190/// How long access tokens should last. This is NOT the length
191/// of the refresh token, which is bound to the issuing session.
192pub const OAUTH2_ACCESS_TOKEN_EXPIRY: u32 = 15 * 60;
193
194/// The absolute maximum that can be requested for max-age requests in OIDC.
195pub const OAUTH2_OIDC_MAX_AGE_CLAMP: i64 = 86400;
196
197/// The amount of time a suppliers clock can be "ahead" before
198/// we warn about possible clock synchronisation issues.
199pub const REPL_SUPPLIER_ADVANCE_WINDOW: Duration = Duration::from_secs(600);
200
201/// The number of days that the default replication MTLS cert lasts for when
202/// configured manually. Defaults to 4 years (including 1 day for the leap year).
203pub const REPL_MTLS_CERTIFICATE_EXPIRY: u64 = 1461 * 86400;
204
205/// The default number of entries that a user may retrieve in a search
206pub const DEFAULT_LIMIT_SEARCH_MAX_RESULTS: u64 = 1024;
207/// The default number of entries than an api token may retrieve in a search;
208pub const DEFAULT_LIMIT_API_SEARCH_MAX_RESULTS: u64 = u64::MAX >> 1;
209/// the default number of entries that may be examined in a partially indexed
210/// query.
211pub const DEFAULT_LIMIT_SEARCH_MAX_FILTER_TEST: u64 = 2048;
212/// the default number of entries that may be examined in a partially indexed
213/// query by an api token.
214pub const DEFAULT_LIMIT_API_SEARCH_MAX_FILTER_TEST: u64 = 16384;
215/// The maximum number of items in a filter, regardless of nesting level.
216pub const DEFAULT_LIMIT_FILTER_MAX_ELEMENTS: u64 = 32;
217
218/// The maximum amount of recursion allowed in a filter.
219pub const DEFAULT_LIMIT_FILTER_DEPTH_MAX: u64 = 12;
220
221/// The maximum number of sessions allowed on a single entry.
222pub(crate) const SESSION_MAXIMUM: usize = 48;
223
224#[cfg(test)]
225// Test only certificate. This is a self-signed server cert.
226pub(crate) const TEST_X509_CERT_DATA: &str = r#"-----BEGIN CERTIFICATE-----
227MIICeDCCAh6gAwIBAgIBAjAKBggqhkjOPQQDAjCBhDELMAkGA1UEBhMCQVUxDDAK
228BgNVBAgMA1FMRDEPMA0GA1UECgwGS2FuaWRtMRwwGgYDVQQDDBNLYW5pZG0gR2Vu
229ZXJhdGVkIENBMTgwNgYDVQQLDC9EZXZlbG9wbWVudCBhbmQgRXZhbHVhdGlvbiAt
230IE5PVCBGT1IgUFJPRFVDVElPTjAeFw0yNTA3MjkwMzMxMDNaFw0yNTA4MDMwMzMx
231MDNaMHoxCzAJBgNVBAYTAkFVMQwwCgYDVQQIDANRTEQxDzANBgNVBAoMBkthbmlk
232bTESMBAGA1UEAwwJbG9jYWxob3N0MTgwNgYDVQQLDC9EZXZlbG9wbWVudCBhbmQg
233RXZhbHVhdGlvbiAtIE5PVCBGT1IgUFJPRFVDVElPTjBZMBMGByqGSM49AgEGCCqG
234SM49AwEHA0IABPFkpVzFH+feItm9JFFm/noge+BlZLpdGWOuSUvfoivAzCgPr7Kr
235nGd8kUzIyJermePzu2SVQLaEt/7GY8Ha+2ujgYkwgYYwCQYDVR0TBAIwADAOBgNV
236HQ8BAf8EBAMCBaAwEwYDVR0lBAwwCgYIKwYBBQUHAwEwHQYDVR0OBBYEFOjucEtX
237mj/wQ7npVaMOyDtLU6dUMB8GA1UdIwQYMBaAFNo5o+5ea0sNMlW/75VgGJCv2AcJ
238MBQGA1UdEQQNMAuCCWxvY2FsaG9zdDAKBggqhkjOPQQDAgNIADBFAiEA1TACf4eS
239g07LRiKhlMgA+6xxztxiZCuV6LakRp7FZdECIFp0rFSiFJdkLEO9IyqYc+zPW770
240ta41VMU3u9UQfHxF
241-----END CERTIFICATE-----
242"#;