Use the policy
plug-in to manage policies for resources.
CLI plugin: policy
| Target: operations
| Release Notes
tanzu operations policy [command]
create Create a policy
delete Delete a policy
get Get a policy
insight Provide insight on the issues related to the policies which are applied on resources
list List policies
policy-template A Policy Template wraps a Kubernetes resource that is a pre-requisite/dependency for creating policies. This is a custom template that customers can create and upload to TMC
recipe A Recipe is a TMC provided policy template that customers can use out of the box to apply policies
type A Type defines the schema of policy instances
update Update a policy
-h, --help help for policy command
create
Create a policy.
tanzu operations policy create [flags]
-t, --cluster-type string type of the cluster (eks/attached), required for cluster scope
--dry-run only create data model, do not apply to server
-f, --file string resource file to create policy
-s, --scope string scope to cluster/clustergroup/project
To create a policy on a cluster using a resource file, sample-policy.yaml
:
tanzu operations policy create -s cluster -f sample-policy.yaml
delete
Delete a policy.
tanzu operations policy delete POLICY_NAME [flags]
-t, --cluster-type string type of the cluster (eks/attached) (default "eks")
-n, --name string name of the resource
-s, --scope string scope to cluster/clustergroup/project
To delete a policy applied on an attached cluster:
tanzu operations policy delete POLICY_NAME -s cluster -n CLUSTER_NAME -m attached -p attached
To delete a policy applied on a workspace:
tanzu operations policy delete POLICY_NAME -s workspace -n WORKSPACE_NAME
get
Get a policy.
tanzu operations policy get POLICY_NAME [flags]
-t, --cluster-type string type of the cluster (eks/attached) (default "eks")
-n, --name string name of the resource
-o, --output string Output format (yaml | json) (default "yaml")
-s, --scope string scope to cluster/clustergroup/project
To get a policy applied on a cluster group:
tanzu operations policy get POLICY_NAME -s clustergroup -n CLUSTERGROUP_NAME
insight
Provides insight on the issues related to the policies which are applied on resources.
tanzu operations policy insight [command]
insight, insights, pis
list Return a list of insights
insight list
Return a list of insights
tanzu operations policy insight list [flags]
--category string filter by category
--cluster-group string filter by name of clustergroup
--cluster-name string filter by name of cluster
--issue-type string filter by issue type
--max-size uint number of records to return
--offset uint offset at which to start returning records
-o, --output string output format (yaml|json)
--policy-name string filter by name of policy
To list all the policy insights:
tanzu operations policy insight list
To filter policy insights by cluster:
tanzu operations policy insight list --cluster-name cluster_name
To filter policy insights by policy:
tanzu operations policy insight list --policy-name policy_name
To filter policy insights by category (policy type):
tanzu operations policy insight list --category security
list
List policies.
tanzu operations policy list [flags]
-t, --cluster-type string type of the cluster (eks/attached)
-n, --resource-name string name of the resource
-s, --scope string scope to cluster/clustergroup/project
--show-effective show all policies effective on a resource, including inherited policies (requires target scope and resource-name flags)
To list all the policies in effect for the attached clusters in a cluster group:
tanzu operations policy list -s clustergroup -t attached -n CLUSTERGROUP_NAME --show-effective
policy-template
A policy template wraps a Kubernetes resource that is a pre-requisite or dependency for creating policies. This is a custom template that you can create and upload to Tanzu Mission Control.
tanzu operations policy policy-template [command]
policy-template, policy-templates, ptl
create Create a policy template
delete Delete a policy template
get Get a policy template
list List policy templates
update Update (overwrite) a policy template
policy-template create
Create a policy template
tanzu operations policy policy-template create [flags]
--data-inventory strings (optional) List of Kubernetes GVKs that need to be synced/replicated in Gatekeeper in order to enforce policy rules on those resources (Use format "Group/Version/Kind")
--description string (optional) Description of the policy template
--object-file string Object file containing yaml-formatted Kubernetes resource (only OPA Gatekeeper "ConstraintTemplate" object supported today)
--object-type string (set by default) Type of kubernetes resource (CRD) encoded in spec.object (only "ConstraintTemplate" supported today) (default "ConstraintTemplate")
--template-type string (set by default) Type of policy template that is being created (only "OPAGatekeeper" supported today) (default "OPAGatekeeper")
To create OPA Gatekeeper ConstraintTemplate allowedrepos as a Tanzu Mission Control policy template (similar for update):
tanzu operations policy policy-template create --object-file template.yaml
To create/update OPA Gatekeeper ConstraintTemplate uniqueingresshost which requires cached/sync resources as a Tanzu Mission Control policy template (similar for update):
tanzu operations policy policy-template create --object-file template.yaml --data-inventory "extensions/v1beta1/Ingress" --data-inventory "networking.k8s.io/v1beta1/Ingress" --data-inventory "networking.k8s.io/v1/Ingress"
policy-template delete
Delete a policy template
tanzu operations policy policy-template delete POLICYTEMPLATE_NAME [flags]
policy-template get
tanzu operations policy policy-template get POLICYTEMPLATE_NAME [flags]
--object get only Kubernetes object used in a policy template (eg. ConstraintTemplate object)
-o, --output string Output format (yaml | json) (default "yaml")
To get a policy template (similar for delete):
tanzu operations policy policy-template get POLICYTEMPLATE_NAME
To get only the OPA Gatekeeper ConstraintTemplate object used in a policy template, you can use “–object” parameter with get:
tanzu operations policy policy-template get POLICYTEMPLATE_NAME --object
To create a custom-policy using a policy template created with this command, create the corresponding resource file and use the tanzu policy create
command as described above. An example resource file to create policy using allowedrepos template:
fullName:
clusterName: CLUSTER_NAME
managementClusterName: MANAGEMENT_CLUSTER_NAME
provisionerName: PROVISIONER_NAME
name: POLICY_NAME
spec:
type: custom-policy
recipe: k8sallowedrepos
input:
targetKubernetesResources:
- apiGroups: [""]
kinds: ["Pod"]
parameters:
repos:
- "REPO_PREFIX1"
- "REPO_PREFIX2"
In the resource file above: - fullName
refers to the unique identifier of the Tanzu Mission Control resource along with a new policy name - type
should be custom-policy for any policies created using custom policy templates - recipe
is same as the ConstraintTemplate object name provided in the policy template (which is also the policy template name) - targetKubernetesResources
refers to the Kubernetes resources on which the policy is applicable - parameters
refers to the inputs required by the policy template as per the openAPIV3Schema mentioned in the ConstraintTemplate object
--object get only Kubernetes object used in a policy template (eg. ConstraintTemplate object)
-o, --output string Output format (yaml | json) (default "yaml")
policy-template list
tanzu operations policy policy-template list [flags]
--max-size uint Number of records to return
--name string scope search to the specified name (default "*")
--offset uint Offset at which to start returning records
-o, --output string Output format (yaml|json)
policy-template update
tanzu operations policy policy-template update [flags]
--data-inventory strings (optional) List of Kubernetes GVKs that need to be synced/replicated in Gatekeeper in order to enforce policy rules on those resources (Use format "Group/Version/Kind")
--description string (optional) Description of the policy template
--force Force in-place update
--object-file string Object file containing yaml-formatted Kubernetes resource (only OPA Gatekeeper "ConstraintTemplate" object supported today)
--object-type string Type of kubernetes resource (CRD) encoded in spec.object (only "ConstraintTemplate" supported today) (default "ConstraintTemplate")
--template-type string Type of policy template that is being updated (only "OPAGatekeeper" supported today) (default "OPAGatekeeper")
recipe
A recipe is a preconfigured policy template that you can use to apply policies.
tanzu operations policy recipe [command]
recipe, recipes, pr
get Retrieve a recipe object
list Return a list of recipes
recipe get
Retrieve a recipe object
tanzu operations policy recipe get RECIPE_NAME [flags]
-o, --output string output format (yaml | json) (default "yaml")
--type-name string name of the type
recipe list
Return a list of recipes
tanzu operations policy recipe list [flags]
--max-size uint number of records to return
--name string filter by specified policy recipe name
--offset uint offset at which to start returning records
-o, --output string output format (yaml|json)
--type-name string filter by specified policy type
To list all the recipes:
tanzu operations policy recipe list
To filter recipes of type custom-policy
:
tanzu operations policy recipe list --type-name custom-policy
type
A Type defines the schema of policy instances.
tanzu operations policy type [command]
type, types, pt
get Retrieve a type object
list Return a list of types
type get
Retrieve a type object
tanzu operations policy type get RECIPE_NAME [flags]
-o, --output string output format (yaml | json) (default "yaml")
type list
Return a list of types
tanzu operations policy type list [flags]
--max-size uint number of records to return
--name string scope search to the specified name
--offset uint offset at which to start returning records
-o, --output string output format (yaml|json)
update
Update a policy.
tanzu operations policy update [flags]
-f, --file string resource file to create policy
-s, --scope string scope to cluster/clustergroup/project
To update a policy on a workspace using a resource file, update-policy.yaml
:
tanzu operations policy update -s workspace -f update-policy.yaml