Resolve [`TransportCredentials`] for this node from operator settings and on-disk state. See module docs for resolution order.
(
settings: &ClusterSettings,
data_dir: &Path,
)
| 65 | /// Resolve [`TransportCredentials`] for this node from operator settings |
| 66 | /// and on-disk state. See module docs for resolution order. |
| 67 | pub fn resolve_credentials( |
| 68 | settings: &ClusterSettings, |
| 69 | data_dir: &Path, |
| 70 | ) -> crate::Result<TransportCredentials> { |
| 71 | if settings.insecure_transport { |
| 72 | warn!( |
| 73 | node_id = settings.node_id, |
| 74 | "cluster.insecure_transport = true — channel authentication DISABLED. \ |
| 75 | This is safe only on fully isolated private networks." |
| 76 | ); |
| 77 | return Ok(TransportCredentials::Insecure); |
| 78 | } |
| 79 | |
| 80 | let tls_dir = data_dir.join(TLS_SUBDIR); |
| 81 | |
| 82 | if let Some(paths) = &settings.tls { |
| 83 | let creds = load_from_paths(paths, &tls_dir)?; |
| 84 | info!( |
| 85 | node_id = settings.node_id, |
| 86 | cert = %paths.cert.display(), |
| 87 | "cluster TLS credentials loaded from operator-provided paths" |
| 88 | ); |
| 89 | return Ok(TransportCredentials::Mtls(creds)); |
| 90 | } |
| 91 | |
| 92 | if tls_dir.join(NODE_CERT_FILE).exists() |
| 93 | && tls_dir.join(NODE_KEY_FILE).exists() |
| 94 | && tls_dir.join(CA_CERT_FILE).exists() |
| 95 | && tls_dir.join(CLUSTER_SECRET_FILE).exists() |
| 96 | { |
| 97 | let creds = load_from_data_dir(&tls_dir)?; |
| 98 | info!( |
| 99 | node_id = settings.node_id, |
| 100 | dir = %tls_dir.display(), |
| 101 | "cluster TLS credentials loaded from data dir" |
| 102 | ); |
| 103 | return Ok(TransportCredentials::Mtls(creds)); |
| 104 | } |
| 105 | |
| 106 | if is_bootstrapping_node(settings) { |
| 107 | let creds = bootstrap_credentials(settings, &tls_dir)?; |
| 108 | info!( |
| 109 | node_id = settings.node_id, |
| 110 | dir = %tls_dir.display(), |
| 111 | "bootstrapped new cluster CA + node credentials" |
| 112 | ); |
| 113 | return Ok(TransportCredentials::Mtls(creds)); |
| 114 | } |
| 115 | |
| 116 | // L.4: token-authenticated cred delivery. When the operator |
| 117 | // exports `NODEDB_JOIN_TOKEN=<hex>` and `NODEDB_JOIN_SEED=<addr>`, |
| 118 | // reach out to the seed's bootstrap listener, fetch the cred |
| 119 | // bundle, write it to `tls/`, and fall through to the normal |
| 120 | // `load_from_data_dir` path on the next pass. The env-driven |
| 121 | // spelling keeps joiners' config files identical to bootstrappers' |
| 122 | // — only the startup environment differs. |
| 123 | if let (Ok(token), Ok(seed_str)) = ( |
| 124 | std::env::var("NODEDB_JOIN_TOKEN"), |