Expose the authorized keys tmate feature (#18)
* Expose the authorized keys tmate feature Described here: https://tmate.io/ in "Access Control" The variable accepts the file content in raw format (with \n) and dumps it into a file which tmate reads * Use echo instead of printf * Add missing quote * Only setup tmate settings if debug is activated
This commit is contained in:
@@ -214,6 +214,9 @@ func registerCompile(app *kingpin.Application) {
|
|||||||
cmd.Flag("tmate-server-ed25519-fingerprint", "tmate server rsa fingerprint").
|
cmd.Flag("tmate-server-ed25519-fingerprint", "tmate server rsa fingerprint").
|
||||||
StringVar(&c.Tmate.ED25519)
|
StringVar(&c.Tmate.ED25519)
|
||||||
|
|
||||||
|
cmd.Flag("tmate-authorized-keys", "tmate authorized keys").
|
||||||
|
StringVar(&c.Tmate.AuthorizedKeys)
|
||||||
|
|
||||||
// shared pipeline flags
|
// shared pipeline flags
|
||||||
c.Flags = internal.ParseFlags(cmd)
|
c.Flags = internal.ParseFlags(cmd)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ type Config struct {
|
|||||||
Port string `envconfig:"DRONE_TMATE_PORT"`
|
Port string `envconfig:"DRONE_TMATE_PORT"`
|
||||||
RSA string `envconfig:"DRONE_TMATE_FINGERPRINT_RSA"`
|
RSA string `envconfig:"DRONE_TMATE_FINGERPRINT_RSA"`
|
||||||
ED25519 string `envconfig:"DRONE_TMATE_FINGERPRINT_ED25519"`
|
ED25519 string `envconfig:"DRONE_TMATE_FINGERPRINT_ED25519"`
|
||||||
|
AuthorizedKeys string `envconfig:"DRONE_TMATE_AUTHORIZED_KEYS"`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -148,6 +148,7 @@ func (c *daemonCommand) run(*kingpin.ParseContext) error {
|
|||||||
Port: config.Tmate.Port,
|
Port: config.Tmate.Port,
|
||||||
RSA: config.Tmate.RSA,
|
RSA: config.Tmate.RSA,
|
||||||
ED25519: config.Tmate.ED25519,
|
ED25519: config.Tmate.ED25519,
|
||||||
|
AuthorizedKeys: config.Tmate.AuthorizedKeys,
|
||||||
},
|
},
|
||||||
Environ: provider.Combine(
|
Environ: provider.Combine(
|
||||||
provider.Static(config.Runner.Environ),
|
provider.Static(config.Runner.Environ),
|
||||||
|
|||||||
@@ -348,6 +348,9 @@ func registerExec(app *kingpin.Application) {
|
|||||||
cmd.Flag("tmate-server-ed25519-fingerprint", "tmate server rsa fingerprint").
|
cmd.Flag("tmate-server-ed25519-fingerprint", "tmate server rsa fingerprint").
|
||||||
StringVar(&c.Tmate.ED25519)
|
StringVar(&c.Tmate.ED25519)
|
||||||
|
|
||||||
|
cmd.Flag("tmate-authorized-keys", "tmate authorized keys").
|
||||||
|
StringVar(&c.Tmate.AuthorizedKeys)
|
||||||
|
|
||||||
cmd.Flag("debug", "enable debug logging").
|
cmd.Flag("debug", "enable debug logging").
|
||||||
BoolVar(&c.Debug)
|
BoolVar(&c.Debug)
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ type Tmate struct {
|
|||||||
Port string
|
Port string
|
||||||
RSA string
|
RSA string
|
||||||
ED25519 string
|
ED25519 string
|
||||||
|
AuthorizedKeys string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compiler compiles the Yaml configuration file to an
|
// Compiler compiles the Yaml configuration file to an
|
||||||
@@ -247,6 +248,10 @@ func (c *Compiler) Compile(ctx context.Context, args runtime.CompilerArgs) runti
|
|||||||
envs["DRONE_TMATE_PORT"] = c.Tmate.Port
|
envs["DRONE_TMATE_PORT"] = c.Tmate.Port
|
||||||
envs["DRONE_TMATE_FINGERPRINT_RSA"] = c.Tmate.RSA
|
envs["DRONE_TMATE_FINGERPRINT_RSA"] = c.Tmate.RSA
|
||||||
envs["DRONE_TMATE_FINGERPRINT_ED25519"] = c.Tmate.ED25519
|
envs["DRONE_TMATE_FINGERPRINT_ED25519"] = c.Tmate.ED25519
|
||||||
|
|
||||||
|
if c.Tmate.AuthorizedKeys != "" {
|
||||||
|
envs["DRONE_TMATE_AUTHORIZED_KEYS"] = c.Tmate.AuthorizedKeys
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the .netrc environment variables if not
|
// create the .netrc environment variables if not
|
||||||
|
|||||||
@@ -63,14 +63,18 @@ remote_debug() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ ! -z "${DRONE_TMATE_HOST}" ]; then
|
if [ "${DRONE_BUILD_DEBUG}" = "true" ]; then
|
||||||
|
if [ ! -z "${DRONE_TMATE_HOST}" ]; then
|
||||||
echo "set -g tmate-server-host $DRONE_TMATE_HOST" >> $HOME/.tmate.conf
|
echo "set -g tmate-server-host $DRONE_TMATE_HOST" >> $HOME/.tmate.conf
|
||||||
echo "set -g tmate-server-port $DRONE_TMATE_PORT" >> $HOME/.tmate.conf
|
echo "set -g tmate-server-port $DRONE_TMATE_PORT" >> $HOME/.tmate.conf
|
||||||
echo "set -g tmate-server-rsa-fingerprint $DRONE_TMATE_FINGERPRINT_RSA" >> $HOME/.tmate.conf
|
echo "set -g tmate-server-rsa-fingerprint $DRONE_TMATE_FINGERPRINT_RSA" >> $HOME/.tmate.conf
|
||||||
echo "set -g tmate-server-ed25519-fingerprint $DRONE_TMATE_FINGERPRINT_ED25519" >> $HOME/.tmate.conf
|
echo "set -g tmate-server-ed25519-fingerprint $DRONE_TMATE_FINGERPRINT_ED25519" >> $HOME/.tmate.conf
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${DRONE_BUILD_DEBUG}" = "true" ]; then
|
if [ ! -z "${DRONE_TMATE_AUTHORIZED_KEYS}" ]; then
|
||||||
|
echo "$DRONE_TMATE_AUTHORIZED_KEYS" > $HOME/.tmate.authorized_keys
|
||||||
|
echo "set -g tmate-authorized-keys \"$HOME/.tmate.authorized_keys\"" >> $HOME/.tmate.conf
|
||||||
|
fi
|
||||||
|
fi
|
||||||
trap remote_debug EXIT
|
trap remote_debug EXIT
|
||||||
fi
|
fi
|
||||||
`
|
`
|
||||||
|
|||||||
Reference in New Issue
Block a user