|
| 1 | +# SafeCLI: Secure Command Line Interface Package |
| 2 | + |
| 3 | +SafeCLI is a specialized Go package aimed at facilitating the secure construction, redaction, and logging of command-line arguments. It's designed particularly to handle sensitive values, ensuring they are managed securely throughout the process of command-line argument preparation and execution. This package is part of the Kanister project. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Secure Argument Handling**: Safely handles sensitive information in command-line arguments, ensuring that sensitive details are never exposed in logs or error messages. |
| 8 | +- **Flexible CLI Construction**: Provides a builder pattern for constructing command-line arguments dynamically, allowing for clean and readable code. |
| 9 | +- **Redaction Interface**: Integrates a redaction system that automatically obscures sensitive information when arguments are converted to strings for logging or debugging. |
| 10 | +- **Logging Utility**: Includes a logging utility that ensures sensitive information is redacted, while still providing helpful output for debugging and monitoring. |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +You can install SafeCLI by running: |
| 15 | + |
| 16 | +```bash |
| 17 | +go get -u github.com/kanisterio/safecli |
| 18 | +``` |
| 19 | + |
| 20 | +## Usage |
| 21 | + |
| 22 | +### Basic CLI Construction |
| 23 | + |
| 24 | +To construct a CLI command, you can use the `NewBuilder` function which initializes a new command builder. You can append arguments, both loggable and sensitive, to the builder: |
| 25 | + |
| 26 | +```go |
| 27 | +import "github.com/kanisterio/safecli" |
| 28 | + |
| 29 | +func main() { |
| 30 | + builder := safecli.NewBuilder("zip"). |
| 31 | + AppendLoggableKV("--output", "/path/to/output"). |
| 32 | + AppendRedactedKV("--password", "secretPass"). |
| 33 | + AppendLoggable("input_file1", "input_file2") |
| 34 | + |
| 35 | + command := builder.Build() |
| 36 | + // Use `command` as required, e.g., execute it |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +In the above example, `--password` is a sensitive argument, and its value will be redacted in logs. |
| 41 | + |
| 42 | +### Secure Logging |
| 43 | + |
| 44 | +To log a CLI command securely, ensuring that sensitive information is redacted: |
| 45 | + |
| 46 | +```go |
| 47 | +logger := safecli.NewLogger(builder) |
| 48 | +logOutput := logger.Log() |
| 49 | +// Use `logOutput` for logging |
| 50 | +``` |
| 51 | + |
| 52 | +## Contribution |
| 53 | + |
| 54 | +Contributions to the SafeCLI package are welcome. Please follow the contribution guidelines of the Kanister project when submitting patches or features. |
0 commit comments