-
Notifications
You must be signed in to change notification settings - Fork 666
Secrets Management #1744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Secrets Management #1744
Conversation
I don't like the idea of new template format. Go2rtc already has support environment variables. I don't mind another section in the config file to hold secrets. But it is important that these secrets are in the same format as the environment variables. |
Thanks for the feedback! I understand your concerns about both the template format and adding a new section to the config file. To clarify, the main purpose of this PR is to provide developers with a way to programmatically update credentials at runtime, particularly for integrations like Ring, Tuya, or Nest that require periodic token refreshes. Environment variables are great for initial configuration, but they're static after the application starts. The proposed system allows:
Regarding the config structure, I'm flexible on the implementation approach. Instead of a dedicated
The template syntax was mainly introduced as a convenience, but it's not the core value of the PR and could be removed. What approach would you prefer that maintains the existing config structure while still providing a way for integrations to handle dynamic credential updates? |
Guys, if you ask me, I think it's a bad idea to store "programmatic" persistent data in go2rtc.yaml like dynamically retrieved credentials. Instead, it should be stored in a separate file like Because go2rtc supports running with no configuration file at all. You can also pass everything through config flags, for example. Or in case of Frigate, the go2rtc.yaml is dynamically generated on every container startup out of the frigate.yaml, and then stored in memory at Again, that's just my opinion. |
I don't mind adding a new section to the config file. For example, env:
CAMERA_PASSWORD: very-secret
streams:
camera1: rtsp://rtsp:${CAMERA_PASSWORD}@192.168.1.123/av_stream/ch0 |
In the first version, go2rtc stored dynamic data in the |
Is there some kind of documentation for that? I may be able to leverage this for Frigate. |
@felipecrs documentation above (go2rtc support multiple config files): https://github.com/AlexxIT/go2rtc/blob/master/internal/app/README.md First file in the list will be selected as "dynamic": Lines 65 to 68 in ae8145f
|
Thank you!! |
@seydx you can probably reconcile your approach with this suggestion. I.e. save the data back into |
Are you sure this (checking config for // ReplaceEnvVars - support format ${CAMERA_PASSWORD} and ${RTSP_USER:admin}
func ReplaceEnvVars(text string) string {
var yamlConfig struct {
Env map[string]string `yaml:"env"`
}
yaml.Unmarshal([]byte(text), &yamlConfig)
re := regexp.MustCompile(`\${([^}{]+)}`)
return re.ReplaceAllStringFunc(text, func(match string) string {
key := match[2 : len(match)-1]
var def string
var dok bool
if i := strings.IndexByte(key, ':'); i > 0 {
key, def = key[:i], key[i+1:]
dok = true
}
if dir, vok := os.LookupEnv("CREDENTIALS_DIRECTORY"); vok {
value, err := os.ReadFile(filepath.Join(dir, key))
if err == nil {
return strings.TrimSpace(string(value))
}
}
if value, vok := os.LookupEnv(key); vok {
return value
}
if yamlConfig.Env != nil {
if value, vok := yamlConfig.Env[key]; vok {
return value
}
}
if dok {
return def
}
return match
})
} |
It is not implemented. It was a suggestion from @AlexxIT on how you can implement it in a way that he would accept. I.e. you'd need to implement support for |
but this means, we need to add a new section anyway? :) since there is no |
And by the way, I would say the change should be done not only in |
Absolutely, that's what he meant. 😅 |
Oh man, i got it now.... I should read everything to the end before i reply >_>
👍 |
- add support for env in config - redact sensitive information in logs/responses
Hey @AlexxIT , I updated the PR. I've now added both I kept these two separate for a specific reason. The The Completely optional, users can put their sensitive information in the The next reason though is that there's also a new What do you think about it? Example: env:
CAMERA_IP: 192.168.178.142
secrets:
hikvision:
username: admin2
password: Admin!Admin
streams:
hikvision:
- rtsp://${hikvision_username}:${hikvision_password}@${CAMERA_IP}/Streaming/channels/101 Logs:
Stream Info {
"producers": [
{
"id": 3,
"format_name": "rtsp",
"protocol": "rtsp+tcp",
"remote_addr": "192.168.178.142:554",
"url": "rtsp://*****:*****@192.168.178.142/Streaming/channels/101",
....
}
],
"consumers": [
...
]
}
|
Utilizing |
Secrets Management
What's this about?
I've added a simple (but effective) secret management system to go2rtc. It lets you store credentials in a dedicated
secrets
section in the config file instead of embedding them directly in stream URLs. It works with existing template system and on top, every values used in secrets, will be auto redacted in log and stream info.Why is this useful?
How it works
Config setup
1. Reference a secret by name (client would manually query the secret, see example code)
2. Template system for direct value insertion:
In the code
Implementation details
Note
I'd like to find a way to directly map stream names to secret names without explicitly specifying the secret in the URL, but haven't found a clean solution yet. I'm open to suggestions and ideas on how to best implement this or other improvements!
The code is pretty straightforward and doesn't change how anything else works, so existing stream configs will continue to work exactly as before.