Skip to main content
To change the IP access list of a ClickHouse Cloud service without the console, send a PATCH request for the service to the ClickHouse Cloud API with an ipAccessList object. Its add and remove arrays list the entries to add and to remove, so you do not have to send the whole list.

Before you start

You need:
  • An API key that is allowed to read and to change the service. In the API reference, the GET request for a service (“Get service details”) requires the control-plane:service:view permission, and the PATCH request (“Update service basic details”) requires control-plane:service:manage. A key with the admin role has full read and write permissions. A key with read-only permissions is not enough for the PATCH request. The list of console permissions also has a separate control-plane:service:manage-ip-access-list permission for IP access lists: if the PATCH request of a key with narrower permissions is rejected, check whether the key has it.
  • The ID of your organization and the ID of the service.
  • curl, and optionally jq to print parts of the response.
Put the key and the IDs into environment variables:
If you do not know the IDs, ask the API. The first request returns the organization of the key, and the second one lists its services:

See the current list

Request the service and print its ipAccessList:
Every entry has a source, which is an IPv4 address or an IPv4 range in CIDR notation, and an optional description.

Add and remove entries

Write the changes to a file. This example adds one address and one range, and removes one address:
Send it with a PATCH request to the service:
A successful response has "status": 200 and returns the service in result, so the command prints its IP access list. If the request is rejected, the response has no result and the command prints null; run it without the jq part to read the error field of the response. To confirm the change, run the command from the previous section again. Both arrays are optional: send only add to add entries, or only remove to remove them.

Things to know

  • The API processes remove before add. To change the description of an entry, put the entry into remove and the new version into add of the same request.
  • In remove, copy the entries from the current list as they are.
  • A service that allows access from anywhere has an entry with the source 0.0.0.0/0. Adding specific addresses restricts nothing while that entry is in the list, so remove it in the same request. Before you do, make sure that add contains every address your applications connect from.
  • IP access lists support only IPv4.
  • The API key has an IP access list of its own. If the key is restricted to specific locations, the request must come from one of them.
  • The list applies only to connections from the public internet, not to connections through PrivateLink, see setting IP filters.