Skip to content

Commit

Permalink
Merge pull request moby#48209 from thaJeztah/remove_deprecated_cors_h…
Browse files Browse the repository at this point in the history
…eaders

remove support for setting CORS headers (deprecated)
  • Loading branch information
thaJeztah authored Jul 26, 2024
2 parents 951a04c + ae96ce8 commit 08d7b56
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 51 deletions.
42 changes: 0 additions & 42 deletions api/server/middleware/cors.go

This file was deleted.

3 changes: 2 additions & 1 deletion cmd/dockerd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ func installCommonConfigFlags(conf *config.Config, flags *pflag.FlagSet) {

// Deprecated flags / options

flags.StringVar(&conf.CorsHeaders, "api-cors-header", "", "Set CORS headers in the Engine API; deprecated, and will be removed in the next release")
// TODO(thaJeztah): option is used to produce error when used; remove in next release
flags.StringVar(&conf.CorsHeaders, "api-cors-header", "", "Set CORS headers in the Engine API; deprecated: this feature was deprecated in 27.0, and now removed")
_ = flags.MarkDeprecated("api-cors-header", "accessing Docker API through a browser is insecure; use a reverse proxy if you need CORS headers")
flags.BoolVarP(&conf.AutoRestart, "restart", "r", true, "--restart on the daemon has been deprecated in favor of --restart policies on docker run")
_ = flags.MarkDeprecated("restart", "Please use a restart policy on docker run")
Expand Down
8 changes: 1 addition & 7 deletions cmd/dockerd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ func (opts routerOptions) Build() []router.Router {
return routers
}

func initMiddlewares(ctx context.Context, s *apiserver.Server, cfg *config.Config, pluginStore plugingetter.PluginGetter) (*authorization.Middleware, error) {
func initMiddlewares(_ context.Context, s *apiserver.Server, cfg *config.Config, pluginStore plugingetter.PluginGetter) (*authorization.Middleware, error) {
exp := middleware.NewExperimentalMiddleware(cfg.Experimental)
s.UseMiddleware(exp)

Expand All @@ -745,12 +745,6 @@ func initMiddlewares(ctx context.Context, s *apiserver.Server, cfg *config.Confi
}
s.UseMiddleware(*vm)

if cfg.CorsHeaders != "" && os.Getenv("DOCKERD_DEPRECATED_CORS_HEADER") != "" {
log.G(ctx).Warn(`DEPRECATED: The "api-cors-header" config parameter and the dockerd "--api-cors-header" option will be removed in the next release. Use a reverse proxy if you need CORS headers.`)
c := middleware.NewCORSMiddleware(cfg.CorsHeaders) //nolint:staticcheck // ignore SA1019 (NewCORSMiddleware is deprecated); will be removed in the next release.
s.UseMiddleware(c)
}

authzMiddleware := authorization.NewMiddleware(cfg.AuthorizationPlugins, pluginStore)
s.UseMiddleware(authzMiddleware)
return authzMiddleware, nil
Expand Down
7 changes: 6 additions & 1 deletion daemon/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ type CommonConfig struct {
Root string `json:"data-root,omitempty"`
ExecRoot string `json:"exec-root,omitempty"`
SocketGroup string `json:"group,omitempty"`
CorsHeaders string `json:"api-cors-header,omitempty"` // Deprecated: CORS headers should not be set on the API. This feature will be removed in the next release.
CorsHeaders string `json:"api-cors-header,omitempty"` // Deprecated: CORS headers should not be set on the API. This feature will be removed in the next release. // TODO(thaJeztah): option is used to produce error when used; remove in next release

// Proxies holds the proxies that are configured for the daemon.
Proxies `json:"proxies"`
Expand Down Expand Up @@ -683,6 +683,11 @@ func Validate(config *Config) error {
}
}

if config.CorsHeaders != "" {
// TODO(thaJeztah): option is used to produce error when used; remove in next release
return errors.New(`DEPRECATED: The "api-cors-header" config parameter and the dockerd "--api-cors-header" option have been removed; use a reverse proxy if you need CORS headers`)
}

// validate platform-specific settings
return config.ValidatePlatformConfig()
}
Expand Down

0 comments on commit 08d7b56

Please sign in to comment.