From 39d7ef3de4b0345274b4b8e8f6918e3b714879ad Mon Sep 17 00:00:00 2001 From: Pavel Vomacka Date: Wed, 5 Oct 2016 12:06:27 +0200 Subject: [PATCH] WebUI: add vault management Add vault management into WebUI, there are some constraints: - There is no crypto library so Symmetric and Assymetric vaults are not supported in WebUI. Also retrieving or archiving data is not supported. - There aren't any container support right now Supported is: - Browsing vaults - Adding Standard vaults (users, service, shared) - Removing vaults - Adding and removing owners - Adding and removing members https://fedorahosted.org/freeipa/ticket/5426 Reviewed-By: Martin Basti Reviewed-By: Petr Vobornik --- install/ui/src/freeipa/app.js | 3 +- install/ui/src/freeipa/ipa.js | 12 + .../ui/src/freeipa/navigation/menu_spec.js | 53 +- install/ui/src/freeipa/vault.js | 819 ++++++++++++++++++ install/ui/test/data/ipa_init.json | 25 + ipaserver/plugins/internal.py | 38 + 6 files changed, 948 insertions(+), 2 deletions(-) create mode 100644 install/ui/src/freeipa/vault.js diff --git a/install/ui/src/freeipa/app.js b/install/ui/src/freeipa/app.js index 5e70dbae3..093737b8f 100644 --- a/install/ui/src/freeipa/app.js +++ b/install/ui/src/freeipa/app.js @@ -51,11 +51,12 @@ define([ './selinux', './serverconfig', './service', + './stageuser', './sudo', './trust', './topology', './user', - './stageuser', + './vault', 'dojo/domReady!' ],function(app_container) { return app_container; diff --git a/install/ui/src/freeipa/ipa.js b/install/ui/src/freeipa/ipa.js index 46b033a00..0ddbd0744 100644 --- a/install/ui/src/freeipa/ipa.js +++ b/install/ui/src/freeipa/ipa.js @@ -240,6 +240,18 @@ var IPA = function () { } })); + batch.add_command(rpc.command({ + entity: 'vaultconfig', + method: 'show', + retry: false, + on_success: function(data, text_status, xhr) { + that.vault_enabled = true; + }, + on_error: function(xhr, text_status, error_thrown) { + that.vault_enabled = false; + } + })); + batch.execute(); }; diff --git a/install/ui/src/freeipa/navigation/menu_spec.js b/install/ui/src/freeipa/navigation/menu_spec.js index 8d13da106..4f78e4bf9 100644 --- a/install/ui/src/freeipa/navigation/menu_spec.js +++ b/install/ui/src/freeipa/navigation/menu_spec.js @@ -215,6 +215,32 @@ var nav = {}; { entity: 'dnsserver' }, { entity: 'dnsconfig' } ] + }, + { + name: 'vault', + entity: 'vault', + facet: 'search', + children: [ + { + entity: 'vault', + facet: 'user_search', + hidden: true + }, + { + entity: 'vault', + facet: 'service_search', + hidden: true + }, + { + entity: 'vault', + facet: 'shared_search', + hidden: true + }, + { + entity: 'vaultconfig', + hidden: true + } + ] } ] }, @@ -298,7 +324,32 @@ nav.self_service = { name: 'self-service', items: [ { entity: 'user' }, - { entity: 'otptoken' } + { entity: 'otptoken' }, + { + entity: 'vault', + facet: 'search', + children: [ + { + entity: 'vault', + facet: 'user_search', + hidden: true + }, + { + entity: 'vault', + facet: 'service_search', + hidden: true + }, + { + entity: 'vault', + facet: 'shared_search', + hidden: true + }, + { + entity: 'vaultconfig', + hidden: true + } + ] + } ] }; diff --git a/install/ui/src/freeipa/vault.js b/install/ui/src/freeipa/vault.js new file mode 100644 index 000000000..b764bfbe3 --- /dev/null +++ b/install/ui/src/freeipa/vault.js @@ -0,0 +1,819 @@ +// +// Copyright (C) 2017 FreeIPA Contributors see COPYING for license +// + +define([ + 'dojo/on', + './ipa', + './jquery', + './phases', + './menu', + './rpc', + './reg', + './text', + './widget'], + function(on, IPA, $, phases, menu, rpc, reg, text, widget) { + +/** + * Vault module + * @class vault + * @alternateClassName IPA.vault + * @singleton + */ +var vault = IPA.vault = { + + search_facet_group: { + name: 'vaults', + facets: { + vault_search: 'vault_search', + user_search: 'vault_user_search', + service_search: 'vault_service_search', + shared_search: 'vault_shared_search', + vaultconfig_details: 'vaultconfig_details' + } + } +}; + + +/** + * Create general specification of "* Vaults" details facets. + */ +var make_vaults_details_page_spec = function() { + return { + $type: 'details', + $factory: vault.custom_details_facet, + update_command_name: 'mod_internal', + disable_facet_tabs: true, + sections: [ + { + name: 'global_info', + layout_ccs_class: 'col-sm-12', + fields: [ + 'cn', + 'description', + { + name: 'ipavaulttype', + read_only: true + }, + { + $type: 'text', + name: 'ipavaultsalt', + visible: false + }, + { + $type: 'pub_key', + name: 'ipavaultpublickey', + visible: false + } + ] + }, + { + $factory: IPA.section, + name: 'divider', + layout_css_class: 'col-sm-12', + fields: [] + }, + { + $factory: IPA.section, + name: 'members', + label: '@i18n:objects.vault.members', + fields: [ + { + $type: 'association_table', + id: 'member_user_cn', + name: 'member_user', + acl_param: 'member', + columns: [ + { + name: 'member_user', + label: '@i18n:objects.vault.user' + } + ] + }, + { + $type: 'association_table', + id: 'member_group_cn', + name: 'member_group', + other_entity: 'group', + acl_param: 'member', + columns: [ + { + name: 'member_group', + label: '@i18n:objects.vault.group' + } + ] + }, + { + $type: 'association_table', + id: 'member_service_cn', + name: 'member_service', + other_entity: 'service', + other_option_name: 'services', + acl_param: 'member', + columns: [ + { + name: 'member_service', + label: '@i18n:objects.vault.service' + } + ] + } + ] + }, + { + $factory: IPA.section, + name: 'owners', + label: '@i18n:objects.vault.owners', + fields: [ + { + $type: 'association_table', + id: 'owner_user_cn', + name: 'owner_user', + add_method: 'add_owner', + remove_method: 'remove_owner', + other_entity: 'user', + acl_param: 'owner', + columns: [ + { + name: 'owner_user', + label: '@i18n:objects.vault.user' + } + ] + }, + { + $type: 'association_table', + id: 'owner_group_cn', + name: 'owner_group', + add_method: 'add_owner', + remove_method: 'remove_owner', + other_entity: 'group', + acl_param: 'owner', + columns: [ + { + name: 'owner_group', + label: '@i18n:objects.vault.group' + } + ] + }, + { + $type: 'association_table', + id: 'owner_service_cn', + name: 'owner_service', + add_method: 'add_owner', + remove_method: 'remove_owner', + other_entity: 'service', + other_option_name: 'services', + acl_param: 'owner', + columns: [ + { + name: 'owner_service', + label: '@i18n:objects.vault.service' + } + ] + } + ] + } + ] + }; +}; + + +/** + * Create entity spec for whole vaults and also spec for search facet, adder + * and deleter dialog. + */ +var make_my_vault_spec = function() { + var entity = { + name: 'vault', + facets: [ + { + $type: 'search', + tab_label: '@i18n:objects.vault.my_vaults_title', + facet_groups: [vault.search_facet_group], + facet_group: 'vaults', + disable_facet_tabs: false, + search_all_entries: true, + tabs_in_sidebar: true, + custom_actions: [ + { + $type: 'add', + hide_cond: [] + }, + { + $type: 'batch_remove', + hide_cond: [] + } + ], + columns: [ + 'cn', + 'ipavaulttype' + ], + policies: [ + vault.config_sidebar_policy + ] + } + ], + adder_dialog: { + $factory: vault.custom_adder_dialog, + name: 'add', + method: 'add_internal', + policies: [ + { $factory: vault.adder_policy } + ] + }, + deleter_dialog: { + // Each parametr is present only in one facet. It could cause errors + // in case that table on each facet gather more columns with these names. + // I.e. facet with user vaults get column with name 'service', then + // the value of 'service' column will be also added to command options. + additional_table_attrs: ['username', 'service', 'shared'] + } + }; + + /** + * This function extends general details facet - so the same declaration + * of facet (which would differ only in several lines) + * should not be present six times. + */ + var update_facet_spec = function(facet, facet_type) { + facet.sections[0].fields.push(facet_type); + facet.refresh_attribute = facet_type; + facet.update_attribute = facet_type; + var user_members = facet.sections[2].fields[0]; + var group_members = facet.sections[2].fields[1]; + var service_members = facet.sections[2].fields[2]; + var user_owners = facet.sections[3].fields[0]; + var group_owners = facet.sections[3].fields[1]; + var service_owners = facet.sections[3].fields[2]; + + var attributes = { + refresh_attribute: facet_type, + additional_add_del_field: facet_type + }; + + $.extend(user_members, attributes); + $.extend(user_owners, attributes); + $.extend(group_members, attributes); + $.extend(group_owners, attributes); + $.extend(service_members, attributes); + $.extend(service_owners, attributes); + }; + + // Create details page for my vauls: + var details_spec = make_vaults_details_page_spec(); + entity.facets.push(details_spec); + + // Create details page for user vaults and modify it + details_spec = make_vaults_details_page_spec(); + + details_spec.name = 'vault_user'; + update_facet_spec(details_spec, 'username'); + details_spec.redirect_info = { + facet: 'user_search' + }; + + entity.facets.push(details_spec); + + // Create details page for service vaults and modify it + details_spec = make_vaults_details_page_spec(); + + details_spec.name = 'vault_service'; + update_facet_spec(details_spec, 'service'); + details_spec.redirect_info = { + facet: 'service_search' + }; + + entity.facets.push(details_spec); + + // Create details page for shared vaults and modify it + details_spec = make_vaults_details_page_spec(); + + details_spec.name = 'vault_shared'; + update_facet_spec(details_spec, 'shared'); + details_spec.redirect_info = { + facet: 'shared_search' + }; + + entity.facets.push(details_spec); + + return entity; +}; + + +vault.custom_details_facet = function(spec) { + spec = spec || {}; + + var that = IPA.details_facet(spec); + + that.load = function(data) { + that.details_facet_load(data); + + // show fields according to the type of vault + + var type_f = that.fields.get_field('ipavaulttype'); + var type = type_f.value[0]; + var salt_w = that.fields.get_field('ipavaultsalt').widget; + var pub_key_w = that.fields.get_field('ipavaultpublickey').widget; + + if (type === 'symmetric') { + pub_key_w.set_visible(false); + salt_w.set_visible(true); + } else if (type === 'asymmetric') { + pub_key_w.set_visible(true); + salt_w.set_visible(false); + } else { + pub_key_w.set_visible(false); + salt_w.set_visible(false); + } + }; + + return that; +}; + + +vault.public_key_widget = function(spec) { + spec = spec || {}; + + var that = IPA.sshkey_widget(spec); + + that.set_user_value = function(value) { + + var previous = that.key; + that.key = value; + that.update_link(); + + if (value !== previous) { + that.value_changed.notify([], that); + that.emit('value-change', { source: that }); + } + }; + + that.update = function(value) { + var key = value[0]; + + if (key) that.key = key; + + if (that.key && that.key !== '') { + that.originally_set = true; + that.original_key = that.key; + } + that.update_link(); + that.on_value_changed(value); + }; + + that.get_status = function() { + + var status = ''; + var value = that.key; + + if (that.original_key) { + + if (value !== that.original_key) { + if (value === '') { + status = text.get('@i18n:objects.publickey.status_mod_ns'); + } else { + status = text.get('@i18n:objects.publickey.status_mod_s'); + } + } else { + // f00c is code of check icon + var decimal_check_i = parseInt('f00c', 16); + status = String.fromCharCode(decimal_check_i); + } + } else { + if (!value || value === '') { + status = text.get('@i18n:objects.publickey.status_new_ns'); + } else { + status = text.get('@i18n:objects.publickey.status_new_ns'); + } + } + + return status; + }; + + that.create_edit_dialog = function() { + + var writable = that.is_writable(); + + var dialog = IPA.dialog({ + name: 'pubkey-edit-dialog', + title: '@i18n:objects.publickey.set_dialog_title', + width: 500, + height: 380 + }); + + dialog.message = text.get('@i18n:objects.publickey.set_dialog_help'); + + dialog.create_button({ + name: 'update', + label: '@i18n:buttons.set', + click: function() { + var value = dialog.textarea.val(); + that.set_user_value(value); + dialog.close(); + } + }); + + dialog.create_button({ + name: 'cancel', + label: '@i18n:buttons.cancel', + click: function() { + dialog.close(); + } + }); + + dialog.create_content = function() { + + dialog.container.append(dialog.message); + + dialog.textarea = $('