Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
comms
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xx network
comms
Commits
364eeb32
Commit
364eeb32
authored
2 years ago
by
Jonah Husson
Browse files
Options
Downloads
Patches
Plain Diff
Update comments
parent
c1d9fafd
No related branches found
No related tags found
4 merge requests
!47
Project/https support
,
!46
Swap to using GetCertificate in tlsconf so the cert can be changed
,
!45
re-enable https for servewithweb, add function to provide certs when available
,
!39
Merge release into master
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
connect/comms.go
+19
-8
19 additions, 8 deletions
connect/comms.go
with
19 additions
and
8 deletions
connect/comms.go
+
19
−
8
View file @
364eeb32
...
...
@@ -161,6 +161,7 @@ listen:
netListener
:
lis
,
tokens
:
token
.
NewMap
(),
Manager
:
newManager
(),
httpsCredChan
:
make
(
chan
tls
.
Certificate
,
1
),
}
for
_
,
h
:=
range
preloadedHosts
{
...
...
@@ -259,10 +260,12 @@ func (c *ProtoComms) ServeWithWeb() {
tlsConf
.
NextProtos
=
append
(
tlsConf
.
NextProtos
,
"h2"
,
"http/1.1"
)
// Wait for creds to be provided for https
c
.
httpsCredChan
=
make
(
chan
tls
.
Certificate
,
1
)
wg
.
Done
()
creds
:=
<-
c
.
httpsCredChan
// We use the GetCertificate field and a function which returns
// c.httpsCertificate wrapped by a ReadLock to allow for future
// changes to the certificate without downtime
c
.
httpsCertificate
=
&
creds
tlsConf
.
GetCertificate
=
c
.
GetCertificateFunc
()
...
...
@@ -274,6 +277,7 @@ func (c *ProtoComms) ServeWithWeb() {
serverName
=
cert
.
DNSNames
[
0
]
tlsConf
.
ServerName
=
serverName
// Start thread which will update the certificate going forward
go
c
.
startUpdateCertificate
()
tlsLis
:=
tls
.
NewListener
(
l
,
tlsConf
)
...
...
@@ -307,9 +311,10 @@ func (c *ProtoComms) ServeWithWeb() {
}
// ProvisionHttps provides a tls cert and key to the thread which serves the
// grpcweb endpoints, allowing it to continue and serve with https.
// This function should be called exactly once after ServeWithWeb, any further
// calls will have undefined behavior
// grpcweb endpoints, allowing it to serve with https. Note that https will
// not be usable until this has been called at least once, unblocking the
// listenHTTP func in ServeWithWeb. Future calls will be handled by the
// startUpdateCertificate thread.
func
(
c
*
ProtoComms
)
ProvisionHttps
(
cert
,
key
[]
byte
)
error
{
if
c
.
httpsCredChan
==
nil
{
return
errors
.
New
(
"https cred chan does not exist; is https enabled?"
)
...
...
@@ -381,6 +386,9 @@ func (c *ProtoComms) Stream(host *Host, f func(conn Connection) (
return
c
.
transmit
(
host
,
f
)
}
// GetCertificateFunc returns a function which serves as the value of
// GetCertificate in the https TLS config, enabling certificate changing
// without downtime
func
(
c
*
ProtoComms
)
GetCertificateFunc
()
func
(
*
tls
.
ClientHelloInfo
)
(
*
tls
.
Certificate
,
error
)
{
return
func
(
clientHello
*
tls
.
ClientHelloInfo
)
(
*
tls
.
Certificate
,
error
)
{
c
.
httpsCertificateLock
.
RLock
()
...
...
@@ -389,6 +397,9 @@ func (c *ProtoComms) GetCertificateFunc() func(*tls.ClientHelloInfo) (*tls.Certi
}
}
// startUpdateCertificate starts a thread which listens for further updates to
// the TLS certificate. When received, it takes the write lock & updates
// the stored certificate
func
(
c
*
ProtoComms
)
startUpdateCertificate
()
{
for
{
select
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment