Skip to content

Commit a6fa3ea

Browse files
wojcik91moubctez
andauthored
Add support for license tiers (#1746)
* add tier field to license metadata * add tier to internal license representation & handle conversion from proto * change naming convention * rename feature gate helper * change naming again * add license tier validation * add tests * add license tier tests * remove unused import * fix comment * pass license tier info to UI * update inputs * disable service location mode in network form * rename helper function * update location wizard * update license tests * Update crates/defguard_core/src/enterprise/license.rs Co-authored-by: Adam <adam@defguard.net> * fix comparison --------- Co-authored-by: Adam <adam@defguard.net>
1 parent 1441bde commit a6fa3ea

30 files changed

Lines changed: 400 additions & 123 deletions

File tree

crates/defguard_core/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
99
&["src/enterprise/proto/license.proto"],
1010
&["src/enterprise/proto"],
1111
)?;
12-
println!("cargo:rerun-if-changed=src/enterprise");
12+
println!("cargo:rerun-if-changed=src/enterprise/proto");
1313
Ok(())
1414
}

crates/defguard_core/src/auth/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{
1818
Group, OAuth2Token, Session, SessionState, User,
1919
models::{group::Permission, oauth2client::OAuth2Client},
2020
},
21-
enterprise::{db::models::api_tokens::ApiToken, is_enterprise_enabled},
21+
enterprise::{db::models::api_tokens::ApiToken, is_business_license_active},
2222
error::WebError,
2323
handlers::SESSION_COOKIE_NAME,
2424
};
@@ -38,7 +38,7 @@ where
3838
let appstate = AppState::from_ref(state);
3939

4040
// first try to authenticate by API token if one is found in header
41-
if is_enterprise_enabled() {
41+
if is_business_license_active() {
4242
let maybe_auth_header: Option<TypedHeader<Authorization<Bearer>>> =
4343
<TypedHeader<_> as OptionalFromRequestParts<S>>::from_request_parts(parts, state)
4444
.await

crates/defguard_core/src/db/models/wireguard.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use super::{
4040
wireguard_peer_stats::WireguardPeerStats,
4141
};
4242
use crate::{
43-
enterprise::{firewall::FirewallError, is_enterprise_enabled},
43+
enterprise::{firewall::FirewallError, is_enterprise_license_active},
4444
grpc::gateway::{send_multiple_wireguard_events, state::GatewayState},
4545
wg_config::ImportedDevice,
4646
};
@@ -1335,7 +1335,8 @@ impl WireguardNetwork<Id> {
13351335
/// - Enterprise is enabled
13361336
#[must_use]
13371337
pub fn should_prevent_service_location_usage(&self) -> bool {
1338-
self.service_location_mode != ServiceLocationMode::Disabled && !is_enterprise_enabled()
1338+
self.service_location_mode != ServiceLocationMode::Disabled
1339+
&& !is_enterprise_license_active()
13391340
}
13401341
}
13411342

crates/defguard_core/src/enterprise/activity_log_stream/activity_log_stream_manager.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use super::ActivityLogStreamReconfigurationNotification;
1010
use crate::enterprise::{
1111
activity_log_stream::http_stream::{HttpActivityLogStreamConfig, run_http_stream_task},
1212
db::models::activity_log_stream::{ActivityLogStream, ActivityLogStreamConfig},
13-
is_enterprise_enabled,
13+
is_business_license_active,
1414
};
1515

1616
// check if enterprise features are enabled every minute
@@ -27,7 +27,7 @@ pub async fn run_activity_log_stream_manager(
2727
let mut enterprise_check_timer = interval(Duration::from_secs(ENTERPRISE_CHECK_PERIOD_SECS));
2828

2929
// initialize enterprise features status
30-
let mut enterprise_features_enabled = is_enterprise_enabled();
30+
let mut enterprise_features_enabled = is_business_license_active();
3131

3232
loop {
3333
let mut handles = JoinSet::<()>::new();
@@ -94,7 +94,7 @@ pub async fn run_activity_log_stream_manager(
9494
}
9595
_ = enterprise_check_timer.tick() => {
9696
// check if enterprise features status has changed
97-
let current_enterprise_features_enabled = is_enterprise_enabled();
97+
let current_enterprise_features_enabled = is_business_license_active();
9898
if current_enterprise_features_enabled != enterprise_features_enabled {
9999
warn!("Activity log stream manager will reload, detected license enterprise features status has changed");
100100
enterprise_features_enabled = current_enterprise_features_enabled;

crates/defguard_core/src/enterprise/db/models/enterprise_settings.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use sqlx::{PgExecutor, Type, query, query_as};
22
use struct_patch::Patch;
33

4-
use crate::enterprise::is_enterprise_enabled;
4+
use crate::enterprise::is_business_license_active;
55

66
#[derive(Debug, Deserialize, Patch, Serialize)]
77
#[patch(attribute(derive(Deserialize, Serialize)))]
@@ -35,7 +35,7 @@ impl EnterpriseSettings {
3535
{
3636
// avoid holding the rwlock across await, makes the future !Send
3737
// and therefore unusable in axum handlers
38-
if is_enterprise_enabled() {
38+
if is_business_license_active() {
3939
let settings = query_as!(
4040
Self,
4141
"SELECT admin_device_management, \

crates/defguard_core/src/enterprise/directory_sync/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ use sqlx::{PgConnection, PgPool, error::Error as SqlxError};
1111
use thiserror::Error;
1212
use tokio::sync::broadcast::Sender;
1313

14-
#[cfg(not(test))]
15-
use super::is_enterprise_enabled;
1614
use super::{
1715
db::models::openid_provider::{DirectorySyncTarget, OpenIdProvider},
1816
ldap::utils::ldap_update_users_state,
1917
};
18+
#[cfg(not(test))]
19+
use crate::enterprise::is_business_license_active;
2020
use crate::{
2121
db::{GatewayEvent, Group, User},
2222
enterprise::{
@@ -383,7 +383,7 @@ pub(crate) async fn test_directory_sync_connection(
383383
pool: &PgPool,
384384
) -> Result<(), DirectorySyncError> {
385385
#[cfg(not(test))]
386-
if !is_enterprise_enabled() {
386+
if !is_business_license_active() {
387387
debug!("Enterprise is not enabled, skipping testing directory sync connection");
388388
return Ok(());
389389
}
@@ -408,7 +408,7 @@ pub(crate) async fn sync_user_groups_if_configured(
408408
wg_tx: &Sender<GatewayEvent>,
409409
) -> Result<(), DirectorySyncError> {
410410
#[cfg(not(test))]
411-
if !is_enterprise_enabled() {
411+
if !is_business_license_active() {
412412
debug!("Enterprise is not enabled, skipping syncing user groups");
413413
return Ok(());
414414
}
@@ -966,7 +966,7 @@ pub(crate) async fn do_directory_sync(
966966
wireguard_tx: &Sender<GatewayEvent>,
967967
) -> Result<(), DirectorySyncError> {
968968
#[cfg(not(test))]
969-
if !is_enterprise_enabled() {
969+
if !is_business_license_active() {
970970
debug!("Enterprise is not enabled, skipping performing directory sync");
971971
return Ok(());
972972
}

crates/defguard_core/src/enterprise/firewall/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::{
2323
db::{Device, User, WireguardNetwork},
2424
enterprise::{
2525
db::models::{acl::AliasKind, snat::UserSnatBinding},
26-
is_enterprise_enabled,
26+
is_business_license_active,
2727
},
2828
};
2929

@@ -903,7 +903,7 @@ impl WireguardNetwork<Id> {
903903
conn: &mut PgConnection,
904904
) -> Result<Option<FirewallConfig>, FirewallError> {
905905
// do a license check
906-
if !is_enterprise_enabled() {
906+
if !is_business_license_active() {
907907
debug!(
908908
"Enterprise features are disabled, skipping generating firewall config for \
909909
location {self}"

crates/defguard_core/src/enterprise/grpc/desktop_client_mfa.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use tonic::Status;
66
use crate::{
77
enterprise::{
88
handlers::openid_login::{extract_state_data, user_from_claims},
9-
is_enterprise_enabled,
9+
is_business_license_active,
1010
},
1111
events::{BidiRequestContext, BidiStreamEvent, BidiStreamEventType, DesktopClientMfaEvent},
1212
grpc::{
@@ -23,7 +23,7 @@ impl ClientMfaServer {
2323
info: Option<DeviceInfo>,
2424
) -> Result<(), Status> {
2525
debug!("Received OIDC MFA authentication request: {request:?}");
26-
if !is_enterprise_enabled() {
26+
if !is_business_license_active() {
2727
error!("OIDC MFA method requires enterprise feature to be enabled");
2828
return Err(Status::invalid_argument("OIDC MFA method is not supported"));
2929
}

crates/defguard_core/src/enterprise/grpc/polling.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use tonic::Status;
55

66
use crate::{
77
db::{Device, User, models::polling_token::PollingToken},
8-
enterprise::is_enterprise_enabled,
8+
enterprise::is_business_license_active,
99
grpc::utils::build_device_config_response,
1010
};
1111

@@ -24,7 +24,7 @@ impl PollingServer {
2424
debug!("Validating polling token. Token: {token}");
2525

2626
// Polling service is enterprise-only, check the lincense
27-
if !is_enterprise_enabled() {
27+
if !is_business_license_active() {
2828
debug!("Instance has enterprise features disabled, denying instance polling info");
2929
return Err(Status::failed_precondition("no valid license"));
3030
}

crates/defguard_core/src/enterprise/handlers/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use axum::{
1717
};
1818

1919
use super::{
20-
db::models::enterprise_settings::EnterpriseSettings, is_enterprise_enabled,
20+
db::models::enterprise_settings::EnterpriseSettings, is_business_license_active,
2121
license::get_cached_license,
2222
};
2323
use crate::{appstate::AppState, error::WebError};
@@ -37,7 +37,7 @@ where
3737
type Rejection = WebError;
3838

3939
async fn from_request_parts(_parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
40-
if is_enterprise_enabled() {
40+
if is_business_license_active() {
4141
Ok(LicenseInfo { valid: true })
4242
} else {
4343
Err(WebError::Forbidden(

0 commit comments

Comments
 (0)