Skip to content

TSA should support reloading authorized keys without restart #1105

Closed

Description

@chendrix

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.


Moved from vmware-archive/tsa#5
/cc @iSynaptic

Activity

  1. added this to the milestone on Aug 8, 2017
  2. removed this from the milestone on Nov 29, 2017
  3. gaelL commented on Mar 6, 2019

    @gaelL
    Contributor

    I would really love it too.

    I'm using team-authorized-keys and 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 ?

  4. 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
  5. xescugc commented on Mar 15, 2019

    @xescugc

    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 --git a/tsa/tsacmd/command.go b/tsa/tsacmd/command.go
    index 3bffb677c..7018fce9b 100644
    --- 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
    +	go func() {
    +		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()
    +			if err != 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)
    +			if err != nil {
    +				logger.Error(fmt.Sprintf("failed to configure SSH server: %s", err))
    +				continue
    +			}
    +
    +			server.config = config
    +		}
    +	}()
    +
     	return serverRunner{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.

  6. muntac commented on May 21, 2020

    @muntac
    Contributor

    @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.

  7. gaelL commented on May 25, 2020

    @gaelL
    Contributor

    thanks, I will give a try to rebase, test it on Concourse 6 this week to push a pull request.

  8. added 2 commits that reference this issue on May 25, 2020
    0ae696a
    4def700
  9. added 2 commits that reference this issue on Jun 12, 2020
    3d465db
    edd89e2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions