CreateSecurityPolicy
client.SecurityPolicies.New(ctx, body) (*SecurityPolicyNewResponse, error)
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
package main
import (
"context"
"fmt"
"github.com/gitpod-io/gitpod-sdk-go"
"github.com/gitpod-io/gitpod-sdk-go/option"
)
func main() {
client := gitpod.NewClient(
option.WithBearerToken("My Bearer Token"),
)
securityPolicy, err := client.SecurityPolicies.New(context.TODO(), gitpod.SecurityPolicyNewParams{
Metadata: gitpod.F(gitpod.SecurityPolicyNewParamsMetadata{
Name: gitpod.F("Veto Exec audit-first"),
}),
Spec: gitpod.F(gitpod.SecurityPolicyNewParamsSpec{
Executables: gitpod.F(gitpod.SecurityPolicyNewParamsSpecExecutables{
DefaultEffect: gitpod.F(gitpod.SecurityPolicyNewParamsSpecExecutablesDefaultEffectEffectAllow),
Rules: gitpod.F([]gitpod.SecurityPolicyNewParamsSpecExecutablesRule{gitpod.SecurityPolicyNewParamsSpecExecutablesRule{
Effect: gitpod.F(gitpod.SecurityPolicyNewParamsSpecExecutablesRulesEffectEffectAudit),
Path: gitpod.F("npx"),
}, gitpod.SecurityPolicyNewParamsSpecExecutablesRule{
Effect: gitpod.F(gitpod.SecurityPolicyNewParamsSpecExecutablesRulesEffectEffectBlock),
Path: gitpod.F("/usr/bin/curl"),
}}),
}),
}),
OrganizationID: gitpod.F("b0e12f6c-4c67-429d-a4a6-d9838b5da047"),
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", securityPolicy.SecurityPolicy)
}
{
"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"
}
}