Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ All notable changes to this project will be documented in this file.
### Added

- The OLM bundle declares that the operator provides a CSI driver and sets `createdAt` ([#779]).
- `autoTls` certificates now contain the Pod's ServiceAccount as a SPIFFE ID URI SAN
(`spiffe://<cluster-domain>/ns/<namespace>/sa/<service-account>`), in the same format as Istio ([#XXX]).

### Fixed

Expand Down
2 changes: 2 additions & 0 deletions docs/modules/secret-operator/pages/scope.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ xref:#node[] and xref:#pod[] would contain the following values in its `subjectA
* The node's IP address
* The node's fully qualified domain name (`my-node.example.com`, without a trailing dot)
* The pod's fully qualified domain name (`my-pod.my-service.my-namespace.svc.cluster.local`, without a trailing dot)

Independent of the scopes, the xref:secretclass.adoc#backend-autotls[`autoTls`] backend always adds the SPIFFE ID of the Pod's ServiceAccount (`spiffe://cluster.local/ns/my-namespace/sa/my-service-account`).
10 changes: 10 additions & 0 deletions docs/modules/secret-operator/pages/secretclass.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ CAUTION: Attributes of the certificate (such as the expiration date, fingerprint

xref:scope.adoc[Scopes] are used to populate the claims (such as `subjectAlternateName`) of the provisioned certificates.

Regardless of the scopes, the `subjectAlternateName` also contains the Pod's ServiceAccount as a https://spiffe.io/docs/latest/spiffe-about/spiffe-concepts/[SPIFFE ID{external-link-icon}^] URI, using the same format as https://istio.io/latest/docs/concepts/security/[Istio{external-link-icon}^].
The Kubernetes cluster domain is used as the trust domain:

```
URI:spiffe://cluster.local/ns/my-namespace/sa/my-service-account
```

This identifies the workload independently of its addresses, and can be used for authorization, for example of TLS client certificates.
Keep in mind that every Pod that is allowed to use the same ServiceAccount gets a certificate with the same SPIFFE ID.

[#backend-tls-certificate-key-pair-generation]
==== `TLS certificate key pair generation`

Expand Down
32 changes: 32 additions & 0 deletions rust/operator-binary/src/backend/auto_tls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,14 @@ impl SecretBackend for TlsGenerate {
Address::Ip(ip) => san_ext.ip(&ip.to_string()),
};
}
if let Some(service_account_name) = &pod_info.service_account_name {
has_san = true;
san_ext.uri(&spiffe_id(
&pod_info.kubernetes_cluster_domain,
&pod_info.namespace,
service_account_name,
));
}
if has_san {
exts.push(san_ext.build(&ctx)?);
}
Expand Down Expand Up @@ -570,6 +578,19 @@ fn cert_lifetime_cap_by_ca(
(cert_lifetime > remaining_ca_lifetime).then_some(remaining_ca_lifetime)
}

/// Returns the [SPIFFE ID](https://github.com/spiffe/spiffe/blob/main/standards/SPIFFE-ID.md)
/// of a ServiceAccount, using the same format as Istio:
/// `spiffe://<trust-domain>/ns/<namespace>/sa/<service-account>`.
///
/// The Kubernetes cluster domain is used as trust domain. SPIFFE requires the trust domain to be
/// lowercase and without a trailing dot, which a [`DomainName`] does not guarantee.
///
/// [`DomainName`]: stackable_operator::commons::networking::DomainName
fn spiffe_id(cluster_domain: &str, namespace: &str, service_account: &str) -> String {
let trust_domain = cluster_domain.trim_end_matches('.').to_lowercase();
format!("spiffe://{trust_domain}/ns/{namespace}/sa/{service_account}")
}

#[cfg(test)]
mod tests {
use rstest::rstest;
Expand Down Expand Up @@ -597,4 +618,15 @@ mod tests {
expected_cap
);
}

#[rstest]
#[case::default_cluster_domain("cluster.local")]
#[case::trailing_dot("cluster.local.")]
#[case::uppercase("Cluster.LOCAL")]
fn spiffe_id(#[case] cluster_domain: &str) {
assert_eq!(
super::spiffe_id(cluster_domain, "my-namespace", "my-service-account"),
"spiffe://cluster.local/ns/my-namespace/sa/my-service-account"
);
}
}
7 changes: 7 additions & 0 deletions rust/operator-binary/src/backend/pod_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ pub struct PodInfo {
pub pod_name: String,
pub pod_uid: String,
pub service_name: Option<String>,
/// Can be empty if the ServiceAccount admission plugin is disabled
pub service_account_name: Option<String>,
pub namespace: String,
pub node_name: String,
pub node_ips: Vec<IpAddr>,
Expand Down Expand Up @@ -159,6 +161,11 @@ impl PodInfo {
pod_name,
pod_uid,
service_name: pod.spec.as_ref().and_then(|spec| spec.subdomain.clone()),
service_account_name: pod
.spec
.as_ref()
.and_then(|spec| spec.service_account_name.clone())
.filter(|name| !name.is_empty()),
namespace,
node_name,
node_ips: node
Expand Down
5 changes: 5 additions & 0 deletions tests/templates/kuttl/tls/10_consumer.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ spec:
cat "/stackable/tls-3d/$CERT_NAME" | openssl x509 -noout -text | grep "DNS:my-tls-service.$NAMESPACE.svc.cluster.local"
cat "/stackable/tls-42h/$CERT_NAME" | openssl x509 -noout -text | grep "DNS:my-tls-service.$NAMESPACE.svc.cluster.local"

echo "Test SPIFFE ID of the ServiceAccount in the SAN"

cat "/stackable/tls-3d/$CERT_NAME" | openssl x509 -noout -text | grep "URI:spiffe://cluster.local/ns/$NAMESPACE/sa/integration-tests-sa"
openssl x509 -in /stackable/tls-domain-components/tls.crt -noout -text | grep "URI:spiffe://cluster.local/ns/$NAMESPACE/sa/integration-tests-sa"


function assert_trusted_roots_contain {
subject=$1
Expand Down
Loading