Skip to content

Commit

Permalink
Merge pull request #90 from coreos/plural
Browse files Browse the repository at this point in the history
Allow multiple verifier proxies, for basic authZ
  • Loading branch information
Jake Moshenko committed Apr 28, 2016
2 parents 85b63a5 + 0ee4513 commit 204f657
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 26 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ The configuration yaml file contains a `jwtproxy` top level config flag, which a
```yaml
jwtproxy:
<Signer Config>
<Verifier Config>

verifier_proxies:
- <Verifier Config>
- <Verifier Config>
```
### Signer Config
Expand Down Expand Up @@ -146,12 +149,12 @@ private_key:
### Verifier Config
Configures and enables the JWT verifying reverse proxy.
Configures and enables one or more JWT verifying reverse proxyies.
```yaml
jwtproxy:
verifier_proxy:
enabled: <bool|true>
verifier_proxies:
- enabled: <bool|true>

# Addr at which to listen for requests
# It can either be an HTTP(s) URL or an UNIX socket path prefixed by 'unix:'
Expand Down
10 changes: 9 additions & 1 deletion cmd/jwtproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ func main() {

func run(config *config.Config) {
// Nothing to run? Abort.
if !config.VerifierProxy.Enabled && !config.SignerProxy.Enabled {
var verifierEnabled bool
for _, verifierCfg := range config.VerifierProxies {
if verifierCfg.Enabled {
verifierEnabled = true
break
}
}

if !verifierEnabled && !config.SignerProxy.Enabled {
log.Error("No proxy is enabled. Terminating.")
return
}
Expand Down
4 changes: 2 additions & 2 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ jwtproxy:
options:
registry: http://localhost:8888/

verifier_proxy:
enabled: true
verifier_proxies:
- enabled: true
listen_addr: :8081
shutdown_timeout: 1m

Expand Down
48 changes: 31 additions & 17 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,35 @@ func (u URL) MarshalYAML() (interface{}, error) {
return nil, nil
}

type DefaultVerifierProxyConfig VerifierProxyConfig

// UnmarshalYAML implements the yaml.Unmarshaler interface for URLs.
func (cfg *VerifierProxyConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
tempCfg := DefaultVerifierProxyConfig{
Enabled: true,
ListenAddr: ":8082",
ShutdownTimeout: 5 * time.Second,
Verifier: VerifierConfig{
MaxSkew: 5 * time.Minute,
MaxTTL: 5 * time.Minute,
NonceStorage: RegistrableComponentConfig{
Type: "local",
Options: map[string]interface{}{
"PurgeInterval": 1 * time.Minute,
},
},
},
}

if err := unmarshal(&tempCfg); err != nil {
return err
}

*cfg = VerifierProxyConfig(tempCfg)

return nil
}

// Represents a config file, which may have configuration for other programs
// as a top level key.
type configFile struct {
Expand All @@ -59,8 +88,8 @@ type configFile struct {

// Config is the global configuration
type Config struct {
SignerProxy SignerProxyConfig `yaml:"signer_proxy"`
VerifierProxy VerifierProxyConfig `yaml:"verifier_proxy"`
SignerProxy SignerProxyConfig `yaml:"signer_proxy"`
VerifierProxies []VerifierProxyConfig `yaml:"verifier_proxies"`
}

type VerifierProxyConfig struct {
Expand Down Expand Up @@ -125,21 +154,6 @@ func DefaultConfig() Config {
},
},
},
VerifierProxy: VerifierProxyConfig{
Enabled: true,
ListenAddr: ":8081",
ShutdownTimeout: 5 * time.Second,
Verifier: VerifierConfig{
MaxSkew: 5 * time.Minute,
MaxTTL: 5 * time.Minute,
NonceStorage: RegistrableComponentConfig{
Type: "local",
Options: map[string]interface{}{
"PurgeInterval": 1 * time.Minute,
},
},
},
},
}
}

Expand Down
6 changes: 4 additions & 2 deletions jwtproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ func RunProxies(config *config.Config) (*stop.Group, chan error) {
go StartForwardProxy(config.SignerProxy, stopper, abort)
}

if config.VerifierProxy.Enabled {
go StartReverseProxy(config.VerifierProxy, stopper, abort)
for _, verifierConfig := range config.VerifierProxies {
if verifierConfig.Enabled {
go StartReverseProxy(verifierConfig, stopper, abort)
}
}

return stopper, abort
Expand Down

0 comments on commit 204f657

Please sign in to comment.