Skip to content

Policies

Generated from core/api/router.go. Edit the router, not this file.

MethodPathWho can call it
GET/api/v1/policiesAny authenticated user
POST/api/v1/policiesOperator, admin
GET/api/v1/policies/:idAny authenticated user
PUT/api/v1/policies/:idOperator, admin
DELETE/api/v1/policies/:idAdmin

Implemented rule types:

rule_typerule_config
key_size{"min_key_size": 2048} — applies to RSA
max_lifetime{"max_days": 90}
ca_restriction{"allowed_providers": ["acme", "vault"]}

severity is INFO, WARNING, or BLOCK. Only BLOCK refuses the request; the rest are returned in the issuance response.

domain_pattern scopes a policy — * matches everything, *.example.com matches any subdomain. A policy applies when any requested domain matches.

key_type, naming, and approval_required are accepted by the schema but not implemented, so policies using them currently do nothing. Policy is evaluated on issuance only, not on renewal.

Endpoint detail

GET /api/v1/policies

Who can call itAny authenticated user
HandlerpolicyHandler.List
Display tokenReadable by an unattended screen

Responses

StatusBody
200An object with data (Policy[]), total
500{ "error": … }
Example request
bash
curl -X GET 'https://certpilot.example.com/api/v1/policies' \
  -H 'Authorization: Bearer <token>'

POST /api/v1/policies

Who can call itOperator, admin
HandlerpolicyHandler.Create
Display tokenRefused — not a viewer-safe GET

Request body

PolicyInput is what a caller may set on a policy. Narrow rather than binding store.Policy, which is what both handlers used to do. That accepted id, created_by, created_at and updated_at from the request body — so a caller could choose a policy's identifier and assert when it was written, and Create handed whatever arrived straight to the store. The binding tags carry the CHECK constraints that migration 001 put on this table. Without them an unknown rule_type reaches PostgreSQL and comes back as a raw SQLSTATE 23514, which tells an operator nothing about which of six values they should have sent.

FieldTypeDescription
namestringrequired
descriptionstring
is_enabledbooleanIsEnabled is a pointer so that omitting it leaves the column's default of true, rather than a Go zero value quietly creating every policy disabled.
rule_typestringrequiredone of key_size, key_type, ca_restriction, max_lifetime, naming, approval_required
rule_configstringrequired
domain_patternstring
severitystringone of INFO, WARNING, BLOCK

Responses

StatusBody
201Created
400{ "error": … }
500{ "error": … }
Example request
bash
curl -X POST 'https://certpilot.example.com/api/v1/policies' \
  -H 'Authorization: Bearer <token>' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "<name>",
  "rule_type": "<rule_type>",
  "rule_config": "<rule_config>",
  "description": "<description>",
  "is_enabled": false
}'

GET /api/v1/policies/:id

Who can call itAny authenticated user
HandlerpolicyHandler.Get
Display tokenReadable by an unattended screen

Parameters

NameInDefault
idpathrequired

Responses

StatusBody
200A Policy object
404{ "error": … }
Example request
bash
curl -X GET 'https://certpilot.example.com/api/v1/policies/<id>' \
  -H 'Authorization: Bearer <token>'

PUT /api/v1/policies/:id

Who can call itOperator, admin
HandlerpolicyHandler.Update
Display tokenRefused — not a viewer-safe GET

Parameters

NameInDefault
idpathrequired

Request body

PolicyInput is what a caller may set on a policy. Narrow rather than binding store.Policy, which is what both handlers used to do. That accepted id, created_by, created_at and updated_at from the request body — so a caller could choose a policy's identifier and assert when it was written, and Create handed whatever arrived straight to the store. The binding tags carry the CHECK constraints that migration 001 put on this table. Without them an unknown rule_type reaches PostgreSQL and comes back as a raw SQLSTATE 23514, which tells an operator nothing about which of six values they should have sent.

FieldTypeDescription
namestringrequired
descriptionstring
is_enabledbooleanIsEnabled is a pointer so that omitting it leaves the column's default of true, rather than a Go zero value quietly creating every policy disabled.
rule_typestringrequiredone of key_size, key_type, ca_restriction, max_lifetime, naming, approval_required
rule_configstringrequired
domain_patternstring
severitystringone of INFO, WARNING, BLOCK

Responses

StatusBody
200Success
400{ "error": … }
500{ "error": … }
Example request
bash
curl -X PUT 'https://certpilot.example.com/api/v1/policies/<id>' \
  -H 'Authorization: Bearer <token>' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "<name>",
  "rule_type": "<rule_type>",
  "rule_config": "<rule_config>",
  "description": "<description>",
  "is_enabled": false
}'

DELETE /api/v1/policies/:id

Who can call itAdmin
HandlerpolicyHandler.Delete
Display tokenRefused — not a viewer-safe GET

Parameters

NameInDefault
idpathrequired

Responses

StatusBody
200An object with message (string)
500{ "error": … }
Example request
bash
curl -X DELETE 'https://certpilot.example.com/api/v1/policies/<id>' \
  -H 'Authorization: Bearer <token>'