Skip to content

Commit 483faf9

Browse files
committed
Merge pull request #1 from liggitt/public_bind
Separate asset bind and asset public addr
2 parents e3a2c83 + 82d1ecc commit 483faf9

File tree

3 files changed

+50
-32
lines changed

3 files changed

+50
-32
lines changed

pkg/cmd/server/origin/auth.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,13 @@ var (
7676
)
7777

7878
type AuthConfig struct {
79-
MasterAddr string
80-
MasterRoots *x509.CertPool
81-
SessionSecrets []string
82-
EtcdHelper tools.EtcdHelper
79+
// URL to call internally during token request
80+
MasterAddr string
81+
// URL to direct browsers to the master on
82+
MasterPublicAddr string
83+
MasterRoots *x509.CertPool
84+
SessionSecrets []string
85+
EtcdHelper tools.EtcdHelper
8386
}
8487

8588
// InstallAPI starts an OAuth2 server and registers the supported REST APIs
@@ -122,9 +125,9 @@ func (c *AuthConfig) InstallAPI(container *restful.Container) []string {
122125
)
123126
server.Install(mux, OpenShiftOAuthAPIPrefix)
124127

125-
CreateOrUpdateDefaultOAuthClients(c.MasterAddr, oauthEtcd)
128+
CreateOrUpdateDefaultOAuthClients(c.MasterPublicAddr, oauthEtcd)
126129
osOAuthClientConfig := c.NewOpenShiftOAuthClientConfig(&OSBrowserClientBase)
127-
osOAuthClientConfig.RedirectUrl = c.MasterAddr + OpenShiftOAuthAPIPrefix + tokenrequest.DisplayTokenEndpoint
130+
osOAuthClientConfig.RedirectUrl = c.MasterPublicAddr + OpenShiftOAuthAPIPrefix + tokenrequest.DisplayTokenEndpoint
128131

129132
osOAuthClient, _ := osincli.NewClient(osOAuthClientConfig)
130133
if c.MasterRoots != nil {
@@ -157,30 +160,30 @@ func (c *AuthConfig) NewOpenShiftOAuthClientConfig(client *oauthapi.Client) *osi
157160
ClientSecret: client.Secret,
158161
ErrorsInStatusCode: true,
159162
SendClientSecretInParams: true,
160-
AuthorizeUrl: c.MasterAddr + OpenShiftOAuthAPIPrefix + "/authorize",
163+
AuthorizeUrl: c.MasterPublicAddr + OpenShiftOAuthAPIPrefix + "/authorize",
161164
TokenUrl: c.MasterAddr + OpenShiftOAuthAPIPrefix + "/token",
162165
Scope: "",
163166
}
164167
return config
165168
}
166169

167-
func CreateOrUpdateDefaultOAuthClients(masterAddr string, clientRegistry oauthclient.Registry) {
170+
func CreateOrUpdateDefaultOAuthClients(masterPublicAddr string, clientRegistry oauthclient.Registry) {
168171
clientsToEnsure := []*oauthapi.Client{
169172
{
170173
ObjectMeta: kapi.ObjectMeta{
171174
Name: OSBrowserClientBase.Name,
172175
},
173176
Secret: OSBrowserClientBase.Secret,
174177
RespondWithChallenges: OSBrowserClientBase.RespondWithChallenges,
175-
RedirectURIs: []string{masterAddr + OpenShiftOAuthAPIPrefix + tokenrequest.DisplayTokenEndpoint},
178+
RedirectURIs: []string{masterPublicAddr + OpenShiftOAuthAPIPrefix + tokenrequest.DisplayTokenEndpoint},
176179
},
177180
{
178181
ObjectMeta: kapi.ObjectMeta{
179182
Name: OSCliClientBase.Name,
180183
},
181184
Secret: OSCliClientBase.Secret,
182185
RespondWithChallenges: OSCliClientBase.RespondWithChallenges,
183-
RedirectURIs: []string{masterAddr + OpenShiftOAuthAPIPrefix + tokenrequest.DisplayTokenEndpoint},
186+
RedirectURIs: []string{masterPublicAddr + OpenShiftOAuthAPIPrefix + tokenrequest.DisplayTokenEndpoint},
184187
},
185188
}
186189

@@ -256,7 +259,7 @@ func (c *AuthConfig) getAuthenticationHandler(mux cmdutil.Mux, sessionStore sess
256259
}
257260

258261
state := external.DefaultState()
259-
oauthHandler, err := external.NewExternalOAuthRedirector(oauthProvider, state, c.MasterAddr+callbackPath, successHandler, errorHandler, identityMapper)
262+
oauthHandler, err := external.NewExternalOAuthRedirector(oauthProvider, state, c.MasterPublicAddr+callbackPath, successHandler, errorHandler, identityMapper)
260263
if err != nil {
261264
glog.Fatalf("unexpected error: %v", err)
262265
}

pkg/cmd/server/origin/master.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,18 @@ const (
8080

8181
// MasterConfig defines the required parameters for starting the OpenShift master
8282
type MasterConfig struct {
83-
BindAddr string
84-
MasterAddr string
85-
AssetAddr string
83+
// host:port to bind master to
84+
MasterBindAddr string
85+
// host:port to bind asset server to
86+
AssetBindAddr string
87+
// url to access the master API on within the cluster
88+
MasterAddr string
89+
// url to access kubernetes API on within the cluster
8690
KubernetesAddr string
8791
// external clients may need to access APIs at different addresses than internal components do
8892
MasterPublicAddr string
8993
KubernetesPublicAddr string
94+
AssetPublicAddr string
9095

9196
TLS bool
9297

@@ -299,7 +304,7 @@ func (c *MasterConfig) RunAPI(installers ...APIInstaller) {
299304
}
300305

301306
server := &http.Server{
302-
Addr: c.BindAddr,
307+
Addr: c.MasterBindAddr,
303308
Handler: handler,
304309
ReadTimeout: 5 * time.Minute,
305310
WriteTimeout: 5 * time.Minute,
@@ -325,7 +330,7 @@ func (c *MasterConfig) RunAPI(installers ...APIInstaller) {
325330
}, 0)
326331

327332
// Attempt to verify the server came up for 20 seconds (100 tries * 100ms, 100ms timeout per try)
328-
cmdutil.WaitForSuccessfulDial("tcp", c.BindAddr, 100*time.Millisecond, 100*time.Millisecond, 100)
333+
cmdutil.WaitForSuccessfulDial("tcp", c.MasterBindAddr, 100*time.Millisecond, 100*time.Millisecond, 100)
329334
}
330335

331336
// wireAuthenticationHandling creates and binds all the objects that we only care about if authentication is turned on. It's pulled out
@@ -421,7 +426,7 @@ func (c *MasterConfig) RunAssetServer() {
421426
)
422427

423428
server := &http.Server{
424-
Addr: c.AssetAddr,
429+
Addr: c.AssetBindAddr,
425430
Handler: mux,
426431
ReadTimeout: 5 * time.Minute,
427432
WriteTimeout: 5 * time.Minute,
@@ -437,16 +442,18 @@ func (c *MasterConfig) RunAssetServer() {
437442
// This allows certificates to be validated by authenticators, while still allowing other auth types
438443
ClientAuth: tls.RequestClientCert,
439444
}
440-
glog.Infof("Started OpenShift static asset server at https://%s", c.AssetAddr)
445+
glog.Infof("OpenShift UI listening at https://%s", c.AssetBindAddr)
441446
glog.Fatal(server.ListenAndServeTLS(c.AssetCertFile, c.AssetKeyFile))
442447
} else {
443-
glog.Infof("Started OpenShift static asset server at http://%s", c.AssetAddr)
448+
glog.Infof("OpenShift UI listening at https://%s", c.AssetBindAddr)
444449
glog.Fatal(server.ListenAndServe())
445450
}
446451
}, 0)
447452

448453
// Attempt to verify the server came up for 20 seconds (100 tries * 100ms, 100ms timeout per try)
449-
cmdutil.WaitForSuccessfulDial("tcp", c.AssetAddr, 100*time.Millisecond, 100*time.Millisecond, 100)
454+
cmdutil.WaitForSuccessfulDial("tcp", c.AssetBindAddr, 100*time.Millisecond, 100*time.Millisecond, 100)
455+
456+
glog.Infof("OpenShift UI available at %s", c.AssetPublicAddr)
450457
}
451458

452459
// RunBuildController starts the build sync loop for builds and buildConfig processing.

pkg/cmd/server/start.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ func NewCommandStartServer(name string) *cobra.Command {
110110
EtcdAddr: flagtypes.Addr{Value: "0.0.0.0:4001", DefaultScheme: "http", DefaultPort: 4001}.Default(),
111111
KubernetesAddr: flagtypes.Addr{DefaultScheme: "https", DefaultPort: 8443}.Default(),
112112
PortalNet: flagtypes.DefaultIPNet("172.30.17.0/24"),
113-
MasterPublicAddr: flagtypes.Addr{Value: hostname, DefaultScheme: "https", DefaultPort: 443, AllowPrefix: true}.Default(),
114-
KubernetesPublicAddr: flagtypes.Addr{Value: hostname, DefaultScheme: "https", DefaultPort: 443}.Default(),
113+
MasterPublicAddr: flagtypes.Addr{Value: "localhost:8443", DefaultScheme: "https", DefaultPort: 8443, AllowPrefix: true}.Default(),
114+
KubernetesPublicAddr: flagtypes.Addr{Value: "localhost:8443", DefaultScheme: "https", DefaultPort: 8443, AllowPrefix: true}.Default(),
115115

116116
Hostname: hostname,
117117
NodeList: flagtypes.StringList{"127.0.0.1"},
@@ -246,20 +246,27 @@ func start(cfg *config, args []string) error {
246246
k8sPublicAddr = cfg.KubernetesAddr
247247
}
248248

249-
assetAddr := net.JoinHostPort(cfg.BindAddr.Host, strconv.Itoa(cfg.BindAddr.Port+1))
249+
// Derive the asset bind address by incrementing the master bind address port by 1
250+
assetBindAddr := net.JoinHostPort(cfg.BindAddr.Host, strconv.Itoa(cfg.BindAddr.Port+1))
251+
// Derive the asset public address by incrementing the master public address port by 1
252+
assetPublicAddr := *masterPublicAddr.URL
253+
assetPublicAddr.Host = net.JoinHostPort(masterPublicAddr.Host, strconv.Itoa(masterPublicAddr.Port+1))
250254

251255
// always include the all-in-one server's web console as an allowed CORS origin
252256
// always include localhost as an allowed CORS origin
253257
// always include master and kubernetes public addresses as an allowed CORS origin
254-
cfg.CORSAllowedOrigins = append(cfg.CORSAllowedOrigins, assetAddr, "localhost", "127.0.0.1",
255-
cfg.MasterPublicAddr.URL.Host, cfg.KubernetesPublicAddr.URL.Host)
258+
for _, origin := range []string{assetPublicAddr.Host, masterPublicAddr.URL.Host, k8sPublicAddr.URL.Host, "localhost", "127.0.0.1"} {
259+
// TODO: check if origin is already allowed
260+
cfg.CORSAllowedOrigins = append(cfg.CORSAllowedOrigins, origin)
261+
}
256262

257263
osmaster := &origin.MasterConfig{
258-
TLS: cfg.MasterAddr.URL.Scheme == "https",
259-
BindAddr: cfg.BindAddr.URL.Host,
264+
TLS: cfg.BindAddr.URL.Scheme == "https",
265+
MasterBindAddr: cfg.BindAddr.URL.Host,
260266
MasterAddr: cfg.MasterAddr.URL.String(),
261267
MasterPublicAddr: masterPublicAddr.URL.String(),
262-
AssetAddr: assetAddr,
268+
AssetBindAddr: assetBindAddr,
269+
AssetPublicAddr: assetPublicAddr.String(),
263270
KubernetesAddr: cfg.KubernetesAddr.URL.String(),
264271
KubernetesPublicAddr: k8sPublicAddr.URL.String(),
265272
EtcdHelper: etcdHelper,
@@ -344,10 +351,11 @@ func start(cfg *config, args []string) error {
344351
osmaster.EnsureCORSAllowedOrigins(cfg.CORSAllowedOrigins)
345352

346353
auth := &origin.AuthConfig{
347-
MasterAddr: cfg.MasterAddr.URL.String(),
348-
MasterRoots: roots,
349-
SessionSecrets: []string{"secret"},
350-
EtcdHelper: etcdHelper,
354+
MasterAddr: cfg.MasterAddr.URL.String(),
355+
MasterPublicAddr: masterPublicAddr.URL.String(),
356+
MasterRoots: roots,
357+
SessionSecrets: []string{"secret"},
358+
EtcdHelper: etcdHelper,
351359
}
352360

353361
if startKube {

0 commit comments

Comments
 (0)