You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TSA should support reloading authorized keys without restart #1105
When changing the authorized_keys file to dynamically add a new worker, the TSA doesn't recognize the new key unless the TSA is restarted. This makes dynamically provisioning a worker via automation difficult.
Please add the ability to automatically pick up changes to the authorized_key files or an API/fly command to trigger the reload.
changed the title [-]TSA does not reload authorized_keys when file changes without restart[/-][+]TSA should support reloading authorized keys without restart[/+]on Mar 10, 2019
Ok so I've been digging into this issue to find a solution, and I have a PoC working with a few changes.
I'll not open a PR for now because I prefer to listen to the opinion of the devs and also it requires changes to the concourse/flag too so it's not "that trivial".
The implementation I have working it's basically using signals to reload the configuration, the signal I used is SIGUSR1 (could be changed if needed, that's not important). When this signal is received by Concourse it'll read again the authorized_keys file and regenerate the config. I've made a few manual tests (with the help of @gaelL ) to see if it worked and It does work.
The code is the following (diffed):
diff--gita/tsa/tsacmd/command.gob/tsa/tsacmd/command.goindex3bffb677c..7018fce9b100644---a/tsa/tsacmd/command.go+++b/tsa/tsacmd/command.go
@@ -5,15+5,17 @@ import (
"fmt""net/http""os"+"os/signal""sync"+"syscall""time""code.cloudfoundry.org/lager"+"github.com/xescugc/flag""golang.org/x/crypto/ssh""github.com/concourse/concourse/tsa"-"github.com/concourse/flag""github.com/tedsuo/ifrit""github.com/tedsuo/ifrit/grouper""github.com/tedsuo/ifrit/http_server"
@@ -118,6+120,40 @@ func (cmd*TSACommand) Runner(args []string) (ifrit.Runner, error) {
sessionTeam: sessionAuthTeam,
}
+// Starts a goroutine that his purpose is to basically listen to the+// SIGUSR1 syscall to then reload the config.+// For now it only reload the TSACommand.AuthorizedKeys but any+// other configuration could be added+gofunc() {
+for {
+// Set up channel on which to send signal notifications.+// We must use a buffered channel or risk missing the signal+// if we're not ready to receive when the signal is sent.+c:=make(chan os.Signal, 1)
+signal.Notify(c, syscall.SIGUSR1)
++// Block until a signal is received.+_=<-c++logger.Info("reloading-config")
++err:=cmd.AuthorizedKeys.Reload()
+iferr!=nil {
+logger.Error(fmt.Sprintf("failed to reload the config: %s", err))
+continue+ }
++// compute again the config so it's updated+config, err:=cmd.configureSSHServer(sessionAuthTeam, cmd.AuthorizedKeys.Keys, teamAuthorizedKeys)
+iferr!=nil {
+logger.Error(fmt.Sprintf("failed to configure SSH server: %s", err))
+continue+ }
++server.config=config+ }
+ }()
+returnserverRunner{logger, server, listenAddr}, nil
}
It also requires this xescugc/flag@8b32f97 to work (I did just change the imports to make it easy to work with).
I would like to know if you would like the 2 PRs. First one for the flag and the other which would be on CC with this diff.
NOTE: If you apply the diff an run it, it'll fail because you'll need to also change some other imports to my flag fork as they fail on types.
@xescugc@gaelL now that concourse/flag#5 has been merged AuthorizedKeys has a reload function. It should be possible to implement the above solution now. If you end up making a PR for this feel free to tag me on the review.
Activity
gaelL commentedon Mar 6, 2019
I would really love it too.
I'm using
team-authorized-keysand having to restart Concourse to add a new worker key dedicated to a team is quite complicated.Any chances to have a way to do it on version 5.0 ? from fly command, or api call or even a SIGNAL to sent to Concourse ?
[-]TSA does not reload authorized_keys when file changes without restart[/-][+]TSA should support reloading authorized keys without restart[/+]xescugc commentedon Mar 15, 2019
Ok so I've been digging into this issue to find a solution, and I have a PoC working with a few changes.
I'll not open a PR for now because I prefer to listen to the opinion of the devs and also it requires changes to the concourse/flag too so it's not "that trivial".
The implementation I have working it's basically using signals to reload the configuration, the signal I used is
SIGUSR1(could be changed if needed, that's not important). When this signal is received by Concourse it'll read again theauthorized_keysfile and regenerate the config. I've made a few manual tests (with the help of @gaelL ) to see if it worked and It does work.The code is the following (diffed):
It also requires this xescugc/flag@8b32f97 to work (I did just change the imports to make it easy to work with).
I would like to know if you would like the 2 PRs. First one for the
flagand the other which would be on CC with this diff.NOTE: If you apply the diff an run it, it'll fail because you'll need to also change some other imports to my
flagfork as they fail on types.muntac commentedon May 21, 2020
@xescugc @gaelL now that concourse/flag#5 has been merged
AuthorizedKeyshas a reload function. It should be possible to implement the above solution now. If you end up making a PR for this feel free to tag me on the review.gaelL commentedon May 25, 2020
thanks, I will give a try to rebase, test it on Concourse 6 this week to push a pull request.
tsa: handling of SIGUSR1 to reload workers keys
tsa: handling of SIGHUP to reload workers keys
tsa: handling of SIGHUP to reload workers keys
tsa: handling of SIGHUP to reload workers keys
web: Add Reloading worker authorized key section