Files
vault/ui/app/models/ldap/role.js
Jordan Reimer a8b593614e LDAP/AD Secrets Engine (#20790)
* adds ldap ember engine (#20786)

* adds ldap as mountable and supported secrets engine (#20793)

* removes active directory as mountable secrets engine (#20798)

* LDAP Config Ember Data Setup (#20863)

* adds secret-engine-path adapter

* adds model, adapater and serializer for ldap config

* adds test for ldap config adapter

* addresses PR feedback

* updates remaining instances of getURL in secrets-engine-path adapter

* adds underscore to getURL method in kubernetes/config adapter

* adds check config vars test for kubernetes/config adapter

* adds comment regarding primaryKey in secrets-engine-path adapter

* adds tab-page-header component for ldap secrets engine (#20941)

* LDAP Config Route (#21059)

* converts secret-mount-path service to ts and moves kubernetes fetch-config decorator to core addon and converts to ts

* adds ldap config route

* fixes withConfig import path in kubernetes roles route

* updates types in ldap config route

* adds unit tests for fetch-secret-config decorator

* updates comments in fetch-secret-config decorator

* renames fetch-secret-config decorator

* LDAP Configure Page Component (#21384)

* adds ldap page configure component

* removes pauseTest and updates radio card selector in ldap config test

* LDAP Configuration (#21430)

* adds ldap configuration route

* adds secrets-engine-mount-config component to core addon

* adds ldap config-cta component

* adds display fields to ldap configuration page and test

* fixes ldap config-cta test

* adds yield to secrets-engine-mount-config component

* fixes tests

* LDAP Overview Route and Page Component (#21579)

* adds ldap overview route and page component

* changes toolbar link action type for create role on overview page

* LDAP Role Model, Adapter and Serializer (#21655)

* adds model, adapter and serializer for ldap roles

* addresses review feedback

* changes ldap role type from tracked prop to attr and sets in adapter for query methods

* adds assertions to verify that frontend only props are returned from query methods in ldap role adapter

* LDAP Library Model, Adapter and Serializer (#21728)

* adds model, adapter and serializer for ldap library

* updates capitalization and punction for ldap role and library form fields

* LDAP Roles Create and Edit (#21818)

* moves stringify and jsonify helpers to core addon

* adds validation error for ttl picker in form field component

* adds ldap roles create and edit routes and page component

* adds ldap mirage handler and factory for roles

* adds example workflow to json editor component

* adds tests for ldap page create and edit component

* addresses feedback

* LDAP Role Details (#22036)

* adds ldap role route to pass down model to child routes

* adds ldap role details route and page component

* updates ldap role model capabilities checks

* adds periods to error messages

* removes modelFor from ldap roles edit and details routes

* adds flash message on ldap role delete success

* LDAP Roles (#22070)

* adds ldap roles route and page component

* update ldap role adapter tests and adds adapter options to query for partialErrorInfo

* updates ldap role adapter based on PR feedback

* adds filter-input component to core addon

* updates ldap roles page to use filter-input component

* updates ldap role adapter tests

* LDAP Role Credentials (#22142)

* adds ldap roles route and page component

* update ldap role adapter tests and adds adapter options to query for partialErrorInfo

* adds credentials actions to ldap roles list menu and fixes rotate action in details view

* adds ldap role credentials route and page component

* adds tests for ldap role credentials

* LDAP Library Create and Edit (#22171)

* adds ldap library create/edit routes and page component

* adds ldap library create-and-edit tests and library mirage factory

* updates form-field component to display validation errors and warnings for all fields

* updates ldap library edit route class name

* updates ldap library model interface name

* adds missing period in flash message

* LDAP Libraries (#22184)

* updates interface and class names in ldap roles route

* adds ldap libraries route and page component

* fixes lint error

* LDAP Library Details (#22200)

* updates interface and class names in ldap roles route

* adds ldap libraries route and page component

* fixes lint error

* adds ldap library details route and page component

* LDAP Library Details Configuration (#22201)

* updates interface and class names in ldap roles route

* adds ldap libraries route and page component

* fixes lint error

* adds ldap library details route and page component

* adds ldap library details configuration route and page component

* updates ldap library check-in enforcement value mapping

* fixes issue in code mirror modifier after merging upgrade

* fixes failing database secrets test

* LDAP Library Account Details (#22287)

* adds route and page component for ldap library accounts

* adds ldap component for checked out accounts

* updates ldap library adapter tests

* LDAP Library Check-out (#22289)

* adds route and page component for ldap library accounts

* adds ldap component for checked out accounts

* adds route and page component for ldap library checkout

* addresses PR feedback

* LDAP Overview Cards (#22325)

* adds overview cards to ldap overview route

* adds create library toolbar action to ldap overview route

* adds acceptance tests for ldap workflows (#22375)

* Fetch Secrets Engine Config Decorator Docs (#22416)

* removes uneccesary asyncs from ldap route model hooks

* updates ldap overview route class name

* adds documentation for fetch-secrets-engine-config decorator

* add changelog

* adding back external links, missed due to merge.

* changelog

* fix test after merging in dashboard work

* Update 20790.txt

---------

Co-authored-by: Angel Garbarino <angel@hashicorp.com>
Co-authored-by: Angel Garbarino <Monkeychip@users.noreply.github.com>
2023-08-25 10:54:29 -06:00

231 lines
7.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import Model, { attr } from '@ember-data/model';
import { withFormFields } from 'vault/decorators/model-form-fields';
import { withModelValidations } from 'vault/decorators/model-validations';
import lazyCapabilities, { apiPath } from 'vault/macros/lazy-capabilities';
const creationLdifExample = `# The example below is treated as a comment and will not be submitted
# dn: cn={{.Username}},ou=users,dc=learn,dc=example
# objectClass: person
# objectClass: top
`;
const deletionLdifExample = `# The example below is treated as a comment and will not be submitted
# dn: cn={{.Username}},ou=users,dc=learn,dc=example
# changetype: delete
`;
const rollbackLdifExample = `# The example below is treated as a comment and will not be submitted
# dn: cn={{.Username}},ou=users,dc=learn,dc=example
# changetype: delete
`;
const validations = {
name: [{ type: 'presence', message: 'Name is required' }],
username: [
{
validator: (model) => (model.isStatic && !model.username ? false : true),
message: 'Username is required.',
},
],
rotation_period: [
{
validator: (model) => (model.isStatic && !model.rotation_period ? false : true),
message: 'Rotation Period is required.',
},
],
creation_ldif: [
{
validator: (model) => (model.isDynamic && !model.creation_ldif ? false : true),
message: 'Creation LDIF is required.',
},
],
deletion_ldif: [
{
validator: (model) => (model.isDynamic && !model.creation_ldif ? false : true),
message: 'Deletion LDIF is required.',
},
],
};
export const staticRoleFields = ['username', 'dn', 'rotation_period'];
export const dynamicRoleFields = [
'default_ttl',
'max_ttl',
'username_template',
'creation_ldif',
'deletion_ldif',
'rollback_ldif',
];
@withModelValidations(validations)
@withFormFields()
export default class LdapRoleModel extends Model {
@attr('string') backend; // dynamic path of secret -- set on response from value passed to queryRecord
@attr('string', {
defaultValue: 'static',
})
type; // this must be set to either static or dynamic in order for the adapter to build the correct url and for the correct form fields to display
@attr('string', {
label: 'Role name',
subText: 'The name of the role that will be used in Vault.',
})
name;
// static role properties
@attr('string', {
label: 'Distinguished name',
subText: 'Distinguished name (DN) of entry Vault should manage.',
})
dn;
@attr('string', {
label: 'Username',
subText:
"The name of the user to be used when logging in. This is useful when DN isn't used for login purposes.",
})
username;
@attr({
editType: 'ttl',
label: 'Rotation period',
helperTextEnabled:
'Specifies the amount of time Vault should wait before rotating the password. The minimum is 5 seconds.',
hideToggle: true,
})
rotation_period;
// dynamic role properties
@attr({
editType: 'ttl',
label: 'Generated credentials time-to-live (TTL)',
detailsLabel: 'TTL',
helperTextDisabled: 'Vault will use the default of 1 hour.',
defaultValue: '1h',
defaultShown: 'Engine default',
})
default_ttl;
@attr({
editType: 'ttl',
label: 'Generated credentials maximum time-to-live (Max TTL)',
detailsLabel: 'Max TTL',
helperTextDisabled: 'Vault will use the engine default of 24 hours.',
defaultValue: '24h',
defaultShown: 'Engine default',
})
max_ttl;
@attr('string', {
editType: 'optionalText',
label: 'Username template',
subText: 'Enter the custom username template to use.',
defaultSubText:
'Template describing how dynamic usernames are generated. Vault will use the default for this plugin.',
docLink: '/vault/docs/concepts/username-templating',
defaultShown: 'Default',
})
username_template;
@attr('string', {
editType: 'json',
label: 'Creation LDIF',
helpText: 'Specifies the LDIF statements executed to create a user. May optionally be base64 encoded.',
example: creationLdifExample,
mode: 'ruby',
sectionHeading: 'LDIF Statements', // render section heading before form field
})
creation_ldif;
@attr('string', {
editType: 'json',
label: 'Deletion LDIF',
helpText:
'Specifies the LDIF statements executed to delete a user once its TTL has expired. May optionally be base64 encoded.',
example: deletionLdifExample,
mode: 'ruby',
})
deletion_ldif;
@attr('string', {
editType: 'json',
label: 'Rollback LDIF',
helpText:
'Specifies the LDIF statement to attempt to rollback any changes if the creation results in an error. May optionally be base64 encoded.',
example: rollbackLdifExample,
mode: 'ruby',
})
rollback_ldif;
get isStatic() {
return this.type === 'static';
}
get isDynamic() {
return this.type === 'dynamic';
}
// this is used to build the form fields as well as serialize the correct payload based on type
// if a new attr is added be sure to add it to the appropriate array
get fieldsForType() {
return this.isStatic
? ['username', 'dn', 'rotation_period']
: ['default_ttl', 'max_ttl', 'username_template', 'creation_ldif', 'deletion_ldif', 'rollback_ldif'];
}
get formFields() {
// filter all fields and return only those relevant to type
return this.allFields.filter((field) => {
// name is the only common field
return field.name === 'name' || this.fieldsForType.includes(field.name);
});
}
get displayFields() {
// insert type after role name
const [name, ...rest] = this.formFields;
const typeField = { name: 'type', options: { label: 'Role type' } };
return [name, typeField, ...rest];
}
get roleUri() {
return this.isStatic ? 'static-role' : 'role';
}
get credsUri() {
return this.isStatic ? 'static-cred' : 'creds';
}
@lazyCapabilities(apiPath`${'backend'}/${'roleUri'}/${'name'}`, 'backend', 'roleUri', 'name') rolePath;
@lazyCapabilities(apiPath`${'backend'}/${'credsUri'}/${'name'}`, 'backend', 'credsUri', 'name') credsPath;
@lazyCapabilities(apiPath`${'backend'}/rotate-role/${'name'}`, 'backend', 'name') staticRotateCredsPath;
get canCreate() {
return this.rolePath.get('canCreate') !== false;
}
get canDelete() {
return this.rolePath.get('canDelete') !== false;
}
get canEdit() {
return this.rolePath.get('canUpdate') !== false;
}
get canRead() {
return this.rolePath.get('canRead') !== false;
}
get canList() {
return this.rolePath.get('canList') !== false;
}
get canReadCreds() {
return this.credsPath.get('canRead') !== false;
}
get canRotateStaticCreds() {
return this.isStatic && this.staticRotateCredsPath.get('canCreate') !== false;
}
fetchCredentials() {
return this.store.adapterFor('ldap/role').fetchCredentials(this.backend, this.type, this.name);
}
rotateStaticPassword() {
return this.store.adapterFor('ldap/role').rotateStaticPassword(this.backend, this.name);
}
}