-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User params #33
User params #33
Changes from 5 commits
a4da612
c20ea70
d47905d
11ab8cf
ab79a66
144939e
e80537f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -327,7 +327,7 @@ an instant cache flush may be built on top of cache namespaces - just switch to | |
to flush the cache. | ||
|
||
### Security | ||
`Chproxy` removes all the query params from input requests (except the `query`, `database`, `default_format`, `compress`, `decompress`, `enable_http_compression`) | ||
`Chproxy` removes all the query params from input requests (except the user's [params](https://github.com/Vertamedia/chproxy/blob/master/config#param_groups_config) and the `query`, `database`, `default_format`, `compress`, `decompress`, `enable_http_compression`) | ||
before proxying them to `ClickHouse` nodes. This prevents from unsafe overriding | ||
of various `ClickHouse` [settings](http://clickhouse-docs.readthedocs.io/en/latest/interfaces/http_interface.html). | ||
|
||
|
@@ -391,6 +391,29 @@ network_groups: | |
- name: "reporting-apps" | ||
networks: ["10.10.10.0/24"] | ||
|
||
# Optional list of GET params to send with each request | ||
param_groups: | ||
# Group name, which may be passed into `params` option on the `user` level. | ||
- name: "cron-job" | ||
# List of key-value params to send | ||
params: | ||
- key: "max_memory_usage" | ||
value: "40000000000" | ||
|
||
- key: "max_bytes_before_external_group_by" | ||
value: "20000000000" | ||
|
||
- name: "web" | ||
params: | ||
- key: "max_memory_usage" | ||
value: "5000000000" | ||
|
||
- key: "max_columns_to_read" | ||
value: "30" | ||
|
||
- key: "max_execution_time" | ||
value: "30" | ||
|
||
# Settings for `chproxy` input interfaces. | ||
server: | ||
# Configs for input http interface. | ||
|
@@ -420,7 +443,6 @@ server: | |
# Certificates are automatically issued and renewed if this section | ||
# is present. | ||
# There is no need in cert_file and key_file if this section is present. | ||
# Autocert requires application to listen on :80 port for certificate generation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this line has been removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was replaced with config/testdata/full.yml where this line was absent. Will add it in both places |
||
autocert: | ||
# Path to the directory where autocert certs are cached. | ||
cache_dir: "certs_dir" | ||
|
@@ -467,6 +489,11 @@ users: | |
# By default responses aren't cached. | ||
cache: "longterm" | ||
|
||
# ParamGroup name to use | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Substitute this with:
|
||
# | ||
# By default no additional params are used | ||
params: "web" | ||
|
||
# The maximum number of requests that may wait for their chance | ||
# to be executed because they cannot run now due to the current limits. | ||
# | ||
|
@@ -488,6 +515,8 @@ users: | |
to_user: "default" | ||
allowed_networks: ["office", "1.2.3.0/24"] | ||
|
||
params: "cron-job" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably, this line must be removed in order to match |
||
|
||
# The maximum number of concurrently running queries for the user. | ||
# | ||
# By default there is no limit on the number of concurrently | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,8 @@ type Config struct { | |
|
||
Caches []Cache `yaml:"caches,omitempty"` | ||
|
||
ParamGroups []ParamGroup `yaml:"param_groups,omitempty"` | ||
|
||
// Catches all undefined fields | ||
XXX map[string]interface{} `yaml:",inline"` | ||
|
||
|
@@ -411,6 +413,9 @@ type User struct { | |
// Name of Cache configuration to use for responses of this user | ||
Cache string `yaml:"cache,omitempty"` | ||
|
||
// Name of ParamGroup to use | ||
Params string `yaml:"params,omitempty"` | ||
|
||
// Catches all undefined fields | ||
XXX map[string]interface{} `yaml:",inline"` | ||
} | ||
|
@@ -464,7 +469,13 @@ func (ng *NetworkGroups) UnmarshalYAML(unmarshal func(interface{}) error) error | |
if err := unmarshal((*plain)(ng)); err != nil { | ||
return err | ||
} | ||
return checkOverflow(ng.XXX, "network_groups") | ||
if len(ng.Name) == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably, this change should be pushed in a separate commit if it is correct, since it is unrelated to the PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True. Should be fixed in a separate PR |
||
return fmt.Errorf("`network_group.name` must be specified") | ||
} | ||
if len(ng.Networks) == 0 { | ||
return fmt.Errorf("`network_group.networks` must contain at least one network") | ||
} | ||
return checkOverflow(ng.XXX, fmt.Sprintf("network_group %q", ng.Name)) | ||
} | ||
|
||
// NetworksOrGroups is a list of strings with names of NetworkGroups | ||
|
@@ -515,6 +526,42 @@ func (c *Cache) UnmarshalYAML(unmarshal func(interface{}) error) error { | |
return checkOverflow(c.XXX, fmt.Sprintf("cache %q", c.Name)) | ||
} | ||
|
||
// ParamGroup describes named group of GET params | ||
// for sending with each query | ||
type ParamGroup struct { | ||
// Name of configuration for further assign | ||
Name string `yaml:"name"` | ||
|
||
// Params contains a list of GET params | ||
Params []Param `yaml:"params"` | ||
|
||
// Catches all undefined fields | ||
XXX map[string]interface{} `yaml:",inline"` | ||
} | ||
|
||
// UnmarshalYAML implements the yaml.Unmarshaler interface. | ||
func (pg *ParamGroup) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
type plain ParamGroup | ||
if err := unmarshal((*plain)(pg)); err != nil { | ||
return err | ||
} | ||
if len(pg.Name) == 0 { | ||
return fmt.Errorf("`param_group.name` must be specified") | ||
} | ||
if len(pg.Params) == 0 { | ||
return fmt.Errorf("`param_group.params` must contain at least one param") | ||
} | ||
return checkOverflow(pg.XXX, fmt.Sprintf("param_group %q", pg.Name)) | ||
} | ||
|
||
// Params describes URL param value | ||
type Param struct { | ||
// Key is a name of params | ||
Key string `yaml:"key"` | ||
// Value is a value of param | ||
Value string `yaml:"value"` | ||
} | ||
|
||
// ClusterUser describes simplest <users> configuration | ||
type ClusterUser struct { | ||
// User name in ClickHouse users.xml config | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,40 @@ func TestLoadConfig(t *testing.T) { | |
HeartBeatInterval: Duration(5 * time.Second), | ||
}, | ||
}, | ||
|
||
ParamGroups: []ParamGroup{ | ||
{ | ||
Name: "cron-job", | ||
Params: []Param{ | ||
{ | ||
Key: "max_memory_usage", | ||
Value: "40000000000", | ||
}, | ||
{ | ||
Key: "max_bytes_before_external_group_by", | ||
Value: "20000000000", | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: "web", | ||
Params: []Param{ | ||
{ | ||
Key: "max_memory_usage", | ||
Value: "5000000000", | ||
}, | ||
{ | ||
Key: "max_columns_to_read", | ||
Value: "30", | ||
}, | ||
{ | ||
Key: "max_execution_time", | ||
Value: "30", | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
Users: []User{ | ||
{ | ||
Name: "web", | ||
|
@@ -116,6 +150,7 @@ func TestLoadConfig(t *testing.T) { | |
MaxQueueSize: 100, | ||
MaxQueueTime: Duration(35 * time.Second), | ||
Cache: "longterm", | ||
Params: "web", | ||
}, | ||
{ | ||
Name: "default", | ||
|
@@ -125,6 +160,7 @@ func TestLoadConfig(t *testing.T) { | |
MaxExecutionTime: Duration(time.Minute), | ||
DenyHTTPS: true, | ||
NetworksOrGroups: []string{"office", "1.2.3.0/24"}, | ||
Params: "cron-job", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either remove Params from this user or add a user without params in order to verify user config without params works as expected. |
||
}, | ||
}, | ||
NetworkGroups: []NetworkGroups{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
substitute this with the following text: