Skip to content

Commit 5525677

Browse files
committed
Bind pgAdmin to every IPv4 address by default
The upstream default is "127.0.0.1", the IPv4 loopback address, which allows only local connections. Issue: #3809 Issue: PGO-842
1 parent fa8ca2d commit 5525677

File tree

4 files changed

+59
-14
lines changed

4 files changed

+59
-14
lines changed

internal/controller/standalone_pgadmin/configmap.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,19 @@ func configmap(pgadmin *v1beta1.PGAdmin,
8181

8282
// generateConfig generates the config settings for the pgAdmin
8383
func generateConfig(pgadmin *v1beta1.PGAdmin) (string, error) {
84+
settings := map[string]any{
85+
// Bind to all IPv4 addresses by default. "0.0.0.0" here represents INADDR_ANY.
86+
// - https://flask.palletsprojects.com/en/2.2.x/api/#flask.Flask.run
87+
// - https://flask.palletsprojects.com/en/2.3.x/api/#flask.Flask.run
88+
"DEFAULT_SERVER": "0.0.0.0",
89+
}
8490

85-
settings := *pgadmin.Spec.Config.Settings.DeepCopy()
86-
if settings == nil {
87-
settings = make(map[string]interface{})
91+
// Copy any specified settings over the defaults.
92+
for k, v := range pgadmin.Spec.Config.Settings {
93+
settings[k] = v
8894
}
95+
96+
// Write mandatory settings over any specified ones.
8997
// SERVER_MODE must always be enabled when running on a webserver.
9098
// - https://github.com/pgadmin-org/pgadmin4/blob/REL-7_7/web/config.py#L110
9199
settings["SERVER_MODE"] = true

internal/controller/standalone_pgadmin/configmap_test.go

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,60 @@ import (
2727
func TestGenerateConfig(t *testing.T) {
2828
require.ParallelCapacity(t, 0)
2929

30-
expectedString := `{
30+
t.Run("Default", func(t *testing.T) {
31+
pgadmin := new(v1beta1.PGAdmin)
32+
result, err := generateConfig(pgadmin)
33+
34+
assert.NilError(t, err)
35+
assert.Equal(t, result, `{
36+
"DEFAULT_SERVER": "0.0.0.0",
37+
"SERVER_MODE": true,
38+
"UPGRADE_CHECK_ENABLED": false,
39+
"UPGRADE_CHECK_KEY": "",
40+
"UPGRADE_CHECK_URL": ""
41+
}`+"\n")
42+
})
43+
44+
t.Run("Mandatory", func(t *testing.T) {
45+
pgadmin := new(v1beta1.PGAdmin)
46+
pgadmin.Spec.Config.Settings = map[string]any{
47+
"SERVER_MODE": false,
48+
"UPGRADE_CHECK_ENABLED": true,
49+
}
50+
result, err := generateConfig(pgadmin)
51+
52+
assert.NilError(t, err)
53+
assert.Equal(t, result, `{
54+
"DEFAULT_SERVER": "0.0.0.0",
55+
"SERVER_MODE": true,
56+
"UPGRADE_CHECK_ENABLED": false,
57+
"UPGRADE_CHECK_KEY": "",
58+
"UPGRADE_CHECK_URL": ""
59+
}`+"\n")
60+
})
61+
62+
t.Run("Specified", func(t *testing.T) {
63+
pgadmin := new(v1beta1.PGAdmin)
64+
pgadmin.Spec.Config.Settings = map[string]any{
65+
"ALLOWED_HOSTS": []any{"225.0.0.0/8", "226.0.0.0/7", "228.0.0.0/6"},
66+
"DEFAULT_SERVER": "::",
67+
}
68+
result, err := generateConfig(pgadmin)
69+
70+
assert.NilError(t, err)
71+
assert.Equal(t, result, `{
3172
"ALLOWED_HOSTS": [
3273
"225.0.0.0/8",
3374
"226.0.0.0/7",
3475
"228.0.0.0/6"
3576
],
77+
"DEFAULT_SERVER": "::",
3678
"SERVER_MODE": true,
3779
"UPGRADE_CHECK_ENABLED": false,
3880
"UPGRADE_CHECK_KEY": "",
3981
"UPGRADE_CHECK_URL": ""
40-
}
41-
`
42-
pgadmin := new(v1beta1.PGAdmin)
43-
pgadmin.Spec.Config.Settings = map[string]interface{}{
44-
"ALLOWED_HOSTS": []interface{}{"225.0.0.0/8", "226.0.0.0/7", "228.0.0.0/6"},
45-
}
46-
actualString, err := generateConfig(pgadmin)
47-
assert.NilError(t, err)
48-
assert.Equal(t, actualString, expectedString)
82+
}`+"\n")
83+
})
4984
}
5085

5186
func TestGenerateClusterConfig(t *testing.T) {

testing/kuttl/e2e/standalone-pgadmin/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Note: due to the (random) namespace being part of the host, we cannot check the
66

77
* 00:
88
* create a pgadmin with no server groups;
9-
* check the correct existence of the secret, service, configmap, and pod.
9+
* check the correct existence of the secret, configmap, and pod.
1010
* 01: dump the servers from pgAdmin and check that the list is empty.
1111

1212
*Phase two*

testing/kuttl/e2e/standalone-pgadmin/files/00-pgadmin-check.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
apiVersion: v1
23
kind: ConfigMap
34
metadata:
@@ -7,6 +8,7 @@ metadata:
78
data:
89
pgadmin-settings.json: |
910
{
11+
"DEFAULT_SERVER": "0.0.0.0",
1012
"SERVER_MODE": true,
1113
"UPGRADE_CHECK_ENABLED": false,
1214
"UPGRADE_CHECK_KEY": "",

0 commit comments

Comments
 (0)