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