|
| 1 | +--- |
| 2 | +title: trusted-certificates |
| 3 | +authors: |
| 4 | + - "@sayan-biswas" |
| 5 | +reviewers: |
| 6 | + - TBD |
| 7 | +approvers: |
| 8 | + - TBD |
| 9 | +creation-date: 2025-11-11 |
| 10 | +last-updated: 2025-12-11 |
| 11 | +status: provisional |
| 12 | +see-also: |
| 13 | +replaces: |
| 14 | +superseded-by: [] |
| 15 | +--- |
| 16 | + |
| 17 | +# SHIP-0042: Trusted Certificates |
| 18 | + |
| 19 | +## Release Signoff Checklist |
| 20 | + |
| 21 | +- [ ] Enhancement is `implementable` |
| 22 | +- [ ] Design details are appropriately documented from clear requirements |
| 23 | +- [ ] Test plan is defined |
| 24 | +- [ ] Graduation criteria for dev preview, tech preview, GA |
| 25 | +- [ ] User-facing documentation is created in [docs](/docs/) |
| 26 | + |
| 27 | +## Open Questions [optional] |
| 28 | + |
| 29 | + |
| 30 | +## Summary |
| 31 | + |
| 32 | +This proposal aims to enhance Shipwright by allowing users to add user certificates in the build container's |
| 33 | +system trust store by extending the Build APIs to let user define a list of Kubernetes Secrets/ConfigMaps, which will |
| 34 | +hold the certificate data and will be added to the trust store. |
| 35 | +This capability is essential for scenarios requiring access to external resources like self-signed |
| 36 | +certificates for Git/image registries or other necessary build artifacts, independent of BuildStrategy |
| 37 | +definitions, overcoming a current limitation where all volumes must be pre-defined or overridable via the strategy. |
| 38 | + |
| 39 | +## Motivation |
| 40 | + |
| 41 | +Currently, Shipwright Builds face challenges when needing to utilize resources like self-signed |
| 42 | +certificates for interacting with private Git repositories or image registries. |
| 43 | + |
| 44 | +### Goals |
| 45 | + |
| 46 | +- Extend `Build` and `BuildRun` resources API to declare a Secrets/ConfigMaps that holds certificate data. |
| 47 | +- Ensure these certificates are loaded and accessible to all primary containers involved |
| 48 | +in executing the build steps throughout the lifecycle of the build's execution Pod. |
| 49 | + |
| 50 | +### Non-Goals |
| 51 | + |
| 52 | +What is out of scope for this proposal? |
| 53 | +Although users can create their own ConfigMap and Secret with the certificates data, we have few options which automate this distribution of trust anchors: |
| 54 | +- Using [TrustManager](https://cert-manager.io/docs/trust/trust-manager/) generate trust bundle and mount it in workload during reconciliation. |
| 55 | +- Use [Cluster trust bundles](https://kubernetes.io/docs/reference/access-authn-authz/certificate-signing-requests/#cluster-trust-bundles) and [clusterTrustBundle projected volumes](https://kubernetes.io/docs/concepts/storage/projected-volumes/#clustertrustbundle) to mount it in workload. |
| 56 | + |
| 57 | +## Proposal |
| 58 | + |
| 59 | +### User Stories |
| 60 | + |
| 61 | +#### Using self-signed certificates |
| 62 | + |
| 63 | +As a user, I want to use Git repositories or image registries that are secured with self-signed |
| 64 | +certificates. These certificates need to be accessible by the build process, potentially across |
| 65 | +multiple steps (e.g., source cloning, image push/pull). |
| 66 | + |
| 67 | +### Implementation Notes |
| 68 | + |
| 69 | +The current BuildRun APIs will be extended to support a list of certificates accepted as kubernetes Secret |
| 70 | +resources that should be loaded in the container's trust store. |
| 71 | + |
| 72 | +```yaml |
| 73 | +apiVersion: shipwright.io/v1beta1 # Ensure this is the correct API group |
| 74 | +kind: Build |
| 75 | +metadata: |
| 76 | + namespace: test |
| 77 | + # ... |
| 78 | +spec: |
| 79 | + # ... |
| 80 | + caBundle: # can define either a secret or a configmap |
| 81 | + secret: |
| 82 | + name: gitea-tls # name of the secret in the same namespace that holds the CA data |
| 83 | + key: tls.crt # key in the secret data to look for. We don't want to mount every key |
| 84 | + configMap: |
| 85 | + name: gitea-tls # name of the secret in the same namespace that holds the CA data |
| 86 | + key: tls.crt # key in the secret data to look for. We don't want to mount every key |
| 87 | +``` |
| 88 | +
|
| 89 | +The CA bundle will be mounted on common locations is linux distributions. |
| 90 | +Reference: https://go.dev/src/crypto/x509/root_linux.go |
| 91 | +```text |
| 92 | + "/etc/ssl/certs/ca-certificates.crt", // Debian/Ubuntu/Gentoo etc |
| 93 | + "/etc/pki/tls/certs/ca-bundle.crt", // Fedora/RHEL |
| 94 | +``` |
| 95 | + |
| 96 | +Consideration for mount point: |
| 97 | +- Certificate defines a CA Bundle. |
| 98 | +- User should provide the CA bundle in a secret or configmap in the same namespace as Build and BuildRun resource. |
| 99 | +- Priority of certificate spec: BuildRun >> Build |
| 100 | +- Use subPath: Sub paths will be used mount for single file injection. This method doesn't support auto-update of when secret is modified. In CI build context, this not relevant. |
| 101 | +- Environment Variables: Mount certain environment variables.. |
| 102 | + - Node.js `NODE_EXTRA_CA_CERTS` |
| 103 | + - Python `REQUESTS_CA_BUNDLE` |
| 104 | + - Openssl `SSL_CERT_FILE` |
| 105 | + - Curl CA bundle `CURL_CA_BUNDLE` |
| 106 | +- Java: Use the jks or pkcs12 target in your trust-manager Bundle spec and mount it to the Java cacerts path `$JAVA_HOME/lib/security/cacerts`. |
| 107 | +- Mount points should not overwrite a symlink. |
| 108 | +- The mounted path will be available as system parameter at `shp-ca-bundle`, so that it can be references in the `BuildRun` resource. |
| 109 | + |
| 110 | +If a certificate with the same name is defined at multiple levels, the following precedence will apply |
| 111 | +for its definition (e.g., which Secret or ConfigMap to use): |
| 112 | + |
| 113 | +- `BuildRun.spec.caBundle` (highest precedence) >> `Build.spec.caBundle` |
| 114 | +- For new, directly mounted volumes, a mountPath and subPath must be specified. |
| 115 | +- Volume names to have postfix (hash or randon) to avoid conflict |
| 116 | +- Standard Kubernetes validation for the source secret will apply. |
| 117 | +- A `CABundle` definition can have either Secret and ConfigMap reference. |
| 118 | +- Validation will be done to check if the referenced resource exists in the cluster and namespace. |
| 119 | +- Syntax validation of CA data in the secret/configmap to be done. |
| 120 | + |
| 121 | +### Test Plan |
| 122 | + |
| 123 | +TBD |
| 124 | + |
| 125 | +### Release Criteria |
| 126 | + |
| 127 | +TBD |
| 128 | + |
| 129 | +#### Upgrade Strategy [if necessary] |
| 130 | + |
| 131 | +This API change doesn't break any existing functionalities. Upgrade strategy is not relevant. |
| 132 | + |
| 133 | +### Risks and Mitigations |
| 134 | + |
| 135 | +- File injection into the operating system's trust store will replace the existing CA bundle which might have CAs for several public domains. |
| 136 | + - This can be solved by mounting the certificates in common places (different linux distros) which provide to mount user certs and then allow OS to index and place it in the right place. (Requires Pod Lifecycle hook, not available in tekton yet) |
| 137 | + - Instead of replacing the CA bundle in the system, append the content of the new CA to the existing one. (Requires Pod Lifecycle hook, not available in tekton yet) |
| 138 | + |
| 139 | +## Drawbacks |
| 140 | + |
| 141 | +- If we don't want to replace the existing certificate, then we have to mount the system's certificate directory (eg: /etc/ssl/cert) as a volume, since we have ReadOnlyRootFileSystem enabled. |
| 142 | + |
| 143 | +## Alternatives |
| 144 | + |
| 145 | +- Define volumes directly in the Strategy and allow Build to override it. Mount volumes to git and image-push containers and user manages everything from defining secret and mounting it to the correct location. Already proposed in [https://github.com/shipwright-io/community/pull/265] |
| 146 | + |
| 147 | +## Infrastructure Needed [optional] |
| 148 | + |
| 149 | +Use this section if you need things from the project. Examples include a new subproject, repos |
| 150 | +requested, GitHub details, and/or testing infrastructure. |
| 151 | + |
| 152 | +Listing these here allows the community to get the process for these resources started right away. |
| 153 | + |
| 154 | +## Implementation History |
| 155 | + |
| 156 | +- 2025-11-11: Initial Draft |
| 157 | +- 2026-02-23: Updated Draft |
0 commit comments