Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proxy server for Dashboard #2684

Merged
merged 14 commits into from
Jun 12, 2020
Merged

Add proxy server for Dashboard #2684

merged 14 commits into from
Jun 12, 2020

Conversation

Yisaer
Copy link
Contributor

@Yisaer Yisaer commented Jun 11, 2020

What problem does this PR solve?

Close #2395

When tlsCluster is enabled, dashboard should be visited after loaded pd client cert in browser which didn't make sense.

What is changed and how does it work?

This pr make discovery service as a proxy-server for the pd dashboard service like following.
When tlsCluster is enabled, the proxy-server would automatically loaded cert from secret and expose the http api. Also, proxy-server ensured that only requestURI started with /dashboard would be redirected. No pdapi would be exposed by proxy-server.

image

Related changes

  • Need to cherry-pick to the release branch

Does this PR introduce a user-facing change?:

Expose `Dashboard` service with `HTTP` endpoint whether `tlsCluster` is enabled.

@Yisaer Yisaer marked this pull request as draft June 11, 2020 05:17
Comment on lines +60 to +63
if strings.HasPrefix(req.RequestURI, "/dashboard") {
director(req)
req.Host = req.URL.Host
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensuring no pdapi would be exposed.

@Yisaer Yisaer marked this pull request as ready for review June 11, 2020 06:09
zjj2wry
zjj2wry previously approved these changes Jun 11, 2020
Copy link
Contributor

@zjj2wry zjj2wry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@cofyc
Copy link
Contributor

cofyc commented Jun 11, 2020

how about passing the part、backend service、tls configs to the discovery service? then this discovery service can be a generic proxy server.

@Yisaer
Copy link
Contributor Author

Yisaer commented Jun 11, 2020

how about passing the part、backend service、tls configs to the discovery service? then this discovery service can be a generic proxy server.

That's ok for me but I think it is not necessary currently as I can't find out second service needed proxy to be exposed.

}
proxy := httputil.NewSingleHostReverseProxy(url)
if url.Scheme == "https" {
tlsConfig, err := pdapi.GetTLSConfig(kubeCli, pdapi.Namespace(namespace), tcName, nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the client secret may be invalid or expired, we need to find a way to refresh HTTP server when the secret is updated
we can mount the secrets into the pod, and reload the TLS when necessary like PD, tidb

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

cmd/discovery/main.go Outdated Show resolved Hide resolved
@Yisaer Yisaer requested review from weekface, cofyc and zjj2wry June 11, 2020 07:27
RootCAs: rootCAs,
}
proxy.Transport = &http.Transport{TLSClientConfig: tlsConfig}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

certs are loaded once at startup, I guess we should reload TLS certificates for every client request

Copy link
Contributor

@cofyc cofyc Jun 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a simple mechanism to make sure this proxy will not fail when the certs are expired
we can also have some unit tests to verify this (this can be tracked in a separate issue)
ref: etcd-io/etcd#7829

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

certs are loaded once at startup, I guess we should reload TLS certificates for every client request

Not sure whether this would be quite time-consuming but is this necessary?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is how PD/TiDB refresh TLS certificates too
it's possible to refresh on expiration (see etcd TODO), but I don't think it's necessary. just read certificates every time
actually these small disk files are cached in buffer in most time

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense. updated. now the proxy would be initialed each time

@Yisaer Yisaer requested a review from cofyc June 11, 2020 10:56
Copy link
Contributor

@zjj2wry zjj2wry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Yisaer Yisaer merged commit 40c2bc9 into pingcap:master Jun 12, 2020
sre-bot pushed a commit to sre-bot/tidb-operator that referenced this pull request Jun 12, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Jun 12, 2020

cherry pick to release-1.1 in PR #2689

sre-bot added a commit that referenced this pull request Jun 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Procedure to access TiDB dashboard with TLS enabled
5 participants