1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
// Copyright 2024 wrkflw contributors
// SPDX-License-Identifier: MIT
//! # wrkflw-secrets
//!
//! Comprehensive secrets management for wrkflw workflow execution.
//! Supports multiple secret providers and secure handling throughout the execution pipeline.
//!
//! ## Features
//!
//! - **Multiple Secret Providers**: Environment variables, file-based storage, with extensibility for cloud providers
//! - **Secret Substitution**: GitHub Actions-style secret references (`${{ secrets.SECRET_NAME }}`)
//! - **Automatic Masking**: Intelligent secret detection and masking in logs and output
//! - **Rate Limiting**: Built-in protection against secret access abuse
//! - **Caching**: Configurable caching for improved performance
//! - **Input Validation**: Comprehensive validation of secret names and values
//! - **Thread Safety**: Full async/await support with thread-safe operations
//!
//! ## Quick Start
//!
//! ```rust
//! use wrkflw_secrets::{SecretManager, SecretMasker, SecretSubstitution};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Initialize the secret manager with default configuration
//! let manager = SecretManager::default().await?;
//!
//! // Set an environment variable for testing
//! std::env::set_var("API_TOKEN", "secret_api_token_123");
//!
//! // Retrieve a secret
//! let secret = manager.get_secret("API_TOKEN").await?;
//! println!("Secret value: {}", secret.value());
//!
//! // Use secret substitution
//! let mut substitution = SecretSubstitution::new(&manager);
//! let template = "Using token: ${{ secrets.API_TOKEN }}";
//! let resolved = substitution.substitute(template).await?;
//! println!("Resolved: {}", resolved);
//!
//! // Set up secret masking
//! let masker = SecretMasker::new();
//! masker.add_secret("secret_api_token_123");
//!
//! let log_message = "Failed to authenticate with token: secret_api_token_123";
//! let masked = masker.mask(log_message);
//! println!("Masked: {}", masked); // Will show: "Failed to authenticate with token: se***123"
//!
//! // Clean up
//! std::env::remove_var("API_TOKEN");
//! Ok(())
//! }
//! ```
//!
//! ## Configuration
//!
//! ```rust
//! use wrkflw_secrets::{SecretConfig, SecretProviderConfig, SecretManager};
//! use std::collections::HashMap;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut providers = HashMap::new();
//!
//! // Environment variable provider with prefix
//! providers.insert(
//! "env".to_string(),
//! SecretProviderConfig::Environment {
//! prefix: Some("MYAPP_SECRET_".to_string())
//! }
//! );
//!
//! // File-based provider
//! providers.insert(
//! "file".to_string(),
//! SecretProviderConfig::File {
//! path: "/path/to/secrets.json".to_string()
//! }
//! );
//!
//! let config = SecretConfig {
//! default_provider: "env".to_string(),
//! providers,
//! enable_masking: true,
//! timeout_seconds: 30,
//! enable_caching: true,
//! cache_ttl_seconds: 300,
//! rate_limit: Default::default(),
//! };
//!
//! let manager = SecretManager::new(config).await?;
//! Ok(())
//! }
//! ```
//!
//! ## Security Features
//!
//! ### Input Validation
//!
//! All secret names and values are validated to prevent injection attacks and ensure compliance
//! with naming conventions.
//!
//! ### Rate Limiting
//!
//! Built-in rate limiting prevents abuse and denial-of-service attacks on secret providers.
//!
//! ### Automatic Pattern Detection
//!
//! The masking system automatically detects and masks common secret patterns:
//! - GitHub Personal Access Tokens (`ghp_*`)
//! - AWS Access Keys (`AKIA*`)
//! - JWT tokens
//! - API keys and tokens
//!
//! ### Memory Safety
//!
//! Secrets are handled with care to minimize exposure in memory and logs.
//!
//! ## Provider Support
//!
//! ### Environment Variables
//!
//! ```rust
//! use wrkflw_secrets::{SecretProviderConfig, SecretManager, SecretConfig};
//!
//! // With prefix for better security
//! let provider = SecretProviderConfig::Environment {
//! prefix: Some("MYAPP_".to_string())
//! };
//! ```
//!
//! ### File-based Storage
//!
//! Supports JSON, YAML, and environment file formats:
//!
//! ```json
//! {
//! "database_password": "super_secret_password",
//! "api_key": "your_api_key_here"
//! }
//! ```
//!
//! ```yaml
//! database_password: super_secret_password
//! api_key: your_api_key_here
//! ```
//!
//! ```bash
//! # Environment format
//! DATABASE_PASSWORD=super_secret_password
//! API_KEY="your_api_key_here"
//! ```
pub use ;
pub use ;
pub use SecretManager;
pub use SecretMasker;
pub use ;
pub use SecretSubstitution;
/// Re-export commonly used types