|
| 1 | +# Keyfactor Utility (kfutil) |
| 2 | + |
| 3 | +`kfutil` is a go-lang CLI wrapper for Keyfactor API. It also includes other utility/helper functions around automating common Keyfactor operations. |
| 4 | + |
| 5 | +#### Integration status: Pilot - Ready for use in test environments. Not for use in production. |
| 6 | + |
| 7 | +## About the Keyfactor API Client |
| 8 | + |
| 9 | +This API client allows for programmatic management of Keyfactor resources. |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +## Support for Keyfactor Utility (kfutil) |
| 14 | + |
| 15 | +Keyfactor Utility (kfutil) is open source and there is **no SLA** for this tool/library/client. Keyfactor will address issues as resources become available. Keyfactor customers may request escalation by opening up a support ticket through their Keyfactor representative. |
| 16 | + |
| 17 | +###### To report a problem or suggest a new feature, use the **[Issues](../../issues)** tab. If you want to contribute actual bug fixes or proposed enhancements, use the **[Pull requests](../../pulls)** tab. |
| 18 | +___ |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | +## Quickstart |
| 24 | + |
| 25 | +```bash |
| 26 | +make install |
| 27 | +kfutil --help |
| 28 | +```` |
| 29 | + |
| 30 | +### Environmental Variables |
| 31 | + |
| 32 | +All the variables listed below need to be set in your environment. The `kfutil` command will look for these variables |
| 33 | +and use them if they are set. If they are not set, the utility will fail to connect to Keyfactor. |
| 34 | + |
| 35 | +```bash |
| 36 | +export KEYFACTOR_HOSTNAME=<mykeyfactorhost.mydomain.com> |
| 37 | +export KEYFACTOR_USERNAME=<myusername> # Do not include domain |
| 38 | +export KEYFACTOR_PASSWORD=<mypassword> |
| 39 | +export KEYFACTOR_DOMAIN=<mykeyfactordomain> |
| 40 | +``` |
| 41 | + |
| 42 | +## Commands |
| 43 | + |
| 44 | +### Bulk operations |
| 45 | + |
| 46 | +#### Bulk create cert stores |
| 47 | + |
| 48 | +This will attempt to process a CSV input file of certificate stores to create. The template can be generated by |
| 49 | +running: `kfutil stores import generate-template` command. |
| 50 | + |
| 51 | +```bash |
| 52 | +kfutil stores import create --file <file name to import> --store-type-id <store type id> --store-type-name <store type name> --results-path <filepath for results> --dry-run <check fields only> [flags] |
| 53 | +``` |
| 54 | + |
| 55 | +```bash |
| 56 | +kfutil stores import --help |
| 57 | +Tool for generating import templates and importing certificate stores |
| 58 | +
|
| 59 | +Usage: |
| 60 | + kfutil stores import [command] |
| 61 | +
|
| 62 | +Available Commands: |
| 63 | + create Create certificate stores |
| 64 | + generate-template For generating a CSV template with headers for bulk store creation. |
| 65 | +
|
| 66 | +Flags: |
| 67 | + -h, --help help for import |
| 68 | +
|
| 69 | +Use "kfutil stores import [command] --help" for more information about a command. |
| 70 | +``` |
| 71 | + |
| 72 | + |
| 73 | +#### Bulk create cert store types |
| 74 | + |
| 75 | +This will attempt to process a CSV input file of certificate store types to create. The template can be generated by |
| 76 | +running: `kfutil generate-template --type bulk-certstore-types` command. |
| 77 | + |
| 78 | +```bash |
| 79 | +kfutil store-types create --name $STORE_TYPE_NAME |
| 80 | +``` |
| 81 | + |
| 82 | +```bash |
| 83 | +kfutil store-types --help |
| 84 | +A collections of APIs and utilities for interacting with Keyfactor Command certificate store types. |
| 85 | +
|
| 86 | +Usage: |
| 87 | + kfutil store-types [command] |
| 88 | +
|
| 89 | +Available Commands: |
| 90 | + create Create a new certificate store type in Keyfactor Command. |
| 91 | + delete Delete a specific store type by ID. |
| 92 | + get Get a specific store type by either name or ID. |
| 93 | + list List certificate store types. |
| 94 | + templates-fetch Fetches store type templates from Keyfactor's Github. |
| 95 | + update Update a certificate store type in Keyfactor. |
| 96 | +
|
| 97 | +Flags: |
| 98 | + -h, --help help for store-types |
| 99 | +
|
| 100 | +Use "kfutil store-types [command] --help" for more information about a command. |
| 101 | +``` |
| 102 | +
|
| 103 | +### Root of Trust |
| 104 | +The root of trust (rot) utility is a tool that allows you to bulk manage Keyfactor certificate stores and ensure that a |
| 105 | +set of defined certificates are present in each store that meets a certain set of criteria or no criteria at all. |
| 106 | +
|
| 107 | +### Root of Trust Quickstart |
| 108 | +```bash |
| 109 | +echo "Generating cert template file certs_template.csv" |
| 110 | +kfutil stores rot generate-template-rot --type certs |
| 111 | +# edit the certs_template.csv file |
| 112 | +echo "Generating stores template file stores_template.csv" |
| 113 | +kfutil stores rot generate-template-rot --type stores |
| 114 | +# edit the stores_template.csv file |
| 115 | +kfutil stores rot audit --add-certs certs_template.csv --stores stores_template.csv #This will audit the stores and generate a report file |
| 116 | +# review/edit the report file generated `rot_audit.csv` |
| 117 | +kfutil stores rot reconcile --import-csv |
| 118 | +# Alternatively this can be done in one step |
| 119 | +kfutil stores rot reconcile --add-certs certs_template.csv --stores stores_template.csv |
| 120 | +``` |
| 121 | +
|
| 122 | +#### Generate Certificate List Template |
| 123 | +
|
| 124 | +This will write the file `certs_template.csv` to the current directory. |
| 125 | +
|
| 126 | +```bash |
| 127 | +kfutil stores generate-template-rot --type certs |
| 128 | +``` |
| 129 | +
|
| 130 | +#### Generate Certificate Store List Template |
| 131 | +
|
| 132 | +This will write the file `stores_template.csv` to the current directory. |
| 133 | +
|
| 134 | +```bash |
| 135 | +kfutil stores generate-template-rot --type stores |
| 136 | +``` |
| 137 | +
|
| 138 | +#### Run Root of Trust Audit |
| 139 | +
|
| 140 | +Audit will take in a list of certificates and a list of certificate stores and check that the certificate store's |
| 141 | +inventory either contains the certificate or does not contain the certificate based on the `--add-certs` and |
| 142 | +`--remove-certs` flags. These flags can be used together or separately. The aforementioned flags take in a path to CSV |
| 143 | +files containing a list of certificate thumbprints. To generate a template for these files, run the following command: |
| 144 | +```bash |
| 145 | +kfutil stores rot generate-template --type certs |
| 146 | +``` |
| 147 | +To prepopulate the template file you can provide `--cn` multiple times. |
| 148 | +```bash |
| 149 | +kfutil stores rot generate-template --type certs \ |
| 150 | + --cn <cert subject name> \ |
| 151 | + --cn <additional cert subject name> |
| 152 | +``` |
| 153 | +
|
| 154 | +In addition, you must provide a list of stores you wish to audit. To generate a template for this file, run the following |
| 155 | +command: |
| 156 | +```bash |
| 157 | +kfutil stores rot generate-template --type stores |
| 158 | +``` |
| 159 | +To prepopulate the template file you can provide `--store-type` and `--container-type` multiple times. |
| 160 | +```bash |
| 161 | +kfutil stores rot generate-template --type stores \ |
| 162 | + --store-type <store type name> \ |
| 163 | + --store-type <additional store type name> \ |
| 164 | + --container-type <container type name> \ |
| 165 | + --container-type <additional container type name> |
| 166 | +``` |
| 167 | +
|
| 168 | +With all the files generated and populated, you can now run the audit command: |
| 169 | +```bash |
| 170 | +kfutil stores rot audit \ |
| 171 | + --stores stores_template.csv \ |
| 172 | + --add-certs certs_template.csv \ |
| 173 | + --remove-certs certs_template2.csv |
| 174 | +``` |
| 175 | +This will generate an audit file that contains the results of the audit and actions that will be taken if `reconcile` is |
| 176 | +executed. By default, the audit file will be named `rot_audit.csv` and will be written to the current directory. To output |
| 177 | +the audit file to a different location, use the `--output` flag: |
| 178 | +```bash |
| 179 | +kfutil stores rot audit \ |
| 180 | + --stores stores.csv \ |
| 181 | + --add-certs addCerts.csv \ |
| 182 | + --remove-certs removeCerts.csv \ |
| 183 | + --output /path/to/output/autdit_file.csv |
| 184 | +``` |
| 185 | +
|
| 186 | +
|
| 187 | +#### Run Root of Trust Reconcile |
| 188 | +
|
| 189 | +Reconcile will take in a list of certificates and a list of certificate stores and check that the certificate store's |
| 190 | +inventory either contains the certificate or does not contain the certificate based on the `--add-certs` and |
| 191 | +`--remove-certs` flags. These flags can be used together or separately. The aforementioned flags take in a path to CSV |
| 192 | +files containing a list of certificate thumbprints. To generate a template for these files, run the following command: |
| 193 | +```bash |
| 194 | +kfutil stores rot generate-template --type certs |
| 195 | +``` |
| 196 | +To prepopulate the template file you can provide `--cn` multiple times. |
| 197 | +```bash |
| 198 | +kfutil stores rot generate-template --type certs \ |
| 199 | + --cn <cert subject name> \ |
| 200 | + --cn <additional cert subject name> |
| 201 | +``` |
| 202 | +In addition, you must provide a list of stores you wish to reconcile. To generate a template for this file, run the following |
| 203 | +command: |
| 204 | +```bash |
| 205 | +kfutil stores rot generate-template --type stores |
| 206 | +``` |
| 207 | +To pre-populate the stores template file you can provide multiple values in any combination of the following flags: |
| 208 | +```bash |
| 209 | +kfutil stores rot generate-template --type stores \ |
| 210 | + --store-type <store type name> \ |
| 211 | + --store-type <additional store type name> \ |
| 212 | + --container-type <container type name> \ |
| 213 | + --container-type <additional container type name> |
| 214 | +``` |
| 215 | +
|
| 216 | +With all the files generated and populated, you can now run the reconcile command: |
| 217 | +```bash |
| 218 | +kfutil stores rot reconcile \ |
| 219 | + --stores stores_template.csv \ |
| 220 | + --add-certs certs_template.csv \ |
| 221 | + --remove-certs certs_template2.csv |
| 222 | +``` |
| 223 | +This will generate an audit file that contains the results of the audit and actions will immediately execute those actions. |
| 224 | +By default, the reconcile file will be named `rot_audit.csv` and will be written to the current directory. To output |
| 225 | +the reconcile file to a different location, use the `--output` flag: |
| 226 | +```bash |
| 227 | +kfutil stores rot reconcile \ |
| 228 | + --stores stores.csv \ |
| 229 | + --add-certs addCerts.csv \ |
| 230 | + --remove-certs removeCerts.csv \ |
| 231 | + --output /path/to/output/audit_file.csv |
| 232 | +``` |
| 233 | +Alternatively you can provide an audit CSV file as an input to the reconcile command using the `--import-csv` flag: |
| 234 | +```bash |
| 235 | +kfutil stores rot reconcile \ |
| 236 | + --import-csv /path/to/audit_file.csv |
| 237 | +``` |
| 238 | +
|
| 239 | +### Development |
| 240 | +
|
| 241 | +This CLI developed using [cobra](https://umarcor.github.io/cobra/) |
| 242 | +
|
| 243 | +#### Adding a new command |
| 244 | +
|
| 245 | +```bash |
| 246 | +cobra-cli add <my-new-command> |
| 247 | +``` |
| 248 | +
|
| 249 | +alternatively you can specify the parent command |
| 250 | +
|
| 251 | +```bash |
| 252 | +cobra-cli add <my-new-command> -p '<parent>Cmd' |
| 253 | +``` |
| 254 | +
|
0 commit comments