2022-11-13 08:10:18 +00:00
|
|
|
import { FeatureId } from '@/react/portainer/feature-flags/enums';
|
2021-11-02 20:57:21 +00:00
|
|
|
|
2021-02-09 08:09:06 +00:00
|
|
|
export default class DockerFeaturesConfigurationController {
|
|
|
|
/* @ngInject */
|
2023-03-03 01:47:10 +00:00
|
|
|
constructor($async, $scope, $state, $analytics, EndpointService, SettingsService, Notifications, StateManager) {
|
2021-02-09 08:09:06 +00:00
|
|
|
this.$async = $async;
|
2021-12-14 19:14:53 +00:00
|
|
|
this.$scope = $scope;
|
2023-03-03 01:47:10 +00:00
|
|
|
this.$state = $state;
|
|
|
|
this.$analytics = $analytics;
|
2021-02-09 08:09:06 +00:00
|
|
|
this.EndpointService = EndpointService;
|
2023-03-03 01:47:10 +00:00
|
|
|
this.SettingsService = SettingsService;
|
2021-02-09 08:09:06 +00:00
|
|
|
this.Notifications = Notifications;
|
|
|
|
this.StateManager = StateManager;
|
|
|
|
|
2023-03-01 21:14:50 +00:00
|
|
|
this.limitedFeatureAutoUpdate = FeatureId.HIDE_AUTO_UPDATE_WINDOW;
|
|
|
|
this.limitedFeatureUpToDateImage = FeatureId.IMAGE_UP_TO_DATE_INDICATOR;
|
2021-11-02 20:57:21 +00:00
|
|
|
|
2021-02-09 08:09:06 +00:00
|
|
|
this.formValues = {
|
|
|
|
enableHostManagementFeatures: false,
|
|
|
|
allowVolumeBrowserForRegularUsers: false,
|
|
|
|
disableBindMountsForRegularUsers: false,
|
|
|
|
disablePrivilegedModeForRegularUsers: false,
|
|
|
|
disableHostNamespaceForRegularUsers: false,
|
|
|
|
disableStackManagementForRegularUsers: false,
|
|
|
|
disableDeviceMappingForRegularUsers: false,
|
|
|
|
disableContainerCapabilitiesForRegularUsers: false,
|
2021-04-12 07:40:45 +00:00
|
|
|
disableSysctlSettingForRegularUsers: false,
|
2021-02-09 08:09:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.isAgent = false;
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
actionInProgress: false,
|
2021-12-14 19:14:53 +00:00
|
|
|
autoUpdateSettings: { Enabled: false },
|
|
|
|
timeZone: '',
|
2021-02-09 08:09:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.save = this.save.bind(this);
|
2021-12-14 19:14:53 +00:00
|
|
|
this.onChangeField = this.onChangeField.bind(this);
|
|
|
|
this.onToggleAutoUpdate = this.onToggleAutoUpdate.bind(this);
|
2023-03-03 01:47:10 +00:00
|
|
|
this.onToggleGPUManagement = this.onToggleGPUManagement.bind(this);
|
|
|
|
this.onGpusChange = this.onGpusChange.bind(this);
|
2021-12-14 19:14:53 +00:00
|
|
|
this.onChangeEnableHostManagementFeatures = this.onChangeField('enableHostManagementFeatures');
|
|
|
|
this.onChangeAllowVolumeBrowserForRegularUsers = this.onChangeField('allowVolumeBrowserForRegularUsers');
|
|
|
|
this.onChangeDisableBindMountsForRegularUsers = this.onChangeField('disableBindMountsForRegularUsers');
|
|
|
|
this.onChangeDisablePrivilegedModeForRegularUsers = this.onChangeField('disablePrivilegedModeForRegularUsers');
|
|
|
|
this.onChangeDisableHostNamespaceForRegularUsers = this.onChangeField('disableHostNamespaceForRegularUsers');
|
|
|
|
this.onChangeDisableStackManagementForRegularUsers = this.onChangeField('disableStackManagementForRegularUsers');
|
|
|
|
this.onChangeDisableDeviceMappingForRegularUsers = this.onChangeField('disableDeviceMappingForRegularUsers');
|
|
|
|
this.onChangeDisableContainerCapabilitiesForRegularUsers = this.onChangeField('disableContainerCapabilitiesForRegularUsers');
|
|
|
|
this.onChangeDisableSysctlSettingForRegularUsers = this.onChangeField('disableSysctlSettingForRegularUsers');
|
|
|
|
}
|
|
|
|
|
|
|
|
onToggleAutoUpdate(value) {
|
|
|
|
return this.$scope.$evalAsync(() => {
|
|
|
|
this.state.autoUpdateSettings.Enabled = value;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-03 01:47:10 +00:00
|
|
|
onToggleGPUManagement(checked) {
|
|
|
|
this.$scope.$evalAsync(() => {
|
|
|
|
this.state.enableGPUManagement = checked;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-14 19:14:53 +00:00
|
|
|
onChange(values) {
|
|
|
|
return this.$scope.$evalAsync(() => {
|
|
|
|
this.formValues = {
|
|
|
|
...this.formValues,
|
|
|
|
...values,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onChangeField(field) {
|
|
|
|
return (value) => {
|
|
|
|
this.onChange({
|
|
|
|
[field]: value,
|
|
|
|
});
|
|
|
|
};
|
2021-02-09 08:09:06 +00:00
|
|
|
}
|
|
|
|
|
2023-03-03 01:47:10 +00:00
|
|
|
onGpusChange(value) {
|
|
|
|
return this.$async(async () => {
|
|
|
|
this.endpoint.Gpus = value;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-09 08:09:06 +00:00
|
|
|
isContainerEditDisabled() {
|
|
|
|
const {
|
|
|
|
disableBindMountsForRegularUsers,
|
|
|
|
disableHostNamespaceForRegularUsers,
|
|
|
|
disablePrivilegedModeForRegularUsers,
|
|
|
|
disableDeviceMappingForRegularUsers,
|
|
|
|
disableContainerCapabilitiesForRegularUsers,
|
2021-04-12 07:40:45 +00:00
|
|
|
disableSysctlSettingForRegularUsers,
|
2021-02-09 08:09:06 +00:00
|
|
|
} = this.formValues;
|
|
|
|
return (
|
|
|
|
disableBindMountsForRegularUsers ||
|
|
|
|
disableHostNamespaceForRegularUsers ||
|
|
|
|
disablePrivilegedModeForRegularUsers ||
|
|
|
|
disableDeviceMappingForRegularUsers ||
|
2021-04-12 07:40:45 +00:00
|
|
|
disableContainerCapabilitiesForRegularUsers ||
|
|
|
|
disableSysctlSettingForRegularUsers
|
2021-02-09 08:09:06 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async save() {
|
|
|
|
return this.$async(async () => {
|
|
|
|
try {
|
|
|
|
this.state.actionInProgress = true;
|
2023-03-03 01:47:10 +00:00
|
|
|
|
|
|
|
const validGpus = this.endpoint.Gpus.filter((gpu) => gpu.name && gpu.value);
|
|
|
|
const gpus = this.state.enableGPUManagement ? validGpus : [];
|
|
|
|
|
|
|
|
const settings = {
|
2021-02-09 08:09:06 +00:00
|
|
|
enableHostManagementFeatures: this.formValues.enableHostManagementFeatures,
|
|
|
|
allowBindMountsForRegularUsers: !this.formValues.disableBindMountsForRegularUsers,
|
|
|
|
allowPrivilegedModeForRegularUsers: !this.formValues.disablePrivilegedModeForRegularUsers,
|
|
|
|
allowVolumeBrowserForRegularUsers: this.formValues.allowVolumeBrowserForRegularUsers,
|
|
|
|
allowHostNamespaceForRegularUsers: !this.formValues.disableHostNamespaceForRegularUsers,
|
|
|
|
allowDeviceMappingForRegularUsers: !this.formValues.disableDeviceMappingForRegularUsers,
|
|
|
|
allowStackManagementForRegularUsers: !this.formValues.disableStackManagementForRegularUsers,
|
|
|
|
allowContainerCapabilitiesForRegularUsers: !this.formValues.disableContainerCapabilitiesForRegularUsers,
|
2021-04-12 07:40:45 +00:00
|
|
|
allowSysctlSettingForRegularUsers: !this.formValues.disableSysctlSettingForRegularUsers,
|
2023-03-03 01:47:10 +00:00
|
|
|
enableGPUManagement: this.state.enableGPUManagement,
|
|
|
|
gpus,
|
2021-02-09 08:09:06 +00:00
|
|
|
};
|
|
|
|
|
2023-03-03 01:47:10 +00:00
|
|
|
const publicSettings = await this.SettingsService.publicSettings();
|
|
|
|
const analyticsAllowed = publicSettings.EnableTelemetry;
|
|
|
|
if (analyticsAllowed) {
|
|
|
|
// send analytics if GPU management is changed (with the new state)
|
|
|
|
if (this.initialEnableGPUManagement !== this.state.enableGPUManagement) {
|
|
|
|
this.$analytics.eventTrack('enable-gpu-management-updated', { category: 'portainer', metadata: { enableGPUManagementState: this.state.enableGPUManagement } });
|
|
|
|
}
|
|
|
|
// send analytics if the number of GPUs is changed (with a list of the names)
|
|
|
|
if (gpus.length > this.initialGPUs.length) {
|
|
|
|
const numberOfGPUSAdded = this.endpoint.Gpus.length - this.initialGPUs.length;
|
|
|
|
this.$analytics.eventTrack('gpus-added', { category: 'portainer', metadata: { gpus: gpus.map((gpu) => gpu.name), numberOfGPUSAdded } });
|
|
|
|
}
|
|
|
|
if (gpus.length < this.initialGPUs.length) {
|
|
|
|
const numberOfGPUSRemoved = this.initialGPUs.length - this.endpoint.Gpus.length;
|
|
|
|
this.$analytics.eventTrack('gpus-removed', { category: 'portainer', metadata: { gpus: gpus.map((gpu) => gpu.name), numberOfGPUSRemoved } });
|
|
|
|
}
|
|
|
|
this.initialGPUs = gpus;
|
|
|
|
this.initialEnableGPUManagement = this.state.enableGPUManagement;
|
|
|
|
}
|
|
|
|
|
|
|
|
await this.EndpointService.updateSecuritySettings(this.endpoint.Id, settings);
|
|
|
|
|
|
|
|
this.endpoint.SecuritySettings = settings;
|
2022-08-10 05:07:35 +00:00
|
|
|
this.Notifications.success('Success', 'Saved settings successfully');
|
2021-02-09 08:09:06 +00:00
|
|
|
} catch (e) {
|
|
|
|
this.Notifications.error('Failure', e, 'Failed saving settings');
|
|
|
|
}
|
|
|
|
this.state.actionInProgress = false;
|
2023-03-03 01:47:10 +00:00
|
|
|
this.$state.reload();
|
2021-02-09 08:09:06 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$onInit() {
|
|
|
|
const securitySettings = this.endpoint.SecuritySettings;
|
|
|
|
|
2023-03-03 01:47:10 +00:00
|
|
|
const applicationState = this.StateManager.getState();
|
|
|
|
this.isAgent = applicationState.endpoint.mode.agentProxy;
|
|
|
|
|
|
|
|
this.isDockerStandaloneEnv = applicationState.endpoint.mode.provider === 'DOCKER_STANDALONE';
|
2021-02-09 08:09:06 +00:00
|
|
|
|
|
|
|
this.formValues = {
|
2023-03-03 01:47:10 +00:00
|
|
|
enableHostManagementFeatures: this.isAgent && securitySettings.enableHostManagementFeatures,
|
|
|
|
allowVolumeBrowserForRegularUsers: this.isAgent && securitySettings.allowVolumeBrowserForRegularUsers,
|
2021-02-09 08:09:06 +00:00
|
|
|
disableBindMountsForRegularUsers: !securitySettings.allowBindMountsForRegularUsers,
|
|
|
|
disablePrivilegedModeForRegularUsers: !securitySettings.allowPrivilegedModeForRegularUsers,
|
|
|
|
disableHostNamespaceForRegularUsers: !securitySettings.allowHostNamespaceForRegularUsers,
|
|
|
|
disableDeviceMappingForRegularUsers: !securitySettings.allowDeviceMappingForRegularUsers,
|
|
|
|
disableStackManagementForRegularUsers: !securitySettings.allowStackManagementForRegularUsers,
|
|
|
|
disableContainerCapabilitiesForRegularUsers: !securitySettings.allowContainerCapabilitiesForRegularUsers,
|
2021-04-12 07:40:45 +00:00
|
|
|
disableSysctlSettingForRegularUsers: !securitySettings.allowSysctlSettingForRegularUsers,
|
2021-02-09 08:09:06 +00:00
|
|
|
};
|
2023-03-03 01:47:10 +00:00
|
|
|
|
2023-03-21 03:06:01 +00:00
|
|
|
// this.endpoint.Gpus could be null as it is Gpus: []Pair in the API
|
|
|
|
this.endpoint.Gpus = this.endpoint.Gpus || [];
|
2023-03-03 01:47:10 +00:00
|
|
|
this.state.enableGPUManagement = this.isDockerStandaloneEnv && (this.endpoint.EnableGPUManagement || this.endpoint.Gpus.length > 0);
|
|
|
|
this.initialGPUs = this.endpoint.Gpus;
|
|
|
|
this.initialEnableGPUManagement = this.endpoint.EnableGPUManagement;
|
2021-02-09 08:09:06 +00:00
|
|
|
}
|
|
|
|
}
|