diff --git a/README.md b/README.md index 353bd8640..da759f04f 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,33 @@ $ S3_GW_PEERS_0_ADDRESS=grpcs://192.168.130.72:8080 \ neofs-s3-gw ``` +## Domains + +By default, s3-gw enable only `path-style access`. +To be able to use both: `virtual-hosted-style` and `path-style` access you must configure `listen_domains`: + +```shell +$ neofs-s3-gw -p 192.168.130.72:8080 --wallet wallet.json --listen_domains your.first.domain --listen_domains your.second.domain +``` + +So now you can use (e.g. `HeadBucket`. Make sure DNS is properly configured): + +```shell +$ curl --head http://bucket-name.your.first.domain:8080 +HTTP/1.1 200 OK +... +``` + +or + +```shell +$ curl --head http://your.second.domain:8080/bucket-name +HTTP/1.1 200 OK +... +``` + +Also, you can configure domains using `.env` variables or `yaml` file. + ## Documentation - [Configuration](./docs/configuration.md) diff --git a/cmd/s3-gw/app.go b/cmd/s3-gw/app.go index 85bf8c886..d8ec9774d 100644 --- a/cmd/s3-gw/app.go +++ b/cmd/s3-gw/app.go @@ -265,7 +265,7 @@ func (a *App) Server(ctx context.Context) { router := mux.NewRouter().SkipClean(true).UseEncodedPath() // Attach S3 API: - domains := fetchDomains(a.cfg) + domains := a.cfg.GetStringSlice(cfgListenDomains) a.log.Info("fetch domains, prepare to use API", zap.Strings("domains", domains)) api.Attach(router, domains, a.maxClients, a.api, a.ctr, a.log) diff --git a/cmd/s3-gw/app_settings.go b/cmd/s3-gw/app_settings.go index bedaa247d..eaa12a05a 100644 --- a/cmd/s3-gw/app_settings.go +++ b/cmd/s3-gw/app_settings.go @@ -161,21 +161,6 @@ func fetchPeers(l *zap.Logger, v *viper.Viper) []pool.NodeParam { return nodes } -func fetchDomains(v *viper.Viper) []string { - cnt := v.GetInt(cfgListenDomains + ".count") - res := make([]string, 0, cnt) - for i := 0; ; i++ { - domain := v.GetString(cfgListenDomains + "." + strconv.Itoa(i)) - if domain == "" { - break - } - - res = append(res, domain) - } - - return res -} - func newSettings() *viper.Viper { v := viper.New() @@ -216,7 +201,7 @@ func newSettings() *viper.Viper { flags.StringP(cfgRPCEndpoint, "r", "", "set RPC endpoint") resolveMethods := flags.StringSlice(cfgResolveOrder, []string{resolver.DNSResolver}, "set bucket name resolve order") - domains := flags.StringArrayP(cfgListenDomains, "d", nil, "set domains to be listened") + domains := flags.StringSliceP(cfgListenDomains, "d", nil, "set domains to be listened") // set defaults: @@ -264,11 +249,7 @@ func newSettings() *viper.Viper { } if domains != nil && len(*domains) > 0 { - for i := range *domains { - v.SetDefault(cfgListenDomains+"."+strconv.Itoa(i), (*domains)[i]) - } - - v.SetDefault(cfgListenDomains+".count", len(*domains)) + v.SetDefault(cfgListenDomains, *domains) } switch { diff --git a/config/config.env b/config/config.env index 61fdfc9bc..b4ee0eb02 100644 --- a/config/config.env +++ b/config/config.env @@ -28,6 +28,9 @@ S3_GW_LISTEN_ADDRESS=0.0.0.0:8080 S3_GW_TLS_CERT_FILE=/path/to/tls/cert S3_GW_TLS_KEY_FILE=/path/to/tls/key +# Domains to be able to use virtual-hosted-style access to bucket. +S3_GW_LISTEN_DOMAINS=s3dev.neofs.devenv + # Config file S3_GW_CONFIG=/path/to/config/yaml diff --git a/config/config.yaml b/config/config.yaml index ae21863f0..70f8a10c1 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -31,6 +31,10 @@ tls: cert_file: /path/to/cert key_file: /path/to/key +# Domains to be able to use virtual-hosted-style access to bucket. +listen_domains: + - s3dev.neofs.devenv + logger: level: debug diff --git a/docs/configuration.md b/docs/configuration.md index 7d4adcf98..236ce2550 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -140,6 +140,10 @@ There are some custom types used for brevity: ```yaml listen_address: 0.0.0.0:8084 +listen_domains: + - s3dev.neofs.devenv + - s3dev2.neofs.devenv + rpc_endpoint: http://morph-chain.neofs.devenv:30333 resolve_order: - nns @@ -163,6 +167,7 @@ allowed_access_key_id_prefixes: | Parameter | Type | Default value | Description | |----------------------------------|------------|----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `listen_address` | `string` | `0.0.0.0:8080` | The address that the gateway is listening on. | +| `listen_domains` | `[]string` | | Domains to be able to use virtual-hosted-style access to bucket. | | `rpc_endpoint` | `string` | | The address of the RPC host to which the gateway connects to resolve bucket names (required to use the `nns` resolver). | | `resolve_order` | `[]string` | `[dns]` | Order of bucket name resolvers to use. Available resolvers: `dns`, `nns`. | | | `connect_timeout` | `duration` | `10s` | Timeout to connect to a node. |