Skip to content

Commit c94a1c5

Browse files
committed
Merge branch 'master' into ssh-cert-templates
2 parents ba91810 + 03d642e commit c94a1c5

File tree

20 files changed

+531
-195
lines changed

20 files changed

+531
-195
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ issues:
6464
- should have a package comment, unless it's in another file for this package
6565
- error strings should not be capitalized or end with punctuation or a newline
6666
- Wrapf call needs 1 arg but has 2 args
67+
- cs.NegotiatedProtocolIsMutual is deprecated
6768
# golangci.com configuration
6869
# https://github.com/golangci/golangci/wiki/Configuration
6970
service:

.travis.yml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
language: go
2+
os: linux
3+
dist: focal
4+
services:
5+
- docker
26
go:
3-
- 1.14.x
7+
- 1.14.x
48
addons:
59
apt:
610
packages:
7-
- debhelper
8-
- fakeroot
9-
- bash-completion
10-
- libpcsclite-dev
11+
- debhelper
12+
- fakeroot
13+
- bash-completion
14+
- libpcsclite-dev
1115
env:
1216
global:
13-
- V=1
17+
- V=1
1418
before_script:
15-
- make bootstrap
19+
- make bootstrap
1620
script:
17-
- make
18-
- make artifacts
21+
- make
22+
- make artifacts
1923
after_success:
20-
- bash <(curl -s https://codecov.io/bash) -t "$CODECOV_TOKEN" || echo "Codecov did
21-
not collect coverage reports"
24+
- bash <(curl -s https://codecov.io/bash) -t "$CODECOV_TOKEN" || echo "Codecov did
25+
not collect coverage reports"
2226
notifications:
2327
email: false
2428
deploy:
2529
provider: releases
26-
skip_cleanup: true
27-
api_key:
30+
cleanup: false
31+
token:
2832
secure: EVV43Vkqn67hhKGYn4WhQp2YO6KFmUDSkLXjYXYGX07Fm8p5KjRFBPOz9LV83QrvVmLigvg0CtR8Jqqcnq2SUhus3nhZaN2g19NhMypZLioyOVP0kAkas8ocuvxkwz3YxIK/yMrmTKbQ7JGXtbc8IjAox9ovNo1fFIQmVMAzPfu++OWBJ0j+gUqKtpaNA7gzsSv8UOw3/T3hNm6E1IbpWxl9BPSOzUOE9F/QOThANzifGfdxvqNJFkAgqu5DVPz8zQNbMrz4zH+KwASKxd6hjhzSSMzouKzOEHTA/elDCHEjke0Jos29MkGWHcIydLtCD95DGecqM8BFSC9f2acHDjmUO1rdfoLA3Pt+UiZJuTwyQm/jrHHhRnH8oJpK15G5LvxSqzY9YDWpAk38+jMw/udW6wt7BGAU8FEXLbq0bsFL3yfTepeWjmzT5WS0YXdiBz2SEK+Og9R2bSdtl4owghRzKNio5DNPuYAbqbpi+jqzqQVLj27x7LWoQ0MHvZcz9U+oO00r6M1tDCmFVRdtfgb2H+MIDY69qYGo5qoGMfH1btCWR8bA9wSYB/Z7hW/xZT9r7f/d5/P40k8yKINmTZqyUTQeplrE3y4BPVzKksclczBZa67syIUQ49I35QppnH4GFQHUwlra7r3W9zfZRvaLnp5qOIKAQe3MAIZqtLg=
2933
file_glob: true
3034
file: .travis-releases/*

Makefile

Lines changed: 27 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,25 @@ VERSION ?= $(shell [ -d .git ] && git describe --tags --always --dirty="-dev")
4646
# If we are not in an active git dir then try reading the version from .VERSION.
4747
# .VERSION contains a slug populated by `git archive`.
4848
VERSION := $(or $(VERSION),$(shell ./.version.sh .VERSION))
49+
ifeq ($(TRAVIS_BRANCH),master)
4950
PUSHTYPE := master
51+
else
52+
PUSHTYPE := branch
53+
endif
5054
endif
5155

5256
VERSION := $(shell echo $(VERSION) | sed 's/^v//')
57+
DEB_VERSION := $(shell echo $(VERSION) | sed 's/-/~/g')
5358

5459
ifdef V
5560
$(info TRAVIS_TAG is $(TRAVIS_TAG))
5661
$(info VERSION is $(VERSION))
62+
$(info DEB_VERSION is $(DEB_VERSION))
5763
$(info PUSHTYPE is $(PUSHTYPE))
5864
endif
5965

66+
include make/docker.mk
67+
6068
#########################################
6169
# Build
6270
#########################################
@@ -134,13 +142,15 @@ lint:
134142

135143
INSTALL_PREFIX?=/usr/
136144

137-
install: $(PREFIX)bin/$(BINNAME) $(PREFIX)bin/$(CLOUDKMS_BINNAME)
145+
install: $(PREFIX)bin/$(BINNAME) $(PREFIX)bin/$(CLOUDKMS_BINNAME) $(PREFIX)bin/$(AWSKMS_BINNAME)
138146
$Q install -D $(PREFIX)bin/$(BINNAME) $(DESTDIR)$(INSTALL_PREFIX)bin/$(BINNAME)
139147
$Q install -D $(PREFIX)bin/$(CLOUDKMS_BINNAME) $(DESTDIR)$(INSTALL_PREFIX)bin/$(CLOUDKMS_BINNAME)
148+
$Q install -D $(PREFIX)bin/$(AWSKMS_BINNAME) $(DESTDIR)$(INSTALL_PREFIX)bin/$(AWSKMS_BINNAME)
140149

141150
uninstall:
142151
$Q rm -f $(DESTDIR)$(INSTALL_PREFIX)/bin/$(BINNAME)
143152
$Q rm -f $(DESTDIR)$(INSTALL_PREFIX)/bin/$(CLOUDKMS_BINNAME)
153+
$Q rm -f $(DESTDIR)$(INSTALL_PREFIX)/bin/$(AWSKMS_BINNAME)
144154

145155
.PHONY: install uninstall
146156

@@ -155,6 +165,12 @@ endif
155165
ifneq ($(CLOUDKMS_BINNAME),"")
156166
$Q rm -f bin/$(CLOUDKMS_BINNAME)
157167
endif
168+
ifneq ($(AWSKMS_BINNAME),"")
169+
$Q rm -f bin/$(AWSKMS_BINNAME)
170+
endif
171+
ifneq ($(YUBIKEY_BINNAME),"")
172+
$Q rm -f bin/$(YUBIKEY_BINNAME)
173+
endif
158174

159175
.PHONY: clean
160176

@@ -167,82 +183,12 @@ run:
167183

168184
.PHONY: run
169185

170-
#########################################
171-
# Building Docker Image
172-
#
173-
# Builds a dockerfile for step by building a linux version of the step-cli and
174-
# then copying the specific binary when building the container.
175-
#
176-
# This ensures the container is as small as possible without having to deal
177-
# with getting access to private repositories inside the container during build
178-
# time.
179-
#########################################
180-
181-
# XXX We put the output for the build in 'output' so we don't mess with how we
182-
# do rule overriding from the base Makefile (if you name it 'build' it messes up
183-
# the wildcarding).
184-
DOCKER_OUTPUT=$(OUTPUT_ROOT)docker/
185-
186-
DOCKER_MAKE=V=$V GOOS_OVERRIDE='GOOS=linux GOARCH=amd64' PREFIX=$(1) make $(1)bin/$(2)
187-
DOCKER_BUILD=$Q docker build -t smallstep/$(1):latest -f docker/$(2) --build-arg BINPATH=$(DOCKER_OUTPUT)bin/$(1) .
188-
189-
docker: docker-make docker/Dockerfile.step-ca
190-
$(call DOCKER_BUILD,step-ca,Dockerfile.step-ca)
191-
192-
docker-make:
193-
mkdir -p $(DOCKER_OUTPUT)
194-
$(call DOCKER_MAKE,$(DOCKER_OUTPUT),step-ca)
195-
196-
.PHONY: docker docker-make
197-
198-
#################################################
199-
# Releasing Docker Images
200-
#
201-
# Using the docker build infrastructure, this section is responsible for
202-
# logging into docker hub and pushing the built docker containers up with the
203-
# appropriate tags.
204-
#################################################
205-
206-
DOCKER_TAG=docker tag smallstep/$(1):latest smallstep/$(1):$(2)
207-
DOCKER_PUSH=docker push smallstep/$(1):$(2)
208-
209-
docker-tag:
210-
$(call DOCKER_TAG,step-ca,$(VERSION))
211-
212-
docker-push-tag: docker-tag
213-
$(call DOCKER_PUSH,step-ca,$(VERSION))
214-
215-
docker-push-tag-latest:
216-
$(call DOCKER_PUSH,step-ca,latest)
217-
218-
# Rely on DOCKER_USERNAME and DOCKER_PASSWORD being set inside the CI or
219-
# equivalent environment
220-
docker-login:
221-
$Q docker login -u="$(DOCKER_USERNAME)" -p="$(DOCKER_PASSWORD)"
222-
223-
.PHONY: docker-login docker-tag docker-push-tag docker-push-tag-latest
224-
225-
#################################################
226-
# Targets for pushing the docker images
227-
#################################################
228-
229-
# For all builds we build the docker container
230-
docker-master: docker
231-
232-
# For all builds with a release candidate tag
233-
docker-release-candidate: docker-master docker-login docker-push-tag
234-
235-
# For all builds with a release tag
236-
docker-release: docker-release-candidate docker-push-tag-latest
237-
238-
.PHONY: docker-master docker-release-candidate docker-release
239-
240186
#########################################
241187
# Debian
242188
#########################################
243189

244190
changelog:
245-
$Q echo "step-certificates ($(VERSION)) unstable; urgency=medium" > debian/changelog
191+
$Q echo "step-certificates ($(DEB_VERSION)) unstable; urgency=medium" > debian/changelog
246192
$Q echo >> debian/changelog
247193
$Q echo " * See https://github.com/smallstep/certificates/releases" >> debian/changelog
248194
$Q echo >> debian/changelog
@@ -270,7 +216,7 @@ define BUNDLE_MAKE
270216
# $(2) -- Go Architecture (e.g. amd64, arm, arm64, etc.)
271217
# $(3) -- Go ARM architectural family (e.g. 7, 8, etc.)
272218
# $(4) -- Parent directory for executables generated by 'make'.
273-
$(q) GOOS_OVERRIDE='GOOS=$(1) GOARCH=$(2) GOARM=$(3)' PREFIX=$(4) make $(4)bin/$(BINNAME) $(4)bin/$(CLOUDKMS_BINNAME)
219+
$(q) GOOS_OVERRIDE='GOOS=$(1) GOARCH=$(2) GOARM=$(3)' PREFIX=$(4) make $(4)bin/$(BINNAME) $(4)bin/$(CLOUDKMS_BINNAME) $(4)bin/$(AWSKMS_BINNAME)
274220
endef
275221

276222
binary-linux:
@@ -290,16 +236,16 @@ define BUNDLE
290236
# $(2) -- Step Platform Name
291237
# $(3) -- Step Binary Architecture
292238
# $(4) -- Step Binary Name (For Windows Comaptibility)
293-
$(q) ./make/bundle.sh "$(BINARY_OUTPUT)$(1)" "$(RELEASE)" "$(VERSION)" "$(2)" "$(3)" "$(4)" "$(5)"
239+
$(q) ./make/bundle.sh "$(BINARY_OUTPUT)$(1)" "$(RELEASE)" "$(VERSION)" "$(2)" "$(3)" "$(4)" "$(5)" "$(6)"
294240
endef
295241

296242
bundle-linux: binary-linux binary-linux-arm64 binary-linux-armv7
297-
$(call BUNDLE,linux,linux,amd64,$(BINNAME),$(CLOUDKMS_BINNAME))
298-
$(call BUNDLE,linux.arm64,linux,arm64,$(BINNAME),$(CLOUDKMS_BINNAME))
299-
$(call BUNDLE,linux.armv7,linux,armv7,$(BINNAME),$(CLOUDKMS_BINNAME))
243+
$(call BUNDLE,linux,linux,amd64,$(BINNAME),$(CLOUDKMS_BINNAME),$(AWSKMS_BINNAME))
244+
$(call BUNDLE,linux.arm64,linux,arm64,$(BINNAME),$(CLOUDKMS_BINNAME),$(AWSKMS_BINNAME))
245+
$(call BUNDLE,linux.armv7,linux,armv7,$(BINNAME),$(CLOUDKMS_BINNAME),$(AWSKMS_BINNAME))
300246

301247
bundle-darwin: binary-darwin
302-
$(call BUNDLE,darwin,darwin,amd64,$(BINNAME),$(CLOUDKMS_BINNAME))
248+
$(call BUNDLE,darwin,darwin,amd64,$(BINNAME),$(CLOUDKMS_BINNAME),$(AWSKMS_BINNAME))
303249

304250
.PHONY: binary-linux binary-darwin bundle-linux bundle-darwin
305251

@@ -323,6 +269,9 @@ artifacts-tag: artifacts-linux-tag artifacts-darwin-tag artifacts-archive-tag
323269
# Targets for creating step artifacts
324270
#################################################
325271

272+
# For all builds that are not tagged and not on the master branch
273+
artifacts-branch:
274+
326275
# For all builds that are not tagged
327276
artifacts-master:
328277

acme/api/handler.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package api
22

33
import (
44
"context"
5+
"crypto/x509"
6+
"encoding/pem"
57
"fmt"
68
"net/http"
79

@@ -162,6 +164,18 @@ func (h *Handler) GetCertificate(w http.ResponseWriter, r *http.Request) {
162164
return
163165
}
164166

167+
block, _ := pem.Decode(certBytes)
168+
if block == nil {
169+
api.WriteError(w, acme.ServerInternalErr(errors.New("failed to decode any certificates from generated certBytes")))
170+
return
171+
}
172+
cert, err := x509.ParseCertificate(block.Bytes)
173+
if err != nil {
174+
api.WriteError(w, acme.Wrap(err, "failed to parse generated leaf certificate"))
175+
return
176+
}
177+
178+
api.LogCertificate(w, cert)
165179
w.Header().Set("Content-Type", "application/pem-certificate-chain; charset=utf-8")
166180
w.Write(certBytes)
167181
}

acme/api/handler_test.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,43 @@ func TestHandlerGetCertificate(t *testing.T) {
526526
problem: acme.ServerInternalErr(errors.New("force")),
527527
}
528528
},
529+
"fail/decode-leaf-for-loggger": func(t *testing.T) test {
530+
acc := &acme.Account{ID: "accID"}
531+
ctx := context.WithValue(context.Background(), acme.AccContextKey, acc)
532+
ctx = context.WithValue(ctx, chi.RouteCtxKey, chiCtx)
533+
return test{
534+
auth: &mockAcmeAuthority{
535+
getCertificate: func(accID, id string) ([]byte, error) {
536+
assert.Equals(t, accID, acc.ID)
537+
assert.Equals(t, id, certID)
538+
return []byte("foo"), nil
539+
},
540+
},
541+
ctx: ctx,
542+
statusCode: 500,
543+
problem: acme.ServerInternalErr(errors.New("failed to decode any certificates from generated certBytes")),
544+
}
545+
},
546+
"fail/parse-x509-leaf-for-logger": func(t *testing.T) test {
547+
acc := &acme.Account{ID: "accID"}
548+
ctx := context.WithValue(context.Background(), acme.AccContextKey, acc)
549+
ctx = context.WithValue(ctx, chi.RouteCtxKey, chiCtx)
550+
return test{
551+
auth: &mockAcmeAuthority{
552+
getCertificate: func(accID, id string) ([]byte, error) {
553+
assert.Equals(t, accID, acc.ID)
554+
assert.Equals(t, id, certID)
555+
return pem.EncodeToMemory(&pem.Block{
556+
Type: "CERTIFICATE REQUEST",
557+
Bytes: []byte("foo"),
558+
}), nil
559+
},
560+
},
561+
ctx: ctx,
562+
statusCode: 500,
563+
problem: acme.ServerInternalErr(errors.New("failed to parse generated leaf certificate")),
564+
}
565+
},
529566
"ok": func(t *testing.T) test {
530567
acc := &acme.Account{ID: "accID"}
531568
ctx := context.WithValue(context.Background(), acme.AccContextKey, acc)
@@ -565,7 +602,7 @@ func TestHandlerGetCertificate(t *testing.T) {
565602
prob := tc.problem.ToACME()
566603

567604
assert.Equals(t, ae.Type, prob.Type)
568-
assert.Equals(t, ae.Detail, prob.Detail)
605+
assert.HasPrefix(t, ae.Detail, prob.Detail)
569606
assert.Equals(t, ae.Identifier, prob.Identifier)
570607
assert.Equals(t, ae.Subproblems, prob.Subproblems)
571608
assert.Equals(t, res.Header["Content-Type"], []string{"application/problem+json"})

api/api.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ func logOtt(w http.ResponseWriter, token string) {
394394
}
395395
}
396396

397-
func logCertificate(w http.ResponseWriter, cert *x509.Certificate) {
397+
// LogCertificate add certificate fields to the log message.
398+
func LogCertificate(w http.ResponseWriter, cert *x509.Certificate) {
398399
if rl, ok := w.(logging.ResponseLogger); ok {
399400
m := map[string]interface{}{
400401
"serial": cert.SerialNumber,
@@ -412,7 +413,11 @@ func logCertificate(w http.ResponseWriter, cert *x509.Certificate) {
412413
if err != nil || len(rest) > 0 {
413414
break
414415
}
415-
m["provisioner"] = fmt.Sprintf("%s (%s)", val.Name, val.CredentialID)
416+
if len(val.CredentialID) > 0 {
417+
m["provisioner"] = fmt.Sprintf("%s (%s)", val.Name, val.CredentialID)
418+
} else {
419+
m["provisioner"] = fmt.Sprintf("%s", val.Name)
420+
}
416421
break
417422
}
418423
}

api/rekey.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (h *caHandler) Rekey(w http.ResponseWriter, r *http.Request) {
5454
caPEM = certChainPEM[1]
5555
}
5656

57-
logCertificate(w, certChain[0])
57+
LogCertificate(w, certChain[0])
5858
JSONStatus(w, &SignResponse{
5959
ServerPEM: certChainPEM[0],
6060
CaPEM: caPEM,

api/renew.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (h *caHandler) Renew(w http.ResponseWriter, r *http.Request) {
2525
caPEM = certChainPEM[1]
2626
}
2727

28-
logCertificate(w, certChain[0])
28+
LogCertificate(w, certChain[0])
2929
JSONStatus(w, &SignResponse{
3030
ServerPEM: certChainPEM[0],
3131
CaPEM: caPEM,

api/revoke.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (h *caHandler) Revoke(w http.ResponseWriter, r *http.Request) {
9191
// TODO: should probably be checking if the certificate was revoked here.
9292
// Will need to thread that request down to the authority, so will need
9393
// to add API for that.
94-
logCertificate(w, opts.Crt)
94+
LogCertificate(w, opts.Crt)
9595
opts.MTLS = true
9696
}
9797

api/sign.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (h *caHandler) Sign(w http.ResponseWriter, r *http.Request) {
8282
if len(certChainPEM) > 1 {
8383
caPEM = certChainPEM[1]
8484
}
85-
logCertificate(w, certChain[0])
85+
LogCertificate(w, certChain[0])
8686
JSONStatus(w, &SignResponse{
8787
ServerPEM: certChainPEM[0],
8888
CaPEM: caPEM,

0 commit comments

Comments
 (0)