cloudapi: Add x-rh-identity header filter

This commit is contained in:
sanne 2021-05-26 15:06:13 +02:00 committed by Tom Gundersen
parent 2a42d05a10
commit 19db3ff1d4
4 changed files with 112 additions and 15 deletions

View file

@ -111,17 +111,21 @@ func (c *Composer) InitAPI(cert, key string, l net.Listener) error {
c.api = cloudapi.NewServer(c.workers, c.rpm, c.distros)
c.koji = kojiapi.NewServer(c.logger, c.workers, c.rpm, c.distros)
tlsConfig, err := createTLSConfig(&connectionConfig{
CACertFile: c.config.Koji.CA,
ServerKeyFile: key,
ServerCertFile: cert,
AllowedDomains: c.config.Koji.AllowedDomains,
})
if err != nil {
return fmt.Errorf("Error creating TLS configuration: %v", err)
}
if len(c.config.ComposerAPI.IdentityFilter) > 0 {
c.apiListener = l
} else {
tlsConfig, err := createTLSConfig(&connectionConfig{
CACertFile: c.config.Koji.CA,
ServerKeyFile: key,
ServerCertFile: cert,
AllowedDomains: c.config.Koji.AllowedDomains,
})
if err != nil {
return fmt.Errorf("Error creating TLS configuration: %v", err)
}
c.apiListener = tls.NewListener(l, tlsConfig)
c.apiListener = tls.NewListener(l, tlsConfig)
}
return nil
}
@ -195,7 +199,7 @@ func (c *Composer) Start() error {
// Add a "/" here, because http.ServeMux expects the
// trailing slash for rooted subtrees, whereas the
// handler functions don't.
mux.Handle(apiRoute+"/", c.api.Handler(apiRoute))
mux.Handle(apiRoute+"/", c.api.Handler(apiRoute, c.config.ComposerAPI.IdentityFilter))
mux.Handle(kojiRoute+"/", c.koji.Handler(kojiRoute))
s := &http.Server{

View file

@ -15,6 +15,9 @@ type ComposerConfigFile struct {
AllowedDomains []string `toml:"allowed_domains"`
CA string `toml:"ca"`
} `toml:"worker"`
ComposerAPI struct {
IdentityFilter []string `toml:"identity_filter"`
} `toml:"composer_api"`
}
func LoadConfig(name string) (*ComposerConfigFile, error) {