From 21eea7c5720f8fcc1bae033a1722e7dd59bd0be1 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Fri, 26 Feb 2021 13:34:17 +0000 Subject: [PATCH 1/5] Add a bunch of new abilities for everything in ACLs --- ui/packages/consul-ui/app/abilities/acl.js | 9 +++-- .../consul-ui/app/abilities/auth-method.js | 21 ++++++++++++ ui/packages/consul-ui/app/abilities/policy.js | 34 +++++++++++++++++++ ui/packages/consul-ui/app/abilities/role.js | 21 ++++++++++++ ui/packages/consul-ui/app/abilities/token.js | 33 ++++++++++++++++++ 5 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 ui/packages/consul-ui/app/abilities/auth-method.js create mode 100644 ui/packages/consul-ui/app/abilities/policy.js create mode 100644 ui/packages/consul-ui/app/abilities/role.js create mode 100644 ui/packages/consul-ui/app/abilities/token.js diff --git a/ui/packages/consul-ui/app/abilities/acl.js b/ui/packages/consul-ui/app/abilities/acl.js index f62383f415bc..ae584a0665f3 100644 --- a/ui/packages/consul-ui/app/abilities/acl.js +++ b/ui/packages/consul-ui/app/abilities/acl.js @@ -1,9 +1,6 @@ import BaseAbility from './base'; import { inject as service } from '@ember/service'; -// ACL ability covers all of the ACL things, like tokens, policies, roles and -// auth methods and this therefore should not be deleted once we remove the on -// legacy ACLs related classes export default class ACLAbility extends BaseAbility { @service('env') env; @@ -13,4 +10,10 @@ export default class ACLAbility extends BaseAbility { get canRead() { return this.env.var('CONSUL_ACLS_ENABLED') && super.canRead; } + get canDuplicate() { + return this.env.var('CONSUL_ACLS_ENABLED') && super.canWrite; + } + get canDelete() { + return this.env.var('CONSUL_ACLS_ENABLED') && this.item.ID !== 'anonymous' && super.canWrite; + } } diff --git a/ui/packages/consul-ui/app/abilities/auth-method.js b/ui/packages/consul-ui/app/abilities/auth-method.js new file mode 100644 index 000000000000..b0af41980a81 --- /dev/null +++ b/ui/packages/consul-ui/app/abilities/auth-method.js @@ -0,0 +1,21 @@ +import BaseAbility from './base'; +import { inject as service } from '@ember/service'; + +export default class AuthMethodAbility extends BaseAbility { + @service('env') env; + + resource = 'acl'; + segmented = false; + + get canRead() { + return this.env.var('CONSUL_ACLS_ENABLED') && super.canRead; + } + + get canCreate() { + return this.env.var('CONSUL_ACLS_ENABLED') && super.canCreate; + } + + get canDelete() { + return this.env.var('CONSUL_ACLS_ENABLED') && super.canDelete; + } +} diff --git a/ui/packages/consul-ui/app/abilities/policy.js b/ui/packages/consul-ui/app/abilities/policy.js new file mode 100644 index 000000000000..739408a187ad --- /dev/null +++ b/ui/packages/consul-ui/app/abilities/policy.js @@ -0,0 +1,34 @@ +import BaseAbility from './base'; +import { inject as service } from '@ember/service'; +import { typeOf } from 'consul-ui/helpers/policy/typeof'; + +export default class PolicyAbility extends BaseAbility { + @service('env') env; + + resource = 'acl'; + segmented = false; + + get canRead() { + return this.env.var('CONSUL_ACLS_ENABLED') && super.canRead; + } + + get canWrite() { + return ( + this.env.var('CONSUL_ACLS_ENABLED') && + (typeof this.item === 'undefined' || typeOf([this.item]) !== 'policy-management') && + super.canRead + ); + } + + get canCreate() { + return this.env.var('CONSUL_ACLS_ENABLED') && super.canCreate; + } + + get canDelete() { + return ( + this.env.var('CONSUL_ACLS_ENABLED') && + (typeof this.item === 'undefined' || typeOf([this.item]) !== 'policy-management') && + super.canDelete + ); + } +} diff --git a/ui/packages/consul-ui/app/abilities/role.js b/ui/packages/consul-ui/app/abilities/role.js new file mode 100644 index 000000000000..5c14e58f6ba7 --- /dev/null +++ b/ui/packages/consul-ui/app/abilities/role.js @@ -0,0 +1,21 @@ +import BaseAbility from './base'; +import { inject as service } from '@ember/service'; + +export default class RoleAbility extends BaseAbility { + @service('env') env; + + resource = 'acl'; + segmented = false; + + get canRead() { + return this.env.var('CONSUL_ACLS_ENABLED') && super.canRead; + } + + get canCreate() { + return this.env.var('CONSUL_ACLS_ENABLED') && super.canCreate; + } + + get canDelete() { + return this.env.var('CONSUL_ACLS_ENABLED') && super.canDelete; + } +} diff --git a/ui/packages/consul-ui/app/abilities/token.js b/ui/packages/consul-ui/app/abilities/token.js new file mode 100644 index 000000000000..a47c39288859 --- /dev/null +++ b/ui/packages/consul-ui/app/abilities/token.js @@ -0,0 +1,33 @@ +import BaseAbility from './base'; +import { inject as service } from '@ember/service'; + +import { isLegacy } from 'consul-ui/helpers/token/is-legacy'; +import { isAnonymous } from 'consul-ui/helpers/token/is-anonymous'; + +export default class TokenAbility extends BaseAbility { + @service('env') env; + + resource = 'acl'; + segmented = false; + + get canRead() { + return this.env.var('CONSUL_ACLS_ENABLED') && super.canRead; + } + + get canCreate() { + return this.env.var('CONSUL_ACLS_ENABLED') && super.canCreate; + } + + get canDelete() { + return ( + this.env.var('CONSUL_ACLS_ENABLED') && + !isAnonymous([this.item]) && + this.item.AccessorID !== this.token.AccessorID && + super.canDelete + ); + } + + get canDuplicate() { + return this.env.var('CONSUL_ACLS_ENABLED') && !isLegacy([this.item]) && super.canWrite; + } +} From 1c61d54f1f79c1e4a72a25715c6f454c43334935 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Fri, 26 Feb 2021 13:34:49 +0000 Subject: [PATCH 2/5] Use the new abilities to control access everywhere in ACLs --- .../app/components/child-selector/index.hbs | 2 ++ .../app/components/consul/acl/list/index.hbs | 12 ++++++++++-- .../components/consul/policy/list/index.hbs | 8 ++++---- .../app/components/consul/role/list/index.hbs | 6 ++++++ .../app/components/consul/token/list/index.hbs | 17 +++++++++++++---- .../app/components/policy-form/index.hbs | 5 ++++- .../app/components/policy-selector/index.hbs | 13 ++++++++++++- .../app/components/role-form/index.hbs | 13 +++++++++++-- .../app/components/role-selector/index.hbs | 13 ++++++++++--- .../consul-ui/app/templates/dc/acls/-form.hbs | 14 ++++++++++---- .../consul-ui/app/templates/dc/acls/edit.hbs | 2 ++ .../consul-ui/app/templates/dc/acls/index.hbs | 2 ++ .../app/templates/dc/acls/policies/-form.hbs | 6 ++++-- .../app/templates/dc/acls/policies/edit.hbs | 6 +++--- .../app/templates/dc/acls/roles/-form.hbs | 6 ++++-- .../dc/acls/tokens/-fieldsets-legacy.hbs | 4 +++- .../templates/dc/acls/tokens/-fieldsets.hbs | 18 +++++++++++++++--- .../app/templates/dc/acls/tokens/-form.hbs | 7 +++++-- .../app/templates/dc/acls/tokens/edit.hbs | 2 +- .../app/templates/dc/acls/tokens/index.hbs | 2 ++ 20 files changed, 123 insertions(+), 35 deletions(-) diff --git a/ui/packages/consul-ui/app/components/child-selector/index.hbs b/ui/packages/consul-ui/app/components/child-selector/index.hbs index 280e17806a3a..f09d04ceb58d 100644 --- a/ui/packages/consul-ui/app/components/child-selector/index.hbs +++ b/ui/packages/consul-ui/app/components/child-selector/index.hbs @@ -3,6 +3,7 @@ ...attributes > {{yield}} +{{#if (not disabled)}} {{yield}} +{{/if}} {{#if (gt items.length 0)}} {{yield}} {{else}} diff --git a/ui/packages/consul-ui/app/components/consul/acl/list/index.hbs b/ui/packages/consul-ui/app/components/consul/acl/list/index.hbs index 371e0155e20d..763dd16f71b4 100644 --- a/ui/packages/consul-ui/app/components/consul/acl/list/index.hbs +++ b/ui/packages/consul-ui/app/components/consul/acl/list/index.hbs @@ -29,7 +29,13 @@
  • - Edit + +{{#if (can "write acl" item=item)}} + Edit +{{else}} + View +{{/if}} +
  • {{#if (eq item.ID token.SecretID) }}
  • @@ -87,10 +93,12 @@
  • {{/if}} +{{#if (can "duplicate acl" item=item)}}
  • - {{# if (not-eq item.ID 'anonymous') }} +{{/if}} +{{#if (can "delete acl" item=item)}}
  • diff --git a/ui/packages/consul-ui/app/components/consul/policy/list/index.hbs b/ui/packages/consul-ui/app/components/consul/policy/list/index.hbs index c4f5dfa3c1b3..a518a84e3eb2 100644 --- a/ui/packages/consul-ui/app/components/consul/policy/list/index.hbs +++ b/ui/packages/consul-ui/app/components/consul/policy/list/index.hbs @@ -35,14 +35,14 @@ as |item|> -{{#if (eq (policy/typeof item) 'policy-management')}} - View -{{else}} +{{#if (can "write policy" item=item)}} Edit +{{else}} + View {{/if}} -{{#if (not-eq (policy/typeof item) 'policy-management')}} +{{#if (can "delete policy" item=item)}} Delete diff --git a/ui/packages/consul-ui/app/components/consul/role/list/index.hbs b/ui/packages/consul-ui/app/components/consul/role/list/index.hbs index ba2da7e60614..9c8254f682ba 100644 --- a/ui/packages/consul-ui/app/components/consul/role/list/index.hbs +++ b/ui/packages/consul-ui/app/components/consul/role/list/index.hbs @@ -19,9 +19,14 @@ as |item|> +{{#if (can "write role" item=item)}} Edit +{{else}} + View +{{/if}} +{{#if (can "delete role" item=item)}} Delete @@ -42,6 +47,7 @@ as |item|> +{{/if}} \ No newline at end of file diff --git a/ui/packages/consul-ui/app/components/consul/token/list/index.hbs b/ui/packages/consul-ui/app/components/consul/token/list/index.hbs index 544045875223..e0e7e13ae8df 100644 --- a/ui/packages/consul-ui/app/components/consul/token/list/index.hbs +++ b/ui/packages/consul-ui/app/components/consul/token/list/index.hbs @@ -30,19 +30,25 @@ as |item|> + +{{#if (can "write token" item=item)}} Edit +{{else}} + View +{{/if}} - {{#if (not (token/is-legacy item))}} +{{#if (can "duplicate token" item=item)}} Duplicate - {{/if}} +{{/if}} + {{#if (eq item.AccessorID token.AccessorID)}} @@ -86,7 +92,9 @@ as |item|> {{/if}} - {{#if (not (or (token/is-anonymous item) (eq item.AccessorID @token.AccessorID)))}} + + +{{#if (can "delete token" item=item token=@token)}} Delete @@ -107,7 +115,8 @@ as |item|> - {{/if}} +{{/if}} + \ No newline at end of file diff --git a/ui/packages/consul-ui/app/components/policy-form/index.hbs b/ui/packages/consul-ui/app/components/policy-form/index.hbs index 18fab4fceede..dee068eb01b5 100644 --- a/ui/packages/consul-ui/app/components/policy-form/index.hbs +++ b/ui/packages/consul-ui/app/components/policy-form/index.hbs @@ -1,5 +1,8 @@ {{yield}} -
    +
    {{#yield-slot name='template'}} {{else}}
    diff --git a/ui/packages/consul-ui/app/components/policy-selector/index.hbs b/ui/packages/consul-ui/app/components/policy-selector/index.hbs index 54166332320d..e18d4ed677ef 100644 --- a/ui/packages/consul-ui/app/components/policy-selector/index.hbs +++ b/ui/packages/consul-ui/app/components/policy-selector/index.hbs @@ -1,4 +1,13 @@ - + {{yield}} Apply an existing policy @@ -107,6 +116,7 @@ /> {{/if}} +{{#if (not disabled)}}
    @@ -122,6 +132,7 @@
    +{{/if}}
    diff --git a/ui/packages/consul-ui/app/components/role-form/index.hbs b/ui/packages/consul-ui/app/components/role-form/index.hbs index 460c6d6904a1..88ea366c0bef 100644 --- a/ui/packages/consul-ui/app/components/role-form/index.hbs +++ b/ui/packages/consul-ui/app/components/role-form/index.hbs @@ -1,5 +1,9 @@ {{yield}} -
    +
    diff --git a/ui/packages/consul-ui/app/components/role-selector/index.hbs b/ui/packages/consul-ui/app/components/role-selector/index.hbs index e1c78bd87bac..f4f049e90366 100644 --- a/ui/packages/consul-ui/app/components/role-selector/index.hbs +++ b/ui/packages/consul-ui/app/components/role-selector/index.hbs @@ -58,7 +58,7 @@ - + Apply an existing role @@ -66,7 +66,6 @@ - {{option.Name}} @@ -96,8 +95,15 @@
  • - Edit + +{{#if (can "edit role" item=item)}} + Edit +{{else}} + View +{{/if}} +
  • +{{#if (not disabled)}}
  • @@ -121,6 +127,7 @@
  • +{{/if}}
    diff --git a/ui/packages/consul-ui/app/templates/dc/acls/-form.hbs b/ui/packages/consul-ui/app/templates/dc/acls/-form.hbs index df995189eab5..1a2e01ca8a3f 100644 --- a/ui/packages/consul-ui/app/templates/dc/acls/-form.hbs +++ b/ui/packages/consul-ui/app/templates/dc/acls/-form.hbs @@ -1,5 +1,7 @@
    -
    +
    -{{#if create }} +{{#if (and create (can "create acls")) }} {{! we only need to check for an empty name here as ember munges autofocus, once we have autofocus back revisit this}} - {{else}} + +{{else}} + {{#if (can "write acl" item=item)}} + + {{/if}} {{/if}} -{{# if (and (not create) (not-eq item.ID 'anonymous')) }} +{{# if (and (not create) (can "delete acl" item=item) ) }} diff --git a/ui/packages/consul-ui/app/templates/dc/acls/edit.hbs b/ui/packages/consul-ui/app/templates/dc/acls/edit.hbs index b10cd728591e..da650481fca0 100644 --- a/ui/packages/consul-ui/app/templates/dc/acls/edit.hbs +++ b/ui/packages/consul-ui/app/templates/dc/acls/edit.hbs @@ -25,6 +25,7 @@ Copy token ID + {{#if (can "duplicate acl" item=item)}} @@ -38,6 +39,7 @@ + {{/if}} {{/if}} diff --git a/ui/packages/consul-ui/app/templates/dc/acls/index.hbs b/ui/packages/consul-ui/app/templates/dc/acls/index.hbs index 7bf7b3da5e78..1546309fa018 100644 --- a/ui/packages/consul-ui/app/templates/dc/acls/index.hbs +++ b/ui/packages/consul-ui/app/templates/dc/acls/index.hbs @@ -32,7 +32,9 @@ as |sort filters items|}} +{{#if (can "create acls")}} Create +{{/if}} {{#if (gt items.length 0) }} diff --git a/ui/packages/consul-ui/app/templates/dc/acls/policies/-form.hbs b/ui/packages/consul-ui/app/templates/dc/acls/policies/-form.hbs index e3ec9be9545b..21a2f790c280 100644 --- a/ui/packages/consul-ui/app/templates/dc/acls/policies/-form.hbs +++ b/ui/packages/consul-ui/app/templates/dc/acls/policies/-form.hbs @@ -7,14 +7,16 @@ {{/if}}
    -{{#if create }} +{{#if (and create (can "create tokens")) }} {{! we only need to check for an empty name here as ember munges autofocus, once we have autofocus back revisit this}} {{ else }} + {{#if (can "write policy" item=item)}} + {{/if}} {{/if}} -{{# if (not create) }} +{{# if (and (not create) (can "delete policy" item=item) ) }} diff --git a/ui/packages/consul-ui/app/templates/dc/acls/policies/edit.hbs b/ui/packages/consul-ui/app/templates/dc/acls/policies/edit.hbs index d16ba5167925..96418a7ec5db 100644 --- a/ui/packages/consul-ui/app/templates/dc/acls/policies/edit.hbs +++ b/ui/packages/consul-ui/app/templates/dc/acls/policies/edit.hbs @@ -30,10 +30,10 @@ {{#if create }} New Policy {{else}} - {{#if (eq (policy/typeof item) 'policy-management')}} - View Policy - {{else}} + {{#if (can "write policy" item=item)}} Edit Policy + {{else}} + View Policy {{/if}} {{/if}} {{else}} diff --git a/ui/packages/consul-ui/app/templates/dc/acls/roles/-form.hbs b/ui/packages/consul-ui/app/templates/dc/acls/roles/-form.hbs index 092fcda21796..886153552f75 100644 --- a/ui/packages/consul-ui/app/templates/dc/acls/roles/-form.hbs +++ b/ui/packages/consul-ui/app/templates/dc/acls/roles/-form.hbs @@ -8,14 +8,16 @@ {{/if}}
    -{{#if create }} +{{#if (and create (can "create roles")) }} {{! we only need to check for an empty name here as ember munges autofocus, once we have autofocus back revisit this}} {{ else }} + {{#if (can "write role" item=item)}} + {{/if}} {{/if}} -{{# if (not create) }} +{{# if (and (not create) (can "delete role" item=item) ) }} diff --git a/ui/packages/consul-ui/app/templates/dc/acls/tokens/-fieldsets-legacy.hbs b/ui/packages/consul-ui/app/templates/dc/acls/tokens/-fieldsets-legacy.hbs index a96aac9cdb77..3dfebadfaec0 100644 --- a/ui/packages/consul-ui/app/templates/dc/acls/tokens/-fieldsets-legacy.hbs +++ b/ui/packages/consul-ui/app/templates/dc/acls/tokens/-fieldsets-legacy.hbs @@ -1,4 +1,6 @@ -
    +