Skip to content

Offline mode for step ca commands #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Mar 4, 2019
Merged

Offline mode for step ca commands #86

merged 14 commits into from
Mar 4, 2019

Conversation

maraino
Copy link
Collaborator

@maraino maraino commented Feb 26, 2019

Description

This PR adds a new offline mode to the following step ca commands:

  • certificate
  • sign
  • renew
  • token

The offline mode is activated with the flag --offline. It requires the file ca.json as well as all the certs and keys that are created with the step ca init command.

step ca token already has a more complex offline mode that will be used if ca.json does not exist.

@codecov
Copy link

codecov bot commented Feb 27, 2019

Codecov Report

Merging #86 into master will decrease coverage by 0.18%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #86      +/-   ##
==========================================
- Coverage   68.46%   68.28%   -0.19%     
==========================================
  Files          59       59              
  Lines        8008     8037      +29     
==========================================
+ Hits         5483     5488       +5     
- Misses       2161     2185      +24     
  Partials      364      364
Impacted Files Coverage Δ
utils/read.go 46.34% <100%> (+7.45%) ⬆️
command/certificate/create.go 52.89% <0%> (-3.95%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4f287f8...63a937c. Read the comment docs.

@maraino maraino marked this pull request as ready for review February 27, 2019 00:23
@maraino maraino requested a review from dopey February 27, 2019 00:23
command/ca/ca.go Outdated
offlineFlag = cli.BoolFlag{
Name: "offline",
Usage: `Creates a certificate without contacting the certificate authority. Offline mode
requires the CA configuration file given using the '--ca-config>' flag.`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be more clear here. It doesn't actually require that flag, because the flag can be inferred.

'''

Request a new certificate using the offline mode, requires the configuration
files, certificates and keys created with **step ca init**:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

certificates, and keys (oxford comma) - yes I'm an asshole.

token := ctx.String("token")
offline := ctx.Bool("offline")

// ofline and token are incompatible because the token is generated before
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling -> ofline

// Start token flow
if tok, err := signCertificateTokenFlow(ctx, hostname); err == nil {
sans := ctx.StringSlice("san")
if tok, err := flow.GenerateToken(ctx, hostname, sans); err == nil {
Copy link
Contributor

@dopey dopey Feb 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if token, err = flow.GenerateToken(ctx, hostname, sans); err != nil {
    return err
}

Renew(tr http.RoundTripper) (*api.SignResponse, error)
}

// oflineCA is a wrapper on top of the certificates authority methods that
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... that what?

return c.config.Root.First()
}

// Provisioners returns the list of provisioners configured.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configured provisioners. (grammar)

return nil, errors.Wrap(err, "error parsing certificate")
}
// renew cert using authority
cert, root, err := c.authority.Renew(peer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically it's the intermediate ... got confused when I saw root here.


// GenerateToken creates the token used by the authority to sign certificates.
func (c *offlineCA) GenerateToken(ctx *cli.Context, subject string, sans []string) (string, error) {
// Use always ca.json information root and audience
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Use ca.json configuration for the root and audience"

'''

Renew a certificate using the offline mode, requires the configuration
files, certificates and keys created with **step ca init**:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... certificates, and keys

return errors.Errorf("error parsing %s: file is not a certificate request", csrFile)
}

// ofline and token are incompatible because the token is generated before
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

offline (spelling)

@@ -388,6 +374,67 @@ func newTokenFlow(ctx *cli.Context, subject string, sans []string, caURL, root,
return generateToken(subject, sans, kid, issuer, audience, root, notBefore, notAfter, jwk)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// offlineTokenFlow generates a provisioning token using  either 
//   1. static configuration from ca.json (created with `step ca init`)
//   2. input from command line flags
// These two options are mutually exclusive and priority is given to ca.json.

Leave this comment above the method. Was confused since I forgot step ca token had an older, more complex implementation.


// Require kid, issuer and keyFile if ca.json does not exists
switch {
case len(kid) == 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we assume the kid here since the user passes the keyFile and the default is to just use jose.Thumbprint(jwk)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. makes sense

@maraino maraino requested a review from dopey March 2, 2019 00:12
@maraino maraino merged commit 096252f into master Mar 4, 2019
@maraino maraino deleted the offline-ca branch March 4, 2019 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants