Skip to content

Commit b8fd9b4

Browse files
authored
Remove use of createcerts in Fulcio (#1834)
Simplify the Fulcio configuration by removing the createcerts job and pre-generating the keys for Fulcio from the setup script. This is a prerequisite to updating ctlog to accept the pre-generated Fulcio roots as an input value rather than using createctconfig to fetch the roots from Fulcio's rootCert HTTP endpoint. Signed-off-by: Colleen Murphy <[email protected]>
1 parent 8bd6867 commit b8fd9b4

File tree

13 files changed

+91
-133
lines changed

13 files changed

+91
-133
lines changed

.github/workflows/add-remove-new-fulcio.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ jobs:
179179

180180
- name: Spin up a new Fulcio with new keys
181181
run: |
182+
pass=$(uuidgen)
183+
tmp=$(mktemp -d)
184+
openssl ecparam -name prime256v1 -genkey | openssl pkcs8 -passout "pass:${pass}" -topk8 -out "${tmp}/key.pem"
185+
openssl req -x509 -new -key "${tmp}/key.pem" -out "${tmp}/cert.pem" -sha256 -days 10 -subj "/O=test/CN=new.fulcio.test" -passin "pass:${pass}"
186+
sed -i -e "s/<private-placeholder>/$(cat "${tmp}/key.pem" | base64 -w0)/" \
187+
-e "s/<cert-placeholder>/$(cat "${tmp}/cert.pem" | base64 -w0)/" \
188+
-e "s/<password-placeholder>/$(echo -n "$pass" | base64 -w0)/" testdata/config/new-fulcio/fulcio/200-secret.yaml
182189
ko apply -BRf ./testdata/config/new-fulcio
183190
kubectl wait --timeout 5m -n fulcio-system --for=condition=Ready ksvc fulcio-new
184191
NEW_FULCIO_URL=$(kubectl -n fulcio-system get ksvc fulcio-new -ojsonpath='{.status.url}')

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,26 +184,27 @@ entry in it called `public` that holds the public key for the Rekor.
184184
## Fulcio
185185

186186
For Fulcio we just need to create a Root Certificate that it will use to sign
187-
incoming Signing Certificate requests. For this we again have a Job
188-
**createcerts**’ that will create a self signed certificate, private/public
189-
keys as well as password used to encrypt the private key.
190-
Basically we need to ensure we have all the
187+
incoming Signing Certificate requests. For this we will need to create a self
188+
signed certificate, private key as well as password used to encrypt the
189+
private key. Basically we need to ensure we have all the
191190
[necessary pieces](https://github.com/sigstore/fulcio/blob/156bc98ddacda11850d7aad5f37cda94ed160315/cmd/app/serve.go#L91-L93)
192191
to start up Fulcio.
193192

194193
This ‘**createcerts**’ job just creates the pieces mentioned above and creates
195194
two Secrets, one called `fulcio-secrets` containing the following keys:
195+
These pieces can be created using openssl:
196196

197-
* cert - Root Certificate
198-
* private - Private key
199-
* password - Password to use for decrypting the private key
200-
* public - Public key
197+
```
198+
pass=$(uuidgen)
199+
openssl ecparam -name prime256v1 -genkey | openssl pkcs8 -passout "pass:${pass}" -topk8 -out "/pki/key.pem"
200+
openssl req -x509 -new -key "/pki/key.pem" -out "/pki/cert.pem" -sha256 -days 10 -subj "/O=yourorg/CN=fulcio.your.domain" -passin "pass:${pass}"
201+
kubectl -n fulcio-system create secret generic --from-file=private=/pki/key.pem --from-file=cert=/pki/cert.pem --from-literal=password=${pass} fulcio-secret
202+
```
201203

202204
We also create another secret that just holds the public information called
203-
`pubkeysecret` that has two keys:
205+
`fulcio-pub-key` that has one key:
204206

205207
* cert - Root Certificate
206-
* public - Public key
207208

208209
And as seen already above, we modify the Deployment to not start the Pod until
209210
all the pieces are available, making our Deployment of Fulcio look (simplified

config/fulcio/certs/100-namespace.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

config/fulcio/certs/101-binding.yaml

Lines changed: 0 additions & 24 deletions
This file was deleted.

config/fulcio/certs/101-service-account.yaml

Lines changed: 0 additions & 6 deletions
This file was deleted.

config/fulcio/certs/300-createcerts.yaml

Lines changed: 0 additions & 30 deletions
This file was deleted.

config/fulcio/certs/placeholder.go

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: fulcio-secret
5+
namespace: fulcio-system
6+
type: Opaque
7+
data:
8+
password: <password-placeholder>
9+
private: <private-placeholder>
10+
cert: <cert-placeholder>
11+
---
12+
apiVersion: v1
13+
kind: Secret
14+
metadata:
15+
name: fulcio-pub-key
16+
namespace: fulcio-system
17+
type: Opaque
18+
data:
19+
cert: <cert-placeholder>

hack/setup-scaffolding-from-release.sh

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,30 @@ echo '::endgroup::'
9191

9292
# Install Fulcio and wait for it to come up
9393
echo '::group:: Install Fulcio'
94+
fulcio=$(mktemp --tmpdir fulcioXXX)
95+
curl -Ls -o "${fulcio}" "${FULCIO}"
9496
if [[ "${NEED_TO_UPDATE_FULCIO_CONFIG}" == "true" ]]; then
9597
echo "Fixing Fulcio config for < 1.23.X Kubernetes"
96-
curl -Ls "${FULCIO}" | sed 's@https://kubernetes.default.svc.cluster.local@https://kubernetes.default.svc@' | kubectl apply -f -
97-
else
98-
kubectl apply -f "${FULCIO}"
98+
sed -i -e 's@https://kubernetes.default.svc.cluster.local@https://kubernetes.default.svc@' "${fulcio}"
9999
fi
100+
pass=$(uuidgen)
101+
tmp=$(mktemp -d)
102+
openssl ecparam -name prime256v1 -genkey | openssl pkcs8 -passout "pass:${pass}" -topk8 -out "${tmp}/key.pem"
103+
openssl req -x509 -new -key "${tmp}/key.pem" -out "${tmp}/cert.pem" -sha256 -days 10 -subj "/O=test/CN=fulcio.scaffolding.test" -passin "pass:${pass}"
104+
cleanup() {
105+
rm "${tmp}/cert.pem" "${tmp}/key.pem"
106+
}
107+
trap cleanup EXIT
108+
sed -i -e "s/<private-placeholder>/$(cat "${tmp}/key.pem" | base64 -w0)/" \
109+
-e "s/<cert-placeholder>/$(cat "${tmp}/cert.pem" | base64 -w0)/" \
110+
-e "s/<password-placeholder>/$(echo -n "$pass" | base64 -w0)/" "${fulcio}"
111+
kubectl apply -f "${fulcio}"
112+
rm "${fulcio}"
100113

101114
kubectl get -n fulcio-system cm fulcio-config -o json
102115

103116
echo '::group:: Wait for Fulcio ready'
104-
kubectl wait --timeout 5m -n fulcio-system --for=condition=Complete jobs --all
117+
kubectl -n fulcio-system get job 2>&1 | grep 'No resources found' || kubectl wait --timeout 5m -n fulcio-system --for=condition=Complete jobs --all
105118
kubectl wait --timeout 5m -n fulcio-system --for=condition=Ready ksvc fulcio
106119
# this checks if the requested version is > 0.4.12 (and therefore has fulcio-grpc in it)
107120
if [[ "${PATCH}" -gt 12 ]] || [[ "${MINOR}" -ge 5 ]]; then
@@ -132,12 +145,12 @@ kubectl apply -f "${TUF}"
132145

133146
# Then copy the secrets (even though it's all public stuff, certs, public keys)
134147
# to the tuf-system namespace so that we can construct a tuf root out of it.
135-
kubectl -n ctlog-system get secrets ctlog-public-key -oyaml | sed 's/namespace: .*/namespace: tuf-system/' | kubectl apply -f -
136-
kubectl -n fulcio-system get secrets fulcio-pub-key -oyaml | sed 's/namespace: .*/namespace: tuf-system/' | kubectl apply -f -
137-
kubectl -n rekor-system get secrets rekor-pub-key -oyaml | sed 's/namespace: .*/namespace: tuf-system/' | kubectl apply -f -
148+
kubectl -n ctlog-system get secrets ctlog-public-key -oyaml | sed -e '/creationTimestamp:/d' -e '/uid:/d' -e '/resourceVersion:/d' -e 's/namespace: .*/namespace: tuf-system/' | kubectl apply -f -
149+
kubectl -n fulcio-system get secrets fulcio-pub-key -oyaml | sed -e '/creationTimestamp:/d' -e '/uid:/d' -e '/resourceVersion:/d' -e 's/namespace: .*/namespace: tuf-system/' | kubectl apply -f -
150+
kubectl -n rekor-system get secrets rekor-pub-key -oyaml | sed -e '/creationTimestamp:/d' -e '/uid:/d' -e '/resourceVersion:/d' -e 's/namespace: .*/namespace: tuf-system/' | kubectl apply -f -
138151

139152
if [[ "${INSTALL_TSA}" == "true" ]]; then
140-
kubectl -n tsa-system get secrets tsa-cert-chain -oyaml | sed 's/namespace: .*/namespace: tuf-system/' | kubectl apply -f -
153+
kubectl -n tsa-system get secrets tsa-cert-chain -oyaml | sed -e '/creationTimestamp:/d' -e '/uid:/d' -e '/resourceVersion:/d' -e 's/namespace: .*/namespace: tuf-system/' | kubectl apply -f -
141154
fi
142155
echo '::endgroup::'
143156

hack/setup-scaffolding.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,30 @@ if [[ "${NEED_TO_UPDATE_FULCIO_CONFIG}" == "true" ]]; then
5757
sed 's@https://kubernetes.default.svc.cluster.local@https://kubernetes.default.svc@' config/fulcio/fulcio/200-configmap.yaml > ./200-configmap-new.yaml
5858
mv ./200-configmap-new.yaml config/fulcio/fulcio/200-configmap.yaml
5959
fi
60+
61+
pass=$(uuidgen)
62+
tmp=$(mktemp -d)
63+
openssl ecparam -name prime256v1 -genkey | openssl pkcs8 -passout "pass:${pass}" -topk8 -out "${tmp}/key.pem"
64+
openssl req -x509 -new -key "${tmp}/key.pem" -out "${tmp}/cert.pem" -sha256 -days 10 -subj "/O=test/CN=fulcio.scaffolding.test" -passin "pass:${pass}"
65+
cleanup() {
66+
rm "${tmp}/cert.pem" "${tmp}/key.pem"
67+
}
68+
trap cleanup EXIT
69+
cp config/fulcio/fulcio/200-secret.yaml 200-secret.original.yaml
70+
sed -i -e "s/<private-placeholder>/$(cat "${tmp}/key.pem" | base64 -w0)/" \
71+
-e "s/<cert-placeholder>/$(cat "${tmp}/cert.pem" | base64 -w0)/" \
72+
-e "s/<password-placeholder>/$(echo -n "$pass" | base64 -w0)/" config/fulcio/fulcio/200-secret.yaml
73+
6074
make ko-apply-fulcio
6175
echo '::endgroup::'
6276

77+
echo "Restoring Fulcio secret placeholder"
78+
mv ./200-secret.original.yaml config/fulcio/fulcio/200-secret.yaml
6379
if [[ "${NEED_TO_UPDATE_FULCIO_CONFIG}" == "true" ]]; then
6480
echo "Restoring Fulcio config"
6581
mv ./200-configmap.yaml config/fulcio/fulcio/200-configmap.yaml
6682
fi
6783
echo '::group:: Wait for Fulcio ready'
68-
kubectl wait --timeout 5m -n fulcio-system --for=condition=Complete jobs --all
6984
kubectl wait --timeout 5m -n fulcio-system --for=condition=Ready ksvc fulcio
7085
kubectl wait --timeout 5m -n fulcio-system --for=condition=Ready ksvc fulcio-grpc
7186
echo '::endgroup::'
@@ -96,10 +111,10 @@ make ko-apply-tuf
96111

97112
# Then copy the secrets (even though it's all public stuff, certs, public keys)
98113
# to the tuf-system namespace so that we can construct a tuf root out of it.
99-
kubectl -n ctlog-system get secrets ctlog-public-key -oyaml | sed 's/namespace: .*/namespace: tuf-system/' | kubectl apply -f -
100-
kubectl -n fulcio-system get secrets fulcio-pub-key -oyaml | sed 's/namespace: .*/namespace: tuf-system/' | kubectl apply -f -
101-
kubectl -n rekor-system get secrets rekor-pub-key -oyaml | sed 's/namespace: .*/namespace: tuf-system/' | kubectl apply -f -
102-
kubectl -n tsa-system get secrets tsa-cert-chain -oyaml | sed 's/namespace: .*/namespace: tuf-system/' | kubectl apply -f -
114+
kubectl -n ctlog-system get secrets ctlog-public-key -oyaml | sed -e '/creationTimestamp:/d' -e '/uid:/d' -e '/resourceVersion:/d' -e 's/namespace: .*/namespace: tuf-system/' | kubectl apply -f -
115+
kubectl -n fulcio-system get secrets fulcio-pub-key -oyaml | sed -e '/creationTimestamp:/d' -e '/uid:/d' -e '/resourceVersion:/d' -e 's/namespace: .*/namespace: tuf-system/' | kubectl apply -f -
116+
kubectl -n rekor-system get secrets rekor-pub-key -oyaml | sed -e '/creationTimestamp:/d' -e '/uid:/d' -e '/resourceVersion:/d' -e 's/namespace: .*/namespace: tuf-system/' | kubectl apply -f -
117+
kubectl -n tsa-system get secrets tsa-cert-chain -oyaml | sed -e '/creationTimestamp:/d' -e '/uid:/d' -e '/resourceVersion:/d' -e 's/namespace: .*/namespace: tuf-system/' | kubectl apply -f -
103118
echo '::endgroup::'
104119

105120
# Make sure the tuf jobs complete

0 commit comments

Comments
 (0)