CreateSecret
secrets.create(SecretCreateParams**kwargs) -> SecretCreateResponse
POST/gitpod.v1.SecretService/CreateSecret
Creates a new secret for a project.
Use this method to:
- Store sensitive configuration values
- Set up environment variables
- Configure registry authentication
- Add file-based secrets
Examples
-
Create environment variable:
Creates a secret that will be available as an environment variable.
name: "DATABASE_URL" projectId: "b0e12f6c-4c67-429d-a4a6-d9838b5da047" value: "postgresql://user:pass@localhost:5432/db" environmentVariable: true -
Create file secret:
Creates a secret that will be mounted as a file.
name: "SSH_KEY" projectId: "b0e12f6c-4c67-429d-a4a6-d9838b5da047" value: "-----BEGIN RSA PRIVATE KEY-----\n..." filePath: "/home/gitpod/.ssh/id_rsa" -
Create registry auth:
Creates credentials for private container registry.
name: "DOCKER_AUTH" projectId: "b0e12f6c-4c67-429d-a4a6-d9838b5da047" value: "username:password" containerRegistryBasicAuthHost: "https://registry.example.com"
Parameters
api_only indicates the secret is only available via API/CLI. These secrets are NOT automatically injected into services or devcontainers. Useful for secrets that should only be consumed programmatically (e.g., by security agents).
container_registry_basic_auth_host: Optional[str]
secret will be mounted as a docker config in the environment VM, mount will have the docker registry host
file_path: Optional[str]
absolute path to the file where the secret is mounted value must be an absolute path (e.g. /path/to/file):
this.matches('^/[^/].*$')CreateSecret
import os
from gitpod import Gitpod
client = Gitpod(
bearer_token=os.environ.get("GITPOD_API_KEY"), # This is the default and can be omitted
)
secret = client.secrets.create(
environment_variable=True,
name="DATABASE_URL",
project_id="b0e12f6c-4c67-429d-a4a6-d9838b5da047",
value="postgresql://user:pass@localhost:5432/db",
)
print(secret.secret){
"secret": {
"id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
"apiOnly": true,
"containerRegistryBasicAuthHost": "https://example.com",
"createdAt": "2019-12-27T18:11:19.117Z",
"creator": {
"id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
"principal": "PRINCIPAL_UNSPECIFIED"
},
"environmentVariable": true,
"filePath": "filePath",
"name": "name",
"projectId": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
"scope": {
"organizationId": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
"projectId": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
"serviceAccountId": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
"userId": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
},
"updatedAt": "2019-12-27T18:11:19.117Z"
}
}Returns Examples
{
"secret": {
"id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
"apiOnly": true,
"containerRegistryBasicAuthHost": "https://example.com",
"createdAt": "2019-12-27T18:11:19.117Z",
"creator": {
"id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
"principal": "PRINCIPAL_UNSPECIFIED"
},
"environmentVariable": true,
"filePath": "filePath",
"name": "name",
"projectId": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
"scope": {
"organizationId": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
"projectId": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
"serviceAccountId": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
"userId": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e"
},
"updatedAt": "2019-12-27T18:11:19.117Z"
}
}