(cmd *Command, args []string)
| 189 | } |
| 190 | |
| 191 | func runAdmin(cmd *Command, args []string) bool { |
| 192 | if *a.debug { |
| 193 | grace.StartDebugServer(*a.debugPort) |
| 194 | } |
| 195 | |
| 196 | *a.cpuProfile = util.ResolvePath(*a.cpuProfile) |
| 197 | *a.memProfile = util.ResolvePath(*a.memProfile) |
| 198 | grace.SetupProfiling(*a.cpuProfile, *a.memProfile) |
| 199 | |
| 200 | // Load security configuration |
| 201 | util.LoadSecurityConfiguration() |
| 202 | |
| 203 | // Optional admin.toml with maintenance task settings |
| 204 | util.LoadConfiguration("admin", false) |
| 205 | |
| 206 | // Apply security.toml / env var fallbacks for credential flags. |
| 207 | // CLI flags take precedence over security.toml / WEED_* env vars. |
| 208 | applyViperFallback(cmd, a.adminUser, "adminUser", "admin.user") |
| 209 | applyViperFallback(cmd, a.adminPassword, "adminPassword", "admin.password") |
| 210 | applyViperFallback(cmd, a.readOnlyUser, "readOnlyUser", "admin.readonly.user") |
| 211 | applyViperFallback(cmd, a.readOnlyPassword, "readOnlyPassword", "admin.readonly.password") |
| 212 | |
| 213 | // Backward compatibility: if -masters is provided, use it |
| 214 | if *a.masters != "" { |
| 215 | *a.master = *a.masters |
| 216 | } |
| 217 | |
| 218 | // Validate required parameters |
| 219 | if *a.master == "" { |
| 220 | fmt.Println("Error: master parameter is required") |
| 221 | fmt.Println("Usage: weed admin -master=master1:9333,master2:9333") |
| 222 | return false |
| 223 | } |
| 224 | |
| 225 | // Validate that master string can be parsed |
| 226 | masterAddresses := pb.ServerAddresses(*a.master).ToAddresses() |
| 227 | if len(masterAddresses) == 0 { |
| 228 | fmt.Println("Error: no valid master addresses found") |
| 229 | fmt.Println("Usage: weed admin -master=master1:9333,master2:9333") |
| 230 | return false |
| 231 | } |
| 232 | |
| 233 | // Security validation: prevent empty username when password is set |
| 234 | if *a.adminPassword != "" && *a.adminUser == "" { |
| 235 | fmt.Println("Error: -adminUser cannot be empty when -adminPassword is set") |
| 236 | return false |
| 237 | } |
| 238 | if *a.readOnlyPassword != "" && *a.readOnlyUser == "" { |
| 239 | fmt.Println("Error: -readOnlyUser is required when -readOnlyPassword is set") |
| 240 | return false |
| 241 | } |
| 242 | // Security validation: prevent username conflicts between admin and read-only users |
| 243 | if *a.adminUser != "" && *a.readOnlyUser != "" && *a.adminUser == *a.readOnlyUser { |
| 244 | fmt.Println("Error: -adminUser and -readOnlyUser must be different when both are configured") |
| 245 | return false |
| 246 | } |
| 247 | // Security validation: admin password is required for read-only user |
| 248 | if *a.readOnlyPassword != "" && *a.adminPassword == "" { |
nothing calls this directly
no test coverage detected