From 2a7acc7c2e85aca85221ae4c199d6e79af8d3d6a Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 1 Dec 2026 22:57:27 +0000 Subject: [PATCH] Clarify Postgres IP restriction CLI help text and table header Clarify the help text and human table header for `pscale database ip-restriction` subcommands to accurately describe how PostgreSQL IP restriction rules work: - Clarify that `--schema` matches the PostgreSQL logical database name from the connection startup packet (not a schema within a database), and label the human table column `database` instead of `schema`. - Document allowlist semantics: with no rules all connections are allowed; when any rule exists, connections must match at least one rule, and role-scoped rules do not allow other roles unless another rule matches them. - Clarify that rules apply to all branches (including future branches), cannot be scoped to a single branch, and deleting a rule removes the access it granted (deleting the last rule allows all IPs on all branches). Co-authored-by: Mike Coutermarsh --- internal/cmd/database/ip_restriction.go | 13 +++++++++---- internal/cmd/database/ip_restriction_create.go | 17 ++++++++++++----- internal/cmd/database/ip_restriction_delete.go | 10 +++++++--- internal/cmd/database/ip_restriction_list.go | 6 +++++- internal/cmd/database/ip_restriction_update.go | 13 ++++++++----- 5 files changed, 41 insertions(+), 18 deletions(-) diff --git a/internal/cmd/database/ip_restriction.go b/internal/cmd/database/ip_restriction.go index c3405efac..07eb90594 100644 --- a/internal/cmd/database/ip_restriction.go +++ b/internal/cmd/database/ip_restriction.go @@ -20,9 +20,14 @@ func IPRestrictionCmd(ch *cmdutil.Helper) *cobra.Command { Short: "Manage Postgres IP restrictions", Long: `Manage IP restrictions for a PostgreSQL database. -IP restrictions limit which IPv4 addresses or ranges can connect. Rules can -optionally be scoped to a specific Postgres schema and/or role. This command -is only available for PostgreSQL databases.`, +IP restrictions are an allowlist of IPv4 CIDR ranges. With no rules, all +connections are allowed. When one or more rules exist, each connection must +match at least one rule (client IP in a CIDR range, role empty or matching +the login role, and database empty or matching the connection database). + +Rules apply to all branches of the database, including branches created later, +and cannot be scoped to a single branch. This command is only available for +PostgreSQL databases.`, } cmd.AddCommand(IPRestrictionListCmd(ch)) @@ -37,7 +42,7 @@ is only available for PostgreSQL databases.`, // IPRestrictionEntry is the human/JSON/CSV view of a Postgres IP restriction entry. type IPRestrictionEntry struct { ID string `header:"id" json:"id"` - Schema string `header:"schema" json:"schema"` + Schema string `header:"database" json:"schema"` Role string `header:"role" json:"role"` CIDRs string `header:"cidrs" json:"cidrs"` Description string `header:"description" json:"description"` diff --git a/internal/cmd/database/ip_restriction_create.go b/internal/cmd/database/ip_restriction_create.go index 645c78c97..c0cf99cee 100644 --- a/internal/cmd/database/ip_restriction_create.go +++ b/internal/cmd/database/ip_restriction_create.go @@ -21,11 +21,18 @@ func IPRestrictionCreateCmd(ch *cmdutil.Helper) *cobra.Command { cmd := &cobra.Command{ Use: "create ", Short: "Create an IP restriction entry", - Long: `Create an IP restriction entry for a PostgreSQL database. + Long: `Create an IP restriction allowlist rule for a PostgreSQL database. At least one IPv4 CIDR is required (e.g. 192.168.1.0/24 or 203.0.113.10/32). -Omit --schema / --role (or leave them empty) to apply the restriction to all -schemas and roles.`, +Rules are an allowlist and apply to all branches of the database (including +branches created later); they cannot be scoped to a single branch. Once any +rule exists, every connection must match at least one rule. + +Scoping a rule with --role allows that role from the given CIDRs and does not +allow other roles to connect unless another rule matches them. --schema matches +the PostgreSQL logical database name in the connection startup packet (not a +schema within a database). Omit --schema or --role to allow all databases or +roles.`, Args: cmdutil.RequiredArgs("database"), ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { return cmdutil.DatabaseCompletionFunc(ch, cmd, args, toComplete) @@ -72,8 +79,8 @@ schemas and roles.`, } cmd.Flags().StringSliceVar(&flags.cidrs, "cidrs", nil, "IPv4 CIDR ranges to allow (required, repeatable or comma-separated)") - cmd.Flags().StringVar(&flags.schema, "schema", "", "Postgres schema to restrict (omit for all schemas)") - cmd.Flags().StringVar(&flags.role, "role", "", "Postgres role to restrict (omit for all roles)") + cmd.Flags().StringVar(&flags.schema, "schema", "", "PostgreSQL logical database name to allow (matches the connection database, not a schema; omit for all databases)") + cmd.Flags().StringVar(&flags.role, "role", "", "PostgreSQL role to allow (omit for all roles)") cmd.Flags().StringVar(&flags.description, "description", "", "Optional description for the IP restriction entry") cmd.MarkFlagRequired("cidrs") // nolint:errcheck diff --git a/internal/cmd/database/ip_restriction_delete.go b/internal/cmd/database/ip_restriction_delete.go index f6853630a..40bcc0816 100644 --- a/internal/cmd/database/ip_restriction_delete.go +++ b/internal/cmd/database/ip_restriction_delete.go @@ -14,9 +14,13 @@ func IPRestrictionDeleteCmd(ch *cmdutil.Helper) *cobra.Command { var force bool cmd := &cobra.Command{ - Use: "delete ", - Short: "Delete an IP restriction entry", - Long: "Delete an IP restriction entry from a PostgreSQL database. Deleting an entry removes the restriction from all database branches.", + Use: "delete ", + Short: "Delete an IP restriction entry", + Long: `Delete an IP restriction allowlist rule from a PostgreSQL database. + +Rules apply to all branches of the database. Deleting a rule removes the access +it granted; deleting the last remaining rule allows connections from all IPs on +all branches.`, Args: cmdutil.RequiredArgs("database", "entry-id"), Aliases: []string{"rm"}, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { diff --git a/internal/cmd/database/ip_restriction_list.go b/internal/cmd/database/ip_restriction_list.go index ac9635a30..e960f1bf8 100644 --- a/internal/cmd/database/ip_restriction_list.go +++ b/internal/cmd/database/ip_restriction_list.go @@ -14,7 +14,11 @@ func IPRestrictionListCmd(ch *cmdutil.Helper) *cobra.Command { cmd := &cobra.Command{ Use: "list ", Short: "List IP restriction entries for a Postgres database", - Args: cmdutil.RequiredArgs("database"), + Long: `List IP restriction allowlist rules for a PostgreSQL database. + +Rules apply to all branches of the database. When no rules exist, all +connections are allowed.`, + Args: cmdutil.RequiredArgs("database"), ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { return cmdutil.DatabaseCompletionFunc(ch, cmd, args, toComplete) }, diff --git a/internal/cmd/database/ip_restriction_update.go b/internal/cmd/database/ip_restriction_update.go index 4fea97507..824c1aca1 100644 --- a/internal/cmd/database/ip_restriction_update.go +++ b/internal/cmd/database/ip_restriction_update.go @@ -21,10 +21,13 @@ func IPRestrictionUpdateCmd(ch *cmdutil.Helper) *cobra.Command { cmd := &cobra.Command{ Use: "update ", Short: "Update an IP restriction entry", - Long: `Update an IP restriction entry for a PostgreSQL database. + Long: `Update an IP restriction allowlist rule for a PostgreSQL database. -Only provided flags are changed. Pass an empty --description to clear it. -Pass an empty --schema or --role to allow access for all schemas or roles.`, +Only provided flags are changed. Rules are an allowlist and apply to all +branches of the database (including branches created later). --schema matches +the PostgreSQL logical database name in the connection startup packet (not a +schema within a database). Pass an empty --schema or --role to match all +databases or roles. Pass an empty --description to clear it.`, Args: cmdutil.RequiredArgs("database", "entry-id"), ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { return cmdutil.DatabaseCompletionFunc(ch, cmd, args, toComplete) @@ -90,8 +93,8 @@ Pass an empty --schema or --role to allow access for all schemas or roles.`, } cmd.Flags().StringSliceVar(&flags.cidrs, "cidrs", nil, "IPv4 CIDR ranges to allow (replaces the existing list)") - cmd.Flags().StringVar(&flags.schema, "schema", "", "Postgres schema to restrict (empty for all schemas)") - cmd.Flags().StringVar(&flags.role, "role", "", "Postgres role to restrict (empty for all roles)") + cmd.Flags().StringVar(&flags.schema, "schema", "", "PostgreSQL logical database name to allow (matches the connection database, not a schema; empty for all databases)") + cmd.Flags().StringVar(&flags.role, "role", "", "PostgreSQL role to allow (empty for all roles)") cmd.Flags().StringVar(&flags.description, "description", "", "Description for the IP restriction entry (empty to clear)") return cmd