mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 11:08:10 +00:00
* Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package. This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License. Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUS-1.1 * Fix test that expected exact offset on hcl file --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com> Co-authored-by: Sarah Thompson <sthompson@hashicorp.com> Co-authored-by: Brian Kassouf <bkassouf@hashicorp.com>
99 lines
3.0 KiB
JavaScript
99 lines
3.0 KiB
JavaScript
/**
|
||
* Copyright (c) HashiCorp, Inc.
|
||
* SPDX-License-Identifier: BUSL-1.1
|
||
*/
|
||
|
||
import Component from '@glimmer/component';
|
||
|
||
/**
|
||
* @module PolicyExample
|
||
* The PolicyExample component receives a policy type ('acl', 'rgp', or 'egp') and renders a copyable policy example of
|
||
* that type using the <JsonEditor> component. Inside a modal, the PolicyExample component must be wrapped in a conditional
|
||
* (example below), otherwise the <JsonEditor> value won't render until it's focused.
|
||
*
|
||
* @example
|
||
* <PolicyExample
|
||
* @policyType={{@model.policyType}}
|
||
* />
|
||
*
|
||
* @example (in modal)
|
||
* <Modal
|
||
* @onClose={{fn (mut this.showTemplateModal) false}}
|
||
* @isActive={{this.showTemplateModal}}
|
||
* >
|
||
* <section class="modal-card-body">
|
||
* {{! code-mirror modifier does not render value initially until focus event fires }}
|
||
* {{! wait until the Modal is rendered and then show the PolicyExample (contains JsonEditor) }}
|
||
* {{#if this.showTemplateModal}}
|
||
* <PolicyExample @policyType={{@model.policyType}}/>
|
||
* {{/if}}
|
||
* </section>
|
||
* <div class="modal-card-head has-border-top-light">
|
||
* <button type="button" class="button" {{on "click" (fn (mut this.showTemplateModal) false)}} data-test-close-modal>
|
||
* Close
|
||
* </button>
|
||
* </div>
|
||
* </Modal>
|
||
* ```
|
||
* @param {string} policyType - policy type to decide which template to render; can either be "acl" or "rgp"
|
||
*/
|
||
|
||
export default class PolicyExampleComponent extends Component {
|
||
// formatting here is purposeful so that whitespace renders correctly in JsonEditor
|
||
policyTemplates = {
|
||
acl: `
|
||
# Grant 'create', 'read' , 'update', and ‘list’ permission
|
||
# to paths prefixed by 'secret/*'
|
||
path "secret/*" {
|
||
capabilities = [ "create", "read", "update", "list" ]
|
||
}
|
||
|
||
# Even though we allowed secret/*, this line explicitly denies
|
||
# secret/super-secret. This takes precedence.
|
||
path "secret/super-secret" {
|
||
capabilities = ["deny"]
|
||
}
|
||
`,
|
||
rgp: `
|
||
# Import strings library that exposes common string operations
|
||
import "strings"
|
||
|
||
# Conditional rule (precond) checks the incoming request endpoint
|
||
# targeted to sys/policies/acl/admin
|
||
precond = rule {
|
||
strings.has_prefix(request.path, "sys/policies/admin")
|
||
}
|
||
|
||
# Vault checks to see if the request was made by an entity
|
||
# named James Thomas or Team Lead role defined as its metadata
|
||
main = rule when precond {
|
||
identity.entity.metadata.role is "Team Lead" or
|
||
identity.entity.name is "James Thomas"
|
||
}
|
||
`,
|
||
egp: `
|
||
import "time"
|
||
|
||
# Expect requests to only happen during work days (Monday
|
||
# through Friday) 0 for Sunday and 6 for Saturday
|
||
workdays = rule {
|
||
time.now.weekday > 0 and time.now.weekday < 6
|
||
}
|
||
|
||
# Expect requests to only happen during work hours (7:00 am -
|
||
# 6:00 pm)
|
||
workhours = rule {
|
||
time.now.hour > 7 and time.now.hour < 18
|
||
}
|
||
main = rule {
|
||
workdays and workhours
|
||
}
|
||
`,
|
||
};
|
||
moreInformationLinks = {
|
||
acl: '/vault/docs/concepts/policies#capabilities',
|
||
rgp: '/vault/tutorials/policies/sentinel#role-governing-policies-rgps',
|
||
egp: '/vault/docs/enterprise/sentinel#endpoint-governing-policies-egps',
|
||
};
|
||
}
|