Skip to content

Commit 9de29f4

Browse files
authored
Merge pull request #10 from Keyfactor/rot_all_stores
All stores flag support
2 parents 0a67f03 + 842ed9d commit 9de29f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1864
-161
lines changed

README.md

Lines changed: 106 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export KEYFACTOR_DOMAIN=<mykeyfactordomain>
4545

4646
#### Bulk create cert stores
4747

48+
For full documentation, see [stores import](docs/kfutil_stores_import.md).
49+
4850
This will attempt to process a CSV input file of certificate stores to create. The template can be generated by
4951
running: `kfutil stores import generate-template` command.
5052

@@ -69,9 +71,10 @@ Flags:
6971
Use "kfutil stores import [command] --help" for more information about a command.
7072
```
7173

72-
7374
#### Bulk create cert store types
7475

76+
For full documentation, see [store-types](docs/kfutil_store-types.md).
77+
7578
This will attempt to process a CSV input file of certificate store types to create. The template can be generated by
7679
running: `kfutil generate-template --type bulk-certstore-types` command.
7780

@@ -101,10 +104,14 @@ Use "kfutil store-types [command] --help" for more information about a command.
101104
```
102105
103106
### 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
107+
108+
For full documentation, see [stores rot](docs/kfutil_stores_rot.md).
109+
110+
The root of trust (rot) utility is a tool that allows you to bulk manage Keyfactor certificate stores and ensure that a
105111
set of defined certificates are present in each store that meets a certain set of criteria or no criteria at all.
106112
107113
### Root of Trust Quickstart
114+
108115
```bash
109116
echo "Generating cert template file certs_template.csv"
110117
kfutil stores rot generate-template-rot --type certs
@@ -121,6 +128,8 @@ kfutil stores rot reconcile --add-certs certs_template.csv --stores stores_templ
121128
122129
#### Generate Certificate List Template
123130
131+
For full documentation, see [stores rot generate template](docs/kfutil_stores_rot_generate-template.md).
132+
124133
This will write the file `certs_template.csv` to the current directory.
125134
126135
```bash
@@ -129,34 +138,45 @@ kfutil stores generate-template-rot --type certs
129138
130139
#### Generate Certificate Store List Template
131140
132-
This will write the file `stores_template.csv` to the current directory.
141+
For full documentation, see [stores rot generate template](docs/kfutil_stores_rot_generate-template.md).
142+
143+
This will write the file `stores_template.csv` to the current directory. For full documentation
133144
134145
```bash
135146
kfutil stores generate-template-rot --type stores
136147
```
137148
138149
#### Run Root of Trust Audit
139150
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
151+
For full documentation, see [stores rot audit](docs/kfutil_stores_rot_audit.md).
152+
153+
Audit will take in a list of certificates and a list of certificate stores and check that the certificate store's
154+
inventory either contains the certificate or does not contain the certificate based on the `--add-certs` and
155+
`--remove-certs` flags. These flags can be used together or separately. The aforementioned flags take in a path to CSV
143156
files containing a list of certificate thumbprints. To generate a template for these files, run the following command:
157+
144158
```bash
145159
kfutil stores rot generate-template --type certs
146160
```
161+
147162
To prepopulate the template file you can provide `--cn` multiple times.
163+
148164
```bash
149165
kfutil stores rot generate-template --type certs \
150166
--cn <cert subject name> \
151167
--cn <additional cert subject name>
152168
```
153169
154-
In addition, you must provide a list of stores you wish to audit. To generate a template for this file, run the following
170+
In addition, you must provide a list of stores you wish to audit. To generate a template for this file, run the
171+
following
155172
command:
173+
156174
```bash
157175
kfutil stores rot generate-template --type stores
158176
```
177+
159178
To prepopulate the template file you can provide `--store-type` and `--container-type` multiple times.
179+
160180
```bash
161181
kfutil stores rot generate-template --type stores \
162182
--store-type <store type name> \
@@ -166,15 +186,19 @@ kfutil stores rot generate-template --type stores \
166186
```
167187
168188
With all the files generated and populated, you can now run the audit command:
189+
169190
```bash
170191
kfutil stores rot audit \
171192
--stores stores_template.csv \
172193
--add-certs certs_template.csv \
173194
--remove-certs certs_template2.csv
174195
```
196+
175197
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
198+
executed. By default, the audit file will be named `rot_audit.csv` and will be written to the current directory. To
199+
output
177200
the audit file to a different location, use the `--output` flag:
201+
178202
```bash
179203
kfutil stores rot audit \
180204
--stores stores.csv \
@@ -183,28 +207,37 @@ kfutil stores rot audit \
183207
--output /path/to/output/autdit_file.csv
184208
```
185209
186-
187210
#### Run Root of Trust Reconcile
188211
212+
For full documentation, see [stores rot](docs/kfutil_stores_rot_reconcile.md).
213+
189214
Reconcile will take in a list of certificates and a list of certificate stores and check that the certificate store's
190215
inventory either contains the certificate or does not contain the certificate based on the `--add-certs` and
191216
`--remove-certs` flags. These flags can be used together or separately. The aforementioned flags take in a path to CSV
192217
files containing a list of certificate thumbprints. To generate a template for these files, run the following command:
218+
193219
```bash
194220
kfutil stores rot generate-template --type certs
195221
```
196-
To prepopulate the template file you can provide `--cn` multiple times.
222+
223+
To pre-populate the template file you can provide `--cn` multiple times.
224+
197225
```bash
198226
kfutil stores rot generate-template --type certs \
199227
--cn <cert subject name> \
200228
--cn <additional cert subject name>
201229
```
202-
In addition, you must provide a list of stores you wish to reconcile. To generate a template for this file, run the following
230+
231+
In addition, you must provide a list of stores you wish to reconcile. To generate a template for this file, run the
232+
following
203233
command:
234+
204235
```bash
205236
kfutil stores rot generate-template --type stores
206237
```
238+
207239
To pre-populate the stores template file you can provide multiple values in any combination of the following flags:
240+
208241
```bash
209242
kfutil stores rot generate-template --type stores \
210243
--store-type <store type name> \
@@ -214,33 +247,92 @@ kfutil stores rot generate-template --type stores \
214247
```
215248
216249
With all the files generated and populated, you can now run the reconcile command:
250+
217251
```bash
218252
kfutil stores rot reconcile \
219253
--stores stores_template.csv \
220254
--add-certs certs_template.csv \
221255
--remove-certs certs_template2.csv
222256
```
223-
This will generate an audit file that contains the results of the audit and actions will immediately execute those actions.
257+
258+
This will generate an audit file that contains the results of the audit and actions will immediately execute those
259+
actions.
224260
By default, the reconcile file will be named `rot_audit.csv` and will be written to the current directory. To output
225261
the reconcile file to a different location, use the `--output` flag:
262+
226263
```bash
227264
kfutil stores rot reconcile \
228265
--stores stores.csv \
229266
--add-certs addCerts.csv \
230267
--remove-certs removeCerts.csv \
231268
--output /path/to/output/audit_file.csv
232269
```
270+
233271
Alternatively you can provide an audit CSV file as an input to the reconcile command using the `--import-csv` flag:
272+
234273
```bash
235274
kfutil stores rot reconcile \
236275
--import-csv /path/to/audit_file.csv
237276
```
238277
239-
### Development
278+
### Certificate Store Inventory
279+
280+
For full documentation, see [stores inventory](docs/kfutil_stores_inventory.md).
281+
282+
#### Show the inventory of a certificate store
283+
284+
For full documentation, see [stores inventory show](docs/kfutil_stores_inventory_show.md).
285+
286+
```bash
287+
# Show by store ID:
288+
```bash
289+
kfutil stores inventory show --sid <store id>
290+
291+
# Nested command lookup: shows inventory of first cert store found
292+
kfutil stores inventory show \
293+
--sid $(kfutil stores list | jq -r ".[0].Id")
294+
```
295+
296+
Show by client machine name:
297+
298+
```bash
299+
kfutil stores inventory show --client <machine name>
300+
301+
# Nested command lookup: shows inventory of first cert store found
302+
kfutil stores inventory show \
303+
--client $(kfutil orchs list | jq -r ".[0].ClientMachine")
304+
```
305+
306+
#### Add certificates to certificate stores
307+
308+
For full documentation, see [stores inventory add](docs/kfutil_stores_inventory_add.md).
309+
310+
```bash
311+
# Add 2 certs to 2 certificate stores
312+
kfutil stores inventory add \
313+
--sid <store id> \
314+
--sid <additional store id> \
315+
--cn <cert subject name> \
316+
--cn <additional cert subject name>
317+
```
318+
319+
#### Remove certificates from certificate stores
320+
321+
For full documentation, see [stores inventory remove](docs/kfutil_stores_inventory_remove.md).
322+
323+
```bash
324+
# Remove 2 certs from all stores associated with a client machine
325+
kfutil stores inventory remove \
326+
--client <machine name> \
327+
--cn <cert subject name> \
328+
--cn <additional cert subject name>
329+
```
330+
331+
## Development
240332
241333
This CLI developed using [cobra](https://umarcor.github.io/cobra/)
242334
243-
#### Adding a new command
335+
### Adding a new command
244336
245337
```bash
246338
cobra-cli add <my-new-command>

cmd/certificates.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package cmd
88

99
import (
1010
"fmt"
11+
"github.com/Keyfactor/keyfactor-go-client/api"
1112

1213
"github.com/spf13/cobra"
1314
)
@@ -35,3 +36,14 @@ func init() {
3536
// is called directly, e.g.:
3637
// certificatesCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
3738
}
39+
40+
func certToString(response *api.GetCertificateResponse) string {
41+
sansString := ""
42+
for _, san := range response.SubjectAltNameElements {
43+
sansString += fmt.Sprintf("%s,", san.Value)
44+
}
45+
if len(sansString) > 0 {
46+
sansString = sansString[:len(sansString)-1]
47+
}
48+
return fmt.Sprintf("DN=(%s),SANs=(%s),TP=(%s),ID=(%d)", response.IssuedDN, sansString, response.Thumbprint, response.Id)
49+
}

0 commit comments

Comments
 (0)