CreateSecurityPolicy
security_policies.create(SecurityPolicyCreateParams**kwargs) -> SecurityPolicyCreateResponse
POST/gitpod.v1.SecurityService/CreateSecurityPolicy
Creates a new security policy.
Use this method to:
- Define environment access controls
- Configure audited or blocked operations
- Manage organization security posture
Examples
-
Create security policy:
Creates an audit-first Veto Exec policy with one audited bare name and one blocked absolute path. Creation stores an inactive definition; assigning it as the organization default validates materializability.
organizationId: "b0e12f6c-4c67-429d-a4a6-d9838b5da047" metadata: name: "Veto Exec audit-first" spec: executables: defaultEffect: EFFECT_ALLOW rules: - path: "npx" effect: EFFECT_AUDIT - path: "/usr/bin/curl" effect: EFFECT_BLOCK
CreateSecurityPolicy
import os
from gitpod import Gitpod
client = Gitpod(
bearer_token=os.environ.get("GITPOD_API_KEY"), # This is the default and can be omitted
)
security_policy = client.security_policies.create(
metadata={
"name": "Veto Exec audit-first"
},
spec={
"executables": {
"default_effect": "EFFECT_ALLOW",
"rules": [{
"effect": "EFFECT_AUDIT",
"path": "npx",
}, {
"effect": "EFFECT_BLOCK",
"path": "/usr/bin/curl",
}],
}
},
organization_id="b0e12f6c-4c67-429d-a4a6-d9838b5da047",
)
print(security_policy.security_policy){
"securityPolicy": {
"metadata": {
"name": "x"
},
"spec": {
"blockDevices": {
"defaultEffect": "EFFECT_UNSPECIFIED"
},
"data": {
"defaultEffect": "EFFECT_UNSPECIFIED",
"rules": [
{
"destination": {
"host": "host"
},
"effect": "EFFECT_UNSPECIFIED",
"source": {
"file": "file",
"integration": "integration",
"selector": "selector"
}
}
]
},
"executables": {
"defaultEffect": "EFFECT_UNSPECIFIED",
"rules": [
{
"effect": "EFFECT_UNSPECIFIED",
"path": "path"
}
]
},
"files": {
"defaultActions": [
"ACTION_UNSPECIFIED"
],
"defaultEffect": "EFFECT_UNSPECIFIED",
"rules": [
{
"actions": [
"ACTION_UNSPECIFIED"
],
"effect": "EFFECT_UNSPECIFIED",
"path": "path"
}
]
},
"ports": {
"maxAdmissionLevel": "ADMISSION_LEVEL_UNSPECIFIED"
}
},
"id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
"createdAt": "2019-12-27T18:11:19.117Z",
"organizationId": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
"updatedAt": "2019-12-27T18:11:19.117Z"
}
}Returns Examples
{
"securityPolicy": {
"metadata": {
"name": "x"
},
"spec": {
"blockDevices": {
"defaultEffect": "EFFECT_UNSPECIFIED"
},
"data": {
"defaultEffect": "EFFECT_UNSPECIFIED",
"rules": [
{
"destination": {
"host": "host"
},
"effect": "EFFECT_UNSPECIFIED",
"source": {
"file": "file",
"integration": "integration",
"selector": "selector"
}
}
]
},
"executables": {
"defaultEffect": "EFFECT_UNSPECIFIED",
"rules": [
{
"effect": "EFFECT_UNSPECIFIED",
"path": "path"
}
]
},
"files": {
"defaultActions": [
"ACTION_UNSPECIFIED"
],
"defaultEffect": "EFFECT_UNSPECIFIED",
"rules": [
{
"actions": [
"ACTION_UNSPECIFIED"
],
"effect": "EFFECT_UNSPECIFIED",
"path": "path"
}
]
},
"ports": {
"maxAdmissionLevel": "ADMISSION_LEVEL_UNSPECIFIED"
}
},
"id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
"createdAt": "2019-12-27T18:11:19.117Z",
"organizationId": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
"updatedAt": "2019-12-27T18:11:19.117Z"
}
}