4
0
Эх сурвалжийг харах

Merge branch 'carl/publish-packages-workflow' of ssh://github.com/smallstep/certificates into carl/publish-packages-workflow

Carl Tashian 11 сар өмнө
parent
commit
61bb5d66fc

+ 12 - 1
CHANGELOG.md

@@ -25,7 +25,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
 
 ---
 
-## [0.29.0] - unreleased
+### [x.y.z] - unreleased
+
+### Changed
+
+- Upgrade HSM-enabled Docker images from Debian Bookworm (12) to Debian Trixie
+  (13) (smallstep/certificates#2493)
+- Use JSON array format for Dockerfile's `CMD` instruction. This prevents shell
+  interpolation of environment variables like `CONFIGPATH` and `PWDPATH`,
+  ensuring consistent command execution. Commands can still be overridden via
+  Kubernetes or Docker configuration when needed (smallstep/certificates#2493)
+
+## [0.29.0] - 2025-12-03
 
 ### Added
 

+ 1 - 1
acme/challenge.go

@@ -231,7 +231,7 @@ func tlsAlert(err error) uint8 {
 	if errors.As(err, &opErr) {
 		v := reflect.ValueOf(opErr.Err)
 		if v.Kind() == reflect.Uint8 {
-			return uint8(v.Uint()) //nolint:gosec // handled by checking its type
+			return cast.Uint8(v.Uint())
 		}
 	}
 	return 0

+ 8 - 4
acme/linker.go

@@ -84,13 +84,17 @@ func GetUnescapedPathSuffix(typ LinkType, provisionerName string, inputs ...stri
 	case NewNonceLinkType, NewAccountLinkType, NewOrderLinkType, NewAuthzLinkType, DirectoryLinkType, KeyChangeLinkType, RevokeCertLinkType:
 		return fmt.Sprintf("/%s/%s", provisionerName, typ)
 	case AccountLinkType, OrderLinkType, AuthzLinkType, CertificateLinkType:
-		return fmt.Sprintf("/%s/%s/%s", provisionerName, typ, inputs[0]) //nolint:gosec // operating on internally defined inputs
+		//nolint:gosec // operating on internally defined inputs
+		return fmt.Sprintf("/%s/%s/%s", provisionerName, typ, inputs[0])
 	case ChallengeLinkType:
-		return fmt.Sprintf("/%s/%s/%s/%s", provisionerName, typ, inputs[0], inputs[1]) //nolint:gosec // operating on internally defined inputs
+		//nolint:gosec // operating on internally defined inputs
+		return fmt.Sprintf("/%s/%s/%s/%s", provisionerName, typ, inputs[0], inputs[1])
 	case OrdersByAccountLinkType:
-		return fmt.Sprintf("/%s/%s/%s/orders", provisionerName, AccountLinkType, inputs[0]) //nolint:gosec // operating on internally defined inputs
+		//nolint:gosec // operating on internally defined inputs
+		return fmt.Sprintf("/%s/%s/%s/orders", provisionerName, AccountLinkType, inputs[0])
 	case FinalizeLinkType:
-		return fmt.Sprintf("/%s/%s/%s/finalize", provisionerName, OrderLinkType, inputs[0]) //nolint:gosec // operating on internally defined inputs
+		//nolint:gosec // operating on internally defined inputs
+		return fmt.Sprintf("/%s/%s/%s/finalize", provisionerName, OrderLinkType, inputs[0])
 	default:
 		return ""
 	}

+ 1 - 1
api/api.go

@@ -382,7 +382,7 @@ func Root(w http.ResponseWriter, r *http.Request) {
 	// Load root certificate with the
 	cert, err := mustAuthority(r.Context()).Root(sum)
 	if err != nil {
-		render.Error(w, r, errs.Wrapf(http.StatusNotFound, err, "%s was not found", r.RequestURI))
+		render.Error(w, r, errs.NotFoundErr(err, errs.WithMessage("root certificate with fingerprint %q was not found", sum)))
 		return
 	}
 

+ 12 - 8
api/api_test.go

@@ -851,20 +851,22 @@ func Test_Health(t *testing.T) {
 }
 
 func Test_Root(t *testing.T) {
+	const sha = "efc7d6b475a56fe587650bcdb999a4a308f815ba44db4bf0371ea68a786ccd36"
 	tests := []struct {
-		name       string
-		root       *x509.Certificate
-		err        error
-		statusCode int
+		name        string
+		root        *x509.Certificate
+		err         error
+		expectedMsg string
+		statusCode  int
 	}{
-		{"ok", parseCertificate(rootPEM), nil, 200},
-		{"fail", nil, fmt.Errorf("not found"), 404},
+		{"ok", parseCertificate(rootPEM), nil, "", 200},
+		{"fail", nil, fmt.Errorf("not found"), fmt.Sprintf("root certificate with fingerprint %q was not found", sha), 404},
 	}
 
 	// Request with chi context
 	chiCtx := chi.NewRouteContext()
-	chiCtx.URLParams.Add("sha", "efc7d6b475a56fe587650bcdb999a4a308f815ba44db4bf0371ea68a786ccd36")
-	req := httptest.NewRequest("GET", "http://example.com/root/efc7d6b475a56fe587650bcdb999a4a308f815ba44db4bf0371ea68a786ccd36", http.NoBody)
+	chiCtx.URLParams.Add("sha", sha)
+	req := httptest.NewRequest("GET", "http://example.com/root/"+sha, http.NoBody)
 	req = req.WithContext(context.WithValue(context.Background(), chi.RouteCtxKey, chiCtx))
 
 	expected := []byte(`{"ca":"` + strings.ReplaceAll(rootPEM, "\n", `\n`) + `\n"}`)
@@ -889,6 +891,8 @@ func Test_Root(t *testing.T) {
 				if !bytes.Equal(bytes.TrimSpace(body), expected) {
 					t.Errorf("caHandler.Root Body = %s, wants %s", body, expected)
 				}
+			} else {
+				require.Contains(t, string(body), tt.expectedMsg)
 			}
 		})
 	}

+ 1 - 1
docker/Dockerfile

@@ -26,4 +26,4 @@ HEALTHCHECK CMD step ca health 2>/dev/null | grep "^ok" >/dev/null
 COPY docker/entrypoint.sh /entrypoint.sh
 
 ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
-CMD exec /usr/local/bin/step-ca --password-file $PWDPATH $CONFIGPATH
+CMD ["/usr/local/bin/step-ca", "--password-file", "/home/step/secrets/password", "/home/step/config/ca.json"]

+ 5 - 5
docker/Dockerfile.hsm

@@ -1,4 +1,4 @@
-FROM golang:bookworm AS builder
+FROM golang:trixie AS builder
 
 WORKDIR /src
 COPY . .
@@ -9,16 +9,16 @@ RUN apt-get install -y --no-install-recommends \
 RUN make V=1 GO_ENVS="CGO_ENABLED=1" bin/step-ca
 RUN setcap CAP_NET_BIND_SERVICE=+eip bin/step-ca
 
-FROM smallstep/step-kms-plugin:bookworm AS kms
+FROM smallstep/step-kms-plugin:trixie AS kms
 
-FROM smallstep/step-cli:bookworm
+FROM smallstep/step-cli:trixie
 
 COPY --from=builder /src/bin/step-ca /usr/local/bin/step-ca
 COPY --from=kms /usr/local/bin/step-kms-plugin /usr/local/bin/step-kms-plugin
 
 USER root
 RUN apt-get update
-RUN apt-get install -y --no-install-recommends opensc opensc-pkcs11 pcscd gnutls-bin libpcsclite1 p11-kit
+RUN apt-get install -y --no-install-recommends opensc opensc-pkcs11 pcscd gnutls-bin libpcsclite1 p11-kit yubihsm-pkcs11
 RUN mkdir -p /run/pcscd
 RUN chown step:step /run/pcscd
 USER step
@@ -33,4 +33,4 @@ HEALTHCHECK CMD step ca health 2>/dev/null | grep "^ok" >/dev/null
 COPY docker/entrypoint.sh /entrypoint.sh
 
 ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
-CMD exec /usr/local/bin/step-ca --password-file $PWDPATH $CONFIGPATH
+CMD ["/usr/local/bin/step-ca", "--password-file", "/home/step/secrets/password", "/home/step/config/ca.json"]

+ 13 - 0
internal/cast/cast.go

@@ -93,3 +93,16 @@ func Uint16(x int) uint16 {
 
 	return u16
 }
+
+func SafeUint8[T number](x T) (uint8, error) {
+	return safecast.Convert[uint8](x)
+}
+
+func Uint8[T number](x T) uint8 {
+	u8, err := SafeUint8(x)
+	if err != nil {
+		panic(err)
+	}
+
+	return u8
+}

+ 14 - 0
internal/cast/cast_test.go

@@ -78,3 +78,17 @@ func TestUint16PanicsOnNegativeValue(t *testing.T) {
 func TestUint16PanicsOnLargeValue(t *testing.T) {
 	require.Panics(t, func() { Uint16(math.MaxUint16 + 1) })
 }
+
+func TestUint8ConvertsValues(t *testing.T) {
+	require.Equal(t, uint8(0), Uint8(0))
+	require.Equal(t, uint8(math.MaxUint8), Uint8(math.MaxUint8))
+	require.Equal(t, uint8(42), Uint8(42))
+}
+
+func TestUint8PanicsOnNegativeValue(t *testing.T) {
+	require.Panics(t, func() { Uint8(-1) })
+}
+
+func TestUint8PanicsOnLargeValue(t *testing.T) {
+	require.Panics(t, func() { Uint8(math.MaxUint8 + 1) })
+}

+ 2 - 4
test/integration/requestid_test.go

@@ -153,11 +153,9 @@ func Test_reflectRequestID(t *testing.T) {
 	var firstErr *errs.Error
 	if assert.ErrorAs(t, err, &firstErr) {
 		assert.Equal(t, 404, firstErr.StatusCode())
-		assert.Equal(t, "The requested resource could not be found. Please see the certificate authority logs for more info.", firstErr.Err.Error())
+		assert.Equal(t, `root certificate with fingerprint "invalid" was not found`, firstErr.Err.Error())
 		assert.NotEmpty(t, firstErr.RequestID)
 
-		// TODO: include the below error in the JSON? It's currently only output to the CA logs. Also see https://github.com/smallstep/certificates/pull/759
-		//assert.Equal(t, "/root/invalid was not found: certificate with fingerprint invalid was not found", apiErr.Msg)
 	}
 	assert.Nil(t, rootResponse)
 
@@ -166,7 +164,7 @@ func Test_reflectRequestID(t *testing.T) {
 	var secondErr *errs.Error
 	if assert.ErrorAs(t, err, &secondErr) {
 		assert.Equal(t, 404, secondErr.StatusCode())
-		assert.Equal(t, "The requested resource could not be found. Please see the certificate authority logs for more info.", secondErr.Err.Error())
+		assert.Equal(t, `root certificate with fingerprint "invalid" was not found`, secondErr.Err.Error())
 		assert.Equal(t, "reqID", secondErr.RequestID)
 	}
 	assert.Nil(t, rootResponse)