Skip to content
Merged
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
9 changes: 8 additions & 1 deletion proxy_agent/src/key_keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl KeyKeeper {
}

// check and update the redirect policy if not updated successfully before, try again here
// this could happen when the eBPF/redirector module was not started yet before
// this could happen when the eBPF/redirector or proxy_server module was not started yet before
if !redirect_policy_updated {
logger::write_warning(
"redirect policy was not update successfully before, retrying now".to_string(),
Expand Down Expand Up @@ -850,6 +850,13 @@ impl KeyKeeper {
/// update the redirector/eBPF policy based on the secure channel status
/// it should be called when the secure channel state is changed
async fn update_redirector_policy(&self, status: &KeyStatus) -> bool {
if !provision::is_proxy_server_provisioned(&self.provision_shared_state).await {
logger::write_warning(
"Proxy server is not provisioned, skipping redirector policy update.".to_string(),
);
return false;
}

// update the redirector policy map
if !redirector::update_wire_server_redirect_policy(
status.get_wire_server_mode() != DISABLE_STATE,
Expand Down
17 changes: 17 additions & 0 deletions proxy_agent/src/provision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ pub async fn listener_started(event_threads_shared_state: EventThreadsSharedStat
.await;
}

/// Check if the proxy server is provisioned
/// It checks if the listener module is ready, which indicates that the proxy server is provisioned.
/// Returns true if the proxy server is provisioned, false otherwise.
pub async fn is_proxy_server_provisioned(provision_shared_state: &ProvisionSharedState) -> bool {
if let Ok(provisioned) = provision_shared_state.get_state().await {
provisioned.contains(ProvisionFlags::LISTENER_READY)
} else {
false
}
}

/// Update provision state for each module to shared_state
async fn update_provision_state(
state: ProvisionFlags,
Expand Down Expand Up @@ -945,6 +956,12 @@ mod tests {
event_threads_shared_state.clone(),
)
.await;
assert_eq!(
true,
super::is_proxy_server_provisioned(&provision_shared_state).await,
"Proxy server must be provisioned after listener is ready"
);

super::update_provision_state(
ProvisionFlags::KEY_LATCH_READY,
Some(temp_test_path.clone()),
Expand Down
Loading