Skip to content

Commit 79df6d7

Browse files
author
omer-topal
authored
Merge pull request #2824 from Permify/fix/separate-http-grpc-target-host
fix: separate HTTP bind host from gRPC gateway target host
2 parents dc04881 + fcac8d1 commit 79df6d7

8 files changed

Lines changed: 43 additions & 5 deletions

File tree

docs/setting-up/configuration.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ docker run -p 3476:3476 -p 3478:3478 ghcr.io/permify/permify --help
2323
# including whether or not TLS is enabled and the certificate and
2424
# key file locations.
2525
server:
26+
host: ""
2627
rate_limit: 100
2728
http:
2829
enabled: true
2930
port: 3476
31+
grpc_target_host: 127.0.0.1
3032
tls:
3133
enabled: true
3234
cert: /etc/letsencrypt/live/yourdomain.com/fullchain.pem
@@ -137,10 +139,12 @@ Server options to run Permify. (`grpc` and `http` available for now.)
137139

138140
```
139141
├── server
142+
├── host
140143
├── rate_limit
141144
├── (`grpc` or `http`)
142145
│ ├── enabled
143146
│ ├── port
147+
│ ├── grpc_target_host
144148
│ └── tls
145149
│ ├── enabled
146150
│ ├── cert
@@ -151,10 +155,12 @@ Server options to run Permify. (`grpc` and `http` available for now.)
151155

152156
| Required | Argument | Default | Description |
153157
|----------|---------------------------|---------|---------------------------------------------------------------------|
158+
| [ ] | host | "" | host/interface to bind the HTTP server. |
154159
| [ ] | rate_limit | 100 | the maximum number of requests the server should handle per second. |
155160
| [x] | [ server_type ] | - | server option type can either be `grpc` or `http`. |
156161
| [ ] | enabled (for server type) | true | switch option for server. |
157162
| [x] | port | - | port that server run on. |
163+
| [ ] | grpc_target_host (HTTP) |127.0.0.1| host the HTTP gateway uses to connect to the local gRPC server. |
158164
| [x] | tls | - | transport layer security options. |
159165
| [ ] | enabled (for tls) | false | switch option for tls |
160166
| [ ] | cert | - | tls certificate path. |
@@ -164,13 +170,15 @@ Server options to run Permify. (`grpc` and `http` available for now.)
164170

165171
| Argument | ENV | Type |
166172
|---------------------------|-----------------------------------|--------------|
173+
| server-host | PERMIFY_SERVER_HOST | string |
167174
| rate_limit | PERMIFY_RATE_LIMIT | int |
168175
| grpc-port | PERMIFY_GRPC_PORT | string |
169176
| grpc-tls-enabled | PERMIFY_GRPC_TLS_ENABLED | boolean |
170177
| grpc-tls-key-path | PERMIFY_GRPC_TLS_KEY_PATH | string |
171178
| grpc-tls-cert-path | PERMIFY_GRPC_TLS_CERT_PATH | string |
172179
| http-enabled | PERMIFY_HTTP_ENABLED | boolean |
173180
| http-port | PERMIFY_HTTP_PORT | string |
181+
| http-grpc-target-host | PERMIFY_HTTP_GRPC_TARGET_HOST | string |
174182
| http-tls-key-path | PERMIFY_HTTP_TLS_KEY_PATH | string |
175183
| http-tls-cert-path | PERMIFY_HTTP_TLS_CERT_PATH | string |
176184
| http-cors-allowed-origins | PERMIFY_HTTP_CORS_ALLOWED_ORIGINS | string array |

example.config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ account_id: ""
44
# including whether or not TLS is enabled and the certificate and
55
# key file locations.
66
server:
7+
host: ""
78
rate_limit: 100
89
http:
910
enabled: true
1011
port: 3476
12+
grpc_target_host: 127.0.0.1
1113
tls:
1214
enabled: false
1315
cert: /etc/letsencrypt/live/yourdomain.com/fullchain.pem

internal/config/config.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type (
3838
HTTP struct {
3939
Enabled bool `mapstructure:"enabled"` // Whether the HTTP server is enabled
4040
Port string `mapstructure:"port"` // Port for the HTTP server
41+
GRPCTargetHost string `mapstructure:"grpc_target_host"` // Host the HTTP gateway uses to reach the local gRPC server
4142
TLSConfig TLSConfig `mapstructure:"tls"` // TLS configuration for the HTTP server
4243
CORSAllowedOrigins []string `mapstructure:"cors_allowed_origins"` // List of allowed origins for CORS
4344
CORSAllowedHeaders []string `mapstructure:"cors_allowed_headers"` // List of allowed headers for CORS
@@ -284,10 +285,11 @@ func DefaultConfig() *Config {
284285
AccountID: "",
285286
Server: Server{
286287
NameOverride: "",
287-
Host: "127.0.0.1",
288+
Host: "",
288289
HTTP: HTTP{
289-
Enabled: true,
290-
Port: "3476",
290+
Enabled: true,
291+
Port: "3476",
292+
GRPCTargetHost: "127.0.0.1",
291293
TLSConfig: TLSConfig{
292294
Enabled: false,
293295
},

internal/config/config_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ func TestNewConfig_FileNotFound(t *testing.T) {
1818
assert.NotNil(t, cfg)
1919

2020
// Check if default values are applied correctly
21+
assert.Equal(t, "", cfg.Server.Host)
2122
assert.Equal(t, "3476", cfg.Server.HTTP.Port)
23+
assert.Equal(t, "127.0.0.1", cfg.Server.HTTP.GRPCTargetHost)
2224
assert.Equal(t, "3478", cfg.Server.GRPC.Port)
2325
assert.Equal(t, "info", cfg.Log.Level)
2426
}
@@ -59,6 +61,8 @@ logger:
5961
assert.Equal(t, "debug", cfg.Log.Level)
6062

6163
// Check if default values are applied correctly
64+
assert.Equal(t, "", cfg.Server.Host)
65+
assert.Equal(t, "127.0.0.1", cfg.Server.HTTP.GRPCTargetHost)
6266
assert.False(t, cfg.Server.HTTP.TLSConfig.Enabled)
6367
assert.False(t, cfg.Server.GRPC.TLSConfig.Enabled)
6468
assert.False(t, cfg.Profiler.Enabled)
@@ -131,6 +135,8 @@ database:
131135
assert.Equal(t, "postgres://user:password@localhost/dbname", cfg.Database.URI)
132136

133137
// Check if default values are applied correctly
138+
assert.Equal(t, "", cfg.Server.Host)
139+
assert.Equal(t, "127.0.0.1", cfg.Server.HTTP.GRPCTargetHost)
134140
assert.Equal(t, "3478", cfg.Server.GRPC.Port)
135141
assert.False(t, cfg.Server.HTTP.TLSConfig.Enabled)
136142
assert.False(t, cfg.Server.GRPC.TLSConfig.Enabled)

internal/servers/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ func (s *Container) Run(
269269
options = append(options, grpc.WithTransportCredentials(insecure.NewCredentials()))
270270
}
271271

272-
targetAddr := net.JoinHostPort(srv.Host, srv.GRPC.Port) // gRPC server address
273-
conn, err := grpc.NewClient(targetAddr, options...) // Create gRPC client connection
272+
targetAddr := net.JoinHostPort(srv.HTTP.GRPCTargetHost, srv.GRPC.Port)
273+
conn, err := grpc.NewClient(targetAddr, options...) // Create gRPC client connection
274274
if err != nil {
275275
return err
276276
}

pkg/cmd/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ func NewConfigCommand() *cobra.Command {
3030
f.Bool("http-enabled", conf.Server.HTTP.Enabled, "switch option for HTTP server")
3131
f.String("account-id", conf.AccountID, "account id")
3232
f.Int64("server-rate-limit", conf.Server.RateLimit, "the maximum number of requests the server should handle per second")
33+
f.String("server-host", conf.Server.Host, "host/interface to bind the HTTP server")
3334
f.String("server-name-override", conf.Server.NameOverride, "server name override")
3435
f.String("grpc-port", conf.Server.GRPC.Port, "port that GRPC server run on")
3536
f.Bool("grpc-tls-enabled", conf.Server.GRPC.TLSConfig.Enabled, "switch option for GRPC tls server")
3637
f.String("grpc-tls-key-path", conf.Server.GRPC.TLSConfig.KeyPath, "GRPC tls key path")
3738
f.String("grpc-tls-cert-path", conf.Server.GRPC.TLSConfig.CertPath, "GRPC tls certificate path")
3839
f.String("http-port", conf.Server.HTTP.Port, "HTTP port address")
40+
f.String("http-grpc-target-host", conf.Server.HTTP.GRPCTargetHost, "host the HTTP gateway uses to connect to the local gRPC server")
3941
f.Bool("http-tls-enabled", conf.Server.HTTP.TLSConfig.Enabled, "switch option for HTTP tls server")
4042
f.String("http-tls-key-path", conf.Server.HTTP.TLSConfig.KeyPath, "HTTP tls key path")
4143
f.String("http-tls-cert-path", conf.Server.HTTP.TLSConfig.CertPath, "HTTP tls certificate path")
@@ -154,12 +156,14 @@ func conf() func(cmd *cobra.Command, args []string) error { // Return config han
154156
data = append(data,
155157
[]string{"account_id", cfg.AccountID, getKeyOrigin(cmd, "account-id", "PERMIFY_ACCOUNT_ID")},
156158
// SERVER
159+
[]string{"server.host", cfg.Server.Host, getKeyOrigin(cmd, "server-host", "PERMIFY_SERVER_HOST")},
157160
[]string{"server.name_override", fmt.Sprintf("%v", cfg.Server.NameOverride), getKeyOrigin(cmd, "server-name-override", "PERMIFY_NAME_OVERRIDE")},
158161
[]string{"server.rate_limit", fmt.Sprintf("%v", cfg.Server.RateLimit), getKeyOrigin(cmd, "server-rate-limit", "PERMIFY_RATE_LIMIT")},
159162
[]string{"server.grpc.port", cfg.Server.GRPC.Port, getKeyOrigin(cmd, "grpc-port", "PERMIFY_GRPC_PORT")},
160163
[]string{"server.grpc.tls.enabled", fmt.Sprintf("%v", cfg.Server.GRPC.TLSConfig.Enabled), getKeyOrigin(cmd, "grpc-tls-enabled", "PERMIFY_GRPC_TLS_ENABLED")},
161164
[]string{"server.grpc.tls.cert", cfg.Server.GRPC.TLSConfig.CertPath, getKeyOrigin(cmd, "grpc-tls-cert-path", "PERMIFY_GRPC_TLS_CERT_PATH")},
162165
[]string{"server.http.enabled", fmt.Sprintf("%v", cfg.Server.HTTP.Enabled), getKeyOrigin(cmd, "http-enabled", "PERMIFY_HTTP_ENABLED")},
166+
[]string{"server.http.grpc_target_host", cfg.Server.HTTP.GRPCTargetHost, getKeyOrigin(cmd, "http-grpc-target-host", "PERMIFY_HTTP_GRPC_TARGET_HOST")},
163167
[]string{"server.http.tls.enabled", fmt.Sprintf("%v", cfg.Server.HTTP.TLSConfig.Enabled), getKeyOrigin(cmd, "http-tls-enabled", "PERMIFY_HTTP_TLS_ENABLED")},
164168
[]string{"server.http.tls.key", HideSecret(cfg.Server.HTTP.TLSConfig.KeyPath), getKeyOrigin(cmd, "http-tls-key-path", "PERMIFY_HTTP_TLS_KEY_PATH")},
165169
[]string{"server.http.tls.cert", HideSecret(cfg.Server.HTTP.TLSConfig.CertPath), getKeyOrigin(cmd, "http-tls-cert-path", "PERMIFY_HTTP_TLS_CERT_PATH")},

pkg/cmd/flags/serve.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ func RegisterServeFlags(flags *pflag.FlagSet) {
2929
panic(err)
3030
}
3131

32+
if err = viper.BindPFlag("server.host", flags.Lookup("server-host")); err != nil {
33+
panic(err)
34+
}
35+
if err = viper.BindEnv("server.host", "PERMIFY_SERVER_HOST"); err != nil {
36+
panic(err)
37+
}
38+
3239
if err = viper.BindPFlag("server.name_override", flags.Lookup("server-name-override")); err != nil {
3340
panic(err)
3441
}
@@ -80,6 +87,13 @@ func RegisterServeFlags(flags *pflag.FlagSet) {
8087
panic(err)
8188
}
8289

90+
if err = viper.BindPFlag("server.http.grpc_target_host", flags.Lookup("http-grpc-target-host")); err != nil {
91+
panic(err)
92+
}
93+
if err = viper.BindEnv("server.http.grpc_target_host", "PERMIFY_HTTP_GRPC_TARGET_HOST"); err != nil {
94+
panic(err)
95+
}
96+
8397
if err = viper.BindPFlag("server.http.tls.enabled", flags.Lookup("http-tls-enabled")); err != nil {
8498
panic(err)
8599
}

pkg/cmd/serve.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ func NewServeCommand() *cobra.Command {
6060
f.Bool("http-enabled", conf.Server.HTTP.Enabled, "switch option for HTTP server")
6161
f.String("account-id", conf.AccountID, "account id")
6262
f.Int64("server-rate-limit", conf.Server.RateLimit, "the maximum number of requests the server should handle per second")
63+
f.String("server-host", conf.Server.Host, "host/interface to bind the HTTP server")
6364
f.String("server-name-override", conf.Server.NameOverride, "server name override")
6465
f.String("grpc-port", conf.Server.GRPC.Port, "port that GRPC server run on")
6566
f.Bool("grpc-tls-enabled", conf.Server.GRPC.TLSConfig.Enabled, "switch option for GRPC tls server")
6667
f.String("grpc-tls-key-path", conf.Server.GRPC.TLSConfig.KeyPath, "GRPC tls key path")
6768
f.String("grpc-tls-cert-path", conf.Server.GRPC.TLSConfig.CertPath, "GRPC tls certificate path")
6869
f.String("http-port", conf.Server.HTTP.Port, "HTTP port address")
70+
f.String("http-grpc-target-host", conf.Server.HTTP.GRPCTargetHost, "host the HTTP gateway uses to connect to the local gRPC server")
6971
f.Bool("http-tls-enabled", conf.Server.HTTP.TLSConfig.Enabled, "switch option for HTTP tls server")
7072
f.String("http-tls-key-path", conf.Server.HTTP.TLSConfig.KeyPath, "HTTP tls key path")
7173
f.String("http-tls-cert-path", conf.Server.HTTP.TLSConfig.CertPath, "HTTP tls certificate path")

0 commit comments

Comments
 (0)