Skip to content

Commit ae96ce8

Browse files
committed
remove support for setting CORS headers (deprecated)
Configuring CORS headers was deprecated in docker 27.0 through 7ea9acc, which disabled them by default with a temporary `DOCKERD_DEPRECATED_CORS_HEADER` env-var to allow using the option. This patch removes the feature altogether; the flag is kept for one more release to allow printing a more informative error, but can be removed in the next release. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 733755d commit ae96ce8

4 files changed

Lines changed: 9 additions & 51 deletions

File tree

api/server/middleware/cors.go

Lines changed: 0 additions & 42 deletions
This file was deleted.

cmd/dockerd/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ func installCommonConfigFlags(conf *config.Config, flags *pflag.FlagSet) {
7575

7676
// Deprecated flags / options
7777

78-
flags.StringVar(&conf.CorsHeaders, "api-cors-header", "", "Set CORS headers in the Engine API; deprecated, and will be removed in the next release")
78+
// TODO(thaJeztah): option is used to produce error when used; remove in next release
79+
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")
7980
_ = flags.MarkDeprecated("api-cors-header", "accessing Docker API through a browser is insecure; use a reverse proxy if you need CORS headers")
8081
flags.BoolVarP(&conf.AutoRestart, "restart", "r", true, "--restart on the daemon has been deprecated in favor of --restart policies on docker run")
8182
_ = flags.MarkDeprecated("restart", "Please use a restart policy on docker run")

cmd/dockerd/daemon.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ func (opts routerOptions) Build() []router.Router {
735735
return routers
736736
}
737737

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

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

748-
if cfg.CorsHeaders != "" && os.Getenv("DOCKERD_DEPRECATED_CORS_HEADER") != "" {
749-
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.`)
750-
c := middleware.NewCORSMiddleware(cfg.CorsHeaders) //nolint:staticcheck // ignore SA1019 (NewCORSMiddleware is deprecated); will be removed in the next release.
751-
s.UseMiddleware(c)
752-
}
753-
754748
authzMiddleware := authorization.NewMiddleware(cfg.AuthorizationPlugins, pluginStore)
755749
s.UseMiddleware(authzMiddleware)
756750
return authzMiddleware, nil

daemon/config/config.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ type CommonConfig struct {
160160
Root string `json:"data-root,omitempty"`
161161
ExecRoot string `json:"exec-root,omitempty"`
162162
SocketGroup string `json:"group,omitempty"`
163-
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.
163+
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
164164

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

686+
if config.CorsHeaders != "" {
687+
// TODO(thaJeztah): option is used to produce error when used; remove in next release
688+
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`)
689+
}
690+
686691
// validate platform-specific settings
687692
return config.ValidatePlatformConfig()
688693
}

0 commit comments

Comments
 (0)