Create policy
POST/metalakes/:metalake/policies
Creates a policy of a built-in or custom type in the metalake and returns it.
Sign in with a bearer token or a local user's password; see Authentication.
Request
Path Parameters
The name of the metalake
- application/json
Body
- CustomPolicyCreateRequest
- IcebergCompactionPolicyCreateRequest
- IcebergEncryptionPolicyCreateRequest
- Encryption required
- Encryption optional
Array [
]
oneOf
A request to create a policy with a custom content structure.
The name of the policy
A comment for the policy
Possible values: [custom]
The type of the policy
Default value: true
Whether the policy is enabled
content
object
required
Content for a custom policy type.
Possible values: [catalog, schema, fileset, table, view, topic, model, function], >= 1
Declares the metadata object types the policy's rules are intended for, limited to the types a policy can be associated with. The field is not enforced: associating a policy does not check it, and object policy lookup does not filter by it. Consumers decide whether a policy type applies to the object they are processing. Responses return the values in lowercase; requests accept any case.
properties
object
A map of string-to-string properties for the policy content.
A map of custom rules where the key is the rule name and the value can be of any type.
A request to create a policy with typed Iceberg compaction content.
The name of the policy
A comment for the policy
Possible values: [system_iceberg_compaction]
The type of the policy
Default value: true
Whether the policy is enabled
content
object
required
Content for the built-in Iceberg data-compaction policy.
Minimum custom-data-file-mse metric that triggers compaction.
Minimum custom-delete-file-number metric that triggers compaction.
Weight of the data-file MSE term in the score expression.
Weight of the delete-file-number term in the score expression.
Maximum partitions selected for one compaction run.
rewriteOptions
object
Options expanded to job.options.* on the rewrite job.
A request to create a policy with typed Iceberg encryption content.
The name of the policy
A comment for the policy
Possible values: [system_iceberg_encryption]
The type of the policy
Default value: true
Whether the policy is enabled
content
object
required
Content for the built-in policy that governs Iceberg table encryption.
oneOf
Possible values: [true]
Possible values: >= 1
Possible values: [false]
Possible values: [1]
The version of this policy content schema.
Default value: true
Whether matching tables must declare an encryption key.
allowedKeys
object[]
Exact {provider, keyId} identities that matching tables may declare. At least one is required when encryption is required. Protocol api is not part of the identity.
Possible values: non-empty, Value must match regular expression ^[A-Za-z0-9][A-Za-z0-9_-]*$
Named KMS config handle. Distinct from catalog plugin provider (for example lakehouse-iceberg). Protocol api is config on this handle, not part of the key identity.
Possible values: non-empty, Value must match regular expression .*\S.*
The unmodified provider-native key identifier.
Possible values: [report, deny-create]
Default value: report
Whether a violation is reported or causes table creation to be denied.
Responses
- 200
- 409
- 5xx
The new policy, with its type, content, enabled state and audit information.
- application/vnd.gravitino.v1+json
- Schema
- Example (from schema)
- PolicyResponse
Schema
- CustomPolicy
- IcebergCompactionPolicy
- IcebergEncryptionPolicy
- Encryption required
- Encryption optional
Array [
]
Possible values: [0]
Status code of the response
policy
object
A policy whose content is determined by its policy type.
oneOf
A policy with custom content
The name of the policy
A comment about the policy
Possible values: [custom]
The type of the policy
Whether the policy is enabled
audit
object
required
Audit information for a Gravitino resource.
The user who created the resource
The time the resource was created
The user who last modified the resource
The time the resource was last modified
Whether the policy is inherited from the parent metadata object
content
object
required
Content for a custom policy type.
Possible values: [catalog, schema, fileset, table, view, topic, model, function], >= 1
Declares the metadata object types the policy's rules are intended for, limited to the types a policy can be associated with. The field is not enforced: associating a policy does not check it, and object policy lookup does not filter by it. Consumers decide whether a policy type applies to the object they are processing. Responses return the values in lowercase; requests accept any case.
properties
object
A map of string-to-string properties for the policy content.
A map of custom rules where the key is the rule name and the value can be of any type.
A policy with typed Iceberg compaction content.
The name of the policy
A comment about the policy
Possible values: [system_iceberg_compaction]
The type of the policy
Whether the policy is enabled
audit
object
required
Audit information for a Gravitino resource.
The user who created the resource
The time the resource was created
The user who last modified the resource
The time the resource was last modified
Whether the policy is inherited from the parent metadata object
content
object
required
Content for the built-in Iceberg data-compaction policy.
Minimum custom-data-file-mse metric that triggers compaction.
Minimum custom-delete-file-number metric that triggers compaction.
Weight of the data-file MSE term in the score expression.
Weight of the delete-file-number term in the score expression.
Maximum partitions selected for one compaction run.
rewriteOptions
object
Options expanded to job.options.* on the rewrite job.
A policy with typed Iceberg encryption content.
The name of the policy
A comment about the policy
Possible values: [system_iceberg_encryption]
The type of the policy
Whether the policy is enabled
audit
object
required
Audit information for a Gravitino resource.
The user who created the resource
The time the resource was created
The user who last modified the resource
The time the resource was last modified
Whether the policy is inherited from the parent metadata object
content
object
required
Content for the built-in policy that governs Iceberg table encryption.
oneOf
Possible values: [true]
Possible values: >= 1
Possible values: [false]
Possible values: [1]
The version of this policy content schema.
Default value: true
Whether matching tables must declare an encryption key.
allowedKeys
object[]
Exact {provider, keyId} identities that matching tables may declare. At least one is required when encryption is required. Protocol api is not part of the identity.
Possible values: non-empty, Value must match regular expression ^[A-Za-z0-9][A-Za-z0-9_-]*$
Named KMS config handle. Distinct from catalog plugin provider (for example lakehouse-iceberg). Protocol api is config on this handle, not part of the key identity.
Possible values: non-empty, Value must match regular expression .*\S.*
The unmodified provider-native key identifier.
Possible values: [report, deny-create]
Default value: report
Whether a violation is reported or causes table creation to be denied.
{
"code": 0
}
{
"code": 0,
"policy": {
"name": "my_policy1",
"comment": "This is a test policy",
"policyType": "custom",
"enabled": false,
"content": {
"customRules": {
"rule1": 123
},
"supportedObjectTypes": [
"schema",
"table",
"model",
"topic",
"fileset",
"catalog"
],
"properties": {
"key1": "value1"
}
},
"inherited": null,
"audit": {
"creator": "anonymous",
"createTime": "2025-08-04T10:29:23.463Z"
}
}
}
A policy with the same name already exists in the metalake.
- application/vnd.gravitino.v1+json
- Schema
- Example (from schema)
- PolicyAlreadyExistsException
Schema
Possible values: >= 1000 and <= 1100
HTTP response code
Internal type definition of the error
A human-readable message
Deprecated diagnostic stack trace. Enterprise omits it by default because it can expose internal implementation details. Operators can opt in for controlled diagnostics with gravitino.server.webserver.includeErrorStackTrace=true. See OWASP REST Security: Error handling and CWE-209.
{
"code": 1002,
"type": "string",
"message": "string"
}
{
"code": 1004,
"type": "PolicyAlreadyExistsException",
"message": "Failed to operate policy(s) [my_policy] operation [CREATE], reason [PolicyAlreadyExistsException]",
"stack": [
"org.apache.gravitino.exceptions.PolicyAlreadyExistsException: Gag my_policy already exists",
"..."
]
}
The server hit an internal error that the client usually cannot fix by changing the request.
- application/vnd.gravitino.v1+json
- Schema
- Example (from schema)
- Example
Schema
Possible values: >= 1000 and <= 1100
HTTP response code
Internal type definition of the error
A human-readable message
Deprecated diagnostic stack trace. Enterprise omits it by default because it can expose internal implementation details. Operators can opt in for controlled diagnostics with gravitino.server.webserver.includeErrorStackTrace=true. See OWASP REST Security: Error handling and CWE-209.
{
"code": 1002,
"type": "string",
"message": "string"
}
{
"code": 1002,
"type": "RuntimeException",
"message": "Internal Server Error",
"stack": [
"java.lang.RuntimeException: Internal Server Error"
]
}