Skip to content

Unable to use evniroment to set internal authentication user and password #5133

@Leone25

Description

@Leone25

Which version are you using?

v1.15.3

Which operating system are you using?

Linux amd64 Docker

Describe the issue

Hello,

I'm trying to setup a public test RTSP server which I can use as a RTSP source.
I've managed to use FFmpeg to push video to the server and now I want to make it secure and prevent others from pushing video to the server while making anyone able to read from it.
I've decided to use an env variable to set user and password to hopefully avoid commiting them, but while in runOnInit the parameters get replaced correctly, the user and pass fields won't. If I replace ${RTSP_STREAMER_USER} and ${RTSP_STREAMER_PASS} (on in the auth config) with the actual values it will work, so it's not an issue of the environment variables getting read.

Any help? Thx

Rico

Describe how to replicate the issue

  1. Set config as provided
  2. Set RTSP_STREAMER_USER and RTSP_STREAMER_PASS environment variables (I'm using a .env file and importing it with docker compose)
  3. Provide any random video file to test and edit the config accordingly
  4. Start mediamtx
  5. Check logs for errors

MediaMTX configuration

# mediamtx.yml
logLevel: info

api: true

authMethod: internal
authInternalUsers:
  - user: ${RTSP_STREAMER_USER}
    pass: ${RTSP_STREAMER_PASS}
    ips: []
    permissions:
    - action: publish
      path:
    - action: read
      path:
    - action: playback
      path:
  - user: any
    pass:
    ips: []
    permissions:
    - action: read
      path:
    - action: playback
      path:

paths:
  big-buck-bunny:
    source: publisher
    runOnInit: >
      ffmpeg -re -stream_loop -1 -i /videos/bbb.mp4
      -c copy -f rtsp -rtsp_transport tcp rtsp://${RTSP_STREAMER_USER}:${RTSP_STREAMER_PASS}@localhost:8554/big-buck-bunny

MediaMTX logs

[rtsp @ 0x7f8c95d17640] method ANNOUNCE failed: 401 Unauthorized
[out#0/rtsp @ 0x7f8c94f23680] Could not write header (incorrect codec parameters ?): Server returned 401 Unauthorized (authorization failed)
Error opening output file rtsp://streamer:fVMA4D7Y@localhost:8554/big-buck-bunny.
Error opening output files: Server returned 401 Unauthorized (authorization failed)
2025/10/27 08:09:13 INF [RTSP] [conn [::1]:45332] closed: authentication failed: authentication failed

Network dump

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions