Skip to content

Conversation

@RyanDraves
Copy link
Contributor

Getting setec into a distroless container was a tricky process of injecting the secrets it needs to start up. Adding the following env var handling simplifies it, at least as far as the settings I was using.

tailscale/tailscale's up command has some of its own handling of files-as-env-vars, so I'm not in love with what I did here. But it does work.

https://github.com/tailscale/tailscale/blob/main/cmd/tailscale/cli/up.go#L205

Comment on lines 165 to 169
if serverArgs.KMSKeyName != "" {
if data, err := os.ReadFile(serverArgs.KMSKeyName); err == nil {
serverArgs.KMSKeyName = strings.TrimSpace(string(data))
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't very consistent on this handling. There are several ideas here and I didn't see native support for it with the flax dependency


func runServer(env *command.Env) error {
// If KMSKeyName is a filepath, read the file contents and use that as the key name. This allows users to specify the KMS key name via a file, which can be useful in some deployment scenarios.
if serverArgs.KMSKeyName != "" {
Copy link
Member

Choose a reason for hiding this comment

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

My main concern with this approach is it introduces "magic" to the argument strings. I'd rather setec not get into the business of guessing whether the operator wants this literal text or some file that may or may not happen to be present in the filesystem (especially not based on its presence/absence).

Environment variables seem fine, though if we are going to use them, I'd like to give them distinctive names, e.g., SETEC_STATE_DIR, SETEC_HOSTNAME, etc., and document them in help text (e.g., as here).

But if we want to read configuration values from files, I'd be more comfortable adding a new opt-in flag to specify a config file that the operator can generate and explicitly set. (Format subject to discussion, but JSON or INI would be reasonable-ish choices).

I'd also prefer to require that either config comes from a config file, or from flags/environments, but never both, and report an error if any of the other flags are explicitly set when a config file is provided.

\cc @danderson in case you have other thoughts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm a fan of the config file idea. Would that include the env vars that are needed but are not currently taken as flags (TS_AUTHKEY, AWS env vars)?

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking primarily of the configurations for setec itself. The boundary is not sharp, but at some point I wonder if it's simpler to let the operator provide a startup script instead, which can read files, populate environment variables, etc.

The marginal utility of baking it into the CLI seems to drop off pretty quickly. Maybe TS_AUTHKEY make sense, but if we add support for GCP key management or other stores, I'd really rather not start carrying around a bunch of ad-hoc API-specific bits. A config file could have a ball of unstructured key-value pairs to stuff into the environment, but at that point maybe it's better to just have that be a script instead.

Having environments for the flags seems unambiguously OK to me, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense. For my use case, I'm not sure I've quite got the hang of adding additional binaries to a distroless container to (cleanly) do what you suggested in a containerized environment. I think for now I'll modify the PR to just add the env vars and keep the bespoke handling on my fork. I'll see about revisiting this with a cleaner pass later

Copy link
Member

@creachadair creachadair left a comment

Choose a reason for hiding this comment

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

Apologies for the delay! I apparently missed the notification for this PR getting updated. A couple small things only.

Co-authored-by: M. J. Fromberger <[email protected]>
@RyanDraves
Copy link
Contributor Author

Apologies for the delay! I apparently missed the notification for this PR getting updated. A couple small things only.

No worries, I appreciate the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants