Skip to content

Conversation

@rektdeckard
Copy link
Member

@rektdeckard rektdeckard commented Aug 5, 2025

https://linear.app/livekit/issue/HA-243/fix-secrets-parsing-when-encountering-special-characters-in-secret

Improve parsing of --secrets flag (and other StringSlice-based key-value arguments) by parsing them properly with godotenv. Previously we used a naive method of splitting on "=" character, but this is insufficient for things like base64 encoded secrets, inline TOML, and anything with that character as part of a secret.

A downside of this approach is that we can no longer use built-in CSV splitting, so a command like this:

lk agent update-secrets --secrets 'foo=yes,bar=42'

Now has to be passed as multiple arguments:

lk agent update-secrets \
  --secrets 'foo=yes' \
  --secrets 'bar=42'

An upside is that we can support inline JSON:

lk agent update-secrets  --secrets 'foo={"a":"b","c":"d"}'

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves the parsing of key-value arguments (particularly the --secrets flag) by replacing naive string splitting with the godotenv library for proper parsing. This change enables support for special characters, base64 encoded secrets, and inline JSON values that contain equals signs.

  • Replaces manual string splitting with godotenv.Parse() and godotenv.Unmarshal() for robust key-value parsing
  • Disables CSV-style comma separation for secrets flags, requiring multiple --secrets flags instead of comma-separated values
  • Adds a new parseKeyValuePairs() utility function for consistent key-value parsing across commands

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
pkg/agentfs/secrets-file.go Simplifies env file parsing by replacing custom logic with godotenv.Parse()
cmd/lk/utils.go Adds new parseKeyValuePairs() function using godotenv.Unmarshal() for robust key-value parsing
cmd/lk/room.go Updates participant attributes parsing to use the new parseKeyValuePairs() function
cmd/lk/agent.go Updates secrets parsing to use parseKeyValuePairs() and disables slice flag separators for affected commands

@rektdeckard rektdeckard requested a review from yoonsio August 5, 2025 16:39
Copy link
Contributor

@real-danm real-danm left a comment

Choose a reason for hiding this comment

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

lgtm!

@rektdeckard rektdeckard merged commit 91b35b2 into main Aug 5, 2025
6 checks passed
@rektdeckard rektdeckard deleted the tobias/ha-243-fix-secrets-parsing-when-encountering-special-characters-in branch August 5, 2025 17:47
@bcherry
Copy link
Contributor

bcherry commented Aug 5, 2025

thank you!

I think you missed updating the usage string though

Usage:    "KEY=VALUE comma separated secrets. These will be injected as environment variables into the agent. These take precedence over secrets-file.",

@rektdeckard
Copy link
Member Author

@bcherry so I did!

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.

4 participants