Skip to main content

rustfs_credentials/
constants.rs

1// Copyright 2024 RustFS Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/// Default Access Key
16/// Default value: rustfsadmin
17/// Environment variable: RUSTFS_ACCESS_KEY
18/// Command line argument: --access-key
19/// Example: RUSTFS_ACCESS_KEY=rustfsadmin
20/// Example: --access-key rustfsadmin
21pub const DEFAULT_ACCESS_KEY: &str = "rustfsadmin";
22/// Default Secret Key
23/// Default value: rustfsadmin
24/// Environment variable: RUSTFS_SECRET_KEY
25/// Command line argument: --secret-key
26/// Example: RUSTFS_SECRET_KEY=rustfsadmin
27/// Example: --secret-key rustfsadmin
28pub const DEFAULT_SECRET_KEY: &str = "rustfsadmin";
29
30/// Environment variable for RPC authentication token
31/// Used to set the authentication token for RPC communication
32/// Example: RUSTFS_RPC_SECRET=your_token_here
33/// Default value: No default value. RUSTFS_SECRET_KEY value is recommended.
34pub const ENV_RPC_SECRET: &str = "RUSTFS_RPC_SECRET";
35
36/// IAM Policy Types
37/// Used to differentiate between embedded and inherited policies
38/// Example: "embedded-policy" or "inherited-policy"
39/// Default value: "embedded-policy"
40pub const EMBEDDED_POLICY_TYPE: &str = "embedded-policy";
41
42/// IAM Policy Types
43/// Used to differentiate between embedded and inherited policies
44/// Example: "embedded-policy" or "inherited-policy"
45/// Default value: "inherited-policy"
46pub const INHERITED_POLICY_TYPE: &str = "inherited-policy";
47
48/// IAM Policy Claim Name for Service Account
49/// Used to identify the service account policy claim in JWT tokens
50/// Example: "sa-policy"
51/// Default value: "sa-policy"
52pub const IAM_POLICY_CLAIM_NAME_SA: &str = "sa-policy";
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57
58    #[test]
59    fn test_security_constants() {
60        // Test security related constants
61        assert_eq!(DEFAULT_ACCESS_KEY, "rustfsadmin");
62        assert!(DEFAULT_ACCESS_KEY.len() >= 8, "Access key should be at least 8 characters");
63
64        assert_eq!(DEFAULT_SECRET_KEY, "rustfsadmin");
65        assert!(DEFAULT_SECRET_KEY.len() >= 8, "Secret key should be at least 8 characters");
66
67        // In production environment, access key and secret key should be different
68        // These are default values, so being the same is acceptable, but should be warned in documentation
69        assert_eq!(DEFAULT_ACCESS_KEY, DEFAULT_SECRET_KEY);
70    }
71
72    #[test]
73    fn test_security_best_practices() {
74        // Test security best practices
75
76        // These are default values, should be changed in production environments
77        assert_eq!(DEFAULT_ACCESS_KEY, "rustfsadmin");
78        assert_eq!(DEFAULT_SECRET_KEY, "rustfsadmin");
79
80        // Verify that key lengths meet minimum security requirements
81        assert!(DEFAULT_ACCESS_KEY.len() >= 8, "Access key should be at least 8 characters");
82        assert!(DEFAULT_SECRET_KEY.len() >= 8, "Secret key should be at least 8 characters");
83
84        // Check if default credentials contain common insecure patterns
85        let _insecure_patterns = ["admin", "password", "123456", "default"];
86        let _access_key_lower = DEFAULT_ACCESS_KEY.to_lowercase();
87        let _secret_key_lower = DEFAULT_SECRET_KEY.to_lowercase();
88
89        // Note: More security check logic can be added here
90        // For example, check if keys contain insecure patterns
91    }
92}