Skip to content

Commit 1c11888

Browse files
authored
fix(query): check enterprise license embedded (#18202)
* fix(query): check enterprise license embedded * fix: return if env changed * z * z
1 parent 8fe3e5c commit 1c11888

File tree

10 files changed

+37
-43
lines changed

10 files changed

+37
-43
lines changed

.github/workflows/reuse.linux.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,70 +124,70 @@ jobs:
124124
timeout-minutes: 60
125125

126126
test_metactl:
127+
needs: [build, check]
127128
runs-on:
128129
- self-hosted
129130
- X64
130131
- Linux
131132
- 2c8g
132133
- "${{ inputs.runner_provider }}"
133134
- "${{ inputs.runner_capacity }}"
134-
needs: [build, check]
135135
steps:
136136
- uses: actions/checkout@v4
137137
- uses: ./.github/actions/test_metactl
138138
timeout-minutes: 10
139139

140140
test_compat_meta_query:
141+
needs: [build, check]
141142
runs-on:
142143
- self-hosted
143144
- X64
144145
- Linux
145146
- 2c8g
146147
- "${{ inputs.runner_provider }}"
147148
- "${{ inputs.runner_capacity }}"
148-
needs: [build, check]
149149
steps:
150150
- uses: actions/checkout@v4
151151
- uses: ./.github/actions/test_compat_meta_query
152152
timeout-minutes: 10
153153

154154
test_compat_fuse:
155+
needs: [build, check]
155156
runs-on:
156157
- self-hosted
157158
- X64
158159
- Linux
159160
- 2c8g
160161
- "${{ inputs.runner_provider }}"
161162
- "${{ inputs.runner_capacity }}"
162-
needs: [build, check]
163163
steps:
164164
- uses: actions/checkout@v4
165165
- uses: ./.github/actions/test_compat_fuse
166166
timeout-minutes: 20
167167

168168
test_compat_meta_meta:
169+
needs: [build, check]
169170
runs-on:
170171
- self-hosted
171172
- X64
172173
- Linux
173174
- 2c8g
174175
- "${{ inputs.runner_provider }}"
175176
- "${{ inputs.runner_capacity }}"
176-
needs: [build, check]
177177
steps:
178178
- uses: actions/checkout@v4
179179
- uses: ./.github/actions/test_compat_meta_meta
180180
timeout-minutes: 20
181181

182182
test_logs:
183+
needs: [build, check]
183184
runs-on:
184185
- self-hosted
185186
- X64
186187
- Linux
187188
- 2c8g
188189
- "${{ inputs.runner_provider }}"
189190
- "${{ inputs.runner_capacity }}"
190-
needs: [build, check]
191191
steps:
192192
- uses: actions/checkout@v4
193193
- uses: ./.github/actions/setup_license
@@ -198,42 +198,42 @@ jobs:
198198
timeout-minutes: 20
199199

200200
test_meta_cluster:
201+
needs: [build, check]
201202
runs-on:
202203
- self-hosted
203204
- X64
204205
- Linux
205206
- 2c8g
206207
- "${{ inputs.runner_provider }}"
207208
- "${{ inputs.runner_capacity }}"
208-
needs: [build, check]
209209
steps:
210210
- uses: actions/checkout@v4
211211
- uses: ./.github/actions/test_meta_cluster
212212
timeout-minutes: 10
213213

214214
test_stateless_standalone:
215+
needs: [build, check]
215216
runs-on:
216217
- self-hosted
217218
- X64
218219
- Linux
219220
- 2c8g
220221
- "${{ inputs.runner_provider }}"
221222
- "${{ inputs.runner_capacity }}"
222-
needs: [build, check]
223223
steps:
224224
- uses: actions/checkout@v4
225225
- uses: ./.github/actions/test_stateless_standalone_linux
226226
timeout-minutes: 18
227227

228228
test_stateless_cluster:
229+
needs: [build, check]
229230
runs-on:
230231
- self-hosted
231232
- X64
232233
- Linux
233234
- 2c8g
234235
- "${{ inputs.runner_provider }}"
235236
- "${{ inputs.runner_capacity }}"
236-
needs: [build, check]
237237
steps:
238238
- uses: actions/checkout@v4
239239
- uses: ./.github/actions/setup_license
@@ -244,13 +244,14 @@ jobs:
244244
timeout-minutes: 18
245245

246246
test_stateful_standalone:
247+
needs: [build, check]
247248
runs-on:
248249
- self-hosted
249250
- X64
250251
- Linux
251252
- 2c8g
252253
- "${{ inputs.runner_provider }}"
253-
needs: [build, check]
254+
- "${{ inputs.runner_capacity }}"
254255
steps:
255256
- uses: actions/checkout@v4
256257
- uses: ./.github/actions/test_stateful_standalone_linux
@@ -262,14 +263,14 @@ jobs:
262263
name: test-stateful-standalone-linux
263264

264265
test_stateful_cluster:
266+
needs: [build, check]
265267
runs-on:
266268
- self-hosted
267269
- X64
268270
- Linux
269271
- 2c8g
270272
- "${{ inputs.runner_provider }}"
271273
- "${{ inputs.runner_capacity }}"
272-
needs: [build, check]
273274
steps:
274275
- uses: actions/checkout@v4
275276
- uses: ./.github/actions/setup_license
@@ -286,28 +287,28 @@ jobs:
286287

287288
test_stateful_large_data:
288289
if: contains(github.event.pull_request.labels.*.name, 'ci-largedata')
290+
needs: [build, check]
289291
runs-on:
290292
- self-hosted
291293
- X64
292294
- Linux
293295
- 2c8g
294296
- "${{ inputs.runner_provider }}"
295297
- "${{ inputs.runner_capacity }}"
296-
needs: [build, check]
297298
steps:
298299
- uses: actions/checkout@v4
299300
- uses: ./.github/actions/test_stateful_large_data
300301
timeout-minutes: 60
301302

302303
test_stateful_iceberg_catalogs:
304+
needs: [build, check]
303305
runs-on:
304306
- self-hosted
305307
- X64
306308
- Linux
307309
- 2c8g
308310
- "${{ inputs.runner_provider }}"
309311
- "${{ inputs.runner_capacity }}"
310-
needs: [build, check]
311312
steps:
312313
- uses: actions/checkout@v4
313314
- uses: ./.github/actions/test_stateful_iceberg_catalogs_standalone

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bendsave/src/storage.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,8 @@ pub async fn verify_query_license(cfg: &InnerConfig) -> Result<()> {
119119
let session = session_manager.register_session(session)?;
120120
let settings = session.get_settings();
121121

122-
LicenseManagerSwitch::instance().check_enterprise_enabled(
123-
unsafe { settings.get_enterprise_license().unwrap_or_default() },
124-
Feature::SystemManagement,
125-
)?;
122+
LicenseManagerSwitch::instance()
123+
.check_enterprise_enabled(settings.get_enterprise_license(), Feature::SystemManagement)?;
126124

127125
debug!("databend license check passed");
128126
Ok(())

src/common/building/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub fn set_env_config() {
7373
}
7474

7575
pub fn add_env_version() {
76+
println!("cargo:rerun-if-env-changed=DATABEND_RELEASE_VERSION");
7677
let version = discover_version().expect(VERSION_ERROR_MESSAGE);
7778
println!("cargo:rustc-env=DATABEND_GIT_SEMVER={}", version);
7879
}
@@ -90,11 +91,13 @@ fn discover_version() -> Result<String> {
9091
}
9192

9293
pub fn add_env_license() {
94+
println!("cargo:rerun-if-env-changed=DATABEND_ENTERPRISE_LICENSE_EMBEDDED");
9395
let v = env::var("DATABEND_ENTERPRISE_LICENSE_EMBEDDED").unwrap_or_default();
9496
println!("cargo:rustc-env=DATABEND_ENTERPRISE_LICENSE_EMBEDDED={v}");
9597
}
9698

9799
pub fn add_license_public_key() {
100+
println!("cargo:rerun-if-env-changed=DATABEND_ENTERPRISE_LICENSE_PUBLIC_KEY");
98101
let v = env::var("DATABEND_ENTERPRISE_LICENSE_PUBLIC_KEY").unwrap_or_default();
99102
let v = base64::Engine::encode(&base64::engine::general_purpose::STANDARD, v.as_bytes());
100103
println!("cargo:rustc-env=DATABEND_ENTERPRISE_LICENSE_PUBLIC_KEY={v}");

src/query/ee/src/storage_encryption/handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl StorageEncryptionHandler for RealStorageEncryptionHandler {
4141

4242
// check for valid license
4343
LicenseManagerSwitch::instance().check_enterprise_enabled(
44-
unsafe { settings.get_enterprise_license().unwrap_or_default() },
44+
settings.get_enterprise_license(),
4545
Feature::StorageEncryption,
4646
)
4747
}

src/query/ee/src/storage_quota/handler.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ impl StorageQuotaHandler for RealStorageQuotaHandler {
3939

4040
let settings = session.get_settings();
4141
// check for valid license
42-
LicenseManagerSwitch::instance()
43-
.get_storage_quota(unsafe { settings.get_enterprise_license().unwrap_or_default() })
42+
LicenseManagerSwitch::instance().get_storage_quota(settings.get_enterprise_license())
4443
}
4544
}
4645

src/query/service/src/sessions/query_ctx.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ use databend_common_storages_stream::stream_table::StreamTable;
121121
use databend_common_users::GrantObjectVisibilityChecker;
122122
use databend_common_users::UserApiProvider;
123123
use databend_common_version::DATABEND_COMMIT_VERSION;
124-
use databend_common_version::DATABEND_ENTERPRISE_LICENSE_EMBEDDED;
125124
use databend_storages_common_session::drop_table_by_id;
126125
use databend_storages_common_session::SessionState;
127126
use databend_storages_common_session::TxnManagerRef;
@@ -1177,11 +1176,7 @@ impl TableContext for QueryContext {
11771176
&& ThreadTracker::capture_log_settings().is_none()
11781177
{
11791178
LicenseManagerSwitch::instance().check_enterprise_enabled(
1180-
unsafe {
1181-
self.get_settings()
1182-
.get_enterprise_license()
1183-
.unwrap_or_default()
1184-
},
1179+
self.get_settings().get_enterprise_license(),
11851180
Feature::SystemHistory,
11861181
)?;
11871182
}
@@ -1411,10 +1406,7 @@ impl TableContext for QueryContext {
14111406
}
14121407

14131408
fn get_license_key(&self) -> String {
1414-
unsafe { self.get_settings().get_enterprise_license() }.unwrap_or_else(|_| {
1415-
// Try load license from embedded env if failed to load from settings.
1416-
DATABEND_ENTERPRISE_LICENSE_EMBEDDED.to_string()
1417-
})
1409+
self.get_settings().get_enterprise_license()
14181410
}
14191411

14201412
fn get_query_profiles(&self) -> Vec<PlanProfile> {

src/query/service/src/table_functions/others/license_info.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,7 @@ impl AsyncSource for LicenseInfoSource {
194194
let settings = self.ctx.get_settings();
195195
// sync global changes on distributed node cluster.
196196
settings.load_changes().await?;
197-
let license = unsafe {
198-
settings.get_enterprise_license().map_err_to_code(
199-
ErrorCode::LicenseKeyInvalid,
200-
|| {
201-
format!(
202-
"failed to get license for {}",
203-
self.ctx.get_tenant().display()
204-
)
205-
},
206-
)?
207-
};
197+
let license = settings.get_enterprise_license();
208198

209199
LicenseManagerSwitch::instance()
210200
.check_enterprise_enabled(license.clone(), Feature::LicenseInfo)?;

src/query/settings/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ databend-common-exception = { workspace = true }
1616
databend-common-io = { workspace = true }
1717
databend-common-meta-app = { workspace = true }
1818
databend-common-users = { workspace = true }
19+
databend-common-version = { workspace = true }
1920
itertools = { workspace = true }
2021
log = { workspace = true }
2122
num_cpus = { workspace = true }

src/query/settings/src/settings_getter_setter.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use databend_common_exception::ErrorCode;
1919
use databend_common_exception::Result;
2020
use databend_common_io::GeometryDataType;
2121
use databend_common_meta_app::principal::UserSettingValue;
22+
use databend_common_version::DATABEND_ENTERPRISE_LICENSE_EMBEDDED;
2223

2324
use crate::settings::Settings;
2425
use crate::settings_default::DefaultSettings;
@@ -559,9 +560,17 @@ impl Settings {
559560
self.try_get_u64("acquire_lock_timeout")
560561
}
561562

562-
/// # Safety
563-
pub unsafe fn get_enterprise_license(&self) -> Result<String> {
564-
self.unchecked_try_get_string("enterprise_license")
563+
pub fn get_enterprise_license(&self) -> String {
564+
let license = unsafe {
565+
self.unchecked_try_get_string("enterprise_license")
566+
.unwrap_or_default()
567+
};
568+
if license.is_empty() {
569+
// Try load license from embedded env if failed to load from settings.
570+
DATABEND_ENTERPRISE_LICENSE_EMBEDDED.to_string()
571+
} else {
572+
license
573+
}
565574
}
566575

567576
/// # Safety

0 commit comments

Comments
 (0)