MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / resolve_credentials

Function resolve_credentials

nodedb/src/control/cluster/tls.rs:67–146  ·  view source on GitHub ↗

Resolve [`TransportCredentials`] for this node from operator settings and on-disk state. See module docs for resolution order.

(
    settings: &ClusterSettings,
    data_dir: &Path,
)

Source from the content-addressed store, hash-verified

65/// Resolve [`TransportCredentials`] for this node from operator settings
66/// and on-disk state. See module docs for resolution order.
67pub 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"),

Calls 7

load_from_pathsFunction · 0.85
load_from_data_dirFunction · 0.85
is_bootstrapping_nodeFunction · 0.85
bootstrap_credentialsFunction · 0.85
joinMethod · 0.80
existsMethod · 0.45