cloudflare / cloudflare/cfssl

[cfssljson] Alternative output file extensions?

Open
#1,094 0 comments 3 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
9.5k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

The main readme says:
> cfssljson reads from standard input. It maps keys in the JSON file to filenames in the following way:
> * if cert or certificate is specified, basename.pem will be produced.
> * if key or private_key is specified, basename-key.pem will be produced.
> * if csr or certificate_request is specified, basename.csr will be produced.
> * if bundle is specified, basename-bundle.pem will be produced.
> * if ocspResponse is specified, basename-response.der will be produced.

I am interested if these defaults could have an option for alternative filename extensions. Specifically I am using cfssl and cfssljson to generate certificates for kubernetes and in order to follow their [best-practices guide](https://kubernetes.io/docs/setup/best-practices/certificates/#certificate-paths) I need to have the outputs land in files with `.crt` and `.key` extensions. This may require additional options and outputs in the cfssl generations side to facilitate a filename or extension.

I was thinking something like this example update to the [cert portion](https://github.com/cloudflare/cfssl/blob/6b49beae21ff90a09aea3901741ef02b1057ee65/cmd/cfssljson/cfssljson.go#L108) of cfssljson:

```
if contents, ok := input["cert"]; ok {
cert = contents.(string)
} else if contents, ok = input["certificate"]; ok {
cert = contents.(string)
}
if contents, ok := input["cert-ext"]; ok {
certExt = contents.(string)
} else if contents, ok = input["certificate-ext"]; ok {
certExt = contents.(string)
}
if cert != "" {
if certExt != "" {
filename = baseName + certExt
} else {
filename = baseName + ".pem"
}
outs = append(outs, outputFile{
Filename: filename,
Contents: cert,
Perms: 0664,
})
}
```

Thanks for any feedback!

Contributor guide

Open the contributing guide

Research direction

Read the output-mapping rules in the main README and the cert handling entry point in cmd/cfssljson/cfssljson.go around the referenced line. Compare the requested .crt and .key paths with the existing cert, key, csr, bundle, and OCSP outputs, then determine how the alternative extensions should be represented and documented. Done means the requested Kubernetes certificate paths can be produced without changing the default mappings.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.